Archived topic
Universal tracking code Google
7 replies · Started by Karim on January 10, 2017
Hello Tom,
I am having an issue with: https://www.rbdakgootreiniging.nl
I wanted to add the universal tracking code to track Google analytics. Instead of adding it to each page seperatly i wanted to use the GP Hooks. So i implemented the code in the wp-head section, but then i saw the code from the front side of the site(see link for attachment), and after deleting the code totally, i keep seeing this small piece of code still from the frontside above the header(see other attachment)
I had to restore a backup eventually.
What did i do wrong to get the universal tracking code working?
http://i65.tinypic.com/2em3qkk.jpg
http://i63.tinypic.com/wb6wzc.jpg
You should add the tracking code inside <script><!--your google tracking goes here--></script> tags.
I do this very frequently.
Hello Roberto,
Thanks for the reply sir:)
So, i can use the GP Hooks "wp-head"?
And if i understand you correctly, my code will look like this:
<script><!--<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', 'UA-11111111-16', 'auto');
ga('send', 'pageview');
</script>--></script> tags.
It starts with 2 times <script> and ends 2 times with </script> ?
This is new for me
Thanks again
not really, mine looks like this:
<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', 'UA-XXXXXXX-1', 'auto');
ga('send', 'pageview');
</script>
where did you get your code from?
This is where i pick it from analytics dashboard:
Yeah, i also took my code from there, but i thought i had to put the code inside the code you sent in the previous comment.
This is what my code looks like from my universal code:
<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', 'UA-xxxxxx-16', 'auto');
ga('send', 'pageview');
</script>
But when i pasted this code in the wp_head hook i got the problem i started this topic with
If you copy the code exactly as it is when Google gives it to you, you won't have this issue.
It needs to be inside <script></script> tags, but only one set of them.
I did it again, and now it seems to work well. I have no idea what went wrong the 1st time.
I thanks you both alot:)
Cheers
Glad we could help :)