Skip to main content

Features

CookieYes Events on Cookie Banner Interactions

Incompatible for CookieYes WordPress plugin without Web App Connection.

The event listeners mentioned in this documentation are incompatible with the CookieYes WordPress plugin when not connected to the web app. However, they seamlessly function with both the web app and the WordPress plugin when it is connected to the web app.

When the user interacts with the banner, the CookieYes script emits an event. You can set up your website to listen to this event and perform the necessary action. To implement the event listener on your website, add the following snippet to your webpage, check the value in the JSON eventData and modify the snippet to perform the desired action for the user.

document.addEventListener("cookieyes_consent_update", function (eventData) 
{
    // Check the value in the JSON eventData and perform desired action
});

The JSON object eventData contains the list of categories accepted and rejected by the user in the format:

detail: { "accepted":[ "Category1", "Category2" ],"rejected":[ "Category3","Category4" ] }

Example of CookieYes Event Listener

This example demonstrates the implementation of an event listener on the website to perform the desired action and check if the analytics category is accepted by adding the following snippet to the HTML.

<script>
  document.addEventListener("cookieyes_consent_update", function (eventData)
 {
   const data = eventData.detail;
   if (data.accepted.includes("analytics")) {
      // perform desired action.
    }
  });
  </script>

This code snippet listens to the event cookieyes_consent_update, which checks if the user has consented to “analytics”.

If you change or edit the category name, you still have to use the default category name (necessary, functional, analytics, performance and advertisement).

For example, if you rename the “Analytics” category to “Analytique,” you would still need to use if (data.accepted.includes("analytics")) instead of

if (data.accepted.includes("analytique")).

When the user accepts the ‘necessary’, ‘analytics’ and ‘advertisement’ and rejects the ‘functional’, ‘performance’ and ‘other’ categories of cookies in the banner; the eventData contains JSON object as mentioned below:

detail: {
	"accepted": ["necessary","analytics","advertisement"],
	"rejected": ["functional","performance","other"]
}

And if the user accepts the ‘necessary’ and ‘advertisement’ and rejects the ‘analytics’, ‘functional’,  ‘performance’ and ‘other’ categories of cookies in the banner; the eventData contains JSON object as mentioned below:

detail: {
     "accepted": ["necessary","advertisement"], 
     "rejected":["analytics","functional","performance","other"]
}

If you have any issues or queries regarding CookieYes, feel free to contact our support team.