Reputation: 5172
I have issues with 2 cookies, that I cannot remove via PHP or Javascript.
1) _ga GA1.2.1247399448.1424678072 .mydomainname.com
2) an _utmz with this value:
44433727.1430294622.1.1.utmcsr=stackoverflow.com|utmccn=(referral)|utmcmd=referral|utmcct=/questions
/431672/how-to-translate-strings-in-js
and like domain .jquery.com
I need to clean all cookies with a click, 'cause the EU cookie law.
Please, could you help me to remove them?
For the first one, I DON'T call no analytics code, until the accept from the user (but I cannot remove it).
For the second one, I don't understand why and because I have it...
Upvotes: 0
Views: 146
Reputation: 3
For the first one i.e Google analytics cookies You can do add the following code on your headers.php : -
<script>
if(document.cookie.split('; ').findIndex(x => x.split('=')[0] == 'cookiename') >= 0)
{
}else{
window["ga-disable-UA-7358061-1"] = true;
}
</script>
window["ga-disable-UA-7358061-1"] = true; this will disable your google analytics cookies
Upvotes: 0
Reputation: 2403
I have setup a custom server using node-static and the cookie is being removed correctly using js-cookie v2.0.0-beta.1 in Chrome:
<!DOCTYPE html>
<script src="js-cookie.js"></script>
<script>
Cookies.defaults.path = "";
document.cookie = "_utmz=44433727.1430294622.1.1.utmcsr=stackoverflow.com|utmccn=(referral)|utmcmd=referral|utmcct=/questions" +
"/431672/how-to-translate-strings-in-js";
alert( Cookies.get( "_utmz" ) );
Cookies.remove( "_utmz" );
alert( Cookies.get( "_utmz" ) );
</script>
It gets an alert with the cookie value first and then an alert undefined
.
Upvotes: 1