Tracking Scripts Firing Before Consent: The Root Cause of Broken Google Ads
Your Google Ads shows conversions. Your GA4 dashboard looks normal. Your cookie banner appears when users visit. But something's wrong: tracking scripts are firing before users consent, breaking measurement and violating privacy regulations.
The Problem:
If tracking scripts (gtag.js, GTM, analytics.js) fire before consent, Google may suppress or ignore conversion data. This breaks Google Ads optimization, GA4 reporting, and can violate GDPR/CCPA requirements. With server-side GTM (e.g. Stape), consent must also propagate from the browser to your server; see our Server-Side GTM + Consent Mode v2 guide for the full picture.
What It Looks Like
You might see these symptoms:
- Google Ads conversions appear in your dashboard but campaign optimization doesn't improve
- GA4 shows pageviews and events but conversion reporting is incomplete or delayed
- Your cookie banner appears but tracking requests fire immediately on page load, before any user interaction
- Consent Mode v2 is installed but Google still sees tracking before consent updates
- Browser console shows gtag/GTM requests within milliseconds of page load, regardless of consent state
The technical reality: your tracking scripts are executing before your consent management logic runs. This creates a race condition where Google receives tracking data before it knows whether consent was granted. This is one of several common ways Google Ads conversion tracking breaks. For a comprehensive overview of how consent, timing, and configuration interact, see why Google Ads conversions break.
Why This Happens
Most websites load tracking scripts in one of these ways:
Measured data: Across dozens of live scans, we've found that most sites fire tracking before consent - even when a banner is present. This isn't theoretical; it's a measured problem in production websites.
1. Scripts in HTML Head
The most common pattern: tracking scripts are placed in the <head> section of your HTML, often via Google Tag Manager or direct gtag.js inclusion.
These scripts execute immediately when the browser parses the HTML, before:
- Your consent banner JavaScript loads
- User interaction occurs
- Consent state is checked
- Consent Mode default settings are applied
Even if you have gtag('consent', 'default', denied) in your code, if gtag.js itself loads before that line executes, Google may receive tracking requests in a default state.
2. React/Next.js Hydration Timing
In modern JavaScript frameworks like React or Next.js, tracking scripts often load during the initial render or hydration phase. Your consent banner might be a React component that renders after the initial page load, creating a timing gap.
What happens:
- Page HTML loads
- React/Next.js starts hydrating
- Tracking scripts initialize (often via useEffect or component mount)
- Consent banner component renders
- User sees banner, but tracking already fired
This is especially common with Google Tag Manager, which often loads synchronously in the head, while consent management platforms (CMPs) load asynchronously or via React components.
3. Third-Party CMP Delays
Cookie consent management platforms (CMPs) like Cookiebot, OneTrust, or Quantcast often load asynchronously. They inject their banner after the page loads, but your tracking scripts may have already executed.
Even if your CMP claims to block tracking, if the CMP script loads after gtag.js or GTM, those scripts may have already sent initial requests to Google servers.
4. Consent Mode Misconfiguration
Consent Mode v2 is designed to handle this, but only if configured correctly. Common mistakes:
- Consent Mode default settings are set after gtag.js loads
- Consent Mode is initialized in a script that runs after tracking scripts
- The
wait_for_updateparameter is missing or too short - Consent updates are called but tracking scripts have already fired
What It Breaks
Google Ads Conversion Tracking
When tracking scripts fire before consent, Google Ads may:
- Suppress conversion data if Consent Mode sees tracking before consent granted
- Use modeled conversions instead of actual conversion data, reducing accuracy
- Optimize campaigns on incomplete data, leading to poor performance
- Show conversions in your dashboard but not use them for bidding optimization
The result: you're paying for Google Ads but the algorithm isn't optimizing effectively because it doesn't trust your conversion data.
GA4 Reporting
GA4 may receive events before consent, but:
- Events may be marked as "modeled" rather than actual user actions
- Conversion reporting becomes unreliable or delayed
- Audience building suffers because user data is incomplete
- Attribution models break because consent state isn't properly tracked
Privacy Compliance
From a legal perspective, tracking before consent can violate:
- GDPR (EU): Requires explicit consent before processing personal data
- CCPA (California): Requires opt-out mechanisms to work before tracking
- ePrivacy Directive: Requires consent before storing or accessing cookies
Even if you have a cookie banner, if tracking fires before the user interacts with it, you may be non-compliant. This problem rarely exists in isolation. It usually appears alongside other consent or timing issues covered in the broader guide on Google Ads conversion failures.
How to Detect It
You can check if tracking scripts fire before consent using browser developer tools:
- Open your website in a private/incognito window
- Open browser DevTools (F12) and go to the Network tab
- Filter by "gtag" or "google-analytics"
- Reload the page
- Check the timestamp of the first tracking request
- Check when your consent banner appears
If tracking requests appear before you interact with the consent banner, tracking is firing before consent.
Quick Test:
Use our free scanner to automatically detect if tracking scripts fire before consent. It simulates a new visitor and checks the exact timing of tracking requests versus consent actions.
The Fix: Load Tracking After Consent
The solution is to ensure tracking scripts only load after consent is granted. Here are the main approaches:
Option 1: Consent Mode v2 with Proper Timing
Use Consent Mode v2, but ensure it's configured before any tracking scripts load:
<!-- This MUST be in <head> BEFORE gtag.js -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Set default consent to denied BEFORE loading scripts
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied',
'wait_for_update': 500
});
</script>
<!-- Then load gtag.js -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
gtag('config', 'GA_MEASUREMENT_ID');
</script>
<!-- Later, when user accepts consent -->
<script>
gtag('consent', 'update', {
'ad_storage': 'granted',
'analytics_storage': 'granted'
});
</script>The key is that the consent default must be set before gtag.js loads. If gtag.js loads first, it may send requests before the default is applied.
Option 2: Conditional Script Loading
Only load tracking scripts after consent is granted:
function loadTrackingScripts() {
// Only called after user accepts consent
const script = document.createElement('script');
script.src = 'https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID';
script.async = true;
document.head.appendChild(script);
// Initialize gtag after script loads
script.onload = function() {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
};
}
// Call this only when user accepts consent
onUserAcceptsConsent(() => {
loadTrackingScripts();
});Option 3: Use a CMP with Proper Blocking
If using a consent management platform, ensure it:
- Loads before tracking scripts
- Actually blocks script execution (not just hides them)
- Integrates with Consent Mode v2
- Updates consent state before allowing scripts to run
Why This Is The Root Cause
Tracking scripts firing before consent is the underlying issue behind many other problems:
- Google Ads tracking breaks because conversions fire before consent
- GA4 consent issues occur because events are sent before consent state is known
- Cookie banners don't block tracking if scripts fire before the banner logic runs
- Consent Mode v2 fails if tracking scripts load before Consent Mode defaults are set
- gtag consent default denied doesn't work if gtag.js loads after the default is set
Fix this root cause, and many other issues resolve automatically.
Verify Your Fix
After implementing a fix, verify it works:
- Clear your browser cookies and cache
- Visit your site in a private/incognito window
- Check the Network tab: no tracking requests should appear before you interact with the consent banner
- Accept consent: tracking requests should appear only after you click accept
- Reject consent: no tracking requests should appear
Not Sure If Your Site Has This Problem?
Run a free scan to automatically detect if tracking scripts fire before consent. Get a detailed report with exact scripts, timing, and fix instructions.
Want ongoing alerts when something changes? Consent Mode monitoring runs weekly scans and emails you only when we detect a change.
Scan Your Site Free →Part of the Google Ads conversion tracking series:
← Back to: Why Google Ads Conversions Break