DEV Community

Or Cohen
Or Cohen

Posted on

Decoding Google Consent Mode v2's 6-Bit Base64 gcd Parameter (and the '-' Trap That Breaks Regex Parsers)

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
Enter fullscreen mode Exit fullscreen mode

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-_
Enter fullscreen mode Exit fullscreen mode
  • Index 0: Version prefix ('1').
  • Indices (1, 2), (3, 4), (5, 6), (7, 8): Four (delegation, state) character pairs for:
    1. ad_storage (index 2)
    2. analytics_storage (index 4)
    3. ad_user_data (index 6)
    4. ad_personalization (index 8)

Each state character maps to a 6-bit integer val (0..63), where:

  • bits 2..3 ((val >> 2) & 0b11) = default state (2 = denied, 3 = granted, 0/1 = unset)
  • bits 0..1 (val & 0b11) = update state (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
Enter fullscreen mode Exit fullscreen mode

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/collect stays locked in gcs=G100 (p/q), silently dropping EEA Google Ads conversions
  • Legacy v1 Masquerading as v2 (V1_LEGACY, e.g. 13r3r3l2l5): 0.6% — gcs=G111 looks 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 explicit Reject All (with GTM Custom HTML tags accounting for 36.9% of offending tags)
  • <head> Race Conditions: 11.0% booted gtm.js before gtag('consent', 'default', ...)

Try the Decoder or Inspect the Dataset (Free, No Login)

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)