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:
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
- Open Google Tag Manager.
- Go to Triggers → New.
- Click Trigger Configuration and choose Custom Event.
- In Event name, type
one-privacy-consent-updated. - 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 URLmatches your checkout page).
- Save.
Any tag using this trigger now fires whenever consent is updated.
Gating tags behind consent: the dual-trigger pattern
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:
- All Pages fires once, at container load. If the visitor hasn't consented yet, the consent check blocks the tag.
- 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 updatedoesn't re-trigger anything.
A blocked tag needs an explicit second trigger. Set it up like this:
- Keep All Pages on the tag (so it fires immediately for returning visitors who already consented).
- Add the
one-privacy-consent-updatedCustom Event trigger from the section above as a second trigger. - In the tag's Advanced Settings → Tag firing options, choose Once per page so the tag can't fire twice when both triggers pass.
- In Consent Settings, keep Require additional consent for tag to fire with the consent types the tag needs (for example
ad_storagefor an advertising pixel).
How it plays out:
| Scenario | What happens |
|---|---|
| First visit, no choice yet | All Pages fires → blocked (consent denied by default). Visitor accepts → one-privacy-consent-updated fires → consent check passes → tag fires. |
| Returning visitor who accepted | One Privacy restores consent before the container trigger → All Pages fires the tag. "Once per page" stops a duplicate on the consent event. |
| Visitor rejects | Both triggers fire, the consent check blocks both. No cookies are set. |
Reading consent inside a tag
In a Custom HTML tag (or any tag with a custom JavaScript variable), read window.onePrivacyCookieGroups to know what's accepted:
<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.
Google Consent Mode is automatic
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.