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.

If you gate a tag with GTM's Consent Settings → Require additional consent for tag to fire, a trigger on All Pages alone is not enough. Here's why:

  1. All Pages fires once, at container load. If the visitor hasn't consented yet, the consent check blocks the tag.
  2. When the visitor later accepts, GTM does not go back and re-fire blocked tags. The consent check is a gate evaluated at trigger time — a later consent update doesn't re-trigger anything.

A blocked tag needs an explicit second trigger. Set it up like this:

  1. Keep All Pages on the tag (so it fires immediately for returning visitors who already consented).
  2. Add the one-privacy-consent-updated Custom Event trigger from the section above as a second trigger.
  3. In the tag's Advanced Settings → Tag firing options, choose Once per page so the tag can't fire twice when both triggers pass.
  4. In Consent Settings, keep Require additional consent for tag to fire with the consent types the tag needs (for example ad_storage for an advertising pixel).

How it plays out:

ScenarioWhat happens
First visit, no choice yetAll Pages fires → blocked (consent denied by default). Visitor accepts → one-privacy-consent-updated fires → consent check passes → tag fires.
Returning visitor who acceptedOne Privacy restores consent before the container trigger → All Pages fires the tag. "Once per page" stops a duplicate on the consent event.
Visitor rejectsBoth triggers fire, the consent check blocks both. No cookies are set.

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.

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