Tuesday, September 2, 2008

Enable Google Analytics without javascript


Site counter tracker has been a very important component for us to trace popularity of a web portal. Luckily, a lot of web site counter we can use freely. All these time I count on two site counter to track my pages. StatCounter.com offer a easy to manage and weekly reporting statistic tracker. Simply sign up and add new project to the account, and paste snippet to your HTML template. StatCounter free edition has limitation of storing last 500 records only for analysis.

Google analytics (GA) offer a more complete service, and advanced reporting tools. But so far I searched across the net, found nothing we can do to implement GA in pages (rss or widget) that not support JavaScript. With such limitation, we can't track images loadings, email reads, pdf files, and the most important to me : WML pages.

Got inspired from LinkLove, which is run smoothly on my server but lack of User Agent info, I try to alter some point. Instead of using fopen remote file, I use CUrl function. With CUrl function, we can send set HTTP header to GA to simulate the actual hit by handset to the GA Server. To know more, simply download and try it on your web server. This script is totally standalone, no external 3rd function needed.

On WML/RSS pages, instead of copying GA Urchin JS snippet, simply add a
<img src="http://yourserver.com/ga.php" alt="" /> tag like this :

<img src="http://yourserver.com/ga.php?t=UrchinCode&amp;d=your-original-domain" alt="GA" />