From b84138adad5da703942d8628ab1fc3f7a9761afd Mon Sep 17 00:00:00 2001 From: "[dyad]" Date: Wed, 21 Jan 2026 08:27:07 +0100 Subject: [PATCH] [dyad] Improve tracking detection logic - wrote 1 file(s) --- src/app/actions.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/app/actions.ts b/src/app/actions.ts index b097c85..7b23fac 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -283,12 +283,28 @@ export async function extractMetaData(url: string, keyword?: string) { 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]); + + // Facebook Pixel (more robust detection) + let fbPixelMatch = htmlContent.match( + /fbq\(\s*['"]init['"]\s*,\s*['"](\d+)['"]\s*\)/ + ); + if (fbPixelMatch) { + uniqueTrackers.set("Facebook Pixel", fbPixelMatch[1]); + } else { + // Fallback to noscript tag + let fbNoscriptMatch = htmlContent.match( + /facebook\.com\/tr\?id=(\d+)/ + ); + if (fbNoscriptMatch) { + uniqueTrackers.set("Facebook Pixel", fbNoscriptMatch[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 })