How to disable cookies with cookieconsent by Insites

Viewed 1771

I don't understand: https://cookieconsent.insites.com/documentation/disabling-cookies/

onInitialise: function (status) {
  var type = this.options.type;
  var didConsent = this.hasConsented();
  if (type == 'opt-out' && !didConsent) {
    // disable cookies
  }
},

What do I have to put instead of "//disable cookies" to disable the cookies?

3 Answers

I think that you could add something like:

window['ga-disable-UA-XXXXX-Y'] = true;

Inside that section (see here). But it mostly depends your needs and your cookies you set.

Additionally I think that the script could be improved to use

  if (navigator.doNotTrack && navigator.doNotTrack === 1) {
    window['ga-disable-{{GA ID}}'] = true;
  }

So we could use the "Do not track" option in the browser here. Not sure if that is already covered in the Insites CookieConsent script.

P.S. Keep noted that there exists currently a small bug (reported here).

If you have more analytics and so on, you can do like:

  1. Define a function which creates a variable on call:

    <script type="text/javascript">
        function setOptOut() {
        localStorage.setItem('optout', 'true');
        window.location.reload(false);
        }
    </script>
    
  2. Insert the call where you find //disable cookies like:

    setOptOut()
    
  3. Load scripts only if not opted out:

    if (!localStorage.getItem('optout')) {
    //your tracking scripts
    }
    
Related