Code BLACKGO: cookie banner free for a year. Create an account →

Publications / Analytics and marketing

GA4 and cookie consent – how to block Google Analytics until consent

Google Analytics 4 stores its own cookies in the browser, so on a website in the EU it may set them only after consent. We show three GA4 setups with the banner, the Consent Mode modes and what a refusal means for your reports.

Author: Robert.S Published: Updated: 10 min read

GA4 and cookie consent – how to block Google Analytics until consent

Google Analytics 4 stores cookies with an identifier in the visitor’s browser. On a website visited by people from the EU, such storage requires consent, and the GA4 tag may store cookies only after it. Below we explain which cookies GA4 sets, where the consent requirement comes from, how to set up GA4 with the banner in three typical configurations and what to expect in your reports.

Which cookies GA4 stores

The GA4 tag (gtag.js or a tag in Google Tag Manager) uses first-party cookies, i.e. cookies stored in your website’s domain. According to the Google Analytics documentation, there are two:

CookieDefault expirationWhat it is for
_ga2 yearsdistinguishes users
_ga_<container-id>2 yearspersists session state

The expiration can be changed in the Google Analytics property settings. Browsers also shorten the life of cookies when the user does not return to the website – Google gives a limit of 400 days in Chrome and 7 days in Safari. If the GA4 property is linked to a Google Ads account, the tag may store further cookies for ad measurement.

The basis is Article 5(3) of the ePrivacy Directive (2002/58/EC). Storing information on the user’s device, or reading information already stored there, is allowed after consent. Without consent, only what is strictly necessary for a service the user asks for may be stored – e.g. a login session, a cart or remembering the choice made in the banner. Visit statistics do not belong to this group. Each Member State implements this rule in its national law, e.g. Germany in § 25 TDDDG and France in Article 82 of the Informatique et Libertés Act (national laws).

In Planet49 (C-673/17), the Court of Justice of the EU held that consent is needed regardless of whether the stored information is personal data. When cookies are used to process personal data – and analytics tools usually do this – the GDPR rules also apply: consent must be freely given, specific, informed and unambiguous, and withdrawing it must be as easy as giving it.

In practice, this means the GA4 tag should not load before the visitor consents to analytics. We describe the legal details on the ePrivacy Directive and GDPR pages. The website owner is responsible for assessing their own website – if in doubt, it is worth asking a lawyer.

Are you adding GA4 from scratch or is it already on your website?

First find out whether GA4 is already running on the website. Adding new code and blocking existing code are two different tasks – mixing them up ends in double counting or a tag that runs without consent.

SituationWhat to do
GA4 is not on the website yetenter the G-XXXXXXXXXX ID in the module (described below) or add a GA4 tag in Google Tag Manager if the website already uses it – do not paste the code into the template
GA4 is in the theme, a plugin or the templatedo not add anything; run the browser scan – the module will recognise GA4; in advanced Consent Mode (default) GA4 sets no cookies until consent, in basic mode it waits for consent
GA4 is in GTMrun the scan; GTM and GA4 inside it wait for consent according to their category
you do not know where the code isin the developer tools (Network tab), click the request to googletagmanager.com and check the Initiator column – it shows the file or script that triggered it

Three ways to set up GA4 with the banner

How you block GA4 depends on where the code is. Below we describe how the consetgo consent module handles each case. In the consent panel, GA4 can only belong to the Analytics or Marketing category – it cannot be marked as a necessary service.

GA4 code in the theme, in a plugin or pasted by hand

If the GA4 code is already on the website, you do not enter anything. In the consent panel, open the Scanner tab, click “Enable scan mode”, then “Open the site in scan mode”, and go through a few pages. The scanner will recognise GA4. By default the module works in advanced Consent Mode: the GA4 tag loads straight away with “denied” signals, sets no cookies before consent and sends only cookieless signals to Google. After you switch off advanced mode (Settings → Integrations), the module blocks GA4 on the server: the script reaches the browser in a form the browser will not execute, and it starts only after consent to its category.

GA4 through Google Tag Manager

The browser scan also sees tags added through Google Tag Manager. By default, GTM is a container in the module (“Container: analytics or marketing”), and the tags inside it are blocked separately, according to their own category. In advanced Consent Mode (default), the container loads straight away, the Google tags inside set no cookies until consent, and third-party tags (e.g. Meta Pixel) wait for consent. In basic mode, the container loads after consent to analytics or marketing – as in the table below.

Visitor’s consentWhat loads in basic Consent Mode (GTM as a container, with GA4 and Meta Pixel inside)
no consentnothing
analytics onlyGTM and GA4, pixel blocked
marketing onlyGTM and the pixel, GA4 blocked
alleverything

If the container sends data in a way the module cannot see in the browser – e.g. server-side GTM or tags that send data in the background – assign GTM to the Marketing category. Then the whole container waits for consent to marketing.

GA4 ID entered in the module

If GA4 is not on the website yet, you can add it from the consent panel. In the Services and categories tab, expand the Google Analytics 4 service and enter the measurement ID in the G-XXXXXXXXXX format in the “Code” field. The module will insert the script on the website itself: in advanced Consent Mode straight away, with “denied” signals, in basic mode after consent. You can do the same in the Tracking scripts tab. Do not enter the ID in the “Name” field – that is the name visitors see.

Leave the “Code” field empty if GA4 is already in the theme or in GTM. Otherwise the website will send data to Google twice.

  1. Open the website in a private browser window so that no earlier consent is saved.
  2. Before you click anything in the banner, open the developer tools (F12). In the cookies tab for your domain there should be no _ga or _ga_… cookies, and in the network tab no requests to Google Analytics.
  3. Click “Reject all” or accept only necessary cookies and go to another page. There should still be no _ga cookies.
  4. Click the cookie settings icon, switch on the Analytics category and save your choice. The page will reload, and the _ga cookies will appear shortly. You will see the visit in the Realtime report in GA4.

If GA4 sets cookies before consent (or, in basic mode, loads before consent), run both scans again in the Scanner tab and check that the service is enabled in “Services and categories”. Also clear the website cache (e.g. of a cache plugin) and the CDN.

What GA4 reports show when a visitor refuses

For people who refused consent to analytics, GA4 receives no complete data: in advanced Consent Mode (default in consetgo) only cookieless signals, in basic mode nothing. The reports therefore cover mainly visitors who gave consent. The number of users and sessions usually drops after the banner is switched on. When comparing periods, note the date the banner went live, and draw conclusions from ratios, such as the conversion rate, rather than from absolute numbers.

Google describes two ways Consent Mode can work. In basic mode, Google tags are blocked until consent – this is how blocking works in consetgo. In advanced mode – the default in consetgo from version 1.3.49 – the tag loads straight away and, without consent, sends cookieless pings from which GA4 can model the missing data. According to the behavioural modelling documentation, modelling requires, among other things, tags that load in every case, not only after consent, at least 1,000 events per day with consent denied for 7 days, at least 1,000 daily users with consent granted for 7 of the last 28 days, and the “Blended” reporting identity in the property settings. Meeting these conditions does not guarantee modelling. We describe the differences between the modes in the article on Google Consent Mode v2 and on the Google Consent Mode v2 page.

The traffic source is kept. The first decision in the banner does not reload the page, so after consent GA4 learns whether the visitor came from a search engine, a campaign or another website. Changing a previously saved consent reloads the page so that newly allowed scripts start working straight away and withdrawn ones stop.

The most common mistakes with GA4 and the banner

  • GA4 inserted twice – in the theme and in the “Code” field, or in the theme and in GTM. Keep one source.
  • Pages from an HTML cache without PHP – the panel then shows “Limited mode — scripts are not blocked.” Exclude such pages from the cache or use a cache plugin that runs PHP (WP Super Cache, W3 Total Cache and WP Rocket work with the module).
  • No scan after changes – after adding a new plugin or a tag in GTM, run the browser scan again.

We describe how server-side blocking works on the How consetgo works page, and the list of panel settings in Features. You can try the module on your domain for 14 days free of charge.

Questions and answers

Can GA4 run as a necessary service, without consent?

Not in consetgo. GA4 can only be assigned to the Analytics or Marketing category, because it stores a user identifier in the browser, and the website does not need that to work.

I have GA4 in Google Tag Manager. Do I need to enter the G- ID in the consent panel?

No. Leave the “Code” field empty. The browser scan will detect GTM and the tags it loads, and the module will block third-party tags until consent; Google tags in advanced Consent Mode (default) work until consent without cookies.

Why does GA4 show fewer users after the banner is switched on?

For people who refused consent to analytics, GA4 receives no complete data: in advanced Consent Mode only cookieless signals, in basic mode nothing. The reports then cover mainly visitors who gave consent, and Google may model part of the missing data.

After consent, will GA4 see where the visitor came from?

Yes. The first decision in the banner does not reload the page, so GA4 gets the traffic source: the search engine, the campaign or the website the visitor came from.

Read also