warch
warch

Reputation: 2599

How to disable cookies in a generic way till cookies are accepted by user

Is there a fancy way to disable cookies untill the user accepts them?

Following Problem: I have a webshop which uses quite a lot cookies and in order to be GDPR conform we need to "disable" cookies untill the user has accepted them. I do not want to rewrite the whole shop system and therefore I am searching for a generic solution.

My aproach is:

But there are still some problems:

Upvotes: 14

Views: 19239

Answers (3)

Rick Hellewell
Rick Hellewell

Reputation: 1122

My approach (not entirely an answer to your question, but perhaps an alternative to yoru question) is to tell the users that my site has cookies, and they have to 'deal with it' if they want to continue to use my site. Of course, this may not work for your site.

I put a notice at the top (with code from https://cookieconsent.insites.com/ as a start), which will show on all pages until they accept (explicit consent from them).

You could use a button to delete all cookies, but then you can't use my site until you accept them again. But that protocol will keep me in compliance.

Upvotes: 2

Josh Bradley
Josh Bradley

Reputation: 1974

If GDPR compliance is your concern, just removing cookies won't be enough. You need to disable any tracking scripts collecting personally identifiable information (PII).

I recommend moving all tracking scripts to Google Tag Manger, and using the methods outlined by Simo Ahava. Guide 1 and Guide 2. His methods don't work great for tracking tags that aren't Google, but with a custom trigger you can stop anything.

That being said, if you do just want to remove cookies, this should do it.

function deleteCookies() {
    var theCookies = document.cookie.split(';');
    for (var i = 0 ; i < theCookies.length; i++) {
        document.cookie = theCookies[i].split('=')[0] + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
    }
}

Upvotes: 15

warch
warch

Reputation: 2599

For disabling JS-Cookies you may use:

if(!document.__defineGetter__) {
Object.defineProperty(document, 'cookie', {
    get: function(){return ''},
    set: function(){return true},
});
} else {
    document.__defineGetter__("cookie", function() { return '';} );
    document.__defineSetter__("cookie", function() {} );
}

Upvotes: 6

Related Questions