Hello,

I am really struggling with this.

I have Google analytics and would like to allow the user to disable tracking if he click on "decline" and turn the tracking on if he clicks on "Accept".

The script I am trying to use is this one:
https://cookieconsent.insites.com/download/

Code:
<script>
window.addEventListener("load", function(){

    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'UA-xxxxxx-1', { 'anonymize_ip': true });

window.cookieconsent.initialise({
    "palette": {
    "popup": {
      "background": "#ffffff"
    },
    "button": {
      "background": "#f1d600"
    }
  },
  "theme": "classic",

content: {
  header: 'Cookies used on the website!',
  message: 'This website uses cookies to ensure you get the best experience on our website.',
  dismiss: 'Got it!',
  deny: 'Decline',
  link: 'Learn more',
  href: 'https://mysitexxxxx.com/privacy-policy',
  close: '&#x274c;',

},
  "type": "opt-out",

onInitialise: function (status) {
  var type = this.options.type;
  var didConsent = this.hasConsented();
  if (type == 'opt-in' && didConsent) {
    window['ga-disable-UA-xxxxx-1'] = false;
  }
  if (type == 'opt-out' && !didConsent) {
    window['ga-disable-UA-xxxxx-1'] = true;
  }
},
 
onStatusChange: function(status, chosenBefore) {
  var type = this.options.type;
  var didConsent = this.hasConsented();
  if (type == 'opt-in' && didConsent) {
    window['ga-disable-UA-xxxxx-1'] = false;
  }
  if (type == 'opt-out' && !didConsent) {
    window['ga-disable-UA-xxxxx-1'] = true;
  }
},

})
});
</script>

With the current code, if the user clicks on "decline" I get a "cookieconsent_status" cookie that get set to "deny" but the _gat_gtag_UA_xxxxx_1 cookie is still set and tracking...


Any idea what am I doing wrong please?


Thank you.