December 15, 2007

Making better use of Google Analytics

Many bloggers and small companies make use of Google Analytics to analyze their web traffic. But how many of them are making full use of it? Analytics don't end at installing the code and setting Goals. There are many fine tuning a web developer needs to do in order to track better. Google itself has added new features from time to time to help its customers track and analyze better. Let's have a look at some tuning to your existing sites or blog.

Before we start, make sure you are using the new Analytics code. To check if you are using new code or not, here is a sample of new code:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : " http://www.");
document.write("\<script src='" + gaJsHost + "' type='text/javascript'>\<\/script>" );
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXXX-X ");

You can get the step-by-step procedure here.

A blog or web site contains different types of links like documents and media files. Apart from these, the site may contain links to external pages which you provide as references. For example, I have link to my Resume below by Profile section. How do I track how many people download my Resume? An instant answer is to set a goal with the specified target URL. But Analytics provide a better solution!

To track downloads of media files like PDF,Doc and others, you can make use of the method _trackVisit(). For example, lets say I want to track my Resume's download. I update my link as follows:

<a href="" onClick="javascript: pageTracker._trackVisit ('/Resume_Download'); ">Resume</a>

Now each download will be tracked as a visit to Resume_Download page. But our code update is not complete. We have some more modifications to make. If you look closely at the basic Analytics code, you will see that we are making use of pageTracker object and calling method like _initData. You need to add _trackVisit(),_setAllowLinker _trackTrans(). Another point to remember is to keep the Analytics code on top, may be the first thing in body tag.

That's not all, before we complete lets see how we can track java script events. For and example, if you click "About Me" from my top menu, I load a page using java script. To tract such event use can make use of the parameterized _trackVisit(). just like how we did in the previous case. But rather than calling it on the link, I call it in my java script functions. This way you can track even the Ajax requests. To track execution of a particular function all you have to do is add:


So now you have a better tracking of your blog or web site. I am still trying out these features and will bring out another update. But these days I get less time to do research. I will be soon releasing my blogger template for others to download as some of you have asked me. Plus, I have started to work on new template and this time it's going to be using Blogger API's. So watch out!

No comments :