Cookie Callback Function

Cookie Callback Function

You can be notified when cookie settings are changed either by creating a global function with the name TruendoCookieControlCallback or by adding a listener for the TruendoCookieControl event to window.

Callback example

<script type="text/javascript">
  function TruendoCookieControlCallback(cookieSettings) {
    if (cookieSettings.ack) {
      console.log('Cookie dialog acknowledged');
    }
    if (cookieSettings.necessary) {
      console.log('Necessary cookies enabled.');
    }
    if (cookieSettings.preferences) {
      console.log('Preference cookies enabled.');
    }
    if (cookieSettings.statistics) {
      console.log('Statistics cookies enabled.');
    }
    if (cookieSettings.marketing) {
      console.log('Marketing cookies enabled.');
    }
    if (cookieSettings.social_content) {
      console.log('Social Content cookies enabled.');
    }
    if (cookieSettings.social_sharing) {
      console.log('Social Sharing cookies enabled.');
    }
  }
</script>

Event listener example

<script type="text/javascript">
  window.addEventListener('TruendoCookieControl', function (event) {
    // cookie settings accessible via event.detail
    var cookieSettings = event.detail;
    
    if (cookieSettings.ack) {
      console.log('Cookie dialog acknowledged');
    }
    if (cookieSettings.necessary) {
      console.log('Necessary cookies enabled.');
    }
    if (cookieSettings.preferences) {
      console.log('Preference cookies enabled.');
    }
    if (cookieSettings.statistics) {
      console.log('Statistics cookies enabled.');
    }
    if (cookieSettings.marketing) {
      console.log('Marketing cookies enabled.');
    }
        if (cookieSettings.social_content) {
      console.log('Social Content cookies enabled.');
    }
        if (cookieSettings.social_sharing) {
      console.log('Social Sharing cookies enabled.');
    }
  });
</script>

In addition to receiving the cookie settings within a callback or event listener, you can access the cookie settings at any time via the read-only Truendo.cookieSettings property.