Using Google Analytics to track more stats in your website/webapp

You can use Google Analytics also to measure more stats then just the pages it loads by calling the analytics tracker yourself in some javascript code. For example to measure how many people click on a link that is referring to the main GNOME website you simply call pageTracker._trackPageview in the onclick parameter of a link

<a onclick="pageTracker._trackPageview('/outgoing/');" href="">GNOME Website</a>

In the example above you will see /outgoing/ in the stats of Google Analytics. In CheapRiver I even use it to track which books people are searching for. Since CheapRiver is a Google Web Toolkit application I use JSNI JavaScript Native Interface to call the pageTracker. I simply added the following method to one of my classes and every time somebody searches I call trackQuery(query)

private native void trackQuery(String query) /*-{
 $wnd.pageTracker._trackPageview('/search/' + escape(query));

Comments are closed.