Skip to documentation content

Events reference

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

Last updated:

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.

EventTargetWhenevent.detail
cookiebeam:consentUpdatewindowThe visitor made or changed a choice, or reset(true) withdrew consentConsentUpdateDetail
cookiebeam:consentRestoredwindowA 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 liveSame shape as consentUpdate; the privacy-signal case adds isDefaultState: true and privacySignalHonored: true
cookiebeam:readywindowThe runtime finished initializingnone
cookiebeam:consentWithdrawndocumentreset(true) deleted an existing consent recordnone
cookiebeam_categories_changedwindowAccepted categories changed. Older event name, kept for existing listenersnone

ConsentUpdateDetail

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

{
  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;
}
FieldDescription
categoriesCategory IDs the visitor has accepted
consentModeGoogle Consent Mode v2 signal states (granted or denied per key). Present only when Consent Mode is enabled
timestampWhen this consent state was written
acceptTypeall (accepted everything), custom (mixed), or necessary (rejected everything non-necessary)
isDefaultStatePresent and true on a consentRestored that restates a machine-written default (privacy signal or US opt-out narrowed it)
privacySignalHonoredPresent and true when a GPC or DNT signal shaped this consent state
usOptOutHonoredPresent 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 nameWhenPayload
cookiebeam_modal_shownThe consent banner or preferences modal opens{ event, modal_type, timestamp }
cookiebeam_modal_hiddenThe 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, the runtime also pushes:

{ 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 and fire synchronously during the consent lifecycle.

CallbackFires when
onFirstConsentThe visitor's first explicit consent is established. Doesn't fire on machine-written defaults or restored records
onConsentAny 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
onChangeThe visitor changes their consent after first consent. Carries the list of categories and services that changed
onModalShowThe consent modal or preferences modal becomes visible
onModalHideA modal is dismissed
onModalReadyA 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

FieldTypeDescription
categoriesstring[]Accepted category IDs
servicesRecord<string, string[]>Map of category to accepted service IDs
acceptType'all' | 'custom' | 'necessary'What the visitor clicked
consentIdstring | nullThe cb1_ identifier of this consent decision when the banner's consent ID setting created one; otherwise null. The cookiebeam:consentUpdate event detail does not carry consentId
revisionnumberConfiguration revision the choice was made against
firstConsentAtstringISO 8601 timestamp of the visitor's first consent
lastConsentAtstringISO 8601 timestamp of the most recent consent write
languageCodestringLanguage the banner was displayed in
customDataunknownCustom data attached via setCookieData

FirstConsentEvent and ConsentEvent

FieldTypeDescription
cookieConsentSnapshotThe consent state
userPreferencesUserPreferencesacceptType, acceptedCategories, rejectedCategories, acceptedServices, rejectedServices (FirstConsentEvent only)
isDefaultStateboolean?Machine-written default, not an explicit choice
isPendingboolean?Pending opt-in default (no consent actually granted)
collectionMethodCollectionMethod?How the consent was collected
interactionActionConsentInteractionAction?The visitor's UI action
privacySignalHonoredboolean?A GPC or DNT signal shaped this write

ChangeEvent (same fields as ConsentEvent, plus):

FieldTypeDescription
changedCategoriesstring[]Categories whose acceptance state changed
changedServicesRecord<string, string[]>Services whose acceptance state changed, keyed by category

ModalLifecycleEvent

FieldTypeDescription
modalName'consentModal' | 'preferencesModal' | 'usOptOutPanel'Which modal

ModalReadyEvent (extends ModalLifecycleEvent):

FieldTypeDescription
modalHTMLElementThe modal's root DOM element
reasonstring'initial-mount', 'remount-after-hide', or 'language-change'

CollectionMethod values

ValueMeaning
bannerVisitor clicked a button on the consent banner
preferencesVisitor saved a choice from the preferences modal
apiConsent set programmatically via acceptCategory()
default_optinMachine-written default in opt-in mode
default_optoutMachine-written default in opt-out mode
default_noticeMachine-written default in notice mode
hidden_autograntRegional rule hid the banner and granted defaultCategories (or read-only categories when no defaults are configured)

InteractionAction values

ValueMeaning
acceptVisitor accepted
rejectVisitor rejected
dismissVisitor dismissed (close button or Escape)
customVisitor saved a custom selection

Firing order

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

  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
  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

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

<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:

<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:

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:

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

Next steps