Blocking cookies
This guide explains how to actually block cookies.
To block cookies effectively, there are several methods: deleting cookies, blocking a snippet, custom JavaScript or Google Tag Manager.
Deleting cookies
This method is the fastest to set up, but also the least reliable. In the Services section of the banner, if you enter the name of the cookies associated with each service (Linked cookies tab of the service), the SDK automatically deletes these cookies when a refusal is recorded for the service.

This method works in some cases, but it may disrupt the reliability of third-party tools, in particular web analytics tools. Use it alongside one of the other methods below.
Blocking a code snippet in the page
This method completely disables a tracking code snippet.
In the HTML code of your page, replace the following snippet:
With:
Replace {your-service-slug} with the identifier of the service, which you find in the Variable name field of the service form:

If the visitor accepted the service, the content of the script is executed automatically.
To load an external script, add the src attribute: the browser downloads it only after consent.
Use the snippets generated by the application
For each service, the Cookie consents integration section of the banner generates ready-to-copy snippets and a checklist. Three tabs are available: Html integration (the snippet above), Custom javascript (the plain JavaScript blocking below) and Google tag manager (the events to connect in Google Tag Manager).
Blocking in plain JavaScript
In JavaScript, you can listen to the events fired on window to collect consent and handle a specific behavior depending on whether cookies are accepted or refused. This method gives you more flexibility:
Google Tag Manager
See the following page:
Google Tag ManagerReminder on the consent lifecycle

JavaScript events
The banner fires several events on the window element of the page. The consent events are fired on every page load, when the banner applies the choices already saved, and then each time a choice is saved.
dastra:consent:<service slug>
Fires when the service is accepted, by the visitor or by default (strictly necessary services are not concerned). If the service is set to "consented by default", the event fires from the first page load.
dastra:refused:<service slug>
Fires when the service is not accepted: by default if no consent is given, or after an explicit refusal.
dastra:consents:ready
Fires when the stored consent (the consent-eu cookie by default) has been read and the first events have been fired.
dastra:consents:updated
Fires on every page load and each time choices are saved (accepted, refused or customized). The event detail contains the list of consents.
dastra:consents:any_refused
Fires when at least one stored consent is a refusal, on every page load and each time choices are saved.
dastra:consents:all_accepted
Fires when no stored consent is a refusal, on every page load and each time choices are saved.
dastra:consents:closed
Fires when the visitor closes the banner with the close cross.
dastra:gpc:applied
Fires when the banner automatically refuses non-essential cookies because of a Global Privacy Control or Do Not Track signal. See US Privacy.
To react to each consent update, you can also use dastra.addConsentDastraListener(callback): the function is called on every dastra:consents:updated event.
FAQ
Can I block a script by category instead of by service? (e.g. data-consent="analytics")
No. The data-consent attribute expects a service slug, not a category slug. Writing <script data-consent="analytics" type="dastra/script"> to block all services in a category in one directive is not supported.
The reason: a user may accept some services within a category while refusing others in the same category. The banner manages consent at the service level, not the category level.
To load a script depending on whether an entire category has been accepted, use the programmatic API:
Last updated
Was this helpful?