Skip to main content

GTM dataLayer integration

One Privacy pushes a custom event into the GTM dataLayer whenever consent is set or updated. You can use this event as a trigger for tags that depend on consent.

The event

Every time consent changes, One Privacy runs:

emitted-by-onePrivacy.js
window.dataLayer.push({
event: 'one-privacy-consent-updated'
});

This is the same event name we fire as a CustomEvent on window, so you can use whichever fits your codebase.

Set up a trigger in GTM

  1. Open Google Tag Manager.
  2. Go to Triggers → New.
  3. Click Trigger Configuration and choose Custom Event.
  4. In Event name, type one-privacy-consent-updated.
  5. Choose when the trigger fires:
    • All Custom Events to react every time the visitor saves a choice.
    • Some Custom Events with a condition (for example, Page URL matches your checkout page).
  6. Save.

Any tag using this trigger now fires whenever consent is updated.

In a Custom HTML tag (or any tag with a custom JavaScript variable), read window.onePrivacyCookieGroups to know what's accepted:

custom-html-tag.html
<script>
var groups = window.onePrivacyCookieGroups || '';
if (groups.indexOf('C0003') !== -1) {
// Performance cookies allowed
}
if (groups.indexOf('C0004') !== -1) {
// Targeting cookies allowed
}
</script>

See Cookie category IDs for the full list.

A common pattern

A typical setup:

  1. Page View tag. Fires on All Pages with consent settings configured to require analytics consent.
  2. One Privacy trigger. Fires on the one-privacy-consent-updated custom event.
  3. GA4 page_view event. Uses the One Privacy trigger so it fires after consent is given.

This way, your analytics stays accurate without any tag running before consent.

You don't need separate logic for Consent Mode. One Privacy already pushes the right gtag('consent', 'default') and gtag('consent', 'update') calls, so any GTM tag with the standard "Consent Settings" panel respects them automatically. See Google Consent Mode.

What's next

JavaScript API.

Consent events.

Installing with Google Tag Manager (for non-developers).