Home / Fix guides / Analytics, cookies and GDPR

Google Analytics tracking before cookie consent: how to check and fix it

If Google Analytics sets cookies or sends data before a visitor clicks your cookie banner, your consent setup is not working. The fix is to stop the Analytics tag loading until the visitor agrees, then prove it with a clean browser test.

Many sites show a cookie banner but still run Google Analytics the moment the page loads. The banner records a choice, yet nothing is actually blocked. Visitors cannot see this, so most owners only find out when they test it. This page shows you how to test it for free and how to fix it.

What the problem looks like

You open your site, a banner asks about cookies, and behind it the page has already set _ga cookies and sent a request to Google. Typical causes:

  • The Analytics code is pasted straight into the theme header, outside the control of your consent tool.
  • Analytics is added twice: once by a plugin or platform setting and once in Google Tag Manager (GTM).
  • The banner only stores the visitor's answer and does not block any scripts.
  • Consent Mode is missing, or its default state is set to granted instead of denied.
  • The GA4 tag in GTM has no consent condition, so it fires on every page.

Why it matters

In the EU and UK, analytics cookies are generally treated as needing consent before they are set. Details vary by country and by how your setup works, and this page is not legal advice. The practical risks are easy to see:

  • Trust: a banner with a Reject button that still tracks people is a broken promise, and it is the kind of thing a privacy-minded visitor or a competitor can spot in a minute.
  • Complaints and sales: larger customers and partners increasingly ask about privacy practices before they buy.
  • Data quality: once you fix this, your Analytics numbers will usually drop, because visitors who decline are no longer counted. That drop is the correct picture, not a new fault.

How to check if your site has it

You only need a browser. Use a private window and turn off any tracker-blocking extension, or the test will show nothing.

  1. Open a new private or incognito window and go to your site. Do not click anything on the banner.
  2. Press F12 to open developer tools and go to the Network tab. Tick Preserve log, then reload the page.
  3. In the filter box type collect. Look for requests to google-analytics.com/g/collect or analytics.google.com.
  4. Open the Application tab (called Storage in Firefox), then Cookies, and select your site. Look for _ga and a cookie starting with _ga_ followed by your measurement ID.
  5. Repeat in a fresh private window, this time clicking Reject, and check again.

If you see the collect requests or the _ga cookies before any choice, or after Reject, Analytics is running without consent. You can also use Tag Assistant preview in GTM, which shows the consent state next to each tag.

One nuance: with Google Consent Mode and analytics_storage set to denied, Google tags may still send cookieless pings without setting cookies. Whether that is acceptable for you depends on your setup and your advisor. See Google Consent Mode v2 missing for how that part works.

How to fix it in general

  1. Find every place Analytics is added. Check the theme header, plugins or apps, platform settings and GTM. Keep one copy and remove the rest.
  2. Use a consent tool that really blocks scripts. Well-known options include Cookiebot, Usercentrics and, on WordPress, Complianz. A banner that only displays text is not enough.
  3. Set the default to denied. The consent tool should set the default consent state before any Google tag loads. In GTM this is normally done with the consent tool's template on the Consent Initialization trigger.
  4. Add a consent condition to the GA4 tag. In GTM open the tag, go to Advanced Settings, then Consent Settings, and require analytics_storage. The Consent Overview screen in your container lists tags that have no consent set.
  5. Make Reject as easy as Accept. Both buttons should be on the first layer of the banner.
  6. Save, publish and retest with the steps above.

Common platforms

Menu names change between versions and themes, so treat these as pointers for where to look.

PlatformWhere to look
WordPressAnalytics plugin settings, header.php or a theme options box, and your consent plugin's script blocking. See the WordPress guide.
ShopifySettings, then Customer privacy, and the way your Google channel or pixel is added. See the Shopify guide.
Google Tag ManagerConsent settings on the GA4 tag and a consent default on Consent Initialization. See the GTM guide.
WixThe cookie banner settings and where Analytics is connected under marketing integrations.
SquarespaceCookie and visitor data settings, and the Analytics connection in the same area.
WebflowProject settings and any custom code in the head. Depending on your setup, Webflow may need a separate consent tool.

Guides for the other platforms are linked from the Google Analytics 4 guide.

How to confirm the fix worked

Run the same test in three situations, using a fresh private window each time:

  • No choice made: there should be no collect requests with cookies and no _ga cookies.
  • Reject clicked: still no _ga cookies and no full tracking requests.
  • Accept clicked: the _ga cookies appear and collect requests are sent. Then check the GA4 Realtime report to see your visit.

If Accept stops working after your changes, the consent update is probably not reaching the tag. Check that the tag fires after the consent update, not only on page load.

How to stop it coming back

This problem often returns quietly after a change that nobody linked to tracking.

  • Decide who owns tracking code on your site, and write down where Analytics is meant to be added.
  • Retest after theme updates, plugin updates, banner changes and any new tag added to GTM.
  • Ask your developer to add new marketing scripts through GTM with consent conditions, not by pasting them into templates.
  • Keep your cookie and privacy pages current. See no cookie policy page if you do not have one yet.

Week 27 of SiteMonday is the GDPR and cookie consent check, so this kind of problem appears in a written report with a ranked fix list. SiteMonday finds and explains it, and the fix itself is for you or your developer to make. More detail is on the week 27 page.

Step by step for your platform

Questions

Is it a problem if Google Analytics loads but sets no cookies?

It depends on your setup and legal advice. With Consent Mode denied, Google tags may send cookieless pings, which some businesses accept and others do not. Check what is actually sent in the Network tab and ask your advisor.

Will my Analytics numbers drop after I fix this?

Usually yes, because visitors who decline are no longer counted. The lower number is a more honest picture of consenting visitors.

Is a cookie banner enough on its own?

No. The banner must control the scripts, so Analytics does not load until the visitor accepts. Testing in a private window shows whether it does.

Do I need Google Tag Manager to fix this?

No. You can fix it with a consent tool that blocks the Analytics script, or with your platform's own consent settings. GTM just gives you finer control through consent conditions on each tag.

Why does Analytics still track after I clicked Reject?

Often a second copy of the code sits in the theme or a plugin, outside the consent tool. Search for every place Analytics is added and keep only one.

How often should I retest?

After any change to your theme, plugins, banner or tags, and at least a few times a year. Consent setups break quietly when something is updated.

Related problems