I am attempting to log the current tracker info to the console as per the Analytics documentation:
(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-80990893-7', 'auto');
ga('send', 'pageview');
ga(function(tracker) {
// Logs the tracker created above to the console.
console.log('test');
console.log(tracker);
});
Nothing is actually outputted to the console. It's as if the function is not even executing. Why is this not working when I've literally copy and pasted from their docs?
3 Answers 3
- Code is working fine at my end, please see the above screenshot.
Comments
Please install and enable Google Tag Assistant from here and start record.
Two things always remember.
- put your ga code in always
<head></head>tag. - don't put your ga code any core function like create one php function and define
<script>ga code is here</script>and exicute it later.>> It's totaly wrong way because exicution is skip your ga code.
Let's go with your question.
- I have noticed your analytics code working fine.
- Google Tag Assistance result as per follow for your code.
- One page view event or tracks found.
Comments
Don't forget to disable ad/tracking blockers ;)
I know that this is an old thread, however, it was the only one I found about this issue and as the others stated the code is actually correct. However, the reason it did not work for me was that I forgot to disable tracking protection.
debuggerbefore it? Does the breakpoint work?