GTM + Consent Mode V2

Google Tag Manager
Cookie Consent Setup

Set up GTM cookie consent with Consent Mode V2 in under 5 minutes. Control exactly which tags fire based on user consent. Under 10KB, async loading, $99 one-time.

Why Use a Cookie Banner with Google Tag Manager?

GTM does not handle consent on its own. You need a consent management layer to control which tags fire -- and to stay GDPR compliant.

Consent Mode V2 Required

Since March 2024, Google requires Consent Mode V2 for Google Ads in the EU. Without it, your remarketing audiences stop growing and conversion modeling breaks.

Granular Tag Control

Fire analytics tags only when analytics consent is granted. Fire advertising tags only when ad consent is granted. No more all-or-nothing.

Deploy via GTM

Add our cookie banner as a Custom HTML tag in GTM. No need to touch your website code -- marketing teams can deploy and manage consent independently.

Preserve Conversion Data

Consent Mode V2 enables Google behavioral modeling for users who deny consent. You keep directional conversion data without violating privacy laws.

GDPR + CCPA Compliant

Automatic compliance with GDPR (EU), CCPA (California), PIPEDA (Canada), and LGPD (Brazil). The banner adjusts opt-in vs. opt-out behavior by region.

Under 10KB, Async

Our script is under 10KB gzipped and loads asynchronously. Zero impact on your Core Web Vitals. No CLS, no render blocking, no performance penalty.

How Does GTM Consent Mode V2 Work?

Consent Mode V2 uses consent signals to control how Google tags behave. Here is what happens under the hood.

What is Consent Mode V2?

Consent Mode V2 is Google's framework for adjusting tag behavior based on user consent. It is required for Google Ads in the EU since March 2024:

  • Automatically adjusts data collection based on consent state
  • Enables behavioral modeling for consented data gaps
  • Required for Google Ads conversion tracking in the EU
  • Supports granular consent categories (ads, analytics, functionality)

Required Consent Types

Consent Mode V2 requires these consent types. Our banner maps cookie categories to each one automatically:

  • ad_storage: Controls advertising cookies (Google Ads, remarketing)
  • ad_user_data: Controls sending user data for advertising
  • ad_personalization: Controls personalized advertising
  • analytics_storage: Controls analytics cookies (GA4)
  • functionality_storage: Controls functional cookies

What Our Banner Does Automatically (You Do Not Write This)

This is the consent flow our script handles for you. Shown here so you understand what happens under the hood.

// 1. On page load, our script sets default consent (denied)
gtag('consent', 'default', {
  'ad_storage': 'denied',
  'ad_user_data': 'denied',
  'ad_personalization': 'denied',
  'analytics_storage': 'denied',
  'functionality_storage': 'denied',
  'security_storage': 'granted'
});

// 2. When user clicks "Accept All" or grants specific categories:
gtag('consent', 'update', {
  'ad_storage': 'granted',
  'ad_user_data': 'granted',
  'ad_personalization': 'granted',
  'analytics_storage': 'granted',
  'functionality_storage': 'granted'
});

// 3. Pushes a consent event to the dataLayer for non-Google tags:
window.dataLayer.push({
  'event': 'cookie_consent_update',
  'consent_analytics': true,
  'consent_marketing': true,
  'consent_preferences': true
});

You do not need to write any of this code. Our cookie banner script handles all consent default/update calls and dataLayer pushes automatically. This is shown for transparency so you can verify the implementation in GTM Preview mode.

How Do You Set Up GTM Cookie Consent?

Two options: deploy our script via GTM (recommended for marketing teams) or add the script directly to your site.

A

Option A: Deploy Cookie Banner via GTM

Recommended -- no code changes to your website needed

Add our cookie banner as a Custom HTML tag in GTM. This is ideal for marketing teams who manage GTM but do not have access to the website code.

<!-- GTM Custom HTML Tag -->
<script
  src="https://www.cookie-banner.ca/api/scripts/YOUR_BANNER_ID.js"
  async
></script>
  1. In GTM, go to TagsNew
  2. Choose Custom HTML tag type
  3. Paste the script above (replace YOUR_BANNER_ID with your actual ID)
  4. Set trigger to Consent Initialization - All Pages
  5. Set tag firing priority to highest (e.g., 9999)
  6. Save, preview, and publish

Why Consent Initialization trigger? This fires before any other tags, ensuring consent defaults are set before GA4, Google Ads, or any other tag loads. This is critical for Consent Mode V2 compliance.

B

Option B: Add Script Before GTM Snippet

For developers who have access to the site HTML

Place our cookie banner script before the GTM container snippet in your HTML head. This ensures consent defaults are set before GTM loads any tags.

<head>
  <!-- Step 1: Cookie Consent Banner (BEFORE GTM) -->
  <script
    src="https://www.cookie-banner.ca/api/scripts/YOUR_BANNER_ID.js"
    async
  ></script>

  <!-- Step 2: Google Tag Manager -->
  <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-XXXXXXX');
  </script>
</head>

Order matters. Our script must be placed before the GTM snippet. This ensures consent defaults are set before GTM initializes and fires any tags.

Next.js App Router with GTM + Cookie Consent

For React/Next.js apps using GTM

// app/layout.tsx
import Script from 'next/script'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <head>
        {/* Step 1: Cookie Consent - loads before GTM */}
        <Script
          src="https://www.cookie-banner.ca/api/scripts/YOUR_BANNER_ID.js"
          strategy="beforeInteractive"
        />

        {/* Step 2: Google Tag Manager */}
        <Script id="gtm" strategy="afterInteractive">
          {`(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-XXXXXXX');`}
        </Script>
      </head>
      <body>{children}</body>
    </html>
  )
}

How Do You Configure GTM Tag Firing Rules for Consent?

Once our cookie banner is deployed, configure your GTM tags to respect consent. Here is how each tag type should be configured.

GTM Trigger: Listen for Consent Events

Create a custom trigger in GTM that fires when consent is granted

// Our banner pushes this to the dataLayer when consent changes:
{
  "event": "cookie_consent_update",
  "consent_analytics": true,    // user granted analytics
  "consent_marketing": false,   // user denied marketing
  "consent_preferences": true   // user granted preferences
}

// In GTM, create a Custom Event trigger:
// Trigger Type: Custom Event
// Event Name: cookie_consent_update
// Fire on: All Custom Events

// Then create Data Layer Variables:
// Variable Name: consent_analytics
// Data Layer Variable Name: consent_analytics

// Use these variables in trigger conditions:
// Fire GA4 tag ONLY when consent_analytics equals true
// Fire Google Ads tag ONLY when consent_marketing equals true

For Google tags (GA4, Google Ads): You do not need custom triggers. These tags have built-in consent checks that read the gtag consent state automatically. The dataLayer events above are for non-Google tags like Facebook Pixel, TikTok, and LinkedIn.

Analytics Tags (GA4)

Automatic
  • GA4 respects Consent Mode V2 natively
  • No custom trigger needed -- just enable "Require additional consent for tag to fire" in the tag settings
  • Set required consent to: analytics_storage
  • GA4 uses behavioral modeling when consent is denied

Advertising Tags (Google Ads)

Automatic
  • Google Ads respects Consent Mode V2 natively
  • Set required consent to: ad_storage, ad_user_data, ad_personalization
  • Conversion modeling fills in data gaps
  • Remarketing audiences continue growing with modeled data

Facebook / Meta Pixel

Custom Trigger
  • Create a Custom Event trigger for cookie_consent_update
  • Add condition: consent_marketing equals true
  • Attach this trigger to your Facebook Pixel tag
  • Pixel only fires when marketing consent is granted

Other Third-Party Tags

Custom Trigger
  • TikTok, LinkedIn, Hotjar, etc. use the same pattern
  • Create a Custom Event trigger for cookie_consent_update
  • Add the appropriate consent condition (analytics or marketing)
  • Tags only fire when the user grants the relevant consent category

How Do You Test GTM Consent Mode V2?

Use GTM Preview mode and the browser console to verify your consent implementation works correctly.

1
Open GTM Preview Mode

Click "Preview" in GTM to open Tag Assistant. Navigate to your site in the new tab.

  • Tag Assistant shows all tags and their firing status
  • You can see consent state changes in real-time
  • Verify that denied tags show "Blocked by consent" status

2
Test Consent Flow

Interact with the cookie banner and verify tag behavior changes:

  • On page load: verify all non-essential tags are blocked
  • Click "Accept All": verify all tags fire
  • Click "Reject All": verify only essential tags fire
  • Use category toggles: verify only consented tag categories fire

3
Verify Consent State in Console

Open browser console and check the consent state:

  • Type: dataLayer.filter(e => e.event === "cookie_consent_update")
  • Verify consent values match the user's banner choices
  • Check that gtag consent default/update calls are logged

4
Publish and Monitor

Once testing passes, publish your GTM container:

  • Publish the container with a descriptive version name
  • Monitor GA4 real-time reports to verify data flow
  • Check Google Ads conversion tracking for any drops
  • Use our cookie scanner to verify no cookies are set before consent

Frequently Asked Questions

Common questions about Google Tag Manager cookie consent and Consent Mode V2

What is Google Tag Manager Consent Mode V2 and why does it matter?

Consent Mode V2 is Google's updated framework for handling user consent signals in GA4, Google Ads, and other Google services. Since March 2024, Google requires Consent Mode V2 for any site running Google Ads in the EU. Without it, your conversion data is incomplete and your remarketing audiences stop growing. Our cookie banner sends the correct consent signals to GTM automatically.

How do I set up cookie consent in Google Tag Manager?

Add our cookie banner script as a Custom HTML tag in GTM, set it to fire on 'All Pages' with the highest priority. Our script automatically pushes consent events to the dataLayer and sends gtag consent updates. Then configure your analytics and advertising tags to use the built-in consent checks. The full step-by-step guide is on this page.

Does this work with GA4, Google Ads, and Facebook Pixel in GTM?

Yes. Our banner automatically manages consent for all tags in your GTM container. Google tags (GA4, Google Ads, Floodlight) use native Consent Mode V2 signals. Non-Google tags (Facebook Pixel, TikTok, LinkedIn) are controlled via dataLayer events and trigger conditions. You set the trigger once, and consent is enforced automatically.

Can I deploy the cookie banner through GTM instead of adding a script tag?

Yes. You can deploy our cookie banner as a Custom HTML tag inside GTM. Create a new tag, paste the script, set the trigger to 'All Pages', and give it the highest tag firing priority. This means you do not need to touch your website code at all -- everything is managed through GTM.

What happens to my Google Ads data if users deny consent?

With Consent Mode V2, Google uses behavioral modeling to estimate conversions from users who denied consent. You still get directional conversion data without violating privacy regulations. Without Consent Mode V2, you lose that data entirely. Our banner ensures the correct consent signals are always sent to Google.

How much does GTM cookie consent setup cost?

Our cookie banner is $99 one-time for the Pro plan. There are no monthly fees, no per-pageview charges, and no usage limits. The free plan lets you build and test your banner. The Pro plan includes unlimited pageviews, custom branding, Consent Mode V2 support, and priority support.

5-minute setup · $99 one-time · Consent Mode V2

Ready to Set Up GTM Cookie Consent?

Build your cookie banner in the visual builder, deploy via GTM or a script tag, and your site has full Consent Mode V2 compliance. Under 10KB, async loading, works with every GTM setup.