Skip to content

How to block cookies 

When setting up CookieTractor on your website, you need to ensure any script setting cookies, not deemed strictly necessary, are blocked until the user gives consent.

There are several ways of doing this. You could use a tag manager like Google Tag Manager or Matomo. But if you're using scripts placed directly in your code, you can use our attribute-based cookie blocking, which lets you block cookies until the user has given consent by adding simple HTML attributes to your script tags.

Attribute-based blocking

This blocking approach is useful if you have simple <script> or <iframe> elements that you want to block. It works by adding the data-consent-category-attribute to those elements, preventing them from running until the user has given an matching consent.

Blocking script tags

For a script element containing a src-attribute, you can rename the src-attribute to data-consent-src and add a data-consent-category-attribute to indicate the category for which the script should fire on.

Here is an example showing how to only load an external script when marketing consent has been given:

<script src="https://yourwebsite.com/script.js">
</script>

// Change to:

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

Blocking inline script tags

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

<script>
  console.log('Inline javascript that requires marketing consent');
</script>

// Change to:

<script type="text/plain" data-consent-category="marketing">
  console.log('Inline javascript that requires marketing consent');
</script>

Blocking iframes

This approach also works for iframes:

<iframe src="https://yourwebsite.com/iframe" >
</iframe>

// Change to:

<iframe data-consent-src="https://yourwebsite.com/iframe" 
        data-consent-category="statistical">
</iframe>