While OneTrust provides some level of integration with GTM (i.e. it sends event messages to the data layer), there is still some manual work required to get GTM to respond to OneTrust consent commands.
https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced
1. Install custom templates
Instead of writing your own JS, use these well-supported community tag templates to standardize your implementation.
Consent Mode (Google tags)
- Tag template
- implements Consent Mode API for use in tags so you don’t have to write custom JS to send gtag consent commands
- Offers regional support for containers deployed on websites serving different international regulatory environments
- Community Template Gallery link
OneTrust Consent Groups
- Variable template
- Gets OneTrust cookie consent opt-in groups so you don’t have to write custom JS to parse OptanonConsent cookie or OptanonActivegroups variable
- Community Template Gallery link
- GitHub
2. Create OneTrust variables
These will communicate with the OneTrust cookie and/or JS variable to determine whether consent for each category has been “granted” or “denied”. They are used in the two tags we will create in the next step.
OneTrust | Consent Groups
- Variable type: OneTrust Consent Groups (from Gallery)
- Output Type: String
- Default Groups: Leave blank
OneTrust | Performance
- Variable type: OneTrust Consent Groups (from Gallery)
- Output Type: String
- Default Groups: Leave blank
OneTrust | Targeting Enabled
- Variable type: OneTrust Consent Groups (from Gallery)
- Output Type: String
- Default Groups: Leave blank
3. Create Triggers
- Consent Initialization - default
- OneTrustLoaded (or consent.onetrust) - update
4. Create Consent Mode tags
Consent Mode | Set Default
Trigger: built-in Consent Initialization
Consent Mode | Update
Trigger: Custom Event - consent.onetrust, or data layer event OneTrustUpdated