GTM & Google Consent Mode
truConsent fires Google Consent Mode signals automatically when the user makes a choice. No custom GTM variables are required for the core setup — you only need to confirm script order and enable Consent Mode in your container.
How it works
Section titled “How it works”Page load → SDK fires gtag('consent', 'default', { all: 'denied' }) → GTM loads but all tags respect the denied state → User clicks "Accept All" → SDK fires gtag('consent', 'update', { all: 'granted' }) → Consent-aware tags (GA4, Google Ads) activate immediately → tru_consent_update pushed to dataLayerStep 1 — Script order
Section titled “Step 1 — Script order”The truConsent script must be placed before the GTM snippet so consent defaults are set before GTM initialises any tags.
<head> <!-- 1. truConsent — sets consent defaults --> <script src="https://cdn.truconsent.io/cmp.min.js" data-banner-type="cookie-consent" data-api-url="%VITE_TRU_CONSENT_API_URL%" data-api-key="%VITE_TRU_CONSENT_API_KEY%" data-org-id="%VITE_TRU_CONSENT_ORGANIZATION_ID%" data-asset-id="%VITE_TRU_CONSENT_ASSET_ID%"> </script>
<!-- 2. GTM — loads after defaults are set --> <script>(function(w,d,s,l,i){...})(window,document,'script','dataLayer','GTM-XXXXXXX');</script></head>Step 2 — Consent category mapping
Section titled “Step 2 — Consent category mapping”| truConsent group | GTM Consent Mode type(s) |
|---|---|
| Necessary | security_storage |
| Analytics / Statistics | analytics_storage |
| Marketing / Advertising | ad_storage, ad_user_data, ad_personalization |
| Functional / Personalisation | functionality_storage |
Step 3 — Enable Consent Mode in GTM
Section titled “Step 3 — Enable Consent Mode in GTM”- In GTM, go to Admin → Container Settings.
- Enable “Enable consent overview”.
- Click Save.
Every tag in your container now has a Consent tab in its settings.
Step 4 — Configure tag consent requirements
Section titled “Step 4 — Configure tag consent requirements”Tags with built-in consent (GA4, Google Ads) — fire automatically in restricted mode when denied, fully when granted. No extra configuration needed.
Tags without built-in consent (Facebook Pixel, Hotjar, etc.)
- Open the tag in GTM.
- Go to Advanced Settings → Consent Settings.
- Select “Require additional consent for tag to fire”.
- Add the relevant type (
analytics_storage,ad_storage, etc.).
Step 5 — Fire tags immediately after consent is granted
Section titled “Step 5 — Fire tags immediately after consent is granted”Tags with an “All Pages” trigger have already fired by the time the user accepts on the same page. Add a tru_consent_update trigger to catch same-page grants.
Create the trigger
- Go to Triggers → New.
- Type: Custom Event.
- Event name:
tru_consent_update. - Fires on: All Custom Events.
- Save as
Event - tru_consent_update.
Add it to your tags
GA4 Configuration tag Triggers: ✓ All Pages ← fires on load if already consented ✓ Event - tru_consent_update ← fires the moment the user acceptsdataLayer events reference
Section titled “dataLayer events reference”On page load
{ event: 'tru_consent_default', tru_consent: { analytics: false, advertising: false, functional: false }}When the user makes a choice
{ event: 'tru_consent_update', tru_consent: { analytics: true, advertising: false, functional: true }, tru_consent_action: 'accept_all' // 'reject_all' | 'save_preferences'}Read individual values in GTM using a Data Layer Variable with name tru_consent.analytics.
Verification
Section titled “Verification”- Open your site with GTM Preview Mode active.
- On first load, confirm all consent types show
deniedin the Consent tab. - Click Accept All on the cookie banner.
- Confirm the Consent tab updates to
grantedfor the relevant types. - Confirm
tru_consent_updateappears in the event list. - Check that consent-gated tags fired after the update event.