PureNews

PureNews is an amazingly sleek and powerful news theme with unlimited color variations.

View full feature list Check out the live demo Buy this theme today

Google Analytics Gets Faster, Better

Posted by on 3rd Dec 2009 | 6 comments

ga-logoMany bloggers are using Google Analytics (GA) on their site to collect information about their visitors. It is feature-rich, accurate, extensible through an API and, most importantly to many, completely free.

However, despite its popularity, it seems that most of its users have missed one of the most important improvements to the service in recent years.

Historically the only drawback to GA has been that it is somewhat slow. It has a tendency to block other elements from loading while it churns, causing sites to slow to a crawl, especially during times of high load for GA, and that forced most to put the code in their footer, where it fails to catch “quick” visits to the site. This caused many to be torn between having a slower site and going without Google’s impressive stat tracking tools.

But on Tuesday Google announced a new Google Analytics tracking code snippet. The new code is asynchronous, meaning that other content can load even while the tracking JavaScript code is opening,

This has been a major boon for my site, according to Pingdom, I managed to shave about 2 seconds off of my loading time (from about 5.6 seconds to 3.9) between when I added the new code and a test taken shortly before. Furthermore, GA itself is reporting about 10% more visitors from the prior day despite no noticeable changes in other statistics.

Though far from definitive as it is too soon to be certain if these changes will hold, it’s a sign that others should be looking into this code as well.

The Basics

When a browser loads up a Web site, it is actually pulling in dozens of elements including the HTML code, the images, the stylesheets, the images as well as any other media. This is downloaded by the browser, rendered and then displayed to the user. Though many elements can download and render at the same time, such as images, JavaScript files “block” the downloading and rendering of other content.

The effect can be like traffic on a one-lane road with a large truck going down it. The other vehicles have to wait for the slow truck to get to its destination before they can travel at normal speeds.

With GA, the solution many took and was recommended by Google was to put the code at the bottom of the page, thus putting the “truck” at the end of the line of traffic. However, this limited the accuracy of the code, causing it to load later, and still slowed down sites as many elements, especially complex media ones, were likely waiting to load until after GA was finished.

What the new code does is effectively create a “passing lane” that lets other items pass it by. This not only speeds up the loading time of sites that use GA, but also means that the code can be moved to the HEAD of the Web site, making it more accurate.

Clearly it is a win-win for current GA users and, with that in mind, here’s how to get the code and put it on your site.

How to Use It

If you want to use the new GA code, the process is very simple. All you have to do is follow these steps:

  1. Remove Your Old Code: Remove the old code from your template (most likely in your footer below the final /BODY tag. If you use a plugin to automatically add the code, disable it for right now. However, keep a copy of your old code, or your GA ID as you will need it.
  2. Get the New Code: Visit GA’s Google Code page and get the new tracking code.
  3. Insert your GA ID: Where the new GA code says “UA-XXXXX-X”, replace it with your ID number, which should be in that format.
  4. Put the New Code In Your Site: Place the new code in your site just before the /HEAD tag, which is mot likely in your header file, rather than your footer.
  5. Clear Your Cache: If you use WP Super Cache or any similar caching program, clear your cache to make sure that all of your pages are refreshed.

Once you do that, you’re done. The new code should be working fine and you can check in your GA account tomorrow to see if it is reading normally.

Bottom Line

GA is a powerful tool for any Web site, including a blog. Knowing how many people visited your site, how long they stayed, what they read and how they got there is crucial information and GA makes it easy and free to collect some of the most robust information possible. Now, with the new code, it is also incredibly fast.

There’s literally almost no drawback to using GA on your site now, unless you have privacy concerns with Google, so it makes sense to at least give it a try. Though WordPress stats and other programs are interesting an useful, GA is the most in-depth solution available right now for free and certainly the most extensible.

I use GA currently with PostRank, on my site and love the combination. But even without PostRank, GA provides so much valuable information, I can’t imagine working without it.


6 comments - Leave a reply
  • Posted by Dean Saliba on 3rd Dec 2009

    Hmm. Two of my blogs are using The Flexibility Theme and I insert an ID and use GA that way.

    I think I might have to see if I can edit it myself as I think they have shutt up shop.

  • Posted by Sarge | beginnerblog on 3rd Dec 2009

    I'm just trying this out now. I installed the WP Super Cache but not 100% sure on now to 'clear the cache' like you say in your instructions.

    Are you able to provide clearer instructions for this part of the process. I'm hoping everything will go smoothly in this transition!

    Also I forgot to backup my existing code so I'm hoping this will be easily retrievable again from GA.

    Sarge | BeginnerBlogger.com

  • Posted by Pascal on 3rd Dec 2009

    I haven't changed the new Google analytics code in my blogs. Now immediately going to replace them. Thanks for the info.

  • Posted by Jonathan Bailey on 4th Dec 2009

    Dean: It's pretty trivial to edit I believe, if it is built into the theme, you should be able to change it without too much headache.

    Sarge: There's actually a "Clear Cache" button in the WP Super Cache settings, just click it and let it work for a few seconds. Or you can just wait an hour or two for it to clear for you.

    As for your backup, you can always retrieve the old code in your GA account, it's still there.

    Pascal: Good luck!

  • Posted by debt on 4th Dec 2009

    Asynchronous loading! I always thought that Google should do this and now its happening. Thanks for the post and I will definitely try this new asynchronously code and see the results.

  • Posted by The 39 Clues fan on 14th Dec 2009

    thanx, have GA on my blog, now I just have to use it =)