Google anayltics activate storage afterwards

Viewed 60

To prevent Google Analytics of settings any cookies before a user accepts it (GDPR), I use analytics.js method base on GA Docs:

ga('create', '####MyCode####', {
    'storage': 'none'
});

Is there a way to reactive it on runtime (after user accepts the cookies)? Something like

ga('set', 'storage', true);
1 Answers

My advise is to call “send” method only when you have required consent.

i.e.:

if (document.cookie.indexOf('consent_cookie_name=')  > -1)  {
        ga('create', 'UA-XXXXXXXX-X', 'auto');
        ga('send', 'pageview');
    }
Related