|
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" /> |
|
<script type="application/javascript" src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script> |
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxx-X"></script> |
|
<script> |
|
function clearCookie(d,b,c){try{if(function(h){var e=document.cookie.split(";"),a="",f="",g="";for(i=0;i<e.length;i++){a=e[i].split("=");f=a[0].replace(/^\s+|\s+$/g,"");if(f==h){if(a.length>1)g=unescape(a[1].replace(/^\s+|\s+$/g,""));return g}}return null}(d)){b=b||document.domain;c=c||"/";document.cookie=d+"=; expires="+new Date+"; domain="+b+"; path="+c}}catch(j){}}; |
|
window.addEventListener("load", function(){ |
|
window.cookieconsent.initialise({ |
|
"palette": { |
|
"popup": { |
|
"background": "#000" |
|
}, |
|
"button": { |
|
"background": "#f1d600" |
|
} |
|
}, |
|
"type": "opt-in", |
|
"content": { |
|
"message": "This forum uses cookies to ensure you get the best experience.", |
|
"dismiss": "Got it!", |
|
"deny": "Decline", |
|
"href": "https://website.com/privacy-policy" |
|
}, |
|
|
|
|
|
onInitialise: function (status) { |
|
var type = this.options.type; |
|
var didConsent = this.hasConsented(); |
|
if (type == 'opt-in' && didConsent) { |
|
// enable cookies |
|
window.dataLayer = window.dataLayer || []; |
|
function gtag(){dataLayer.push(arguments);} |
|
gtag('js', new Date()); |
|
gtag('config', 'UA-xxxxxxxx-X'); |
|
} |
|
if (type == 'opt-out' && !didConsent) { |
|
// disable cookies |
|
clearCookie('_ga','.website.com','/'); |
|
clearCookie('_gat_gtag_UA-xxxxxxxx-X','.website.com','/'); |
|
clearCookie('_gid','.website.com','/'); |
|
} |
|
}, |
|
|
|
onStatusChange: function(status, chosenBefore) { |
|
var type = this.options.type; |
|
var didConsent = this.hasConsented(); |
|
if (type == 'opt-in' && didConsent) { |
|
// enable cookies |
|
window.dataLayer = window.dataLayer || []; |
|
function gtag(){dataLayer.push(arguments);} |
|
gtag('js', new Date()); |
|
gtag('config', 'UA-xxxxxxxx-X'); |
|
} |
|
if (type == 'opt-out' && !didConsent) { |
|
// disable cookies |
|
clearCookie('_ga','.website.com','/'); |
|
clearCookie('_gat_gtag_UA-xxxxxxxx-X','.website.com','/'); |
|
clearCookie('_gid','.website.com','/'); |
|
} |
|
}, |
|
|
|
onRevokeChoice: function() { |
|
var type = this.options.type; |
|
if (type == 'opt-in') { |
|
// disable cookies |
|
clearCookie('_ga','.website.com','/'); |
|
clearCookie('_gat_gtag_xxxxxxxx-X','.website.com','/'); |
|
clearCookie('_gid','.website.com','/'); |
|
} |
|
if (type == 'opt-out') { |
|
// enable cookies |
|
window.dataLayer = window.dataLayer || []; |
|
function gtag(){dataLayer.push(arguments);} |
|
gtag('js', new Date()); |
|
gtag('config', 'UA-xxxxxxxx-X'); |
|
} |
|
}, |
|
|
|
})}); |
|
</script> |
Make sure to replace UA-xxxxxxxx-X with your proper UA and website.com with your website.