Hi, my name is Christoffer and I am an Internet addict.

Hazards of hosting the Google Analytics scripts yourself and how to avoid them

2011-02-06 14:33

If you are running a popular website with a lot of visitors and use Google Analytics to track them, you might already have heard that you could host the Google Analytics scripts yourself to increase your site's response time. Even I have written a post concerning the impact on loading external scripts and how it impacts your own response time, thus also the user experience of the site.

Concerning Google Analytics, I am not going to argue if that's a good or a bad idea to host the scripts yourself. As a web developer, you have to take that decision yourself; do you want to sacrifice the response time to have a more reliable tracking or is it more important with a faster response time by removing any external dependencies.

The hazards of hosting the scripts yourself

If you decide to host the files yourself, you introduce the risk that the scripts can become old and deprecated (due to Google upgrades the original scripts) and you won't track anything at all. However, there are some solutions to avoid this.

Two kind of solutions

The solutions can be divided into two groups. The idea behind the first group solutions is to automatically update your hosted scripts regularly. The second group of solutions is to be notified when the scripts are out of date and manually update them.

Both solutions have their benefits and disadvantages depending on how much time and effort you want to put down before and after the launch of the site, and how secure you want it.

The benefit of automatically updating the scripts is:

The disadvantage are:

The benefits of being notified are:

The disadvantages are:

Different ways to automatically update the scripts

Being notified when the your scripts are outdated

Using Google's asynchronous solution

It is also possible to forget this whole post and implement Google's latest tracking code, which is instead asynchronous based. According to Google it's faster, more accurate and more resistant against errors.