I’m using an Enflod Child Theme and have copied into Google Services -> Tracking Code. Everything works fine.
I have followed this tutorial to exclude traffic via a filter in Google Analytics:
However, when I add the php function that checks if a special cookie is set before ga('send', 'pageview');
then the tracking stops working for all users. How can I add such a function in Enfold?
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-X', 'auto');
<?php
if( isset( $_COOKIE['user_is_admin'] ) ) {
echo 'ga(\'set\', \'dimension1\', \'true\');';
}
?>
ga('send', 'pageview');
</script>
Hey Eneas,
Unfortunately, it would require quite some time and customization of the theme to achieve this, so I am sorry to tell you that this is not covered by our support. However, if it’s really important for you to get this done, you can always hire a freelancer to do the job for you :)
Best regards,
Vinay
Hi Vinay! Thank you for your reply. The question was just why the embedded php code in the script snippet above is not working as expected in Enfold?