klaro-org / klaro-js

Klaro Privacy Manager. An open-source, privacy-friendly & compliant consent manager for your website.
https://klaro.org
Other
1.2k stars 254 forks source link

Cleanup local storage #332

Closed saschafoerster closed 2 years ago

saschafoerster commented 3 years ago

I am trying to use Klaro with Mautic: https://www.mautic.org

Mautic is using cookies and local storage as well. When I consent one time to use Mautic, then cookies as well as local storage are used. When I remove my consent later in the cookie-modal, then only the cookies will be deleted.

This is the relevant part of my configuration:

// Mautic
            {
                    name: 'mautic',
                    default: false,
                    title: 'Kontaktprofil und Marketing',
                    purposes: ['marketing'],
                    cookies: [
                            [/^mtc.*$/, '/', 'marketing.bonn.digital'],
                            [/^mautic.*$/, '/', 'marketing.bonn.digital'],
                            [/^mtc.*$/, '/', "." + location.hostname],
                            [/^mautic.*$/, '/', "." + location.hostname],
                            'mautic_device_id',
                            'mtc_id',
                            'mtc_sid',
                    ],
                    callback: function(consent, service) {
                            console.log(
                                    'cookie.bonn.digital: Einwilligung für Dienst ' + service.name + ': ' + consent
                            );
                    },
            },

Did I misconfigure something? Or is Klaro not able to cleanup local storage? I added

                            'mautic_device_id',
                            'mtc_id',
                            'mtc_sid',

to try out, if local storage is deleted, when I don't define any domain, but now I don't have any more ideas.

adewes commented 3 years ago

Hi @saschafoerster, right now you'd have to do this via a callback, we'll add a way to clean up localStorage / sessionStorage keys with the next release though!

tpinne commented 3 years ago

Is this already implemented but maybe not documented? There have been 9 releases since we'll add a way to clean up localStorage / sessionStorage keys with the next release though and I found no information on this topic in the release notes.

69bruno commented 3 years ago

Is there still anything about clearing the local storage, or has the idea died ? Where can i get documentation, how to use/configure the callbackfunction ?

trevor87 commented 2 years ago

Where can i get documentation, how to use/configure the callbackfunction ?

@69bruno: There is an example in the annotated config.js:

            // An optional callback function that will be called each time
            // the consent state for the service changes (true=consented). Passes
            // the `service` config as the second parameter as well.
            callback: function(consent, service) {
                // This is an example callback function.
                console.log(
                    'User consent for service ' + service.name + ': consent=' + consent
                );
                // To be used in conjunction with Matomo 'requireCookieConsent' Feature, Matomo 3.14.0 or newer
                // For further Information see https://matomo.org/faq/new-to-piwik/how-can-i-still-track-a-visitor-without-cookies-even-if-they-decline-the-cookie-consent/
                /*
                if(consent==true){
                    _paq.push(['rememberCookieConsentGiven']);
                } else {
                    _paq.push(['forgetCookieConsentGiven']);
                }
                */
            },

Update: A quick fix I used in my case was this to remove all elements beginning with "us-" from the local storage:

      callback: function (consent, service) {
        if (consent == false) {
            Object.keys(localStorage).filter(x => x.startsWith('us-')).forEach(x => localStorage.removeItem(x))
        }
      },

Source: https://stackoverflow.com/questions/24551578/clear-localstorage-values-with-certain-prefix

saschafoerster commented 2 years ago

Thank you, that worked and helped clean the local storage!