tags:

views:

33

answers:

1

I want to track when user clicks external links for analytics purposes. The simplest solution is to replace all external links with links to special record-and-redirect controller, but that would slow the user unnecessarily.

The second idea would be to override click event and within in $.post a message to record controller, then let the main event handler happen, which will usually be either click (open link in same tab) or middle click (open in new tab) - good either way, and the user won't have to wait for wait for my server to record it, it's fire-and-forget. (I don't care if users without Javascript don't get tracked)

Is that a reasonable way to go? Or what else would be the best way to track all external link clicks?

A: 

I would check how Google Analytics or Piwik are doing it. They both track outgoing links.

Fabian
Piwik seems to be using `image = new Image(1,1); image.src = tracking_url;` from within `click` handler as far as I can tell from its JS source.
taw