views:

876

answers:

4

How do you track outbound links for your web sites, since the request is logged on the destination server, not yours? What method works best for an HTML site, a PHP or ASP.NET site, a template site, or a framework-based site?

+1  A: 

Add an onclick or onmousedown handler to the anchor tag. You can see many sites doing this, such as Google.

Moishe
A: 

On one system I've worked on, we ended up storing redirects in a database table and creating a redirect page that takes an id as an input. On our content pages, we link to the redirect page with an unique id from this table. Once the redirect page looks up the url via the id from the table, it then sends the client a redirect response, sending them to the ending page.

This does give us logging of external links, and as an added bonus, it makes mass changes to external urls a bit easier in some cases.

Eric Tuttleman
+4  A: 

You can add a quick JQuery script to the page that will track external links and can either redirect them to a file on your server that will track the link and then forward to it, or add an ajax request that will submit on click for external links, and track them that way.

See here: http://www.prodevtips.com/2008/08/19/tracking-clicks-with-jquery-and-google-analytics/

and here: http://www.justskins.com/development/how-to-track-clicks-on-outgoing-links/132

Eli
I like this approach - the site will work perfectly normally if the visitor does not have JavaScript, and you get the bonus of tracking if he does.Also Eric makes a good point below that if you want to guarantee that all clickthroughs are tracked, then using JavaScript is not an option.
Alison
+1  A: 

I don't like the redirect as described by Eric Tuttleman, as you unfortunately lose the 'search engine friendliness' of the link.

I handle this on a site I own by adding an onClick to my outgoing links, which fires a function which sends the link URL and a timestamp to my database. I then wrote a backend which retrieves the data, and lets me view it by such categories as 'Most clicked / 24h', 'Most clicked / 1w' etc.

I hope this helps.

BrianV
That's a good point about sites losing search engine features. I'm not sure if it's true though. If you absolutely must track all links, then doing something like the redirect that I describe will catch all situations that I can think of. Javascript can be lost in some situations.
Eric Tuttleman