[dyad] Improve tracking detection logic - wrote 1 file(s)

This commit is contained in:
[dyad]
2026-01-21 08:27:07 +01:00
parent 8a615c11f8
commit b84138adad

View File

@@ -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 })