If you have ever debugged Google Analytics 4 (/g/collect) or Google Ads (/pagead/) network requests in Chrome DevTools, you have probably seen two cryptic consent query parameters:
&gcs=G100&gcd=13p3p3p2p5l1
Most engineers recognize gcs immediately (G100 = denied, G111 = granted). But gcs only encodes Consent Mode v1 (ad_storage and analytics_storage). All four Consent Mode v2 signals (ad_storage, analytics_storage, ad_user_data, ad_personalization) live inside gcd.
When we audited 2,328 live European websites from Frankfurt across a 3-pass headless browser state machine (Cold Load -> Reject All -> Accept All), we originally wrote a quick regex/letter-map parser for gcd. It passed our unit tests — and then immediately tripped over two wild-web strings that taught us why regex parsers for gcd silently break.
1. How gcd Actually Works: Fixed-Position 6-Bit Base64
gcd is not a free-form <letter><digit> string. It is a fixed-position 6-bit Base64url bitfield using the alphabet:
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_
-
Index
0: Version prefix ('1'). -
Indices
(1, 2),(3, 4),(5, 6),(7, 8): Four(delegation, state)character pairs for:-
ad_storage(index2) -
analytics_storage(index4) -
ad_user_data(index6) -
ad_personalization(index8)
-
Each state character maps to a 6-bit integer val (0..63), where:
-
bits 2..3((val >> 2) & 0b11) =defaultstate (2= denied,3= granted,0/1= unset) -
bits 0..1(val & 0b11) =updatestate (2= denied,3= granted,0/1= unset)
Here is the entire exact decoder in Python (verified with 100% parity across all 64 symbols against @analytics-debugger/consent-string):
ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
CHAR_TO_VAL = {ch: idx for idx, ch in enumerate(ALPHABET)}
def decode_state_char(ch: str) -> tuple[str | None, str | None]:
val = CHAR_TO_VAL[ch]
default_bits = (val >> 2) & 0b11
update_bits = val & 0b11
default_state = "denied" if default_bits == 2 else "granted" if default_bits == 3 else None
update_state = "denied" if update_bits == 2 else "granted" if update_bits == 3 else None
return default_state, update_state
2. Two Real-World gcd Traps That Break Regex Parsers
Trap A: 13u3u3-2u5l1 — '-' Is Not Unset!
In gcs=G1--, a hyphen (-) means "not applicable / unset." Naturally, many hand-rolled gcd parsers add if ch == "-": return NOT_SET.
That is a bug. In Google's 6-bit Base64url alphabet, '-' is index 62 (0b111110):
-
default_bits = (62 >> 2) & 0b11 = 3->default: granted -
update_bits = 62 & 0b11 = 2->update: denied
So in 13u3u3-2u5l1 (which shows up on live European sites when a user clicks Reject All after a granted default), treating '-' as not_set silently misclassifies an explicit denied after update state!
Trap B: 13l3lPl2l1l1 — Uppercase Delegation Flags
A regex that scans for letters [a-zA-Z] and lowercases them will see the uppercase 'P' at index 5 in 13l3lPl2l1l1 and mistake it for 'p' (denied_default).
In reality, index 5 is a delegation/flag slot, not a state slot. The four actual state characters sit strictly at indices 2, 4, 6, 8 — all four are 'l' (21 = 0b010101, meaning no default and no update set).
3. What Showed Up Across 2,328 Live European Sites
Once we ran our exact 6-bit decoder across n = 2,328 completed Frankfurt browser audits (Cold Load -> Reject All -> Accept All):
-
Compliant Advanced Consent Mode v2 (
ADVANCED_V2):29.5% -
Compliant Basic / Strict Blocking (
BASIC_OR_BLOCKED):24.7% -
Stuck in Denied After Clicking Accept All (
BROKEN_STUCK_DENIED):1.6%— the banner closes, yet/g/collectstays locked ingcs=G100(p/q), silently dropping EEA Google Ads conversions -
Legacy v1 Masquerading as v2 (
V1_LEGACY, e.g.13r3r3l2l5):0.6%—gcs=G111looks green at a glance while slots 3 and 4 (ad_user_data,ad_personalization) stay'l'(unset) -
Post-Reject Marketing Pixel Leaks:
23.5%continued firing third-party trackers after explicitReject All(with GTMCustom HTMLtags accounting for36.9%of offending tags) -
<head>Race Conditions:11.0%bootedgtm.jsbeforegtag('consent', 'default', ...)
Try the Decoder or Inspect the Dataset (Free, No Login)
-
Interactive 6-Bit Base64
gcdDecoder (paste a rawgcdstring or a full/g/collectURL): https://consentpulse.dev/tools/gcd-decoder -
Example Breakdown (
13r3r3l2l5— the classic v1-masquerading-as-v2 trap): https://consentpulse.dev/tools/gcd-decoder/13r3r3l2l5 - Full 2,328-Site EU Consent Mode v2 Benchmark Study: https://consentpulse.dev/benchmarks/consent-mode-v2-study
- Bonus — Offline sGTM Subdomain Blocklist Checker (79k domains): https://consentpulse.dev/tools/sgtm-blocklist-checker
If you have seen any weird gcd strings in the wild (especially version prefixes other than 1), drop them in the comments — always happy to inspect them!
Top comments (0)