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
urchinTracker()
- 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.
Did Google need to create a new tracking code? Maybe not. But I think the modifications necessary to implement event tracking were easier using a completely new set of code rather than the old code. If you look at the entire GA system, almost every part had been re-worked since the acquisition of Urchin in 2005 except the javascript tracking code. It was time for an update and, with the addition of event tracking, the timing was right.
What Exactly has Changed?
In short, everything has changed. All of the functions that we’ve been using are now gone. Functions like urchinTracker()
and __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 pageTracker._trackPageview()
.
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.
And Finally…
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!
Thanks for a great series of posts, Justin. This is really useful.
But I have one question relating to the ‘should you upgrade’ issue.
You suggest that if there is no urgent need to track events, then the new version is not an immediate ‘must have’ upgrade.
But what about the new internal search features? Those seem extremely valuable to me. Or have I missed something (such as those being available using the old tracking code)?
Guess you forgot to tell the Webmaster.
New accounts still get the old code.
Arrggghhhh!
Fantastic! It’s about time they upgraded this part of GA.
Do you think they’ve done a good job of the re-write?
Thanks a lot for the info. I just bought your O’Reilly short cut, and was planning some cross domain tracking implementation. So 2 questions:
1. Where can I find info on how to implement cross domain tracking with the new ga.js?
2. When will an updated short cut be published?
Hi Adam,
The official Google documentation should be out soon, I’m not sure when. I’ll try to post some information later this weekend.
As for an updated Short Cut, look for that in a few weeks.
Thanks for reading!
Justin
Hi Douglas,
The new changes are not live yet so GA will still spit out the old code. However, if you’re feeling adventurous you should be able to manually install the new code.
Be sure to test any changes, you don’t want to eliminate data.
Justin
Hi Tim,
The site search reports will be available to all users, even those that do not upgrade to ga.js. Sorry if that was not clear in my post.
Justin
Hi Christopher,
Yes, I think Google did a great job with the rewrite of ga.js. They created a nice framework that will be easy to expand in the future. The event tracking feature is amazing and I think developers will really like the new object oriented style.
Justin
A very informative post, thanks for the detailed analysis of the difference between the two codes. I am eager to see what Google puts out regarding implementation etc.
Hi Justin,
thanks for this very interesting report. The big question i aks myself: “Should I upgrade”?
You write:
“However, if you have a complex implementation, one where you’re calling urchinTracker() a lot, you’re doing cross domain tracking….”
-> we don’t have a complicated implementation, but our shopping cart is hosted on a different domain, so we had to make minor changes, so GA would store the conversions correctly. If this is the only add. configuration we did, yould you recommend us to upgrade to the new code?
Wont´t work!
Cannot place a script-tag inside a script-tag like the above image.
So writing the image off will generate a error “Nested Script Block” – Sorry.
Hi Kolumbien-Andre,
If you’re using cross domain tracking on your current site then the migration should be fairly simple. All you’ll need to do is update the function calls and tracking code.
Thanks for reading and thanks for the comment.
Justin
Will there be a gap in the data when we upgrade to the new GA.JS code? Or will Urchin continue tracking data until GA.JS is activated. What should I anticipate? Thanks.
Hi Nhu-Chi,
There should not be any gap in data collection. The new tracking code does the same thing as the old tracking code. It requests the __utm.gif file from a server. As long as the code is added correctly, and the __utm.gif is requested from the GA server, there should be no loss in data.
Justin
Hi Mike,
I’m not sure which site you’re trying to use ga.js on, but I ran a few tests and it seems to be working. Remember, this is all in beta, so stuff could break unexpectedly.
Justin
GA does not consider a flash ad on adtech.panthercustomer.com as a referral :(
Adtech is a major advertisement partner for large portals, magazines etc.
GA identifies these as (direct) even though we in our servers log-files identify the complete url as a referral, GA choose to strip these out.
Is there a reason that GA choose to NOT display large ad-companies? How about beeing independent. I other word you should seriously consider buying a tracking application that displays all referrals, and not just Google.
Looking around a little, there were some interesting answers on a Google help page:
http://adwords.google.com/support/bin/answer.py?hl=jp&answer=55585
and in english:
http://adwords.google.com/support/bin/answer.py?hl=en&answer=55585
With the english help text still referring to the older urchinTracker. Some different topics are handled in the japanese version.
PS! The _udn=”example.com”; is changed into pageTracker._setDomainName(“example.com”);
Regards,
Rune Karlsen
Hi Harley,
GA does not discriminate against any referring site. What’s probably happening is that there is some type of redirect that is altering the original referral information.
I would examine the GA tracking cookies to verify that the values, which identify the visit source, are correct. If they’re not correct then there is probably a server or programatic redirect betweenthe visitor’s click and the landing page.
Thanks for reading and I hope that helps.
Justin
Hi Justin, For the new ga.js. How would this affect the 404 error page code tracking?
We have the following on our custom 404 error page
urchinTracker(“/404.html?page=” + _udl.pathname + _udl.search). Are there functions with the new ga.js that can be used to track the source path of the 404 errors?
I am still looking for any documentation on the Google Analytics Help Center, do you happen to know when any might become available? Or am I just not looking in the right spots.
Thanks!
Wendi
Will the new script function on anyone’s account? I noticed it’s not yet in my Analytics settings. If it works, why has Google not put it in yet? Wasn’t there a big hoo-haw about it?
Hi Wendi,
New documentation should be released when the new tracking code is pushed out to all accounts. I’m not sure when that will be, but I think it will be soon.
Regarding your 404 question, yes you will still be able to track 404s. However, the urchinTracker() function does not exist in the new version of the tracking code. If you choose to migrate to the new tracking code you will need to replace all instances of urchinTracker() with the new function pageTracker.trackPageview().
You’ll also need to remove the _udl variable references because those variables no longer exist in ga.js.
I know I’m short on answers, but thing will be more clear when the code is live and you start digging into it.
Thanks for reading and thanks for the question!
Justin
Hi Justin
Thanks alot for the info.
What is the answer to the nestet-script-error? Code #1 works. Code #2 does not. Is it just not possible to implement ga.js yet or have i missed something?
Thanks.
Brian
Hey Jenny,
The new JS code should work on any account. It has not been rolled out yet because there is no documentation to support it. Once there is some documentation to help user migrate it will be released.
Justin
hello!
i’ve just tried but doesn’t work in my site!!
i’ve got an asp error
I get the following error when I place the new Google Analytics code on my pages:
Active Server Pages error ‘ASP 0138’
Nested Script Block
/an-asp-page.asp, line 87
A script block cannot be placed inside another script block.
Is this a known bug because I’m just cutting and pasting out of Analytics into my wbe pages, just above the closing body tag, as instructed. Would appreciate any solutions to this. Thanks.
Hi
My question is this….. at the time of this post, the tracking code was in beta…. is it still, or is this now official? I’d like to migrate but I’m scared of things breaking….. or loss of data, although you said I shouldn’t loose any data.
hi Justin, I bought the shortcut ebook too and I’m still waiting for the updated version.. any news on that?
Hi Inge,
The tracking code is not in beta and can be used. There were a few issues when it rolled out, but things seem to be working fine.
Justin
Hi – we were using urchin tracker and migrated to the ga code. However, we are no longer receiving 404 hits. How do I remedy and/or troubleshoot this? Any information would be greatly appreciated.
Hi Jason,
ga.js does not contain urchinTracker() or any of the other functions or parameters you referenced in your comments (both of them :) ). If you want to use ga.js then you need to re-write any existing JavaScript that uses GA code.
Hope that helps put you on the right track,
Justin
Justin –
By what date must we update to ga.js from the former urchin Google Analytics? When does Google say it will no longer support the former urchin application? Thank you.
Hi Patricia,
There has been no official date set for the termination of urchin.js tracking. My guess is that they will let people use it for some time to come.
However, I still think it’s a good idea to migrate in the near future.
Justin
I have one question about GATC?
we have used the urchin.js, now i want migrate to the ga.js. now i have paste that code in every page. if i want to change my GA code, i have to change in every page, so, i create the separate .js file within my folder and can call from that script, its possible?
Velmurugan,
I’m not exactly sure that I understand the question, but if you want to migrate from the old tracking code to the new tracking code you need to replace the old GA page tag with the new GA page tag. The new code no longer contains the old functions. So you can’t just swap the urchin.js file with the ga.js file.
Also be aware that if you are creating any virtual pageviews, of using ecommerce tracking, then other parts of your implementation will also need to change.
Hope that helps.
Justin
Hi,
We’re quite new to GA and unfortunately implemented the old urchin.js code by mistake. Is there likely to be any issues or loss of data if we simply replace the old code with the new GA.js code that is available from our profile settings?
Cheers,
Kylie
Kylie,
There shouldn’t be any issues if you just swap out the old code for the new code. Some things to keep in mind though:
1. If you’re making any additional calls to utchinTracker() then you need to change those to trackPageview().
2. If you’re using ecommerce tracking you’ll need to change that code.
The best advice is to test the new code on a dev site just to make sure everything works as expected.
Justin