Coding and Dismantling Stuff

Don't thank me, it's what I do.

About the author

Russell is a .Net developer based in Lancashire in the UK.  His day job is as a C# developer for the UK's largest online white-goods retailer, DRL Limited.

His weekend job entails alternately demolishing and constructing various bits of his home, much to the distress of his fiance Kelly, 3-year-old daughter Amelie, and menagerie of pets.


  1. Fix dodgy keywords Google is scraping from my blog
  2. Complete migration of NHaml from Google Code to GitHub
  3. ReTelnet Mock Telnet Server à la Jetty
  4. Learn to use Git
  5. Complete beta release FHEMDotNet
  6. Publish FHEMDotNet on Google Code
  7. Learn NancyFX library
  8. Pull RussPAll/NHaml into NHaml/NHaml
  9. Open Source Blackberry Twitter app
  10. Other stuff

Google Analytics and the Bogus Account Number

I've recently fallen hit a snag with the Google Analytics API, that's really put a dint in my day. The suggested script comes with a caveat, that it should be included in the header of the page. But this goes against current performance guidelines, that you want all of your scripts to go at the bottom of the page, particularly if they're loading in third-party scripts.

So why does that script need to go at the top of the page? Is it anything to do with page load timings? Nope, the APIs used to time pages are built into the browser, or on some versions of IE they're built into the Google toolbar where it's present. So it ain't that. Could it be because if you put anything into the global "_gaq" array before the account number, those instructions go in with a bogus made-up account number?

We don't get a nice clear JS error telling us something's wrong. the analytics JS file doesn't look for the account number first before sending the rest of the traffic, it doesn't refuse to send the commands (so the bug might be more obvious if you're monitoing HTTP traffic using Fiddler or Firebug, etc), it sends the commands with a bogus account number. Ouch.

I propose a minor tweak to the Analytics code block that fixes this problem, but first some background.


Categories: Hacking
Permalink | Comments (0)