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.
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.
A common pattern
A typical setup:
- Page View tag. Fires on
All Pageswith consent settings configured to require analytics consent. - One Privacy trigger. Fires on the
one-privacy-consent-updatedcustom event. - 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.
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.