2
votes

I am trying to disable cookies until the user has provided consent. I dont have a lot of cookies on my website, the only ones that may collect some "personal data" are added by google analytics.

Google analytics has provided with the following scripts to disable their cookies:

window['ga-disable-UA-xxxxxxxx-y'] = true;

But this only removed _ga _gat _gid. I am trying to find a way to remove these as well:

gadwp_wg_default_dimension,

gadwp_wg_default_metric,

gadwp_wg_default_swmetric

Also, some cookies are being set by third party, like like _biz_dfsA, _biz_nA are being set by cloudfare.

Is there a way to disable specific cookie knowing just it's name?

Thanks.

1

1 Answers

2
votes

I'm not sure if you can prevent them from being set but you can check if they are set:

if (document.cookie.split(';').filter(function(item) {
    return item.indexOf('reader=') >= 0
}).length) {
    console.log('The cookie "reader" exists')
}

//ES2016

if (document.cookie.split(';').filter((item) => item.includes('reader=')).length) {
    console.log('The cookie "reader" exists')
}

And delete:

document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";

https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie