---
title: "Events reference"
description: "Complete catalog of every event the CookieBeam runtime dispatches, including DOM custom events, GTM dataLayer pushes, and configuration callbacks."
url: "https://cookiebeam.com/docs/api-reference/events-reference"
lang: "en"
last_updated: "2026-11-16"
---

# Events reference

Complete catalog of every event the CookieBeam runtime dispatches, including DOM custom events, GTM dataLayer pushes, and configuration callbacks.

CookieBeam fires events at every stage of the consent lifecycle. DOM custom events let any page script react without polling. GTM dataLayer pushes drive tag-manager triggers. Configuration callbacks give self-hosted installs a typed hook into each moment.

## DOM events

All events are `CustomEvent` instances dispatched on `window` unless noted otherwise.

| Event | Target | When | `event.detail` |
| ----- | ------ | ---- | -------------- |
| `cookiebeam:consentUpdate` | `window` | The visitor made or changed a choice, or `reset(true)` withdrew consent | `ConsentUpdateDetail` |
| `cookiebeam:consentRestored` | `window` | A valid stored consent record was re-applied on page load. Nothing changed. Also fires (before `cookiebeam:ready`) when a respected privacy signal narrowed the automatic default, on every page view while the signal is live | Same shape as `consentUpdate`; the privacy-signal case adds `isDefaultState: true` and `privacySignalHonored: true` |
| `cookiebeam:ready` | `window` | The runtime finished initializing | none |
| `cookiebeam:consentWithdrawn` | `document` | `reset(true)` deleted an existing consent record | none |
| `cookiebeam_categories_changed` | `window` | Accepted categories changed. Older event name, kept for existing listeners | none |

### ConsentUpdateDetail

Both `cookiebeam:consentUpdate` and `cookiebeam:consentRestored` carry this shape on `event.detail`:

```ts
{
  categories: string[];
  consentMode: Partial<Record<
    | 'ad_storage'
    | 'ad_user_data'
    | 'ad_personalization'
    | 'analytics_storage'
    | 'functionality_storage'
    | 'personalization_storage'
    | 'security_storage',
    'granted' | 'denied'
  >>;
  timestamp: string;       // ISO 8601
  acceptType: 'all' | 'custom' | 'necessary';
  isDefaultState?: true;
  privacySignalHonored?: true;
  usOptOutHonored?: true;
}
```

| Field | Description |
| ----- | ----------- |
| `categories` | Category IDs the visitor has accepted |
| `consentMode` | Google Consent Mode v2 signal states (`granted` or `denied` per key). Present only when Consent Mode is enabled |
| `timestamp` | When this consent state was written |
| `acceptType` | `all` (accepted everything), `custom` (mixed), or `necessary` (rejected everything non-necessary) |
| `isDefaultState` | Present and `true` on a `consentRestored` that restates a machine-written default (privacy signal or US opt-out narrowed it) |
| `privacySignalHonored` | Present and `true` when a GPC or DNT signal shaped this consent state |
| `usOptOutHonored` | Present and `true` when a durable US opt-out choice shaped this consent state |

### Distinguishing consentUpdate from consentRestored

`consentUpdate` means the visitor changed something. Consumers that count choices (consent logging, analytics, SDK history) should treat it as a new decision.

`consentRestored` means "nothing changed, here's the current state." It fires on every page load when a valid record exists, so vendor consent bridges and tag-manager triggers that need to re-apply consent on every navigation can listen to it.

If you need the current state on every page view regardless of whether something changed, listen to both. If you only care about actual choices, listen to `consentUpdate` alone.

## GTM dataLayer pushes

The runtime pushes events to `window.dataLayer` for Google Tag Manager triggers:

| Event name | When | Payload |
| ---------- | ---- | ------- |
| `cookiebeam_modal_shown` | The consent banner or preferences modal opens | `{ event, modal_type, timestamp }` |
| `cookiebeam_modal_hidden` | The consent banner or preferences modal closes | `{ event, modal_type, timestamp }` |

`modal_type` is `'consentModal'`, `'preferencesModal'`, or `'usOptOutPanel'`.

**Deduplication:** the runtime suppresses only an immediately repeated identical event key. If the visitor opens the preferences modal, closes it, and opens it again, the second `cookiebeam_modal_shown` for `preferencesModal` fires because the intervening `cookiebeam_modal_hidden` changed the key.

### Passive analytics push

When `consentMode.passiveAnalytics` is enabled in the [configuration](https://cookiebeam.com/docs/api-reference/config-reference#consentmode), the runtime also pushes:

```js
{ cookiebeam_cmp_mode: 'passive', _tcf_cmp_mode: 'passive' }
```

This tells the GTM Consent Mode template that the CMP is running in passive mode. It does not grant `analytics_storage`; it only pushes this dataLayer marker when `analytics_storage` is denied, so the GTM template can distinguish "denied by passive CMP" from "denied by active CMP".

## Lifecycle callbacks

Callbacks are set on the [RuntimeConfig](https://cookiebeam.com/docs/api-reference/config-reference#lifecycle-callbacks) and fire synchronously during the consent lifecycle.

| Callback | Fires when |
| -------- | ---------- |
| `onFirstConsent` | The visitor's first explicit consent is established. Doesn't fire on machine-written defaults or restored records |
| `onConsent` | Any consent **write**: first consent, defaults, and subsequent changes. Does not fire on restored consent (return visits with a valid record). For return visits, listen to `cookiebeam:consentRestored` |
| `onChange` | The visitor changes their consent after first consent. Carries the list of categories and services that changed |
| `onModalShow` | The consent modal or preferences modal becomes visible |
| `onModalHide` | A modal is dismissed |
| `onModalReady` | A modal's DOM has been created and is ready to show |

### Callback event shapes

All consent callbacks carry a `cookie` field with the full consent snapshot:

**ConsentSnapshot**

| Field | Type | Description |
| ----- | ---- | ----------- |
| `categories` | `string[]` | Accepted category IDs |
| `services` | `Record<string, string[]>` | Map of category to accepted service IDs |
| `acceptType` | `'all' \| 'custom' \| 'necessary'` | What the visitor clicked |
| `consentId` | `string \| null` | The `cb1_` identifier of this consent decision when the banner's [consent ID setting](https://cookiebeam.com/docs/configure/consent-id) created one; otherwise `null`. The `cookiebeam:consentUpdate` event detail does not carry `consentId` |
| `revision` | `number` | Configuration revision the choice was made against |
| `firstConsentAt` | `string` | ISO 8601 timestamp of the visitor's first consent |
| `lastConsentAt` | `string` | ISO 8601 timestamp of the most recent consent write |
| `languageCode` | `string` | Language the banner was displayed in |
| `customData` | `unknown` | Custom data attached via `setCookieData` |

**FirstConsentEvent** and **ConsentEvent**

| Field | Type | Description |
| ----- | ---- | ----------- |
| `cookie` | `ConsentSnapshot` | The consent state |
| `userPreferences` | `UserPreferences` | `acceptType`, `acceptedCategories`, `rejectedCategories`, `acceptedServices`, `rejectedServices` (FirstConsentEvent only) |
| `isDefaultState` | `boolean?` | Machine-written default, not an explicit choice |
| `isPending` | `boolean?` | Pending opt-in default (no consent actually granted) |
| `collectionMethod` | `CollectionMethod?` | How the consent was collected |
| `interactionAction` | `ConsentInteractionAction?` | The visitor's UI action |
| `privacySignalHonored` | `boolean?` | A GPC or DNT signal shaped this write |

**ChangeEvent** (same fields as ConsentEvent, plus):

| Field | Type | Description |
| ----- | ---- | ----------- |
| `changedCategories` | `string[]` | Categories whose acceptance state changed |
| `changedServices` | `Record<string, string[]>` | Services whose acceptance state changed, keyed by category |

**ModalLifecycleEvent**

| Field | Type | Description |
| ----- | ---- | ----------- |
| `modalName` | `'consentModal' \| 'preferencesModal' \| 'usOptOutPanel'` | Which modal |

**ModalReadyEvent** (extends ModalLifecycleEvent):

| Field | Type | Description |
| ----- | ---- | ----------- |
| `modal` | `HTMLElement` | The modal's root DOM element |
| `reason` | `string` | `'initial-mount'`, `'remount-after-hide'`, or `'language-change'` |

### CollectionMethod values

| Value | Meaning |
| ----- | ------- |
| `banner` | Visitor clicked a button on the consent banner |
| `preferences` | Visitor saved a choice from the preferences modal |
| `api` | Consent set programmatically via `acceptCategory()` |
| `default_optin` | Machine-written default in opt-in mode |
| `default_optout` | Machine-written default in opt-out mode |
| `default_notice` | Machine-written default in notice mode |
| `hidden_autogrant` | Regional rule hid the banner and granted `defaultCategories` (or read-only categories when no defaults are configured) |

### InteractionAction values

| Value | Meaning |
| ----- | ------- |
| `accept` | Visitor accepted |
| `reject` | Visitor rejected |
| `dismiss` | Visitor dismissed (close button or Escape) |
| `custom` | Visitor saved a custom selection |

## Firing order

The order events fire depends on whether the visitor already has a stored consent record.

### First visit (no stored consent, opt-in mode)

1. Runtime initializes
2. `onConsent` fires with the default state (`isPending: true` in opt-in, `isDefaultState: true` in opt-out)
3. Banner shows, `onModalShow` fires, `cookiebeam_modal_shown` pushed to dataLayer
4. `cookiebeam:ready` fires
5. Visitor clicks "Accept all"
6. `BUS_CONSENT_CHANGE` (internal), then `cookiebeam_categories_changed` and `cookiebeam:consentUpdate` dispatched on `window`
7. `onFirstConsent` fires with the new consent state
8. `onConsent` fires with the updated state
9. `onChange` fires with the changed categories
10. Banner hides, `onModalHide` fires, `cookiebeam_modal_hidden` pushed to dataLayer

### Return visit (valid stored consent)

1. Runtime initializes, reads the stored record
2. `cookiebeam:consentRestored` dispatched on `window`
3. `cookiebeam:ready` fires

No banner is shown. `onConsent` does **not** fire. No `consentUpdate` fires unless the visitor opens the preferences modal and changes something.

### Visitor changes their choice

1. Visitor opens preferences, `onModalShow`, `cookiebeam_modal_shown`
2. Visitor saves changes
3. `cookiebeam_categories_changed` and `cookiebeam:consentUpdate` dispatched
4. `onConsent` fires with the new state
5. `onChange` fires with `changedCategories` listing what flipped
6. Modal hides, `onModalHide`, `cookiebeam_modal_hidden`

### Privacy signal on first visit (US opt-out, GPC active)

1. Runtime initializes, detects GPC signal
2. Signal strips blocked categories from the default grant
3. `cookiebeam:consentRestored` fires with `isDefaultState: true`, `privacySignalHonored: true`
4. `onConsent` fires
5. `cookiebeam:ready` fires
6. If the toast is enabled, it shows

When Google Consent Mode is enabled, a `consentUpdate` fires to announce the adjusted Consent Mode state. Without Consent Mode, no `consentUpdate` fires because the signal is a restatement, not a choice.

## Common patterns

### React to consent on every page view

Listen to both events to cover first visits and return visits:

```html
<script>
  function handleConsent(e) {
    if (e.detail.categories.indexOf('analytics') !== -1) {
      // analytics is accepted, start tracking
    }
  }
  window.addEventListener('cookiebeam:consentUpdate', handleConsent);
  window.addEventListener('cookiebeam:consentRestored', handleConsent);
</script>
```

### Log only actual choices

Use `consentUpdate` alone when you want to record that the visitor made a decision:

```html
<script>
  window.addEventListener('cookiebeam:consentUpdate', function (e) {
    fetch('/my-consent-log', {
      method: 'POST',
      body: JSON.stringify({
        categories: e.detail.categories,
        acceptType: e.detail.acceptType,
        timestamp: e.detail.timestamp,
      }),
    });
  });
</script>
```

### Detect category revocation

Use the `onChange` callback to react when a visitor revokes a category:

```js
CookieBeam.run({
  // ...config
  onChange: function (event) {
    event.changedCategories.forEach(function (cat) {
      if (event.cookie.categories.indexOf(cat) === -1) {
        console.log(cat + ' was revoked');
      }
    });
  },
});
```

### Wait for the runtime before calling the API

If your script might run before the banner, wait for `cookiebeam:ready`:

```html
<script>
  window.addEventListener('cookiebeam:ready', function () {
    if (window.CookieBeam.acceptedCategory('analytics')) {
      startAnalytics();
    }
  });
</script>
```

## Next steps

- [Browser API](https://cookiebeam.com/docs/api-reference/browser-api): the full `window.CookieBeam` method reference
- [Consent record](https://cookiebeam.com/docs/concepts/consent-record): what's stored in the consent cookie
- [Configuration reference](https://cookiebeam.com/docs/api-reference/config-reference): every RuntimeConfig field
