Google Tag Manager + consenso ai cookie: configurazione completa
Configura GTM per attivare i tag solo dopo il consenso dell'utente. Setup dei trigger, mappatura dei segnali di consenso, importazione del template community e verifica con Anteprima.
Pubblicato il
Google Tag Manager and cookie consent should fit together cleanly, and since the GTM 2022 redesign they mostly do. But the integration has enough moving pieces that a fresh setup usually takes a couple of hours to get right, and a misconfigured one is the most common reason I see GA4 data “disappearing” from a site that recently added a banner.
This guide covers the built-in consent settings, the two integration patterns (CMP as a GTM tag vs CMP outside GTM), the community template route, and how to actually verify it's working before you ship.
GTM's built-in consent layer
In 2022 Google added a Consent Overview page to every GTM container (Admin → Container Settings → Additional Settings → Enable consent overview). Once enabled, every tag in the container gets two new sections in its configuration:
- Built-in consent checks — does this tag need
ad_storageoranalytics_storageor both? Tags from Google's own templates (GA4, Google Ads) come pre-filled with the right values. Third-party templates (Hotjar, Meta Pixel) might or might not. - Additional consent checks — custom consent signals beyond the four GCM v2 standard ones. You can require, say,
functionality_storagefor a chat widget.
GTM checks these against the current consent state (managed by your CMP via gtag('consent', 'update', ...)) before allowing the tag to fire. If consent isn't granted, the tag silently doesn't fire. No error, just no execution.
The two integration patterns
Pattern A: CMP as a GTM tag. Your CMP ships as a Custom Template from the GTM Community Template Gallery. You import the template, create a tag using it, and set the trigger to Consent Initialization. The CMP loads first, sets defaults, and fires consent updates as the visitor interacts with the banner. Other tags (GA4, Meta) sit behind their built-in consent checks and fire only after the CMP unlocks them.
Pattern B: CMP outside GTM. Your CMP loads via a standalone <script> tag in <head> (outside GTM's control). It calls gtag('consent', ...) directly, which GTM picks up via its consent layer. GTM's built-in checks still gate the tags, but GTM doesn't know about the CMP itself.
Pattern A is cleaner when GTM is the source of truth for tag management. Pattern B is simpler when the CMP team and the analytics team are different groups. ConsentTrustee supports both. Most teams pick Pattern B unless they specifically want the CMP managed inside GTM.
The Consent Initialization trigger
GTM has a special trigger called Consent Initialization — All Pages. It fires before any other trigger (before Initialization, before Page View, before everything). Tags attached to it run first, which is exactly what you want for a CMP that needs to set consent defaults before any analytics tag has a chance to fire.
If you're using Pattern A, attach your CMP tag to the Consent Initialization trigger. If you're using Pattern B, the CMP's standalone script tag effectively does the same thing (loads before GTM via async in the page head).
What “consent default” looks like in GTM
Either pattern, you need a Consent Default to set initial signals to denied for non-essential categories before any tag fires:
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
wait_for_update: 500
});With Pattern A, the CMP's GTM template ships this as part of its initialization. With Pattern B, your standalone CMP script handles it. Either way, it has to run before any Google tag has a chance to fire its first pageview.
The community template gallery
The GTM Community Template Gallery is where CMPs publish their official integrations. To import: in your GTM workspace, go to Templates → New (under Tag Templates) → Search Gallery → search for “ConsentTrustee” (or your CMP). Click Add to Workspace, accept the permissions, then you can create tags using the template like any built-in tag type.
Community templates are sandboxed JavaScript that runs inside GTM with limited API access. They're safer than custom HTML tags and they don't need your developer to maintain custom code. The trade-off is that template authors can't do everything you might want, and updates ship on the template author's schedule.
Verifying it works (the part everyone skips)
The honest answer is that GTM + consent is hard to verify because most signals are invisible. The tests that actually work:
Use Preview mode. GTM Preview opens a debug panel showing every tag that fires and every consent check. Look for the Consent column. Tags that pass should show ✓, tags blocked should show a clear reason.
Check Network tab for gcs parameter. In DevTools, load your site in incognito. Find requests to google-analytics.com/g/collect. The gcs URL parameter shows the consent state at the time the ping was sent. G100 means both ad and analytics denied. G111 means both granted. You should see G100 on first pageview (before consent), transitioning to G110 or G111 after the visitor accepts.
Test with Google Tag Assistant. The Chrome extension shows the consent signal state for each event and flags mismatches.
If you see tags firing when consent should be denied, the usual cause is a tag without the right built-in consent check. Edit the tag, expand the Consent Settings section, and add the required signal. If you see consent updates not propagating, the usual cause is timing: the CMP fires update before GTM has finished initialising. The Consent Initialization trigger and wait_for_update: 500 together handle this in most cases.
The mistakes I see most often
Forgetting to enable the Consent Overview. Without it enabled in container settings, the per-tag consent checks aren't enforced. Tags fire regardless of consent state. Fix: Admin → Container Settings → check “Enable consent overview”.
Missing the v2 signals on existing tags. Tags configured before March 2024 might only have the original two GCM signals (ad_storage, analytics_storage). Audit every Google Ads / Floodlight tag and ensure ad_user_data and ad_personalization are also in the consent check.
Tags without any consent check. Custom HTML tags don't inherit built-in consent automatically. You have to manually add the consent requirements in the tag's Advanced Settings → Consent Settings.
Race condition between CMP and GTM. Both load async, and the first GA pageview can fire before the CMP's consent update. Solutions: wait_for_update in defaults, Consent Initialization trigger for the CMP, and making the CMP's script tag synchronous (no async) if needed.
What I'd read next
Google Consent Mode v2 for the underlying signal protocol GTM uses. Block Third-Party Scripts for the lower-level pattern that works outside GTM. And What Is a CMP for the broader system the GTM piece fits into.