[dyad] Add tracking detection tab - wrote 4 file(s)
This commit is contained in:
@@ -32,6 +32,11 @@ export interface DetectedSystem {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface TrackingTool {
|
||||
name: string;
|
||||
id: string | null;
|
||||
}
|
||||
|
||||
export async function extractMetaData(url: string, keyword?: string) {
|
||||
if (!url) {
|
||||
return { error: "URL is required." };
|
||||
@@ -229,11 +234,10 @@ export async function extractMetaData(url: string, keyword?: string) {
|
||||
links.push({ href: absoluteUrl, text, type, rel });
|
||||
});
|
||||
|
||||
const detectedSystems: DetectedSystem[] = [];
|
||||
const htmlContent = $.html();
|
||||
const uniqueSystems = new Set<string>();
|
||||
|
||||
// WordPress
|
||||
// System Detection
|
||||
if (
|
||||
$('meta[name="generator"][content*="WordPress"]').length > 0 ||
|
||||
htmlContent.includes("/wp-content/") ||
|
||||
@@ -241,47 +245,54 @@ export async function extractMetaData(url: string, keyword?: string) {
|
||||
) {
|
||||
uniqueSystems.add("WordPress");
|
||||
}
|
||||
|
||||
// Shopify
|
||||
if (
|
||||
htmlContent.includes("cdn.shopify.com") ||
|
||||
htmlContent.includes("Shopify.theme")
|
||||
) {
|
||||
uniqueSystems.add("Shopify");
|
||||
}
|
||||
|
||||
// Next.js
|
||||
if ($("#__next").length > 0) {
|
||||
uniqueSystems.add("Next.js");
|
||||
uniqueSystems.add("React"); // Next.js uses React
|
||||
uniqueSystems.add("React");
|
||||
}
|
||||
|
||||
// React (generic)
|
||||
if ($("#root").length > 0) {
|
||||
uniqueSystems.add("React");
|
||||
}
|
||||
|
||||
// Webflow
|
||||
if (
|
||||
$('meta[name="generator"][content="Webflow"]').length > 0 ||
|
||||
htmlContent.includes("<!-- This site was created in Webflow.")
|
||||
) {
|
||||
uniqueSystems.add("Webflow");
|
||||
}
|
||||
|
||||
// Wix
|
||||
if ($('meta[name="generator"][content*="Wix.com"]').length > 0) {
|
||||
uniqueSystems.add("Wix");
|
||||
}
|
||||
|
||||
// Squarespace
|
||||
if (htmlContent.includes("static1.squarespace.com")) {
|
||||
uniqueSystems.add("Squarespace");
|
||||
}
|
||||
const detectedSystems: DetectedSystem[] = Array.from(uniqueSystems).map(
|
||||
(name) => ({ name })
|
||||
);
|
||||
|
||||
uniqueSystems.forEach((system) => {
|
||||
detectedSystems.push({ name: system });
|
||||
});
|
||||
// Tracking Detection
|
||||
const uniqueTrackers = new Map<string, string | null>();
|
||||
let gtmMatch = htmlContent.match(/['"](GTM-[A-Z0-9]+)['"]/);
|
||||
if (gtmMatch) uniqueTrackers.set("Google Tag Manager", gtmMatch[1]);
|
||||
let ga4Match = htmlContent.match(/['"](G-[A-Z0-9]+)['"]/);
|
||||
if (ga4Match) uniqueTrackers.set("Google Analytics (GA4)", ga4Match[1]);
|
||||
let uaMatch = htmlContent.match(/['"](UA-\d{4,9}-\d{1,4})['"]/);
|
||||
if (uaMatch)
|
||||
uniqueTrackers.set("Google Analytics (Universal)", uaMatch[1]);
|
||||
let fbPixelMatch = htmlContent.match(/fbq\(['"]init['"], ['"](\d+)['"]\)/);
|
||||
if (fbPixelMatch) uniqueTrackers.set("Facebook Pixel", fbPixelMatch[1]);
|
||||
let hotjarMatch = htmlContent.match(/hjid:(\d+)/);
|
||||
if (hotjarMatch) uniqueTrackers.set("Hotjar", hotjarMatch[1]);
|
||||
let hubspotMatch = htmlContent.match(/js\.hs-scripts\.com\/(\d+)\.js/);
|
||||
if (hubspotMatch) uniqueTrackers.set("HubSpot", hubspotMatch[1]);
|
||||
const detectedTracking: TrackingTool[] = Array.from(
|
||||
uniqueTrackers,
|
||||
([name, id]) => ({ name, id })
|
||||
);
|
||||
|
||||
return {
|
||||
data: {
|
||||
@@ -300,6 +311,7 @@ export async function extractMetaData(url: string, keyword?: string) {
|
||||
images: imageAltData.length > 0 ? imageAltData : null,
|
||||
links: links.length > 0 ? links : null,
|
||||
systems: detectedSystems.length > 0 ? detectedSystems : null,
|
||||
tracking: detectedTracking.length > 0 ? detectedTracking : null,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user