This is an implementation problem.
I would need access to your installations to figure out what is wrong.
Btw, do you have a caching plugin or server cache installed?
If so, your site is serving a cached version of the page, where the cookies were not allowed.
If that’s the case, I would do it the javascript way instead.
I had problems initially with my setup as I had GA block running in a theme options text box (Genesis Theme Options in my case). Moving the GA block to run in functions.php then worked. Rather than just dumping the block on the documentation I put it into the main GA block like this:
Note: My GA doesn’t use the same cookies as you have listed instead inserts _utma etc, so replace with your cookies and your GA ID:
function google_analytics_tracking_code(){
if ( is_allowed_cookie( '_utma' ) ){
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php }
}
add_action('wp_footer', 'google_analytics_tracking_code');
-
This reply was modified 7 years, 9 months ago by
John Hogan.
Thread Starter
zissis
(@zissis)
Yeah I am using cache. This is the code for the JS that i should run right? If so it doesnt work with that either.
if ( ! is_allowed_cookie( '_ga' ) ) {
window['ga-disable-UA-xxxxxxx-x'] = true;
}
I have a similar problem and have autoptimize and w3totalcache installed. I am running the code as in the first post and although it works, it won’t update when I toggle the cookie on and off. Can anyone let me know the correct way to implement this the javascript way?
Thanks
After a bit more testing it seems to only happen when logged out. When logged in, the cookie on/off toggle works as it should
It’s work with admin login ?
yes, works with admin login but with another user it says “we could not verify the security token. Please try again”.
The βwe could not verify the security token. Please try againβ only happens on mobile device which is a known sporadic bug afaik. Works fine on pc
The reason why it happens to offline users is that caching is disabled for admins most of the time.
About the security token issue, it happens for desktop too. It’s a random error that can be caused by several reasons. I’m releasing v2 today(finally) and that should fix the issue by making the requests work with ajax.
Hi Fernando, That is what I thought. Could you please share how I could bypass the caching issue by using the Javascript code and will this solve the issue?
Looking forward to V2. Thanks again for this great plugin. It has helped me a lot in getting ready for the GDPR!!
it can be a problem if I use the plugin: Google Analytics Dashboard for WP (GADWP) ?
Hi Imloic. I removed the GADWP as I had issues with not beeing able to control the cookies. I now inject the GA code with the cookie allowed check straight into my header section:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXX-X"></script>
<script>
if (is_allowed_cookie('_ga')) {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());gtag('config', 'UA-XXXX-X', {"anonymize_ip":true,"allow_display_features":false,"link_attribution":false});
}
</script>
I know it is a caching issue. Just need to find a solution as I do not want to remove my caching plugins π
Thanks morpheus101
i try you script and remove GADWP.
_ga etc. is always load even if i desactivate in privacy preferences
@imloic
Does this also happen when logged in as admin?. Do you use a caching plugin?
no cache plugin and connected in admin profile. Maybe before desactivate GADWP Maybe I should have cleared the plugin cache of it.