Click Tracking with jQuery


Generally I use only Google Analytics for the stats of my web apps, but for one of my current projects (Bröllopia – sökmotorn för ditt bröllop – a swedish wedding site) I needed a bit more. I wanted to have detailed statistics for links leading to other sites to use these stats in the app itself. One way of doing this is of course to make all these links go to a page on my site and then when this page loads I record all the stats I want and then redirects to the external site, for example the link loads tracker.php and logs a click on the link with the id “123” (this id needs to be mapped to a link in the database) and then forwards to The link on my site would then look like this:

<a href=''>WebHostNinja</a>

The problems with this is that it is slow (one more page load) and that the link the user sees does not lead to the page, ie the link text “WebHostNinja” and then the user expects the link to be something like “” and nothing else. I don’t like this from a usability point of view. Not that I have any evidence for it, but I suspect that relevant outgoing links help the sites Google juice. Definitly it helps the Page Rank of the site I link to, and why should I not help them?

My solution is to use some jQuery magic. Download and install jQuery (btw, if you like jQuery, then take a look at the fantastic jQuery tools). Then add the class “track_this_link” to each link tag that you want to track as well as give each link tag an unique id (so you can track which link is which). The href attribute should point to the external site directly and not to some internal page. The link above would now look like this:

<a href='' id='123' class='track_this_link'>WebHostNinja</a>

Next step is to add a some javascript that adds an onClick event to all the links with the class “external_link”:

$('a.track_this_link').click(function() {
$.post(, {});
return true;

This means that each time an external link is clicked a post request is sent to with a unique id for the link in question. What is left is to implement the tracker.php script so that it can handle the post and save the data you are interested in to the database in a secure and correct way. I am happy to just summarize the number of clicks per link on a daily basis, but if you want to save detailed data for each click.

Do you have a better solution to this problem? Let me know!

Paranoia around Google Knol


The blogosphere and the twittersphere (is that a real word yet?) are going crazy around Google Knol, mostly it is FOG (= Fear Of Google) and paranoia. I do not see much difference between what Google have been doing for years and what they will be doing with Knol.

What is Google Knol?
Google Knol will allow you to write an article about a specific subject. Google will host the article and hightlight it when somebody search for releated keywords in their search engine. If there are several related Knol’s then the users will help rank them and in that way provide quality assurance. The writers of a Knol have the option to get a share (50% is the speculation) on all advertising revenue Google makes from the article.

Read more about Google Knol in the Official Google Blog, Read/Write Web or TechCrunch.

Why the Paranoia?
The paranoia around Knol is that Google will kill Squidoo (whatever) and Wikipedia (yeah, right) by rolling over them with their user base and Mr. Burns-like piles of cash. The irony is that by doing all the complaining about Knol the blogosphere are once again giving Google lot’s of free publicity. I agree that it is a bit sad that Google can kill off complete ecosystems of startups just by releasing a semi-done project to their gigantic user base, but sorry to say that is the name of the game. Microsoft did the same for years, and before that it was IBM. Even Saint Jobs at Apple does this. It is nothing specific to the internet industry either. The key is that in the Web 2.0 world it is possible for startups to move and innovate smarter and quicker than the big boys, so if Squidoo and Wikipedia do not adapt and join the deadpool because of that then all I can say is R.I.P.

Another big reason for all the writing about Knol is of course that posts about Google gets a lot of attention and traffic, and thus make more money to the writer via Google AdSense.

Knol is just an extension to what Google is doing already
Google is already based on user generated content. Even their revolutionary Page Rank algorithm is based on user generated content. Think about it – every time you make a hyperlink to a page you tell Google that this page is a little bit more important than before and that it probably has something to do with the page you link from. If you make money from your page it is very likely that you do that via Google AdSense, so Google is already paying you for your content.

For Knol Google will host the content themselves, and that is basically the only difference. The content is still user generated and you can still make money on the content via Google. The only thing you really need to be aware of when adding content to Knol is that Google and not you will own that content, but other than that I see no reason for the paranoia.

First mover advantage
While the still unreleased Knol gets hyped I suggest that you start writing some Knol articles about your area of expertise to be ready to add them to Knol ASAP when it launches. Of course you need to give the article an angle that promotes you and your site. Since you will be one of the first Knol’s out there you might use this to get more traffic. Another good SEO tool.

Update: Read this very interesting article from TechCrunch analyzing Google Knol