seo

Google Analytics JavaScript is Broken

I really like Google Analytics – the interface is easy to use, the information easy to interpret and it’s free. You can do great tricks with filters to slice the data in different ways. I do wish that less of the reports used sample data and it’d be nice if you could label points in your data to cross-reference with your SEO activities. But the one thing that really bugs me about Google Analytics is that the JavaScript you tag your site with is broken.

OK – it’s not completely broken but it is brittle. Brittle enough that the standard version doesn’t work at all when I access sites at work. On every page I visit on Twitter (which uses Google Analytics) I see something like this:

Twitter Tweet showing JS error

See that long dashed line at the bottom of the page that looks like a very long JavaScript comment? Let’s have a look at the source code:

Source for Twitter JS error

What is missing here is the JavaScript include reference to google-analytics.com/ga.js. It has been replaced with the long JavaScript comment. This is how it should look:

Google Analytics JavaScript working on Twitter

The long comment also causes a JavaScript error. Here is one from Distilled‘s site (who also used Google Analytics):

JavaScript error in Internet Explorer

This error is saying that the browser is not able to find an object called _gat and so it is not able to execute the _getTracker() method on it. In effect this means that my visit to this site is not being tracked.

Interestingly enough, if you get the very latest Google Analytics JavaScript it includes a

try { } catch (Exception e) {}

block around the whole section that does the _getTracker() bit. This will suppress the JavaScript warning but is a bit like burying your head in the sand.

Ostrich Burying Head In The Sand

So what is happening here? The _gat object is set up in the ga.js file that should have been loaded, but the line that loads this file has been commented out. Why has that line been commented out? Well, I don’t know exactly, but I’m pretty sure it is some form of filtering going on by the firewall in the network at my work. I imagine the same filtering is happening on other networks with the same firewall.

If you are still following me (I know this is quite techie – I will show you a solution to the problem soon), you might be asking, “Why would a firewall block this piece of JavaScript?” My hypothesis here is that the firewall is taking issue with the combination of document.write and unescape to dynamically include the ga.js JavaScript file. This is probably because it matches the signature of JavaScript attacks such as cross-site scripting.

So why does the JavaScript do a dynamic include using document.write instead of just using a simple

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button