The consent record
How CookieBeam stores a visitor's consent choice, what each field in the cookie means, and how to read it from JavaScript or your server.
Last updated:
When a visitor makes a choice in the banner, CookieBeam writes a JSON record that holds every detail of that choice: which categories were accepted, how the choice was made, and when. The runtime reads this record on later page loads to restore the visitor's state without showing the banner again.
Where the record lives
By default the record is a browser cookie. If you turn on Use Local Storage Instead of Cookies in banner settings, it moves to localStorage instead. With localStorage, your server can't read the record because localStorage is only accessible from JavaScript. The rest of this page assumes the default cookie storage.
Cookie properties
| Property | Default | Notes |
|---|---|---|
| Name | cb_cookie | Configurable under Banner settings > Consent > Consent cookie |
| Path | / | Accessible on every path of the site |
| Domain | Current host | Set a domain (e.g. .example.com) to share the cookie across subdomains. See Cross-domain consent |
SameSite | Lax | Configurable. None requires Secure: true |
Secure | true | Configurable |
HttpOnly | Never | The banner reads and writes the cookie from JavaScript, so it can't be HttpOnly |
| Lifetime | 182 days | Set by Max-Age. Regional rules can override this per-region with consentExpiryDays |
The value is the consent record serialized as JSON and URL-encoded with encodeURIComponent. Most server frameworks decode it automatically; see Read consent on your server for the details.
The V2 schema
All records written by current versions of CookieBeam use schema version 2. A decoded record looks like this:
{
"schemaVersion": 2,
"categories": ["necessary", "analytics"],
"revision": 3,
"data": null,
"consentId": "anonymous",
"consentTimestamp": "2026-11-02T09:41:12.512Z",
"lastConsentTimestamp": "2026-11-02T09:41:12.512Z",
"firstConsentTimestamp": "2026-10-15T14:22:08.100Z",
"languageCode": "en",
"acceptType": "custom",
"collectedVia": "banner"
}
Field reference
| Field | Type | Description |
|---|---|---|
schemaVersion | 2 | Always 2 for current records. A record without this field is a V1 record |
categories | string[] | The accepted category ids. Read-only categories (like necessary) are always included. The defaults are necessary, analytics, marketing, and preferences, but your banner can define custom ids |
revision | number | The banner's consent revision when this record was written. See Revision and re-consent |
data | unknown | Your own values, set with CookieBeam.setCookieData(). The banner can drop this field when the record approaches the cookie size limit |
consentId | string | 'anonymous' by default. When the banner's consent ID setting is on (core 0.3.88+) and the visitor made a choice that creates an identifier, this holds a cb1_… value. CookieBeam does not store this identifier on its side today; it exists only in the cookie. When the setting is off, the field stays 'anonymous' for backward compatibility |
consentTimestamp | string | ISO 8601 time of the most recent save. This is rewritten every time the record is updated, not the time of the first choice |
lastConsentTimestamp | string | The time of the most recent consent update. setCookieData() updates only lastConsentTimestamp, not consentTimestamp |
firstConsentTimestamp | string? | The time of the visitor's very first choice. Present only when it differs from consentTimestamp. If absent, consentTimestamp is the first consent |
languageCode | string | The banner's language when the choice was made |
acceptType | 'all' | 'custom' | 'necessary' | What the visitor clicked: accept all, a custom selection, or necessary only |
services | Record<string, string[]>? | When the banner offers per-service toggles, maps each category id to the accepted service names |
jurisdictions | string[]? | Reserved for region codes. Not currently written by the runtime |
gpcRespected | boolean? | true when a Global Privacy Control signal shaped this record |
usOptOutChoices | object? | US opt-out purpose choices: saleSharing, targetedAdvertising, sensitiveData, profiling (each boolean, true = opted out) |
isPending | boolean? | See Pending and default-state records |
isDefaultState | boolean? | See Pending and default-state records |
collectedVia | string? | How the record was produced. See Collection methods |
purposeConsent | object? | Explicit visitor purpose choices with the policy experience that collected them |
consentMode | object? | A Consent Mode snapshot for Google Tag Manager |
New optional fields can be added in the future. A breaking change would raise schemaVersion.
Pending and default-state records
Not every record represents an active visitor choice. The runtime writes records in two situations where the visitor hasn't explicitly decided:
Pending records (isPending: true). In opt-in mode, published banners keep visitors cookieless until they make a choice. If you use the core runtime standalone (self-hosted, without the CDN-published banner), writeOptInDefaultAtLoad defaults to true and the runtime writes a pending record at load with read-only categories and any unscoped auto-grants. A pending record grants nothing: the runtime treats it as "no consent." Published banners set writeOptInDefaultAtLoad: false, so no cookie exists until the visitor chooses.
Default-state records (isDefaultState: true). In opt-out and notice modes, the banner writes a record at load that grants the configured categories. The visitor hasn't chosen, but the consent model says scripts should run. These records are valid: the runtime activates scripts according to their categories.
When Google Consent Mode is enabled with deferMachineDefaults, default-state records also carry isPending: true. This prevents the GTM Consent Mode template from restoring them as grants at Consent Initialization; the CookieBeam runtime announces them instead.
The rules for interpreting a record:
isPending | isDefaultState | collectedVia | Meaning |
|---|---|---|---|
true | true | default_optin | No consent granted. The visitor hasn't chosen (opt-in default) |
true | true | default_optout, default_notice, hidden_autogrant | Valid default. Categories are in effect, but the visitor hasn't actively chosen |
| absent/false | true | default_optout, default_notice, hidden_autogrant | Valid default without Consent Mode deferral |
| absent/false | absent/false | banner, preferences, api | Active choice. The visitor made a decision |
Collection methods
The collectedVia field records how the record was produced:
| Value | Meaning |
|---|---|
banner | The visitor clicked a button in the consent modal |
preferences | The visitor saved a choice in the preferences modal |
api | Your code called CookieBeam.acceptCategory() or another API method |
default_optin | Machine-written default in opt-in mode (pending, grants nothing) |
default_optout | Machine-written default in opt-out mode (grants configured categories) |
default_notice | Machine-written default in notice mode (grants configured categories) |
hidden_autogrant | Auto-granted because a regional rule hides the banner for this visitor |
Revision and re-consent
Every banner has a consent revision number. When you turn on Ask visitors again in banner settings and publish, the revision increments. From that point on, the banner treats any record with an older revision as invalid and shows the consent dialog again.
The record's revision field is the banner's revision at the time it was written. When you read the record on your server, compare it to the current banner revision. If they don't match, treat the record as no consent.
Get the current revision from the published configuration without an API key:
curl "https://cookiebeam.com/api/v1/mobile/config?bannerId=PUBLIC_BANNER_ID"
The revision is the version.consentRevision field in the response. Cache this value; don't call the endpoint on every request.
The Consent Mode snapshot
When Google Consent Mode is enabled, the record includes a consentMode field:
{
"consentMode": {
"v": 1,
"revision": 3,
"expiresAt": 1762185672512,
"state": {
"ad_storage": "denied",
"ad_user_data": "denied",
"ad_personalization": "denied",
"analytics_storage": "granted",
"functionality_storage": "granted",
"personalization_storage": "granted",
"security_storage": "granted"
}
}
}
This snapshot lets the GTM Consent Mode template restore consent state at Consent Initialization, before the CookieBeam runtime has loaded. It's written on explicit visitor choices. When Consent Mode is enabled and the banner uses cookie storage (not localStorage only), the runtime also refreshes the snapshot on page load for returning visitors with a valid stored choice. The refresh is skipped when the record has no existing snapshot and the banner's consent lifetimes differ across regions, or when another tab has changed the cookie. v is the contract version (currently 1); the GTM template skips snapshots with an unknown version. revision matches the banner's consent revision, and expiresAt is an epoch-millisecond timestamp after which the snapshot should be treated as expired.
The 7 Consent Mode keys and how CookieBeam maps categories to them are documented in Google Consent Mode v2.
Reading the record
In the browser. Use the Browser API: CookieBeam.acceptedCategory('analytics') checks a single category, CookieBeam.getUserPreferences() returns the full state, and CookieBeam.getCookie() returns the raw record. Listen for changes with the cookiebeam:consentUpdate event.
On your server. Parse the cookie value as JSON (URL-decode first if it starts with %), validate the schema, then read categories and revision. Use the interpretation table to classify the record: isPending, isDefaultState, and collectedVia together determine whether the record represents an active choice or a machine default. See Read consent on your server for production-ready snippets in Node.js, Python, Ruby, PHP, Go, Java, and .NET.
V1 records
Records written by older CookieBeam versions don't have a schemaVersion field. They carry the same categories, revision, consentId, consentTimestamp, lastConsentTimestamp, languageCode, and services fields as V2, but lack acceptType, isPending, isDefaultState, collectedVia, and the other V2 additions.
Treat a record without schemaVersion as V1. The categories and revision fields work the same way, so the core consent check doesn't change. The V2-only fields (isPending, isDefaultState, collectedVia) are simply absent, meaning you can't distinguish a machine default from an active choice in a V1 record.
The runtime upgrades V1 records to V2 on the visitor's next interaction with the banner. No migration is needed on your side.