This week on X, a Kyle Gawley post from November 24 was going around again: software is a $1.4 trillion market, and yet someone will still declare it dead because they "vibe coded their google analytics over the weekend." In the thread, samtestsai added the punchline I keep seeing: the vibe-coded Google Analytics only ever tracks one visitor. Him.
That is not a Realtime glitch. It is usually a leftover from the prompt that installed the tag.
The coding agent pastes the official gtag snippet. Then it wraps the config call in if (location.hostname === 'localhost') so a test property will not get polluted. It leaves debug_mode: true on. It hardcodes page_location to http://localhost:5173/ because that is where Vite is running. And the measurement id is still the placeholder from the docs, G-XXXXXXXXXX. The founder opens Realtime, hits the site from the dev server, sees themselves, and ships it. Chrome looks like a record shop. Production analytics is dark.
It does not matter whether the site came from Cursor, Claude Code or an AI website builder. If the snippet you ship only runs on the developer's laptop, or only points at a fake id, this applies.
So I wrote the kind of site a coding agent produces for "a neighborhood record shop in East Nashville with hours, a buy-records page, and a Friday in-store." The HTML is prerendered on purpose. There is a real title, a real H1, hours, and an address — this is not an empty #root. Then I wrote a short checker, analytics_tag.py, that reads the local HTML and source files and reports leftover or broken analytics. I ran it on the gated snippet, on the same site after I only removed the localhost if, and on a version with a real-looking measurement id and no debug flags. All the numbers below come from those three runs.
The fixture
The business is fictional. It is called Cedar Room Records, and it sells new and used vinyl on East Lapis Street in Nashville. The "before" tree is a finished-looking marketing site: a title, an H1, hours, a phone number, and JSON-LD. The leftovers are all in one script block in the head.
Here is the analytics that actually got deployed, with the body omitted.
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script> <script> // Only enable analytics while developing so we do not pollute the property. if (location.hostname === 'localhost' || location.hostname === '127.0.0.1') { window.dataLayer = window.dataLayer || []; function gtag(){ dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'G-XXXXXXXXXX', { debug_mode: true, page_location: 'http://localhost:5173/' }); } </script> If you open the site in a browser on your laptop, you see a visitor in Realtime. If you open the same files on the production host, the library may load, the config call never runs, and the measurement id was never yours in the first place.
The checker
analytics_tag.py reads a local HTML file — or the HTML and JS/TS/JSX files under a directory — and looks for analytics snippets. It does not call Google, it does not open a browser, and it does not prove that hits arrive in a property. Pass --host if you want it to flag a hardcoded page_location that does not match the production hostname.
It reports:
- a snippet gated to
localhost,127.0.0.1,import.meta.env.DEV, orNODE_ENV !== 'production' - a placeholder measurement id such as
G-XXXXXXXXXX,GTM-XXXXXXX, orYOUR_MEASUREMENT_ID - a Universal Analytics
UA-property (those stopped collecting on 1 July 2023) -
debug_mode: trueortraffic_type: 'internal'left on - a hardcoded
page_location,page_path, orcookie_domainpointing at localhost or a preview host - no analytics snippet at all
- a Content-Security-Policy that loads gtag but does not allow
googletagmanager.comorgoogle-analytics.com -
send_page_view: falsewith no manualpage_viewevent (warning) - a client-side router with no virtual page view (warning)
It does not claim Google will count a given session. A localhost gate is the sharp one: production visitors are never sent. A placeholder id is almost as sharp: the hits go nowhere you can see. debug_mode on a real id is a messier hint — DebugView gets noisy, and some filters will drop the traffic. Either way, you should not ship it.
#!/usr/bin/env python3 """analytics_tag.py — static checker for leftover or broken analytics tags. Reads local HTML and source files. Does not call Google, does not open a browser, and does not prove that hits arrive in a property. """ from __future__ import annotations import argparse import os import re import sys import tempfile import unittest from dataclasses import dataclass, field from pathlib import Path VERSION = "1.0" SKIP_DIRS = { "node_modules", ".git", ".hg", ".svn", ".next", ".cache", ".venv", "venv", "__pycache__", "coverage", "dist", # still scanned if you point the tool AT dist/ "build", } # If the user passes a tree, we *do* want dist/ and build/ when they are the # deploy root. We only skip them when they appear as nested noise next to src/. SKIP_NESTED = {"node_modules", ".git", ".hg", ".svn", ".next", ".cache", ".venv", "venv", "__pycache__", "coverage"} EXTENSIONS = { ".html", ".htm", ".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".vue", ".astro", ".svelte", } GA4_RE = re.compile(r"\bG-[A-Z0-9]{6,14}\b") GTM_RE = re.compile(r"\bGTM-[A-Z0-9]{4,12}\b") UA_RE = re.compile(r"\bUA-\d{4,10}-\d{1,3}\b") PLACEHOLDER_ID_RE = re.compile( r""" \b( G-(?:X{6,14}|0{6,14}|YOUR[A-Z0-9]*|EXAMPLE[A-Z0-9]*| PLACEHOLDER[A-Z0-9]*|CHANGEME[A-Z0-9]*|INSERT[A-Z0-9]*| TODO[A-Z0-9]*) | GTM-(?:X{4,12}|0{4,12}|XXXXXXX) | UA-(?:X+|0+)(?:-\d+)? )\b """, re.I | re.X, ) PLACEHOLDER_NAME_RE = re.compile( r"""['"](?:YOUR_?(?:GA|GTM|MEASUREMENT|ANALYTICS)_?ID|MEASUREMENT_ID| GA_MEASUREMENT_ID|GTM_ID|INSERT_?ID_?HERE|YOUR_DOMAIN)['"]""", re.I | re.X, ) GTAG_HINT_RE = re.compile( r"gtag\s*\(|googletagmanager\.com|google-analytics\.com|" r"window\.dataLayer|function\s+gtag\s*\(|gtag/js", re.I, ) ANALYTICS_HINT_RE = re.compile( r"gtag\s*\(|googletagmanager\.com|google-analytics\.com|www\.google-analytics\.com|" r"GTM-[A-Z0-9]+|\bG-[A-Z0-9]{6,14}\b|\bUA-\d+-\d+|" r"plausible\.io|usefathom\.com|umami\.is|cdn\.usefathom|" r"posthog\.|mixpanel|analytics\.js|ga\(\s*['\"]create|" r"goatcounter|cloudflareinsights|simpleanalytics|matomo|amplitude", re.I, ) ROUTER_RE = re.compile( r"\b(BrowserRouter|createBrowserRouter|HashRouter|RouterProvider|" r"createWebHistory|vue-router|useNavigate|useRouter)\b", ) VIRTUAL_PAGEVIEW_RE = re.compile( r"""gtag\(\s*['"]event['"]\s*,\s*['"]page_view['"]""" r"""|gtag\(\s*['"]config['"]""" r"""|analytics\.page\s*\(|plausible\(\s*['"]pageview['"]""" r"""|posthog\.capture\(\s*['"]\$pageview['"]""" r"""|mixpanel\.track\(\s*['"]Page\s*View['"]""", re.I, ) DEBUG_RE = re.compile(r"""debug_mode\s*:\s*true|['"]debug_mode['"]\s*:\s*true""", re.I) INTERNAL_TRAFFIC_RE = re.compile( r"""traffic_type\s*:\s*['"]internal['"]|['"]traffic_type['"]\s*:\s*['"]internal['"]""", re.I, ) PAGE_LOCATION_RE = re.compile( r"""(?:page_location|page_path|cookie_domain)\s*:\s*['"]([^'"]+)['"]""", re.I, ) MANUAL_PAGEVIEW_RE = re.compile( r"""gtag\(\s*['"]event['"]\s*,\s*['"]page_view['"]""" r"""|analytics\.page\s*\(|plausible\(\s*['"]pageview['"]""" r"""|posthog\.capture\(\s*['"]\$pageview['"]""" r"""|mixpanel\.track\(\s*['"]Page\s*View['"]""", re.I, ) SEND_PAGE_VIEW_FALSE_RE = re.compile(r"""send_page_view\s*:\s*false""", re.I) CSP_RE = re.compile( r"""<meta\s+http-equiv\s*=\s*['"]Content-Security-Policy['"][^>]*content\s*=\s*['"]([^'"]+)['"]""" r"""|Content-Security-Policy['"]?\s*:\s*['"]([^'"]+)""", re.I, ) IF_RE = re.compile(r"\bif\s*\(([^)]{0,400})\)\s*\{", re.S) AND_GATE_RE = re.compile( r"""((?:location\.hostname|window\.location\.hostname|import\.meta\.env\.DEV|process\.env\.NODE_ENV)[^\n]{0,200}?)&&\s*\{?""", re.I, ) LOCAL_POS_RE = re.compile( r"""(?:location\.hostname|window\.location\.hostname|location\.host)\s*===?\s*['"](?:localhost|127\.0\.0\.1)['"]""" r"""|['"](?:localhost|127\.0\.0\.1)['"]\s*===?\s*(?:location\.hostname|window\.location\.hostname|location\.host)""" r"""|\.includes\(\s*(?:location\.hostname|window\.location\.hostname)\s*\)""" r"""|import\.meta\.env\.DEV\b""" r"""|process\.env\.NODE_ENV\s*===?\s*['"]development['"]""" r"""|process\.env\.NODE_ENV\s*!==?\s*['"]production['"]""", re.I, ) LOCAL_NEG_RE = re.compile( r"""(?:location\.hostname|window\.location\.hostname|location\.host)\s*!==?\s*['"](?:localhost|127\.0\.0\.1)['"]""" r"""|['"](?:localhost|127\.0\.0\.1)['"]\s*!==?\s*(?:location\.hostname|window\.location\.hostname|location\.host)""" r"""|import\.meta\.env\.PROD\b""" r"""|process\.env\.NODE_ENV\s*===?\s*['"]production['"]""" r"""|process\.env\.NODE_ENV\s*!==?\s*['"]development['"]""", re.I, ) LOOPBACK_HOST_RE = re.compile(r"""(?:^|://)(?:localhost|127\.0\.0\.1)(?::\d+)?(?:/|$)""", re.I) PREVIEW_HOST_RE = re.compile( r"""(?:^|://)(?:[^/]+\.)?(?:vercel\.app|netlify\.app|netlify\.com|ngrok-free\.app|ngrok\.io|fly\.dev|onrender\.com)(?:/|$)""", re.I, ) # Hosts commonly used as placeholder domains in snippets. PLACEHOLDER_DOMAINS = { "example.com", "yoursite.com", "yourdomain.com", "your-site.com", "mysite.com", "localhost", } @dataclass class Finding: code: str message: str path: str = "" severity: str = "error" # error | warning @dataclass class Report: root: Path files: list[Path] = field(default_factory=list) ids: list[str] = field(default_factory=list) findings: list[Finding] = field(default_factory=list) title: str = "" h1: str = "" notes: list[str] = field(default_factory=list) def add(self, code: str, message: str, path: str = "", severity: str = "error") -> None: key = (code, message, path, severity) if any((f.code, f.message, f.path, f.severity) == key for f in self.findings): return self.findings.append(Finding(code, message, path, severity)) def rel(path: Path, root: Path) -> str: try: return str(path.relative_to(root)) except ValueError: return str(path) def collect_files(root: Path) -> list[Path]: if root.is_file(): return [root] out: list[Path] = [] for dirpath, dirnames, filenames in os.walk(root): p = Path(dirpath) # If the user pointed us at dist/ or build/, keep it. If they pointed # us at a repo, skip those as nested output unless they are the root. dirnames[:] = [ d for d in dirnames if d not in SKIP_NESTED and not d.startswith(".") ] for name in filenames: fp = p / name if fp.suffix.lower() in EXTENSIONS: out.append(fp) return sorted(out) def extract_brace_block(src: str, open_idx: int) -> str: if open_idx >= len(src) or src[open_idx] != "{": return "" depth = 0 for i, ch in enumerate(src[open_idx:], open_idx): if ch == "{": depth += 1 elif ch == "}": depth -= 1 if depth == 0: return src[open_idx : i + 1] return src[open_idx:] def looks_like_placeholder_id(value: str) -> bool: v = value.strip() if PLACEHOLDER_ID_RE.fullmatch(v) or PLACEHOLDER_ID_RE.search(v): # fullmatch on the id itself if PLACEHOLDER_ID_RE.fullmatch(v): return True if re.fullmatch(r"G-X{6,14}", v, re.I): return True if re.fullmatch(r"G-0{6,14}", v, re.I): return True # All-X or obviously fake after the prefix. m = re.fullmatch(r"G-([A-Z0-9]{6,14})", v, re.I) if m and re.fullmatch(r"X+", m.group(1), re.I): return True if re.search(r"YOUR|EXAMPLE|PLACEHOLDER|CHANGEME|INSERT|TODO", v, re.I): return True return bool(PLACEHOLDER_ID_RE.fullmatch(v)) def first_heading(html: str, tag: str) -> str: m = re.search(rf"<{tag}[^>]*>(.*?)</{tag}>", html, re.I | re.S) if not m: return "" text = re.sub(r"<[^>]+>", "", m.group(1)) return re.sub(r"\s+", " ", text).strip() def staging_kind(value: str) -> str | None: if LOOPBACK_HOST_RE.search(value) or "localhost" in value.lower() or "127.0.0.1" in value: return "loopback" if PREVIEW_HOST_RE.search(value): return "preview" return None def condition_is_local_positive(cond: str) -> bool: """True when the condition is true only in local / dev.""" if LOCAL_NEG_RE.search(cond) and not LOCAL_POS_RE.search(cond): return False # Mixed conditions: if both pos and neg appear, be conservative. if LOCAL_NEG_RE.search(cond) and LOCAL_POS_RE.search(cond): return False return bool(LOCAL_POS_RE.search(cond)) def find_localhost_gates(src: str, path_label: str, report: Report) -> None: for m in IF_RE.finditer(src): cond = m.group(1) if not condition_is_local_positive(cond): continue # m.end() is just after "{", so the brace starts at m.end()-1 block = extract_brace_block(src, m.end() - 1) if ANALYTICS_HINT_RE.search(block) or GTAG_HINT_RE.search(block): report.add( "localhost-gated", f"analytics snippet runs only when ({_squash(cond)}) in {path_label}", path_label, ) for m in AND_GATE_RE.finditer(src): left = m.group(1) if not condition_is_local_positive(left): continue window = src[m.start() : m.start() + 400] if ANALYTICS_HINT_RE.search(window) or GTAG_HINT_RE.search(window): report.add( "localhost-gated", f"analytics snippet is short-circuit gated on ({_squash(left)}) in {path_label}", path_label, ) def _squash(s: str) -> str: return re.sub(r"\s+", " ", s).strip()[:160] def extract_csp(src: str) -> str: m = CSP_RE.search(src) if not m: return "" return m.group(1) or m.group(2) or "" def csp_allows_google(csp: str) -> bool: lower = csp.lower() # script-src or default-src must mention the Google hosts or be extremely loose. if "script-src" in lower: section = lower.split("script-src", 1)[1].split(Source:https://dev.to/polydraft/your-vibe-coded-analytics-only-tracks-you-i-wrote-a-checker-376gRelated posts

Why `"SKU42" === "SKU42"` Can Be False When One Value Is Pasted
Modelling EU VAT across 7 countries in a static site (no backend, no library)
One Remotion scene, three sizes: 16:9, 9:16 and 1:1 without cropping
2Baba Backs ‘Rig and Die’ Slogan Ahead of 2027
Teni Promises 2027 Song With Sister Niniola

