Blocking cookies

legal.js currently uses manual categorisation to properly block cookies that are set on your website, so you must make changes to your HTML for blocking to work. In future, an automatic option will be available that will not require this step.

Necessary cookies will always be enabled, so there is no need to categorise scripts that set them, unless those scripts also set cookies in another category. If that applies to a script on your website, you should categorise the script appropriately (e.g. as setting analytics cookies).

legal.js currently supports blocking (and enabling) of analytics and marketing cookies; more categories will be available in the future.

To ensure that cookies set by scripts are properly blocked or allowed, you must update how you include those scripts on your website. They will normally look something like this example for Google Analytics:

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

The next step is essential to make cookie-blocking work correctly. If you do not change/set these attributes as described, cookies will not be blocked when expected.

You must update the way you include all scripts that set analytics or marketing cookies, adding the type attribute with a value of text/plain (or changing it, if already present), and adding a data-cookieconsent attribute with a value of analyticsor marketing based on the type of cookie that the script sets.

The example above would look like this when correctly updated to add the extra attributes for analytics to the scripts:

<script
type="text/plain"
data-cookieconsent="analytics"
async
src="https://www.googletagmanager.com/gtag/js?id=UA-123456789-0"
>
</script>
<script
type="text/plain"
data-cookieconsent="analytics"
>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123456789-0');
</script>