Open Source

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

01

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.

02

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.

03

Runs Anywhere

ESM, CommonJS and a browser build that exposes a ConsentString global, including an ES5 build for older browsers.

04

Zero Dependencies

MIT licensed, fully typed with TypeScript and free of runtime dependencies.

Simple API, powerful results

Installation

terminal
npm install @analytics-debugger/consent-string
# or
bun add @analytics-debugger/consent-string

Decode a gcd value

client.js
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 used

In the browser

server.js
<!-- 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.