Consent-first GTM and GA4 on a Netlify site

How ricardoze.in loads Google Tag Manager only after analytics consent, preserves a usable no-consent experience and keeps event ownership in one place.

Consent acting as a gate before Google Tag Manager and GA4Measurement begins after an explicit choice, while the site remains useful either way.Visitor01Consent gate02GTM03GA4 events04
Measurement begins after an explicit choice, while the site remains useful either way.

01 / The field note

Analytics should be part of the product architecture, not a script pasted into the page. On this site, the requirement was simple: use GTM and GA4, respect an explicit consent choice and keep the implementation small enough to understand without a paid consent platform.

01

Start from default denied

The page initializes consent state before it loads analytics. Until the visitor opts in, analytics storage remains denied and the GTM container is not invited to make the decision on its own.

The banner explains the purpose in plain language, offers equivalent accept and reject actions and exposes cookie settings again in the footer. Refusal is a supported product state, not an error path.

02

One measurement layer

GA4 is configured inside GTM rather than installed as a second independent page script. The application pushes named events into one data layer for booking clicks, form progress and successful submissions.

This keeps event naming, consent behaviour and environment checks in one place. It also reduces the chance that two implementations count the same page view.

03

Test the states, not only the tags

The QA matrix includes a first visit, acceptance, rejection, reopening preferences and withdrawing a prior choice. The network panel is checked before and after consent, and functional actions must work in every state.

GTM Preview and GA4 DebugView validate the measurement path. Browser storage and request inspection validate the privacy claim. Both are needed.

04

Keep ownership visible

The legal page lists the operator, purpose, lawful basis, retention context and third-party processor. Event names live in the codebase, while marketing configuration lives in the GTM workspace.

That boundary lets the site evolve without hiding what data is collected or who can change the measurement logic.

03 / Working principles

The reusable part

What to carry into the next system.

  1. 01

    Initialize analytics consent before loading Google measurement scripts.

  2. 02

    Install GA4 through GTM once, not through competing page integrations.

  3. 03

    Test accept, reject, revisit and withdraw states as separate journeys.

  4. 04

    Keep business events named in code and tag configuration reviewable.

05 / Contact

AI · AWS · DevOps · WordPress · Software

Need this kind of decision in your system?

A discovery call is enough to map the constraint, identify the evidence still missing and decide on the smallest useful intervention.

Start with the problem

Tell me what needs to move.

A short description is enough. I will review it personally and reply with a useful next step.

By sending this enquiry, you confirm that you have read how the information is handled in Legal & privacy.