The short answer is.. you don't have to change your snippet

Friday, January 16, 2009 | 3:44 PM

Labels: ,

If you've added a profile recently to your account or read a help article that discusses the tracking code, you may have noticed an addition to the tracking code snippet. You do not need to change the tracking code in your existing pages, although doing so will add a layer of functionality that I'll explain in a minute. Here is the updated snippet, with the additions in bold.

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-50020-1");
pageTracker._trackPageview();
} catch(err) {}
</script>


So why the change? Adding the try and catch to the snippet removes the possibility that your visitor sees a JavaScript message that doesn't apply to her. It's a fairly rare occurrence because messages like these (frequently in the form of an alert box) can only appear if JavaScript messaging has been enabled on the browser. Most browsers have JavaScript messaging turned off by default, but sometimes people unintentionally turn it on. For those visitors who have enabled messaging, the try and catch will have the effect of halting any messages from the Google Analytics tracking code snippet.

As a best practice, we're including the try and catch in the snippet and updating our help materials to reflect this change.