\n```\n\n## After user accepts analytics\n```html\n\n```\n\n## After user rejects all non-essential\n```html\n\n```\n\n---\n\n# Best practice recommendation\nIf your site uses Google Analytics, Ads, or GTM, the cleanest path is:\n\n- implement a cookie banner/CMP\n- set default consent to denied\n- update consent on user action\n- let GTM fire tags based on consent\n\nThis is safer and easier to maintain than manually conditionally loading every tag.\n\nIf you want, I can give you:\n1. a **plain HTML/JavaScript example**, \n2. a **Google Tag Manager setup**, or \n3. a **WordPress / Shopify / React-specific implementation**."}}}

Prompt

How do I set up a cookie banner that blocks tags until consent is given?

Technology / Marketing Automation1 observationLast seen Oct 29, 2026

Latest observation

Oct 29, 2026OpenAI APIWeb search: off

To set up a cookie banner that blocks tags until consent is given, you generally want a consent management setup that does two things:

  1. Shows a banner before any non-essential cookies/tags load
  2. Prevents tracking scripts from firing until the user opts in

The exact setup depends on your stack, but the common pattern is:


1) Classify your tags

Split your scripts into categories:

  • Strictly necessary: required for site functionality
  • Analytics: GA4, Matomo, etc.
  • Marketing/ads: Google Ads, Meta Pixel, etc.
  • Preferences: language, layout, etc.

Only the necessary ones should load by default.


2) Use a Consent Management Platform or consent mode

You can do this with:

  • Google Tag Manager + Consent Mode
  • A CMP like OneTrust, Cookiebot, Quantcast, iubenda, etc.
  • A custom implementation if you only have a few tags

If you use Google tags, Consent Mode v2 is usually the recommended approach.


3) Block scripts before consent

If using Google Tag Manager

Set your tags to require consent:

  • In GTM, open each tag
  • Go to Consent settings
  • Require the appropriate consent types, such as:
    • analytics_storage
    • ad_storage
    • ad_user_data
    • ad_personalization

Then configure the site so consent is denied by default until the user chooses.

Example default consent state

Before the user acts, set:

  • analytics: denied
  • ads: denied
  • personalization: denied

Then update on user choice.


4) Add the banner UI

Your banner should:

  • appear on first visit
  • explain what cookies are used for
  • offer at least:
    • Accept all
    • Reject non-essential
    • Customize settings

Make sure “Reject” is as easy as “Accept” in regions where that’s required.


5) Update consent when the user responds

When the user clicks accept/reject, store the choice and notify your tag system.

If using Google consent mode, the flow is:

  • Set default consent to denied
  • On banner action, call consent update with granted/denied values
  • GTM/tags then fire only when allowed

6) Do not load tracking tags prematurely

A common mistake is including the analytics script directly in the page <head>. Instead:

  • Load it only after consent
  • Or load it in a consent-aware mode that suppresses cookies until allowed

For example, if you’re using GTM, load GTM with a consent default state and let GTM handle firing.


7) Store consent preferences

Save the user’s choice in:

  • a cookie
  • localStorage
  • your CMP’s storage

Then on future visits:

  • read the stored preference
  • apply it before any non-essential tag runs

8) Test carefully

Verify that:

  • no analytics/ad requests happen before consent
  • rejection truly blocks tags
  • consent changes update behavior immediately
  • scripts remain blocked after page refresh until consent is changed

Use browser dev tools:

  • Network tab
  • Application > Cookies / Local Storage
  • Tag Assistant / CMP preview tools

Simple implementation pattern

Before consent

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

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

After user accepts analytics

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

After user rejects all non-essential

<script>
  gtag('consent', 'update', {
    'analytics_storage': 'denied',
    'ad_storage': 'denied',
    'ad_user_data': 'denied',
    'ad_personalization': 'denied'
  });
</script>

Best practice recommendation

If your site uses Google Analytics, Ads, or GTM, the cleanest path is:

  • implement a cookie banner/CMP
  • set default consent to denied
  • update consent on user action
  • let GTM fire tags based on consent

This is safer and easier to maintain than manually conditionally loading every tag.

If you want, I can give you:

  1. a plain HTML/JavaScript example,
  2. a Google Tag Manager setup, or
  3. a WordPress / Shopify / React-specific implementation.

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.