Cookie consent bannerTracker fires before consent

Tracking scripts load before cookie consent: how to block them until users agree

A consent banner only works if every optional tracker waits for the visitor's choice. Scripts added directly to the page, injected by a plugin, or loaded by a tag manager can run before anyone clicks. Load the site as a new visitor, list every third-party request and cookie before a choice and after Reject, then block anything optional until consent is given.

This guide covers check 09: Compliance and audit surface in the Zenveus Production Readiness Standard.

For builders

What this means, in plain words

A cookie banner asks visitors what they agree to, but it doesn't stop anything by itself. If a tracking script is pasted into the site or added by a plugin, it can run before anyone clicks, or even after they click Reject. Check what loads for a brand-new visitor and for someone who rejected, then make every optional tracker wait for consent.

A scoped repair request

Using an AI builder? Paste this

Use this prompt in Lovable, Cursor, Replit, or Claude Code with the relevant server files available.

Audit my site's tracking and consent setup. List every third-party script and how it is loaded (theme, plugin, inline snippet, tag manager). For each, say whether it is necessary, analytics or marketing, and whether it currently waits for the matching consent. Show the smallest change that makes optional scripts inert until consent using my existing consent tool, without removing the trackers or changing what loads after the visitor accepts.

The same failure may appear as

  • Visitor-tracking cookies set while the banner is still open
  • A tracker keeps loading after the visitor clicks Reject
  • A plugin's script ignores the consent tool
  • Global Privacy Control is announced but marketing tags still run

Find the failure layer

Run these checks before rewriting anything

Each check removes a class of causes. Keep the first failing result, its timestamp, and the production log beside it.

01

Record requests as a new visitor

Open a private window, clear site data, load a page and wait without touching the banner. In the browser's network panel, filter to third-party domains and note every request.

If this failsAny analytics, advertising or visitor-identification request at this stage is loading without consent.
02

Check cookies and storage

In the browser's storage panel, list cookies and local storage entries set by the page before a choice.

If this failsCookies from tracking tools before consent mean their scripts already ran; strictly necessary cookies, such as a session or security token, are a different category.
03

Repeat after Reject

Click Reject, load another page, and repeat the request and cookie check.

If this failsA tracker that still loads after Reject is ignoring the choice, which is usually worse than loading before it.
04

Find where each script comes from

Search the page source for each tracker's domain or global variable, then trace it to a theme file, plugin, tag manager container or header-script setting.

If this failsInline snippets and scripts added by plugins are the ones a URL-based blocker most often misses.
curl -s https://example.com/ | grep -oiE '<script[^>]*>[^<]{0,200}' | grep -iE 'track|analytics|pixel|insight'

Ranked diagnosis

Common root causes, in the order we would test them

01

Blocker matches a fixed list

The consent tool only holds back scripts it recognises, so a tracker added later loads freely.

02

Inline loader snippets

A small inline script creates the tracker's script tag at runtime, so the external URL never appears in the HTML the blocker inspects.

03

Plugin or theme injection

A plugin prints its own tracking code into the page head, outside the consent tool's control.

04

Tag manager without consent rules

The container loads before consent, or its tags have no consent conditions.

Step-by-step repair

How to fix this in your app

Work in the consent tool's configuration, the tag manager container, and any theme file, plugin setting or header-scripts box that prints tracking code.

Production safety ruleNever disable access controls, expose service keys, or add wildcard CORS as a routine shortcut.

01

Classify every tracker

For each third-party script, decide whether it is strictly necessary, analytics or marketing. Visitor-identification and advertising tools belong in marketing.

02

Hold optional scripts until consent

Render optional scripts as inert (for example type="text/plain" with a category attribute) and let the consent tool turn them into real scripts only after the matching choice.

03

Respect Reject and Global Privacy Control

Make sure a Reject choice, and a browser's Global Privacy Control signal where you honour it, keep marketing tags off on every later page.

04

Add new tags through the same gate

Route future tracking code through the consent tool or tag manager consent rules, never straight into the theme or a header-scripts box.

Implementation example

Hold an inline tracker until marketing consent

<!-- Before: runs on every page load -->
<script>(function(){ /* tracker loader */ })();</script>

<!-- After: inert until the consent tool activates the marketing category -->
<script type="text/plain" data-consent-category="marketing">(function(){ /* tracker loader */ })();</script>

The attribute name depends on your consent tool; use the one it documents. The tool must swap the type to a runnable script only after the visitor accepts that category.

Prove the repair

How to check that the fix worked

Run these checks with synthetic data in your test environment, then repeat the relevant acceptance checks after deployment.

  • Fresh private window, no choice made: no optional third-party requests or tracking cookies.
  • After Reject, on the next page: still no optional requests or cookies.
  • After accepting marketing: the intended trackers load.
  • With Global Privacy Control enabled, where you honour it: marketing tags stay off.

If the check still fails

If a tracker still loads, it is probably injected after the page renders. Search for its global variable in plugin and theme files, or check whether a tag manager container loads it without a consent condition.

When the built-in AI fix makes it worse

Recover one reproducible failure.

Pause generated changes, restore a known working branch, and capture one failing request with its logs. Change one layer and rerun the allowed and denied checks before proceeding.

Engineering handoff

What Zenveus checks when the quick fix is not enough

We trace one production request through the complete path, isolate the failing boundary, and leave behind evidence your team can repeat.

Tracker inventory

Every third-party script, cookie and request, with where it is loaded from.

Consent behaviour

What runs before a choice, after Reject and with Global Privacy Control.

Policy alignment

Whether the cookie and privacy policies list the tools that actually run.

Change control

How new tags are added so they can't bypass consent again.

Typical repair pattern

No optional tracker loads until the matching consent is given

A fresh visitor and a visitor who rejected see no optional third-party requests or cookies, and accepted categories load as expected.

Evidence left behind
  • Root-cause note
  • Verified production check
  • Rollback and prevention steps

Before the next release

Prevent this failure from returning

Re-run the new-visitor and after-Reject checks whenever a plugin, tag or marketing tool is added.
Keep the privacy and cookie policies in step with the trackers the site actually uses.

Clear answers

Questions teams ask before they touch production

01Is a banner enough on its own?

No. The banner records a choice; the site still has to stop optional scripts from running until that choice allows them.

02Are analytics cookies allowed without consent?

It depends on the law where your visitors are and how the tool is configured. In the UK and EU, regulators generally treat analytics and advertising cookies as needing consent; check the guidance that applies to you.

03What about cookies that were already set?

Blocking the script stops new cookies. Existing ones stay until they expire or the visitor clears them, unless your consent tool removes them on Reject.

04How do I know the fix worked in my app?

Run the verification checks on this page in a fresh private window, both before any choice and after Reject. Then accept marketing and confirm the trackers you still want do load.

Free next step

Check the boundary before you hand it over

The free tool helps you inspect this symptom. Its result does not establish whether the whole app is production ready.

Take it further

Fixed this one? Find the next one first.

This fix solves one symptom. A guided self-assessment walks you through the rest of the app, one session at a time, and ends with a report and a ranked fix list you can act on or hand to a developer.

Planning more than one stage? Founder Bundles combine the guided products from $149 and save up to $405.

The Verdict

Know whether the symptom is contained or structural.

We can see the symptom from here. What we cannot tell you from outside is whether it is contained or structural. A scanner collects evidence. A named senior engineer makes the decision. For $299, a named senior engineer reads your code and signs a written Verdict against the nine checks in the Zenveus Production Readiness Standard. The 48-hour clock begins when the required access and context are available. If the report does not give your developer a list they can act on, you do not pay.

The 48-hour clock starts when the required access and context are available.

Scroll to Top

Optional tracking stays off until you enable it. You can change your choice at any time.

Essential — always active
Security, requested features, and remembering these choices.

Read our cookie policy