2

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?

asked Jun 14, 2017 at 5:08
2
  • Can you use Chrome Devtools set a break point before ga('create...)? Or simply insert debugger before it? Does the breakpoint work? Commented Jun 14, 2017 at 5:15
  • How long ago did you create the Google analytics account (takes 24 -48 hours) for it to start logging data. Are you checking the Real-time reports it can take 24 hours for data to appear in the standard reports. Commented Jun 14, 2017 at 6:44

3 Answers 3

1

enter image description here

  • Code is working fine at my end, please see the above screenshot.
answered Jun 14, 2017 at 5:32
Sign up to request clarification or add additional context in comments.

Comments

1

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.

enter image description here

answered Jun 14, 2017 at 5:53

Comments

0

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.

answered Sep 3, 2020 at 9:53

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.