# 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.\
\
This guide outlines the concept of blocking cookies manually, by example of a Google analytics script, but the concept should be easily transferrable to any other script.

{% hint style="info" %}
**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).
{% endhint %}

## Step 1: Get an overview

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

```javascript
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
```

## Step 2: Edit scripts

Now that you know which scripts you have on your site, you must edit *each one* to the following:&#x20;

* Add the `type` attribute with value `text/plain` *(or changing it, if already present)*
* Add a `data-cookieconsent` attribute with a value of either `analytics` or `marketing` based on the type of cookie the scripts set.&#x20;

Both these changes are applied to the `<script>`-tag, like so:

```javascript
<script type="text/plain" data-cookieconsent="analytics">
...
</script>
```

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

```javascript
<!-- Google Analytics -->
<script
    type="text/plain"
    data-cookieconsent="analytics"
>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
```

## Done!

Congratulations on completing your first step towards collecting compliant cookie consent. Pat your self on the back and know that our privacy mascot Li is proud of you.&#x20;

![](/files/zs6pyohoGPpemrZGhYeD)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.openli.com/docs/documentation/legaljs-widget/collecting-cookie-consent/blocking-cookies.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
