Packing 79,463 CNAME-Cloaked sGTM Domains Into a
While auditing 2,328 live European websites from Frankfurt on Google Consent Mode v2 (gcs/gcd transitions across Cold Load -> Reject All -> Accept All), one recurring pattern stood out:
Sites paying for server-side Google Tag Manager (sGTM) — often hosted on Stape or Cloud Run behind a custom subdomain like sgtm.example.com or metrics.example.com — were still losing tracking hits because their custom subdomain had already landed on public CNAME-cloaking and DNS ad-blocker lists.
I wanted to build an instant, zero-login checker that runs entirely at the edge on Cloudflare Workers with < 5ms cold start and lookup latency, zero external DNS queries, and zero database round-trips.
Here is how we packed 79,463 domains across 5 major filter lists into a compact Worker bundle.
1. The 5 Blocklists We Indexed
Ad-blocker and DNS filter maintainers actively sweep CNAME-cloaked first-party tracking proxies. Merging and deduplicating the 5 most widely deployed lists (used by AdGuard, Brave, NextDNS, Pi-hole, and uBlock Origin) yields 79,463 unique indexed domains:
| Blocklist Source | Raw Entries | Indexed sGTM / Proxy Domains |
|---|---|---|
AdGuard CNAME-Cloaked Trackers (stape_justdomains) | 69,332 | 49,569 |
| HaGeZi Multi Normal DNS Blocklist | 179,620 | 23,077 |
AdGuard DNS Filter (AdguardSDNSFilter) | 195,395 | 21,827 |
| EasyPrivacy | 47,855 | 4,409 |
| 1Hosts (Lite) | 202,954 | 1,335 |
(A single domain can appear in multiple lists — e.g. both adguard_cname and hagezi_multi.)
2. Why a Naive JSON Object Blows Up Cloudflare Worker Cold Starts
Dropping a raw JSON map of 79,463 domain strings -> list arrays into a Cloudflare Worker causes two immediate problems:
- Bundle size & memory: Plain JSON with list names repeated 79k times quickly balloons past multi-megabyte Worker size limits.
- Cold-start CPU: Parsing a massive JSON object or building a
new Set(...)on every isolate boot burns tens of milliseconds of startup CPU before the first request is even served.
Our Fix: Bitmask Buckets + Front-Coded Blocks + Lazy Binary Search
Instead of storing an array of list names per domain, we assign each of the 5 lists a single bit (1 << 0 through 1 << 4), group domains by their 5-bit mask (1..31), sort each bucket lexicographically, and front-code adjacent entries in fixed-size blocks separated by blank lines:
analytics.chimar.com Lityskydive.nl # shares 11-char prefix ("analytics.c") + "ityskydive.nl" Mur.cz # shares 12-char prefix ("analytics.ci") + "ur.cz" Because every block starts with one unencoded header domain, the Worker never decompresses the whole index at startup:
- At request time, it binary-searches only the block headers inside each bitmask bucket (zero heap allocations for untouched blocks).
- Only the single candidate block that could contain the target domain is decoded sequentially.
- For any queried hostname like
collect.sgtm.brand.de, we walk parent suffixes (collect.sgtm.brand.de->sgtm.brand.de->brand.de) so wildcard/parent rules match immediately:
const parts = host.split("."); let matchedRule: string | null = null; let matchedMask = 0; for (let i = 0; i <= parts.length - 2; i++) { const candidate = parts.slice(i).join("."); const mask = lookupDomainBitmask(candidate); if (mask !== 0) { matchedRule = candidate; matchedMask = mask; break; } } Result: < 5ms cold start and lookup latency inside a standard Cloudflare Worker, with zero external API calls.
3. Catching "Not Listed Yet" Subdomains With Giveaway-Prefix Heuristics
Even if a brand-new sgtm.example.com subdomain hasn't been scraped into adguard_cname yet, filter-list maintainers regularly sweep obvious tracking prefixes. Alongside exact blocklist matching, we check subdomain labels against high-risk giveaway prefixes (sgtm, ssgtm, sst, gtm, tagging, metrics, analytics, telemetry, tracking, collect, pixel, stats) and surface a HIGH / MEDIUM / LOW heuristic risk rating.
If you're deploying server-side GTM:
- Prefer A/AAAA records or Same-Origin routing over CNAMEs whenever your DNS host supports it.
- Pick a neutral subdomain instead of
sgtm.*ormetrics.*. - Pair Custom Loader with request-path encoding so
/g/collectisn't trivially pattern-matched.
Try It Live (Free, No Login)
- sGTM Subdomain Blocklist Checker: https://consentpulse.dev/tools/sgtm-blocklist-checker
- Google Consent Mode v2 6-Bit Base64
gcdDecoder: https://consentpulse.dev/tools/gcd-decoder - Full 2,328-Site EU Consent Mode v2 Benchmark Study: https://consentpulse.dev/benchmarks/consent-mode-v2-study
If you've run into interesting edge cases with CNAME-cloaking detection or Cloudflare Worker static-index packing, I'd love to hear how you approached it in the comments!