Skip to main content
AnalyticsLearner

Module 3

GA4 base config through GTM (consent-gated)

Configure a GA4 tag in GTM that fires only when analytics_storage is granted. The correct implementation of GA4 with Consent Mode v2.

ga4gtmconsent-mode-v2

What this does

A GA4 Configuration Tag in GTM fires on all pages and initialises the GA4 measurement session. When Consent Mode v2 is active, the tag must be gated on analytics_storage: 'granted'. Otherwise it fires without consent, which breaks GDPR compliance.

This snippet shows the data layer pattern and the GTM tag configuration required to implement this correctly.

Data layer (page-level push)

You do not need to push a custom event for GA4 page_view: GA4 fires this automatically when the Configuration Tag fires. The required setup is the Consent Mode default-deny baseline (see Consent Mode v2 default-deny baseline).

For custom events, push to dataLayer like this:

// Generic GA4 custom event push
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: 'custom_event_name',
  // Custom parameters - use snake_case to match GA4 parameter naming
  parameter_name: 'parameter_value',
  numeric_value: 0,
});

GTM tag configuration

In the GTM UI, configure the Google Tag (GA4):

Tag type:          Google Tag
Tag ID:            G-XXXXXXXXXX   ← your GA4 Measurement ID
Triggering:        All Pages
Consent settings:  Require analytics_storage

The "Require analytics_storage" consent check is what gates the tag. Do not rely on a custom trigger to handle consent. Use GTM's built-in consent checking.

What fires in GTM Preview (denied path)

When analytics_storage is 'denied', the GA4 tag shows "Blocked by consent settings" in the GTM Preview Summary. It does not fire. This is the correct behaviour.

What fires in GTM Preview (granted path)

When analytics_storage is 'granted' (after the visitor accepts), the GA4 tag fires and GA4 DebugView shows a page_view event.

Verification checklist

  1. Open GTM Preview on your site
  2. Confirm consent_default fires before gtm.js in the Summary
  3. Confirm GA4 tag shows "Blocked by consent settings" on page load
  4. Accept consent via the banner
  5. Confirm consent_update fires with analytics_storage: granted
  6. Confirm GA4 tag fires after the update
  7. Confirm GA4 DebugView shows page_view in the GA4 property

The free GA4 + Consent Mode v2 Starter Container has this configuration pre-built.

Free container for this module

GA4 + Consent Mode v2 Starter Container

A pre-built GTM container that implements the Consent Mode v2 default-deny baseline, region-aware EEA/UK settings, and a GA4 Configuration Tag gated on analytics_storage. Drop it into any GTM account and connect your CMP.

Get the container →