\n ```\n3. **After consent is granted**, replace or activate it via JavaScript.\n\n### Example\n\n```html\n\n\n\n\n\n```\n\n### Important notes\n- This works for **external scripts** and inline scripts.\n- If you need to block scripts for privacy/compliance reasons, also consider:\n - **not rendering** the script at all until consent\n - delaying any **network requests** triggered by the script\n - ensuring your consent mechanism is compliant with GDPR/ePrivacy or relevant laws\n\n### Alternative approach\nIf you use a consent management platform (CMP), it may provide:\n- script classification\n- auto-blocking\n- consent state handling\n- vendor-specific activation\n\nIf you want, I can also give you:\n- a **jQuery version**\n- a **Vanilla JS reusable function**\n- a **Google Tag Manager / Consent Mode setup**\n- an example for **WordPress** or **Cookiebot**"}}}

Prompt

Script blocking based on consent

Technology / Marketing Automation1 observationLast seen Oct 29, 2026

Latest observation

Oct 29, 2026OpenAI APIWeb search: off

To block scripts until a user gives consent, the common pattern is:

  1. Do not load the script as type="text/javascript" initially
  2. Store it in a non-executing tag like:
    <script type="text/plain" data-consent="analytics" src="..."></script>
    
  3. After consent is granted, replace or activate it via JavaScript.

Example

<script type="text/plain" data-consent="analytics" src="https://example.com/analytics.js"></script>

<button id="accept">Accept analytics</button>

<script>
  document.getElementById('accept').addEventListener('click', function () {
    document.querySelectorAll('script[type="text/plain"][data-consent="analytics"]').forEach(function (blockedScript) {
      var script = document.createElement('script');
      Array.from(blockedScript.attributes).forEach(function (attr) {
        if (attr.name !== 'type') {
          script.setAttribute(attr.name, attr.value);
        }
      });
      blockedScript.parentNode.replaceChild(script, blockedScript);
    });
  });
</script>

Important notes

  • This works for external scripts and inline scripts.
  • If you need to block scripts for privacy/compliance reasons, also consider:
    • not rendering the script at all until consent
    • delaying any network requests triggered by the script
    • ensuring your consent mechanism is compliant with GDPR/ePrivacy or relevant laws

Alternative approach

If you use a consent management platform (CMP), it may provide:

  • script classification
  • auto-blocking
  • consent state handling
  • vendor-specific activation

If you want, I can also give you:

  • a jQuery version
  • a Vanilla JS reusable function
  • a Google Tag Manager / Consent Mode setup
  • an example for WordPress or Cookiebot

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.