Google Analytics and PHP Function
-
Hei! I need help! I want to place GA code in Header.
I want to use PHP Function:if ( function_exists('cookie_accepted') && cookie_accepted() ) { // Your code }
Does not work but.
I have written in header.php:<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','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'XX-XXXXXXXX-X', 'auto'); ga('send', 'pageview'); ga('set', 'anonymizeIp', true); </script>
GA Works supper! GA is not blocked!
Plus PHP Function:
if ( function_exists('cookie_accepted') && cookie_accepted() ) { <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','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'XX-XXXXXXXX-X', 'auto'); ga('send', 'pageview'); ga('set', 'anonymizeIp', true); </script> }
GA does not work! What is wrong?
- The topic ‘Google Analytics and PHP Function’ is closed to new replies.