Google Tag Manager
CookieBoss pushes consent events to the GTM dataLayer so you can fire tags only when the visitor has given consent.
Quick setup: Import our GTM template
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.