Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cookies Plugin
#23
Hi, thanks for the plugin.

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.
Reply


Messages In This Thread
Cookies Plugin - by cumbe - 2013-12-01, 04:03:08
RE: Cookies Plugin - by oldRemovedUser - 2013-12-04, 10:14:10
RE: Cookies Plugin - by datiswous - 2013-12-05, 06:00:09
RE: Cookies Plugin - by cumbe - 2013-12-05, 07:34:04
RE: Cookies Plugin - by phpman - 2014-04-28, 22:36:16
RE: Cookies Plugin - by cumbe - 2014-04-29, 01:31:05
RE: Cookies Plugin - by phpman - 2014-04-29, 08:01:36
RE: Cookies Plugin - by Carlos - 2014-04-29, 23:41:02
RE: Cookies Plugin - by cumbe - 2014-04-30, 16:16:26
RE: Cookies Plugin - by cumbe - 2015-11-29, 07:47:56
RE: Cookies Plugin - by Dora - 2016-04-25, 21:53:48
RE: Cookies Plugin - by cumbe - 2016-04-25, 22:17:28
RE: Cookies Plugin - by morvy - 2016-05-06, 18:33:49
RE: Cookies Plugin - by cumbe - 2017-01-07, 19:16:10
RE: Cookies Plugin - by lindacarey - 2018-06-08, 00:58:11
RE: Cookies Plugin - by datiswous - 2018-06-08, 18:57:59
RE: Cookies Plugin - by lindacarey - 2018-06-11, 23:35:02
RE: Cookies Plugin - by Oleg06 - 2018-06-08, 01:16:49
RE: Cookies Plugin - by lindacarey - 2018-06-11, 23:20:08
RE: Cookies Plugin - by lindacarey - 2018-06-11, 23:49:03
RE: Cookies Plugin - by lindacarey - 2018-06-11, 23:50:55
RE: Cookies Plugin - by backit - 2019-08-14, 00:15:16
RE: Cookies Plugin - by tuxy - 2023-02-17, 21:11:09
RE: Cookies Plugin - by islander - 2023-02-18, 00:56:13
RE: Cookies Plugin - by tuxy - 2023-02-18, 07:44:52
RE: Cookies Plugin - by hawk - 2023-10-08, 06:01:19



Users browsing this thread: 1 Guest(s)