Skip to content

Block Cookies with Tag Attributes

When you install CookieTractor on your website, you need to ensure that all scripts which set cookies – and are not considered strictly necessary – are blocked until the visitor has given consent.

If you are using scripts that are embedded directly in your code, you can use our attribute-based cookie blocking. This allows you to prevent scripts from being loaded before the visitor has provided the appropriate consent, simply by adding HTML attributes to your <script> or <iframe> tags.

Blocking Script Tags

For a script element with a src attribute, you can replace src with data-consent-src and add a data-consent-category attribute to specify which category of consent is required for the script to run:

  • marketing
  • statistical
  • functional

When the visitor Accepts all cookies, only the categories that represent the cookies present on your website are accepted. Therefore, make sure to condition only the categories that actually exist in your cookie list.

Here is an example showing how an external script is only loaded once the visitor has given their consent for marketing:

<script src="https://dinwebbplats.se/script.js">
</script>

// Change to:

<script data-consent-src="https://dinwebbplats.se/script.js"
        data-consent-category="marketing">
</script>

Blocking Inline Scripts

For inline JavaScript, you need to add the attribute type="text/plain" as well as data-consent-category to ensure that the script only runs once consent has been given:

<script>
  console.log('Inlinescript som behöver marknadsförings-samtycke');
</script>

// Change to:

<script type="text/plain" data-consent-category="marketing">
  console.log('Inlinescript som behöver marknadsförings-samtycke');
</script>

Blockering Iframes

The same approach also works for iframes:

<iframe src="https://dinwebbplats.se/iframe">
</iframe>

// Change to:

<iframe data-consent-src="https://dinwebbplats.se/iframe" 
        data-consent-category="statistical">
</iframe>

Support

If you have questions about the installation, feel free to contact us at info@cookietractor.com.​