Speed Up Google Analytics – Host it Locally
Posted by Jon Lee in Efficiency, Web Development, tags: caching, google, Google-Analytics, speed-up-your-blog
What’s worse than having to wait 10 seconds for a page to load completely? Waiting 11 seconds. Sometimes when a site using Google Analytics loads, you might notice that the status bar says something like:
Transferring data from http://www.google-analytics.com…
What it is doing is fetching urchin.js from the Google servers. Although Google has fast servers, it would make more sense for you to host this file locally since the user already has a connection open to your server.
By having to open another connection, it can freeze the page load until the file is fetched which is why Google recommends the Analytics code be placed at the end of the page right before the </body> tag.
Simply download urchin.js, upload it to your server and point your analytics code to your local version by changing the line:
http://www.google-analytics.com/urchin.js
What if Google Updates urchin.js?
If you’re afraid of the file becoming out-of-date when Google updates urchin.js then you can create a cronjob to periodically download the file to the same location. But keep in mind that the file has updated less than once a year (over the past few years).
How much time would this save?
For returning visitors, not much since urchin.js will be cached the first time the user tries to access your site. Every subsequent time will not require connecting to Google’s servers. However, if your blog gets a lot of one-time visitors (I get hundreds a day), it will give a small speed increase for the user.
Whether or not this speed increase is worth the risk of having an out-of-date urchin.js is up to you. Since it is usually at the end of your code anyway, it may not even matter to you at all!
Popularity: 6% [?]
Entries (RSS)
Download time is very important, sometimes even 12 sec of download time could be enough to drive away visitors, so much has to be done to reduce it. It is a brilliant idea to host Google Analytics. I also discovered that the mybloglog widget affects alot download time
I have never been tempted to run analytics, does it offer anything over and above webalizer / awstats?
I would rather wait and get some more comments. I am a bit conservative and the marginal improvement does not really attract me.
i use analytics as the standard stats application. it has some bit of difficulties. it doesn’t refresh real-time and sometimes goes nuts and shows ireal stats.
could you please recomment some other soft ?
Yeh, Google analytics is better than awstats. Google Analytics gives you a lot more infor, particularly regarding the actiivities of people on your site, how long they stay there, how many leave and bounce and on what page. Of course it won’t be able to count an unknown percentage of users because it is JS based. Also something that doesn’t get mentioned much is that some people will block google analytics with a firewall or other security software. For example I have a server running ISA security and it blocks anayltics.
Jez, I’m tuning into one of my backlink groupies and following you everywhere you go
Just kidding, I followed Bart here.
PS, Good post John. Every little thing that helps make a site better gets a thumbs up from me.
[...] Speed Up Google Analytics – Host it Locally | jon lee dot see eh (tags: Google Analytics Speed) [...]
[...] speeding up Google Analytics doesn’t give you enough of a performance boost in terms of page load time, then maybe this [...]
Well, this is of great help, especially in checking how many people visit your site. Thanks for this!
That is a good idea, I don’t think in is against Google TOS, but unless you really have reliable server, preferably to keep relaying on Google’s servers.
As long as it’s not adsence related they probly won’t mind
. Nice idea never thought of that I might give it a go on one of my higher traffic websites.
[...] to our topic. Recently I came across an article in JonLee.ca on speeding Up Google Analytics by hosting urchin.js it locally. Google support says that it is allowed, though not recommended, to [...]
For the record, Joyce Babu has created a great script to automatically update the local copy of urchin.js. I just installed it myself: http://www.joycebabu.com/blog/speed-up-google-analytics-using-simple-php-script.html
Thanks, I missed it on my trackbacks. That’s what I love about the Internet — people taking an idea and building on it to make it better!
Interesting idea, but wondering how much a speed increase it’ll make because within the .js file it communicates with google-analytics.com anyway to load a gif.
Thanks for this tip. I just tested it and it works fine on some of my projects.
However, I also compressed the urchin javascript file to decrease page load time as well.
Nice, can’t believe I didn’t think about compressing!
Impressive i like this idea simple yet effective.
The topic is a little old but if anyone stumbles upon this and also uses Drupal, there is a module which will locally store the analytics code for you and refresh once per day which makes things nice and easy for you.
Compression may be a nice feature request for it as well.