Speeding up your website when using Google Analytics

2009 February 13
tags: ,
by Barry

With Google Analytic improving and embracing on page download/action tracking, it is increasingly popular to insert the Google Analytic code before the page loads, inside the tag and call it OnLoad.

With that comes the problem of executing a piece of script which will make your page load slowly if there’s a delay in loading the external ga.js file.

0.3 seconds average load time

Regardless if you place the code in the or just before the tag, some interesting information is available from Pingdom on the average load times of the external Google Analytics code.

Loads 97% slower at peak hours – in Europe


google-analytics-loading-time

On average the load time across Europe is 0.3 seconds, which may not seem large, but with the popularity increasing and the relevantly poor internet connections in Ireland – this can be an issue.

Installing it locally

Hosting the JavaScript file locally is easy, with advise by Google themselves.

First, you’ll need to download this file http://www.google-analytics.com/ga.js and upload it to your web server. (note: this is the newer Google Analytics code)

Now replace the following piece of code on your web page or blog

document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

and replace it with

document.write(unescape("%3Cscript src='" + gaJsHost + "your-website.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

Once complete, you can verify that the code is tracking by checking the tracking status in Google Analytics.

More reading

I'd LOVE if you shared this:
Talk to me on Twitter!

I'm @barryhand on Twitter.
Talk to me, that's how I find people to follow :)
Click here to find me on Twitter.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS

blog comments powered by Disqus