\n\n```\nThis loads GA immediately, before consent.\n\n### 2. Load analytics only after consent\nWait until the user accepts analytics cookies, then inject the script dynamically.\n\nExample:\n```html\n\n```\n\n### 3. Block consent until the user chooses\nYour banner should not just say “By continuing, you agree.” It should have:\n- **Reject** or **Decline**\n- **Accept** analytics\n- Ideally granular controls if required by your jurisdiction\n\n### 4. If using Google Tag Manager, use consent mode correctly\nIf GTM is in use, it can still fire tags unless configured properly. Use:\n- **Google Consent Mode**\n- Default analytics consent = denied\n- Only update consent to granted after user acceptance\n\nExample:\n```html\n\n```\nThen after consent:\n```html\n\n```\n\n### 5. Verify it’s really blocked\nUse browser DevTools:\n- Open **Network**\n- Reload the page **before consent**\n- Search for:\n - `googletagmanager.com`\n - `google-analytics.com`\n - `gtag/js`\n- There should be **no GA requests** before consent\n\nAlso check:\n- Cookies set by GA (`_ga`, `_gid`, `_gat`)\n- Local/session storage\n- Any iframe or pixel that may be related to analytics\n\n### 6. Watch out for third-party plugins and embedded tools\nYour site may still leak analytics through:\n- WordPress plugins\n- Shopify apps\n- CMS theme settings\n- Tag managers inserted by a marketing plugin\n- Embedded YouTube/Meta/Hotjar widgets\n\nMake sure all tracking sources are behind consent logic, not just the banner.\n\n## Best-practice checklist\n- [ ] GA scripts are not hardcoded in the page before consent\n- [ ] Consent defaults to denied\n- [ ] Analytics code loads only after opt-in\n- [ ] Banner has an actual reject option\n- [ ] No GA cookies appear before consent\n- [ ] Verified in DevTools network tab\n- [ ] Third-party plugins are also controlled\n\nIf you want, I can give you a **copy-paste implementation** for:\n- plain HTML/JavaScript\n- Google Tag Manager\n- React / Next.js\n- WordPress\n- Shopify"}}}

Prompt

How do I make sure my cookie banner actually blocks Google Analytics until consent is given?

Technology / Marketing Automation1 observationLast seen Oct 29, 2026

Latest observation

Oct 29, 2026OpenAI APIWeb search: off

To make sure your cookie banner actually blocks Google Analytics until consent, you need more than just displaying a banner — you need to prevent any GA scripts, tags, or network requests from loading before consent.

What to do

1. Don’t load Google Analytics by default

If you use gtag.js, analytics.js, Google Tag Manager, or any plugin that injects GA, make sure it is not included in the page head unconditionally.

Bad example:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXX');
</script>

This loads GA immediately, before consent.

2. Load analytics only after consent

Wait until the user accepts analytics cookies, then inject the script dynamically.

Example:

<script>
  function loadGoogleAnalytics() {
    if (window.gaLoaded) return;
    window.gaLoaded = true;

    var script = document.createElement('script');
    script.async = true;
    script.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX';
    document.head.appendChild(script);

    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    window.gtag = gtag;
    gtag('js', new Date());
    gtag('config', 'G-XXXXXXX');
  }

  function onConsentAccepted() {
    localStorage.setItem('analytics_consent', 'yes');
    loadGoogleAnalytics();
  }

  if (localStorage.getItem('analytics_consent') === 'yes') {
    loadGoogleAnalytics();
  }
</script>

3. Block consent until the user chooses

Your banner should not just say “By continuing, you agree.” It should have:

  • Reject or Decline
  • Accept analytics
  • Ideally granular controls if required by your jurisdiction

4. If using Google Tag Manager, use consent mode correctly

If GTM is in use, it can still fire tags unless configured properly. Use:

  • Google Consent Mode
  • Default analytics consent = denied
  • Only update consent to granted after user acceptance

Example:

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}

  gtag('consent', 'default', {
    'analytics_storage': 'denied'
  });
</script>

Then after consent:

<script>
  gtag('consent', 'update', {
    'analytics_storage': 'granted'
  });
</script>

5. Verify it’s really blocked

Use browser DevTools:

  • Open Network
  • Reload the page before consent
  • Search for:
    • googletagmanager.com
    • google-analytics.com
    • gtag/js
  • There should be no GA requests before consent

Also check:

  • Cookies set by GA (_ga, _gid, _gat)
  • Local/session storage
  • Any iframe or pixel that may be related to analytics

6. Watch out for third-party plugins and embedded tools

Your site may still leak analytics through:

  • WordPress plugins
  • Shopify apps
  • CMS theme settings
  • Tag managers inserted by a marketing plugin
  • Embedded YouTube/Meta/Hotjar widgets

Make sure all tracking sources are behind consent logic, not just the banner.

Best-practice checklist

  • GA scripts are not hardcoded in the page before consent
  • Consent defaults to denied
  • Analytics code loads only after opt-in
  • Banner has an actual reject option
  • No GA cookies appear before consent
  • Verified in DevTools network tab
  • Third-party plugins are also controlled

If you want, I can give you a copy-paste implementation for:

  • plain HTML/JavaScript
  • Google Tag Manager
  • React / Next.js
  • WordPress
  • Shopify

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.