Skip to content

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.

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 dataLayer

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>

truConsent groupGTM Consent Mode type(s)
Necessarysecurity_storage
Analytics / Statisticsanalytics_storage
Marketing / Advertisingad_storage, ad_user_data, ad_personalization
Functional / Personalisationfunctionality_storage

  1. In GTM, go to Admin → Container Settings.
  2. Enable “Enable consent overview”.
  3. Click Save.

Every tag in your container now has a Consent tab in its settings.


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.)

  1. Open the tag in GTM.
  2. Go to Advanced Settings → Consent Settings.
  3. Select “Require additional consent for tag to fire”.
  4. Add the relevant type (analytics_storage, ad_storage, etc.).

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

  1. Go to Triggers → New.
  2. Type: Custom Event.
  3. Event name: tru_consent_update.
  4. Fires on: All Custom Events.
  5. 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 accepts

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.


  1. Open your site with GTM Preview Mode active.
  2. On first load, confirm all consent types show denied in the Consent tab.
  3. Click Accept All on the cookie banner.
  4. Confirm the Consent tab updates to granted for the relevant types.
  5. Confirm tru_consent_update appears in the event list.
  6. Check that consent-gated tags fired after the update event.