On October 16, 2007 Google announced a new version of the Google Analytics Tracking Code named ga.js. This means that there are now two versions of the GATC: the old urchin.js and the new ga.js. What makes the new ga.js different from urchin.js?
- The ability to track events
- New object oriented style; no more functions like
- Smaller size for faster downloads
This post is all about why Google introduced a new GATC, what has changed and how this is going to affect your GA implementation.
Why the Change?
Simply put, Google changed the code to support event tracking. I’m not going to focus on event tracking here, this post is just about the style and usage of the new tracking code. Please see my posts on Event tracking for more information.
What Exactly has Changed?
In short, everything has changed. All of the functions that we’ve been using are now gone. Functions like
__utmSetVar() no longer exist. The reason is that the new tracking code is completely object oriented. For those of you that are unfamiliar with programming styles, object oriented programming is a more modular way of creating code.
Object oriented programming does not have functions and variables, it has objects, methods and properties. Each object has an associated set of methods and an associated set of properties. Think of an object as a car. The methods are the actions that you can do with a car, like start, stop. Properties are characteristics of the car, like the color, number of doors, etc.
Details of the New Page Tag
Let’s look at the old and new code to better understand the difference. I’ve numbered the lines so I can better explain what’s going on.
Code #1: Page Tag using urchin.js:
Code #2: Page tag using ga.js
While there are some similarities, you can see that the new code is different. Let me walk you through what it does.
The first part of the code is the reference to ga.js (line #1-#4). This is analogous to the call for urchin.js in the old code (line #1). The big change here is that the code will automatically detect if the current page is secure or non-secure (i.e. using HTTP or HTTPS). It will then dynamically request the appropriate ga.js file from the server. This is a little piece of code that was borrowed from website optimizer.
Next section of code, lines #6 – #8, is where all the work happens. First, we tell GA the account number using
pageTracker._gat.__getTracker() (line #6). This is similar to setting the account number variable in the old code (line #4). Then we call the
pageTracker._initData() method. This method collects information about the browser, the referral information, etc. And finally, on line #8, we call
pageTracker._trackPageview(). This is the new
urchinTracker(). This is how we send the data to GA and create pageviews.
The new code does the same thing as the old code, but in a very different way. Again, all of the old functions have changed and in some cases they’ve gone away. If you were using
urchinTracker() to generate pageviews (like I was) then you will eventually need to replace that code with
Should you Upgrade?
This is the question that everyone is going to ask and there is no right or wrong answer. Eventually Google will kill urchin.js and you will have to change. But I don’t think that will happen for at least 18 months.
Here’s how I would approach the decision making process. First, do you absolutely need event tracking? If yes, then you should upgrade. You can read all about event tracking in this series of posts.
If you don’t need event tracking then my suggestion is to evaluate the complexity of your current GA implementation and then decide. If it’s fairly straight forward, i.e. you’re not an e-commerce site or you don’t have additional
urchinTraker() calls, then I would suggest migrating.
However, if you have a complex implementation, one where you’re calling
urchinTracker() a lot, you’re doing cross domain tracking, or you’ve implemented e-commerce tracking, then I would take my time. Plan your migration. There is no rush and you want to get it right.
No matter when you choose to upgrade, make sure you test your implementation before migrating. You don’t want a big hole in your data due to a mistake.
There is a lot more to the ga.js. As I mentioned before, all of the old functions have been replaced. I’ll have a listing of all the new methods soon. Until then, start thinking about your migration!