views:

115

answers:

2

I have a site where I have a lot of outgoing links and I would like to count the clicks to those outgoing links.

I need to keep the links need to be visible. (as in, no Digg like links or redirects).

So I was thinking of hooking some jQuery function to all outgoing links. This function then calls a PHP script via AJAX that updates the counter.

I have done similar things with form submitting. Where the form's onsubmit does a return of a JavaScript function. But does it work with onclick and links? Wondering about scenarios like when a person middle clicks in Firefox to get a new tab.

BTW I do not care about people with JavaScript off. They will just go to the link and not be counted, it's fine.

+5  A: 

I know this isn't directly answering your question, but you might want to rethink redirects (if done the Google way). Taken from someone else's answer:

Google has found a sneaky way around this problem by actually using Javascript to change the link instead of the status bar. When the page is loaded, the links in the results list go to their actual destinations, but every link has an onmousedown javascript event that changes the link when you click on it. You can see this in action by right-clicking on a link. After you've done that, hovering over the link will now show the true destination (Google's click-tracking script) in the status bar instead of the result's real URL.

That way you could maintain visible links but also be able to monitor traffic via redirects. (As I understand it, your only opposition to redirects are the accessibility of links - if there's more, then ignore this answer.)

Daniel Lew
Interesting stuff, i indeed do not want redirects due to the fact that people do not see the destination in the status bar.
Ólafur Waage
BTW that rightclick thing did not work on my local google (google.is) but it does work on google.com
Ólafur Waage
+1  A: 

You might need client side javascript which can make an XMLHTTPRequest to a webservice or a page with parameters (e.g. unique client id)


<a href="http://www.google.com" onclick="registerClick(this.document.getElementById('uniqueId')); return true;">google</a>

Here registerClick could be a function which can make a request to a server side page, which can become the click register.

shahkalpesh