2019-08-14, 00:15:16
Hi, thanks for the plugin.
To set cookies only if the user accept it, i added a reload document in acceptco function:
and where is the set cookies function (i.e. googleanalytics):
in this way everywhere you have to set a cookie just use checkCookie() before setting it.
To set cookies only if the user accept it, i added a reload document in acceptco function:
Code:
<script type="text/javascript">
function acceptco(id, ident){
if (ident == "cbcookies"){
var frm=document.getElementById(id);
if(frm.style.display=="block"){
var fecha = new Date();
tiempo = <?php echo $cbtmp; ?>;
fecha.setTime(fecha.getTime() + tiempo);
document.cookie = "acceptco" + ' = ' + escape("Y") + ((tiempo == null) ? "" : "; expires = " + fecha.toGMTString()) +"; path=/";
frm.style.display="none";
}
}
location.reload(); // <<== added this line
}
</script>
and where is the set cookies function (i.e. googleanalytics):
Code:
<!-- Check if cookie accepted -->
<script>
function checkCookie(){
// acceptco = getsimple cookies plugin
if (document.cookie.split(';').filter((item) => item.trim().startsWith('acceptco=')). length) {
return true;
}
return false;
}
</script>
<!-- -------- -->
<script async src="https://www.googletagmanager.com/gtag/js?id=xxxxx"></script>
<script>
if ( checkCookie() ){
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'xxxxx', { 'anonymize_ip':true });
}
</script>
in this way everywhere you have to set a cookie just use checkCookie() before setting it.