Support » Plugin: Cookie Notice for GDPR & CCPA » Script blocking to comply with GDPR

  • Hello
    As GDPR requires non-functional cookies to be consented by users, I’m trying to figure out how to block scripts should the user decline to be tracked by.

    I’ve tried making Google Analytics work when the user clicks yes and get blocked by the plugin when the user says no.
    I’ve tested it in the real-time overview in Google Analytics, and it seems to be working – but only with Google Chrome. The plugin does not track at all when I click yes in both the newest version of Firefox, Microsoft Edge and Safari on my iPhone 6S.

    So here’s my question:
    For the plugin to block scripts, I need to add them in the “script blocking”-box in the Cookie Notice settings. I’ve done it like this (my unique tracking code removed):

    if ( function_exists(‘cn_cookies_accepted’) && cn_cookies_accepted() ) {
    <!– Global site tag (gtag.js) – Google Analytics –>
    <script async src=”https://www.googletagmanager.com/gtag/js?id=xxxxx”></script&gt;
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag(‘js’, new Date());

    gtag(‘config’, ‘xxxxxxxx’);
    </script>

    <!– Google Analytics end –>
    }

    Is this the correct way?

    Cheers!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author dFactory

    (@dfactory)

    Hi,
    Not exacly – you should just enter the pure javascript code there (not a php function).

    <!– Global site tag (gtag.js) – Google Analytics –>
    <script async src=”https://www.googletagmanager.com/gtag/js?id=xxxxx”></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag(‘js’, new Date());
    
    gtag(‘config’, ‘xxxxxxxx’);
    </script>
    
    <!– Google Analytics end –>

    Hi,
    Thank you for the answer.
    I tried adding only the javascript code as you’ve written above – and included my unique tracking ID, obviously.

    However, I still have the same problem. The script blocking and the tracking works in Google Chrome, but not in Firefox, Microsoft Edge or Safari on iOS.

    Any ideas? 🙂

    Plugin Author dFactory

    (@dfactory)

    This is just a code added to the site if cookies are accepted.
    It should work properly without exceptions. We’d look for a different issue somewhere in your install.

    Hi,

    Sorry to post of this thread but I am trying to achieve the same as above.

    Problem being I can’t find where my google analytics java script is?

    My website is camerabeanbags.co.uk

    Thanks,

    Harvey

    I just installed this, and the Script blocking is now located outside of the “refuse” option. If I am not using the refuse but only have the “accept” button Do I still need to add script (Google Analitycs)

    Hi – thank you for this answer, I was looking all through the forum for the specific code. There seemed to be different variations. The script works for me to block the gtag cookie, but The _ga and _gid cookies still install before the visitor clicks “ok”. So, do I need to add a bit of script under this:

    gtag(‘config’, ‘UA-XXX-X’);

    in the script blocking code box so that all Google Analytics cookies are blocked until the visitor clicks “ok”?

    Thank you very much.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Script blocking to comply with GDPR’ is closed to new replies.