Js-cookie: Can't delete Google Analytics cookies.

Created on 10 Aug 2018  路  5Comments  路  Source: js-cookie/js-cookie

Hello,

It may be due to my unability to use your tool even as it seems pretty straightforward.

I want to remove all cookies left over after blocking GA. My .js file contains following code:

window['ga-disable-UA-XXXXXXXX-X'] = true; // This blocks GA service, works properly.
var DelCookies = Cookies.noConflict();
var cookies    = DelCookies.get();

if ( '' !== cookies ) {

    jQuery.each( cookies, function( index ) {

        index = '' + index;

        if ( '_ga' === index || '_gid' === index || '_gat' === index ) {

            DelCookies.remove( index, { path: '/' });
        }

    });

}

But cookies are still there when I check Chrome's developer console. I used '/' as domain path. I've found this path in the developer console as well.

Best regards, Dan.

good first issue

Most helpful comment

@carhartl It's mentioned but with no obvious example of how the code should look like afted adding 'domain' attribute. One might thing the domain should be put where the 'path' is, i.e.:

Cookies.remove('name', { path: 'yourdomain.com/the/path' });

@FagnerMartinsBrack Under the line saying

IMPORTANT! When deleting a cookie, you must pass the exact same path and domain attributes that were used to set the cookie

I would add the line showing exactly how the code with domain attribute should look like:

Cookies.remove('name', { path: '', domain: 'yourdomain.com' });

Thank you very much guys for your time given to help me out.
Best regards, Dan.

All 5 comments

Hi Dan, you may have to add the domain attribute as well, which must match the one with which the cookies had been written.

DelCookies.remove( index, { path: '/', domain: '.yourdomain.com' });

Well, it worked! Thank you!

Call me blind but I can't find this information anywhere on the plugin's main page.

Regards, Dan.

It鈥榮 mentioned in the readme:

IMPORTANT! When deleting a cookie, you must pass the exact same path and domain attributes that were used to set the cookie

@junglized Any suggestion on how we can improve the README to make that information clearer for other people?

@carhartl It's mentioned but with no obvious example of how the code should look like afted adding 'domain' attribute. One might thing the domain should be put where the 'path' is, i.e.:

Cookies.remove('name', { path: 'yourdomain.com/the/path' });

@FagnerMartinsBrack Under the line saying

IMPORTANT! When deleting a cookie, you must pass the exact same path and domain attributes that were used to set the cookie

I would add the line showing exactly how the code with domain attribute should look like:

Cookies.remove('name', { path: '', domain: 'yourdomain.com' });

Thank you very much guys for your time given to help me out.
Best regards, Dan.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiangdefu picture jiangdefu  路  3Comments

czebe picture czebe  路  3Comments

DeadcatDev picture DeadcatDev  路  3Comments

sudhir600 picture sudhir600  路  9Comments

nanndemoiikara picture nanndemoiikara  路  5Comments