It appears that Google Analytics now has a new tracking code. I went to add a new site into Analytics today, and I noticed that the tracking code was different. I know it just happened today, because yesterday I also added a site. So far, there’s been no word from Google on this tracking code update.
When you go to where your tracking code is displayed, there are now two “tabs”, one called “New Tracking Code (ga.js)”, and the other called “Legacy Tracking Code (urchin.js)”. The new code now uses a different JavaScript file (on Google’s side) to track your site. Obviously, the old code will continue to work.
For reference, here’s what the old code looked like:
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-1138117-1"; urchinTracker(); </script>
…And here’s what the new code looks like:
<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write("\<script src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'>\<\/script>" ); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-1138117-1"); pageTracker._initData(); pageTracker._trackPageview(); </script>
What it appears to do differently is (other than using a different JS file, and different variables and functions) determine if the current page is using a SSL certificate (https://), and, if so, it will get the JS file from Google through a secure site, otherwise it’ll just get the file normally. The reason behind this is, most likely, so that when a user goes to the site, any alerts saying that some parts of the site are insecure, won’t be because of the Analytics tracking file.
Right above the tracking code, it says this:
Use this tracking code to gain access to a wide range of exciting new features as they become available.
…And above the legacy tracking code:
Refer to this tracking code if your site already has urchin.js installed. Please note that urchin.js will not receive feature updates and is not compatible with new features.
So, using the new code, or updating your currently tracked sites, will be beneficial. I wonder what new features are coming…
It appears to also be okay to update your current code with the new one:
Note: We recommend that you do not include both tracking code snippets together on any given page. Doing so might generate inaccurate report data. You can, however, migrate select pages of your site to the new tracking code while the legacy code remains on others.
To find the new code for one of your sites, head over to the list of your Analytics tracked sites, click edit beside it, and then click “Check Status” beside the checkmark and “Receiving Data”.
Well, I guess I’m going to start updating my Analytics tracked sites to use the new code (I just added two sites yesterday, too)…
Update [December 13, 2007 at 8:45 PM]: Google’s got a post on it over at the Analytics blog.