How to Track Outbound Links
A key aspect of strategic website usability is being able to track goals and measure conversion. For an e-commerce site, tracking goals is usually pretty simple: you want visitors to make a purchase, fill out a contact form, etc., and that process generally results in a specific page that can be logged and measured.What if the goal you're tracking is a link to an outside site? You might, for example, want to track the effectiveness of advertising, or you might have a third-party handling some aspect of your shopping cart, subscription process, etc. As simple as outbound links are to create, tracking them is an entirely different matter. The core problem is that, even though an outbound link "lives" on your website, when a visitor clicks on that link, the request goes straight from their web browser to the server that hosts that other site. Your website never sees the request, it never gets logged, and you'll never see it in your analytics.
So, how do we go about tracking these off-site actions?
The Redirection Trap
A classic way to track outbound links is by trapping them using redirection. This usually requires writing some code, but it's pretty basic. Essentially, instead of linking directly to an outside site, you'll link to a page on your own site that requests that other site.Let's use this site as an example. I manage my subscribers through Feedburner, and it would be nice to be able to track how many people click on that link. Using PHP, one option would be for me to create a new page, let's call it "subscribe.php", with code that looks something like this:
header("Location: http://feeds.feedburner.com/usereffect");That new page simply redirects to the outside site, a process which is virtually invisible to the website visitor. The key is that this intermediary page (subscribe.php) is logged, allowing me to track it through my traffic logs and analytics.
Fun With Redirection
The simple method above can be used to power some much more interesting features as well. Let's say, for example, that you want to build your own banner ad tracking system, capturing all of your outbound ad clicks. By passing a parameter (let's call it $link) to your redirection page, that one page can serve as a portal to multiple outbound links. A simple PHP example (using some of my blogroll links) might look like this:if ($link == 1) {
header("Location: http://www.kaushik.net/avinash");
} elseif ($link == 2) {
header("Location: http://www.seomoz.org/blog");
} elseif ($link == 3) {
header("Location: http://www.thehotiron.com");
}Of course, this could be expanded to any number of links and could also include code before the redirection to, for example, store the ad click to a tracking database.
Google Analytics to The Rescue
If you don't like the do-it-yourself approach, Google Analytics includes a function you can use to track outbound links. This function essentially rewrites a link as the page you specify. Continuing my example above, if I wanted to track my Feedburner subscription link using Google Analytics, I would simply add the following JavaScript in my link (<a> tag):onClick="javascript: pageTracker._trackPageview('/subscribe.php');"Whenever someone clicked on that link, Google Analytics would log that click as a visit to the virtual page "subscribe.php". To use this feature, you do need the latest version of Google Analytics. Visit this GA help page for more details.
Mike Maddaloni - The Hot Iron
· Tuesday, June 10Tracking redirections is a good thing, both on the sending and receiving side (especially if you control both sites). Great topic Pete!
I wasn't aware of the Google Analytics redirect code, but in general I try not to develop a Web site around a specific set of vendor tools unless it is necessary. For example, if you went away from GA, the code would break. Granted that is a long-shot, but something to consider.
mp/m
Dr. Pete
· Tuesday, June 10@Laura: If you decide to use it, definitely check out the help-page. It's slightly temperamental.
@Mike: Usually I'd agree, but I've had really positive experiences with Google Analytics, so I'm more willing to experiment. The PHP solution is pretty easy, though, and I've implemented something similar in ColdFusion (and am sure it could be easily done in ASP).
Linda Bustos
· Thursday, June 19This is exactly the answer I was looking for to a question I didn't know someone could answer ;) Gonna try this on our blog subscribe link.
Dr. Pete
· Friday, June 20@Linda: I'm glad I could answer a question that you may or may not have known you wanted to ask :) I should warn that the Google Analytics tip is slightly tricky to implement; I think they're still working some of the kinks out (especially if you use Google Website Optimizer).



Laura
· Tuesday, June 10I had no idea that analytics had that feature! Very cool