Curious Case: Google Analytics not working with Blogger
The problem
So after a couple of blog posts I decided to track Debuggerman’s stats (page visits, bounce rate, average time on site, keywords, etc.) and I setup Google Analytics account for it. The basic setup was straight forward and regular. You signup, give your blog’s address and then they give you a code to copy in your theme’s source “at the end of the theme right before </body>” tag. I did exactly that, but somehow it did not seem to work. Analytics kept showing me the warning sign. This post seemed like a ray of hope, but It didn’t work.
I waited for a couple of days but still Google Analytics showed a warning sign in front of Debuggerman’s account. What to do? Did I do anything wrong? I searched the internet and could not find a remedy per se. So I dug deeper and viewed my blog’s source that is generated by Blogger. Not surprisingly, Blogger was adding extra widget source at the end of my post right before </body> and right after the Analytics code (see picture).
If you are suffering from the same problem, you can verify this by typing in your blog address in the browser (e.g. http://debuggerman.blogspot.com) and when it is loaded, right click on the page and click “View Source”.
The remedy
Simple. Move the Analytics source to right before the </head> tag. The reasoning for this that I can think of from top of my head is that Analytics source conflicts with some Blogger generated source (I'm not sure, I'm not Java Script or web-dev/design expert per se). So moving it to the <head> tag ensure that 1. it is loaded and 2. it is loaded before anything else.
Right after I made this change I went back to Analytics. On my Debuggerman’s dashboard there, I clicked on ‘Edit’ action and then ‘Check Status’ link as shown in this post. All seems to work now. Hence solved the Analytics/Blogger mystery.

9 comments:
I'm having the same problem with blogger, so many thanks for the tip! I will go try it now :)
great, it works immediately after I did what u told. Thanks!
does it make a difference if the code pasted before body or before head?
It also worked for me. Thanks!
Worked like a charm ... Thanks a lot
So helpful! Thanks!
Really a wonderful blog. I have been searching for this all around the web and now got it. Thanks
Post a Comment