Consent String
A tiny, dependency-free decoder for the gcd parameter Google sends with Consent Mode hits. See the effective state of every consent signal, and whether it came from a default, an update or was never set.
Consent Mode, decoded
gcd Decoding
Turn a 12-character gcd value like 13l3l3R2l5l1 into the effective state of ad_storage, analytics_storage, ad_user_data and ad_personalization.
Default vs Update
See how each signal was set: by a default, an update, a declaration or not at all, plus container-scoped defaults and the GPC flag.
Runs Anywhere
ESM, CommonJS and a browser build that exposes a ConsentString global, including an ES5 build for older browsers.
Zero Dependencies
MIT licensed, fully typed with TypeScript and free of runtime dependencies.
Simple API, powerful results
Installation
npm install @analytics-debugger/consent-string
# or
bun add @analytics-debugger/consent-stringDecode a gcd value
import * as ConsentString from
"@analytics-debugger/consent-string";
// gcd value taken from a GA4 /collect hit
const consent = ConsentString.decode("13p3lPR2l5l1");
consent.ad_storage; // "denied"
consent.analytics_storage; // effective state
consent.flags; // GPC, Consent Mode active...
consent.meta; // which commands were usedIn the browser
<!-- Browser build: exposes a ConsentString global -->
<script src="https://cdn.jsdelivr.net/npm/@analytics-debugger/consent-string"></script>
<script>
// Decode the gcd parameter of a captured hit
var hit = new URL(requestUrl);
var gcd = hit.searchParams.get("gcd");
var consent = ConsentString.decode(gcd);
console.log(consent.ad_user_data);
</script>Let's get your tracking right
Server-side setup, Conversion APIs, implementations or an audit of what you already have. Tell us about your setup and we'll tell you where to start.