Integrations
GTM advanced setup
Custom triggers, data layer vars, and ordering
Available on the Pro plan and above. See pricing for what each plan includes.
This guide covers advanced Google Tag Manager configuration with GetCookies, including tag firing order, custom consent triggers, data layer variables, hybrid blocker setups, and debugging techniques.
Tag Firing Order (Critical)
The most important aspect of a GTM + consent setup is the order in which tags fire. Get this wrong and trackers will fire before consent.
Required Order
- GetCookies CMP tag -- must use the Consent Initialization - All Pages trigger. This is the special trigger that fires before ALL other triggers in GTM, including "All Pages" and "DOM Ready".
- Google tags with consent requirements -- GA4, Google Ads, Meta Pixel, etc. These only fire after the corresponding consent type is granted.
- Other tags -- Custom HTML tags, conversion pixels, etc.
Why "Consent Initialization" Matters
GTM has a specific trigger firing order:
1. Consent Initialization ← GetCookies goes here
2. Initialization
3. Page View (All Pages) ← Google tags go here
4. DOM Ready
5. Window Loaded
6. Custom EventsIf you put the GetCookies tag on "All Pages" instead of "Consent Initialization", other tags on "All Pages" may fire simultaneously, before consent defaults are set.
Configuring Consent Requirements on Tags
For each tracking tag in GTM:
- Open the tag.
- Go to Advanced Settings > Consent Settings.
- Check Require additional consent for tag to fire.
- Add the appropriate consent types:
| Tag type | Required consent types |
|---|---|
| GA4 Configuration | analytics_storage |
| GA4 Event | analytics_storage |
| Google Ads Conversion | ad_storage, ad_user_data |
| Google Ads Remarketing | ad_storage, ad_user_data, ad_personalization |
| Meta (Facebook) Pixel | ad_storage, ad_user_data, ad_personalization |
| LinkedIn Insight | ad_storage, ad_user_data |
| TikTok Pixel | ad_storage, ad_user_data, ad_personalization |
| Hotjar / Session recording | analytics_storage |
| Intercom / Chat widgets | functionality_storage |
| Custom analytics | analytics_storage |
| Custom advertising | ad_storage |
Custom Triggers for Consent Events
Consent Update Trigger
Create a trigger that fires when a user updates their consent (e.g., to send a custom event to your analytics):
- Go to Triggers > New.
- Choose Custom Event.
- Set the event name to:
cookie_consent_update - Save.
Use this trigger on tags that should fire only when consent changes (e.g., a custom GA4 event that records the consent action).
Category-Specific Triggers
To fire a tag only when a specific consent category is granted:
- Create a Custom Event trigger with event name
cookie_consent_update. - Add a condition: use a Data Layer Variable (see below) to check the specific category.
Example: Fire a tag only when marketing consent is granted:
- Trigger: Custom Event =
cookie_consent_update - Condition:
DLV - cookie_consent.marketingequalstrue
Data Layer Variables
GetCookies pushes consent data to the GTM data layer. Create these variables to use consent state in your triggers and tags:
Setting Up Data Layer Variables
- Go to Variables > New > Data Layer Variable.
- Create these variables:
| Variable name | Data Layer Variable Name | Returns |
|---|---|---|
| DLV - cookie_consent.analytics | cookie_consent.analytics | true/false |
| DLV - cookie_consent.marketing | cookie_consent.marketing | true/false |
| DLV - cookie_consent.preferences | cookie_consent.preferences | true/false |
| DLV - cookie_consent.necessary | cookie_consent.necessary | true (always) |
Using Data Layer Variables in Tag Conditions
You can use these variables as firing conditions on any tag:
- Open a tag.
- In the trigger, click Add Exception or edit the trigger conditions.
- Add a condition:
DLV - cookie_consent.marketingequalstrue.
This is useful for Custom HTML tags that do not support GTM's built-in consent settings.
Hybrid Setup: Blocker + GTM
For maximum pre-consent blocking, combine the GetCookies synchronous blocker with GTM:
Script Order in <head>
<!-- 1. GetCookies blocker (FIRST - blocks hard-coded scripts) -->
<script src="https://app.getcookies.co/api/v1/widget/blocker.js"></script>
<!-- 2. Google Tag Manager (SECOND) -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- 3. Any other scripts come after -->How the Hybrid Works
- blocker.js loads synchronously and immediately pauses any hard-coded tracking scripts on the page (scripts with known tracking domains).
- GTM loads and the GetCookies CMP tag fires at Consent Initialization, setting consent defaults to "denied".
- The GetCookies widget loads (either via GTM Custom HTML tag or directly).
- When the user consents, both the blocker and GTM consent states update simultaneously.
- Hard-coded scripts unblock and GTM tags fire.
When to Use the Hybrid
- You have scripts hard-coded in your HTML that you cannot move to GTM.
- You need to block scripts that load before GTM initializes.
- Your site has third-party embeds (e.g., YouTube, social widgets) that set cookies on load.
Custom HTML Tags and Consent
For Custom HTML tags in GTM that do not integrate with Consent Mode natively:
Method 1: Use Built-in Consent Settings
- Open the Custom HTML tag.
- Go to Advanced Settings > Consent Settings.
- Require the appropriate consent type.
- GTM will hold the tag until consent is granted.
Method 2: JavaScript Consent Check
If you need more granular control inside a Custom HTML tag:
<script>
(function() {
// Check if user has consented to marketing
var consent = window.GetCookies ? window.GetCookies.getConsent() : null;
if (consent && consent.choices && consent.choices.marketing) {
// Initialize your marketing tool here
}
})();
</script>Tag Sequencing
For tags that depend on other tags (e.g., a conversion tag that needs GA4 to initialize first):
- Open the dependent tag.
- Go to Advanced Settings > Tag Sequencing.
- Check Fire a tag before [this tag] fires and select the prerequisite tag.
- Both tags still need their own consent requirements.
Server-Side Tagging
If you use GTM Server-Side:
- The client-side GetCookies CMP handles consent on the browser.
- The consent state is included in the event data sent to your server-side container.
- Server-side tags can check consent state from the event data before processing.
- This ensures server-side tags also respect user consent choices.
Debugging
GTM Preview Mode
- Open GTM and click Preview.
- Enter your site URL.
- In the debug panel, check:
- Consent Initialization phase: GetCookies CMP tag should fire here.
- Tags Fired vs Tags Not Fired: tracking tags should be in "Not Fired" before consent.
- Consent tab: shows the current consent state for each type.
- Interact with the consent banner and verify tags move from "Not Fired" to "Fired" (or stay blocked if consent was denied).
Common Debugging Issues
| Problem | Cause | Fix |
|---|---|---|
| All tags fire immediately | GetCookies tag not on Consent Initialization trigger | Change trigger to "Consent Initialization - All Pages" |
| Tags never fire after consent | Consent types do not match | Verify the consent type strings match exactly (e.g., analytics_storage not analytics) |
| Consent state resets on navigation | localStorage blocked or cleared | Check if the browser blocks localStorage; verify the consent cookie persists |
| Some tags fire, others do not | Mixed consent requirements | Check each tag's consent settings individually |
| GetCookies tag shows as "Blocked" | Another CMP or consent tool conflicting | Remove any other consent management tools |
Console Debugging
Open Chrome DevTools > Console and look for:
GetCookies: Consent defaults set {ad_storage: "denied", analytics_storage: "denied", ...}
GetCookies: Consent updated by user {ad_storage: "granted", analytics_storage: "granted", ...}If these messages do not appear, verify the GetCookies script is loading correctly and the Domain ID is valid.
Still stuck?
Email [email protected] with your domain and what you tried. Signed-in customers can also open a ticket from the dashboard.