How to install GA4 with Google Tag Manager and Consent Mode v2

To install Google Analytics 4 properly in 2026, create a GA4 property with a web data stream, create a Google Tag Manager web container and add its two snippets to every page, set consent defaults before any tag runs (with a consent banner where the law requires one), add the Google tag in GTM, then test in Tag Assistant and DebugView before you publish. Use GTM or a hard-coded Google tag, not both. The 2017 version of this post pasted a tracking code into each page's HTML; that still works, but it leaves consent and every future tag change in your site code.

Key takeaways

  • Order matters: Google's consent-mode guide says "The order of the code here is vital" and the default consent command must run before any measurement command, on every page.
  • Google's EU user consent policy covers end users in the EEA, the UK and Switzerland and requires consent for cookies "where legally required" and for personal data used for ad personalisation.
  • Basic consent mode blocks Google tags until the visitor chooses; advanced mode loads them with denied defaults and sends "measurements without cookies" until consent is granted.
  • Google warns that using both a hard-coded Google tag and Tag Manager can overcount your data.
  • On our own site, a Cookiebot banner appears only for visitors in the EEA, UK and Switzerland, and we run advanced Consent Mode.

What do you need before you start?

Three decisions and two accounts.

  • Consent approach. Which regions need a banner, and basic or advanced consent mode. This is a legal and business decision as much as a technical one; the notes in this article are general information, not legal advice.
  • A consent management platform (CMP). If you need a banner, choose one with a Tag Manager template. Google's Tag Manager help says its featured CMPs "have templates available in the Tag Manager Community Template Gallery".
  • What to measure. Page views come automatically; list the few actions that matter to the business (form sent, call booked) before you build. Our GA4 event plan for a lead-generation website is a ready template.
  • Accounts: a Google Analytics account and a Tag Manager account, both owned by the business, not by a contractor.

Step 1: How do you create the GA4 property and data stream?

From Google's Analytics help:

  1. At analytics.google.com, go to Admin, Create, Account, and name the account.
  2. Create a property: name, reporting time zone and currency, then industry and business size.
  3. In Admin, Data streams, Add stream, Web, enter your website URL and a stream name, and create the stream.
  4. Leave enhanced measurement on; Google says it "automatically collects page views and other events". You can switch individual events off later.
  5. Note the stream's measurement ID (it starts with "G-"). You will paste it into Tag Manager.

Step 2: How do you create and install the Tag Manager container?

  1. At tagmanager.google.com, create an account and a container of type Web, named after your site's top-level address. One container covers the whole site.
  2. Tag Manager shows two snippets. Google's help is specific about placement: the first goes as high in the <head> of every page as possible, and the second (a noscript iframe) immediately after the opening <body> tag.
  3. If the site already has a hard-coded Google tag (gtag.js) for the same property, remove it. Google's troubleshooting page says to use one method or the other, because using both can overcount.
  4. On a CMS, use the platform's Tag Manager integration or a theme setting rather than editing templates, so updates do not remove the snippet.

Step 3: How do you set Consent Mode v2 defaults?

Consent mode tells Google tags what the visitor has agreed to. The four signals Google's tags read are:

Signal What it controls
ad_storage Advertising cookies; when denied, "new cookies won't be set for advertising purposes"
ad_user_data "Sending user data related to advertising to Google"
ad_personalization "Personalized advertising"
analytics_storage Analytics cookies

"Consent Mode v2" is the common name for the version that added ad_user_data and ad_personalization. Google's consent-mode concepts page says denying ad_user_data disables personal data collection for online advertising, including enhanced conversions.

Set the defaults in one of two ways:

  • Through the CMP template in Tag Manager, fired on the Consent Initialization trigger. Google says this trigger is "designed to help you ensure that all consent settings are honored before any other triggers fire".
  • With a short gtag('consent', 'default', ...) script placed before the Tag Manager snippet, which the CMP then updates.

Either way, three settings deserve attention:

  • Regions. You "can set defaults for specific regions, and then set a different default for all other regions", using ISO 3166-2 codes. The more specific region wins when they overlap.
  • wait_for_update. "If your banner loads asynchronously, it might not always run before your Google tags." A wait value in milliseconds gives the banner time to apply a stored choice.
  • Basic or advanced. In basic mode, tags do not load until the visitor interacts with the banner, and nothing is sent if they decline. In advanced mode, tags load with the defaults, send cookieless measurements while consent is denied, and Google uses an advertiser-specific conversion model rather than a general one.

On impingesolutions.com we use advanced Consent Mode, and our Cookiebot banner appears only for visitors in the EEA, the UK and Switzerland, the regions Google's EU user consent policy names. Our privacy policy describes this. Our GTM and Consent Mode write-up explains the full build, including click IDs and enhanced conversions.

Step 4: How do you add GA4 in Tag Manager?

  1. In the container's workspace, create a new tag and choose Google tag.
  2. Enter your measurement ID in Tag ID.
  3. Set the trigger to Initialization - All pages, as Google's Tag Manager help instructs.
  4. Leave the tag's built-in consent checks in place. Google tags have consent checks built in that change how they run depending on consent, and the container's Consent Overview shows "a high level view of all the consent settings across the tags in your container".
  5. Add GA4 event tags for your key actions, ideally triggered by dataLayer events your site pushes (for example generate_lead when a form succeeds), rather than by fragile click selectors.

Step 5: How do you test before publishing?

Do not publish until all four checks pass.

  1. Tag Assistant preview. Tag Manager's preview mode lets you browse the site "as if the current container draft was deployed" and "inspect which tags fired and in which order". Confirm the consent defaults fire first, then the Google tag.
  2. Consent behaviour. Test from a region that gets the banner (or with your CMP's test setting): decline, then accept, and watch the consent state change in Tag Assistant.
  3. GA4 DebugView. With Tag Assistant connected, your events appear in DebugView within seconds. Google notes that events will not appear "if consent mode is active and the user hasn't consented to Analytics cookies", so accept analytics while testing.
  4. Realtime. After publishing, click around and check the Realtime report. Google says data collection can take up to 30 minutes to begin.

Then Submit and publish the container version with a clear description. Google's troubleshooting page reminds that unpublished changes collect nothing.

Step 6: Which GA4 settings should you change after install?

  • Key events. In Admin, Events, click the star next to an event to mark it as a key event (the actions that matter to the business).
  • Data retention. Choose 2 or 14 months for user-level data. Google says this setting "only affects explorations and funnel reports", not standard reports. We suggest 14 months unless you have a reason to keep less.
  • Internal traffic. Define internal traffic by IP in the web stream's tag settings, create a data filter in Testing state, check it, then switch it to Active. Google warns that active filters change data permanently.
  • Consent settings check. In Admin, Data collection and modification, Consent settings, check that advertising and analytics consent signals are arriving; Google says notifications can take 48 to 72 hours to update after a change.
  • Links. Link Google Ads and Search Console to the property if you use them.

For how to report honestly when many visitors decline cookies, see analytics when visitors decline cookies.

When should you get help?

When the site has several forms, booking tools, phone and chat buttons, or ads that bid on conversions, small tracking mistakes become expensive. If you would rather hand the work over, see our digital marketing and SEO services and our Google Analytics development page.

FAQ

Do I need Google Tag Manager to use GA4?

No. You can paste the Google tag directly into every page. Tag Manager is worth it once you have consent requirements, more than one tag, or people other than developers who need to change tracking.

Can I install both the Google tag and Tag Manager?

Google recommends using one or the other. Using both for the same property can overcount your data.

Do I need a cookie banner?

It depends on where your visitors are and what you collect. Google's EU user consent policy requires consent for end users in the EEA, the UK and Switzerland. This is general information, not legal advice.

What is the difference between basic and advanced consent mode?

Basic mode blocks Google tags until the visitor responds to the banner and sends nothing if they decline. Advanced mode loads tags with denied defaults and sends cookieless measurements until consent is given, which supports more detailed conversion modelling.

Why do my events not show in DebugView?

Check that Tag Assistant is connected, the container draft is in preview, and you have accepted analytics consent. Google notes that DebugView does not show events when analytics consent has not been given.

How long until GA4 shows data?

Google says data collection can take up to 30 minutes to start; use the Realtime report to confirm. Its troubleshooting page adds that new data can take up to 24 hours to process in reports.

Sources (15 links)
Share this article