Nice Catch, Google

Google Analytics is a great tool for webmasters and webmistresses to help them get a handle on website statistics of visitors.  On the browser, this is made possible by the Google Analytics Tracking Code (GATC), which is hidden JavaScript code embedded into millions of web pages on the Internet. This works wonderful because most Internet users are probably unaware that Google is silently tracking much of their browsing habits.  Those who do know and care enough to do something about it, for example by blocking this code through something like the MVPS HOSTS File, are often reminded (through script errors and message boxes in Internet Explorer, such as those shown below) that Google no longer loves them.  However, that should hopefully finally start to change as more websites are beginning to use the latest GATC example, which now shows a try/catch block around the JavaScript code that can generate these errors.

A Runtime Error has occurred. Do you wish to Debug? Error: '_gat' is undefined

A Runtime Error has occurred. Do you wish to Debug? Error: 'pageTracker' is null or not an object

The change in the example code seems to have happened about two months ago, and it is already starting to work its way into Content Management Systems such as Joomla! and Drupal, through their BIGSHOT Google Analytics plug-in (version 1.5.2) and Google Analytics module (after version 6.x-2.0), respectively.  Hopefully web developers would remember to also include such try/catch blocks or conditional logic around other code where the infamous _gat and pageTracker variables are used.  The play-nice logic has been in place at Tiaan.com for about 18 months already, but I am glad to see this change is finally starting to make its way into other websites on a larger scale; there should soon be more of the love aspect in my love-hate relationship with Google.  Nice catch, Google!

Comments

The Clock is Ticking

Unfortunately, though, Google does not practice what they preach: these script errors still show up on the company's own pages, even on the page with the updated example. It will be interesting to see how long it takes Google to actually follow its own recommendations.

The Short Answer

About six hours after my blog post, Christina Park from the Google Analytics Team also posted a message about this change in the tracking code on The Official Google Analytics Blog; the post provides "the short answer" to why the change was made, highlights the change as a best practice and points out that you don't have to change the snippets on your existing pages (although that would then obviously not be best practice).  The post explains the error messages that I have shown by stating it is because "sometimes people unintentionally turn it on", and (since their post is only "the short answer") it is understandable that it didn't mention how sometimes other people, in particularly software developers, use this "Disable script debugging (Internet Explorer)" option (which you turn off to enable the JavaScript messaging feature), to assist in debugging their code.  Although finding a web developer that truly cares about eliminating all script errors on web pages may also be "a fairly rare occurrence", it can become a tedious process to constantly switch this feature on an off.  But even when the JavaScript messaging feature is not enabled, you would still get the warning messages showing up in the bottom of Internet Explorer, as illustrated in the image below.

Error: 'window._gat' is null or not an object

It may still take a while for this change to propagate to the majority of web pages that already contain the GATC, and it doesn't sound as if Google is in any hurry to change their own pages either.  After all, implementing this best practice would also allow people to opt-out of Google Analytics tracking more easily (that is, without being bombarded with all these warning and error messages on websites all over the Internet).  Although "the short answer" does tone down the importance of following best practices in web development, it is still encouraging to see that the Google Analytics Team has made this change and is not backing away from it entirely.