DEV Community

mamangwarkop
mamangwarkop

Posted on Originally published at github.com

How to detect if a website runs Meta Pixel, TikTok Pixel or Google Tag Manager with plain Python

Agencies and freelancers lose hours opening DevTools on prospect sites. You can automate it in 20 lines because every pixel leaves a fingerprint in the HTML.

import urllib.request

SIGNS = {
    "Meta Pixel": ("connect.facebook.net", "fbq("),
    "TikTok Pixel": ("analytics.tiktok.com", "ttq."),
    "Google Tag Manager": ("googletagmanager.com/gtm.js",),
    "GA4": ("gtag(", "google-analytics.com"),
}

def audit(url):
    req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
    html = urllib.request.urlopen(req, timeout=10).read().decode("utf-8", "replace").lower()
    return {name: any(s in html for s in sigs) for name, sigs in SIGNS.items()}

print(audit("https://example.com"))
Enter fullscreen mode Exit fullscreen mode

Limits to know

  • Pixels injected only after consent or via server-side tagging will not show up in raw HTML. Treat "missing" as "not detected", not as proof.
  • Single-page apps may load tags late. For those, use a headless browser.

Doing it for 1,000 domains

Run this with concurrency and add email, WhatsApp and social extraction, plus a 0-100 lead score and a ready pitch sentence. I packaged exactly that as an Apify Actor: https://apify.com/mamang_warkop/b2b-website-contact-and-pixel-lead-enricher (open-source repo: https://github.com/mamangwarkop/b2b-website-contact-and-pixel-lead-enricher).

Top comments (0)