Custom JavaScript Events

By Admin

Published on 15th August 2015

Cookie Law Info 2.0.0 has two custom JavaScript events:

  1. Cookie consent given
  2. The [delete_cookies] shortcode button has been pressed

These custom events mean you can extend Cookie Law Info for all kinds of things such as setting a global JavaScript variable to indicate you have consent, showing the visitor a custom message on receiving consent, updating a data layer or CRM system or even recording the IP address of those who have accepted if you wish to.

Difficulty level: intermediate To use these, add some JavaScript to your page like this:

[javascript]function cli_test_listener() {
    console.log("You have cookie consent");
function cli_test_listener_del() {
    alert("Cookie deleted");
document.addEventListener('cookielawinfo-consent', cli_test_listener, false);
document.addEventListener('cookielawinfo-delete-viewed', cli_test_listener_del, false);[/javascript]

Enjoy! I'd be interested to hear how you decided to use these custom events on your own website. Let me know in the comments below :)

Make Your Website GDPR Compliant With CookieYes

CookieYes is a new and easy solution to make your website comply with the GDPR Cookie Law from Cookie Law Info. Join the 700,000+ website using our solutions now!


Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Post a Comment