Has anyone successfully blocked google analytics script?
-
Has anyone successfully set up Cookie Notice to run the GA script only after the user accepts the notice? How did you do it?
As of right now, GA is not running on my site whether they accept or reject the cookie notice.
Here are the steps I have taken:
I removed the GA script from my header.php file. I then pasted the GA script into the Script blocking field, making sure to “Enable to give to the user the possibility to refuse third party non functional cookies” first. After saving the plugin, clearing my caches, etc., I clear all browser cookies & history, and re-visited my website. While viewing the website on Chrome with DevTools, I accept the cookie notice, and the cookie_notice_accepted value is then true. I would expect the GA cookies to load after that, but they are not.
Here is the script I pasted into the script blocking field (replacing xxxx for my actual ID):
<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxx"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-xxxxxx'); </script>
Now here is the interesting thing – perhaps this could be the cause of the problem? When I save the settings in Cookie Notice, the script changes to this:
<!-- Global site tag (gtag.js) - Google Analytics --> <a href="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx">https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx</a> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-xxxxxx'); </script>
Notice the
<a href="...">
etc. If I manually change this back to the original<script async src=....>
it reverts to<a href="...">
upon saving. Could this be the cause of the problem? and do others experience this / has anyone found a solution?
- The topic ‘Has anyone successfully blocked google analytics script?’ is closed to new replies.