Some functionality on the website depends upon the installation of certain cookies in the browser of the user. All these cookies are distributed in cookie categories. To make such functionality work, your script needs to know that whether the user consented to the cookie consent banner and more particularly those cookie categories or not.

Therefore, you can setup your website to listen to such events and function accordingly. We have mentioned a list of events (some of which are category-specific events), and the JavaScript code examples to use these events.

List of Mandatly Events

These Events are fired each time when the user interacts with the banner. Therefore, if the user interacts multiple times with the banner on the same page, these events will be fired multiple times on the same page.

MandatlyCookieOnAcceptAll – This event fires when the user clicks on the Accept All button. The firing of this event accepts all the cookies on the website.


  • MandatlyCookieOnDeclineAll – This event fires when user clicks on the Decline All button. The firing of this event declines all the cookie categories except essential category.
  • MandatlyCookieOnAcceptSelected - This event fires when the user accepts some categories from the cookie preference banner.

Cookie Category Events

We also provide category-specific events. These events are useful when you want to include a third-party functionality for any specific category. These events are designed to fire once per page, so you can include some third-party code without worrying about the events. Events will fire when the user agrees to certain cookie category and on page load if the visitor agreed to the cookie category on the previous page.

  • MandatlyDataCategory-0001 – This events fires when the user agrees to the Essential cookie category.
  • MandatlyDataCategory-0002 - This events fires when the user agrees to the Marketing cookie category.

Similarly, you just need to replace the ID of each category available in the Cookie categories page of Mandatly Solution.

Note: You are not limited to use these names or categories. You can rename them or create your own. 

You can use same events for Google Tag Manager as well. Learn how to use these events with Google Tag Manager.

Code Examples


  1. Accept All Event

window.addEventListener(‘MandatlyCookieOnAcceptAll’, function() {

 //enter your code here

})


  1. Accept Selected Event

window.addEventListener(‘MandatlyCookieOnAcceptSelected’, function(e) {

 // e.detail will include:

//[{"ID":"0001","Name":"Essential"},{"ID":"0006","Name":"Unclassified"}]

// enter your code here

})


  1. Category wise Event

window.addEventListener(‘MandatlyDataCategory-0001’, function() {

//enter your code here

})


Note:

Manual Blocking Script option needs to be enabled while using the Custom tags, Custom events or GTM events on your website.


To enable the Manual Blocking Script option in your Mandatly account:

Navigate to Websites -> Edit website -> More Settings and turn on the Manual Blocking Script option.