Google Tag Manager
There are two ways to use CookieBoss with Google Tag Manager. They work together.
- CookieBoss Consent Mode tag template (recommended for Google tags). A tag you fire on Consent Initialization - All Pages. It loads the CookieBoss banner and runs Google Consent Mode v2: denied defaults, optional regional defaults, an immediate update for returning visitors, and an update on every banner choice. See CookieBoss for Google Tag Manager for setup.
- dataLayer events (this page). CookieBoss pushes consent events to the GTM
dataLayerso you can fire other tags only when the visitor has given consent.
Using the tag template?
Switch off Google Consent Mode v2 in the banner editor (Behaviour tab) so the template is the only source of Consent Mode commands, and remove the CookieBoss script tag from the page: the template loads the script. The dataLayer events below keep working.
Quick setup: Import our GTM container
Skip the manual configuration below by importing our pre-built container template. It includes all the triggers, variables, and an example GA4 tag.
- Download GTM Template
- In GTM, go to Admin > Import Container
- Choose the downloaded file
- Select Merge and Rename conflicting tags, triggers, and variables
- Review the imported items and click Confirm
- Update the example GA4 tag with your Measurement ID (
G-XXXXXXXXXX) - Preview, test, and Publish
What's in the template?
The template includes 3 custom event triggers (cookieboss_consent_update, cookieboss_consent_accept_all, cookieboss_consent_reject_all), 3 data layer variables for consent categories, and an example GA4 configuration tag. You still need to add firing conditions to your own tags — see the manual steps below for guidance.
Prerequisites
- GTM enabled in your CookieBoss banner settings
- The CookieBoss script loaded before the GTM container script
How it works
When a visitor interacts with the consent banner, CookieBoss pushes three types of events to window.dataLayer:
| Event | When |
|---|---|
cookieboss_consent_update | Every consent change |
cookieboss_consent_accept_all | Visitor accepts all categories |
cookieboss_consent_reject_all | Visitor rejects all optional categories |
Each event includes the full consent state:
{
"event": "cookieboss_consent_update",
"cookieboss": {
"siteId": "01KHJTD0CZG42333Z4P3F6X7Z4",
"consent": {
"necessary": true,
"analytics": true,
"marketing": false,
"functional": true
}
}
} Step 1: Create Data Layer Variables
In GTM, go to Variables > New > Data Layer Variable and create these variables:
| Variable name | Data Layer Variable Name |
|---|---|
CB - Analytics Consent | cookieboss.consent.analytics |
CB - Marketing Consent | cookieboss.consent.marketing |
CB - Functional Consent | cookieboss.consent.functional |
Step 2: Create a Custom Event Trigger
Go to Triggers > New > Custom Event:
- Event name:
cookieboss_consent_update - This trigger fires on: All Custom Events
Name it CB - Consent Update.
Step 3: Add Firing Conditions to Tags
For each tag that requires consent, add a firing condition:
Example: Google Analytics tag
- Trigger:
CB - Consent Update - Condition:
CB - Analytics Consentequalstrue
Example: Meta Pixel tag
- Trigger:
CB - Consent Update - Condition:
CB - Marketing Consentequalstrue
Step 4: Handle returning visitors
For visitors who already gave consent on a previous visit, CookieBoss fires cookieboss_consent_update automatically on page load with their stored preferences. Your GTM triggers will fire accordingly — no extra configuration needed.
Combine with Google Consent Mode
For Google tags specifically, use Google Consent Mode V2 instead of manual GTM triggers. It handles consent-aware data collection automatically, including conversion modeling for non-consenting visitors.