Tracking Outbound Links with Google Analytics

Posted by Sheldon Finlay on December 18, 2009

I recently set up some social media links on a site and wanted to be able to track the clicks to each one. These were a couple of graphics that linked to a Twitter page and a Facebook fan page. The site uses Google Analytics to keep track of web statistics, and I wanted to be able to track the clicks to these two graphics. However Google Analytics doesn’t automatically track outbound links. Fortunately Google Analytics does have a little bit of JavaScript that you can append on to a link which will add outbound tracking to your Analytic Contents reports. Here’s the full image/link code for the two graphics:

<a onclick="javascript: pageTracker._trackPageview('/outgoing/twitter');" href="http://twitter.com/myaccount/" target="_blank"><img src="images/extras/social/rightnav/rightnav-twitter.gif" alt="Follow us on Twitter!" width="292" height="70" /></a></code>

<a onclick="javascript: pageTracker._trackPageview('/outgoing/facebook');" href="http://www.facebook.com/pages/myaccount/174805948058" target="_blank"><img src="images/extras/social/rightnav/rightnav-facebook.gif" alt="Join our Facebook fan page!&lt;/code&gt;" width="292" height="61" /></a>

Now the important thing here is the onclick event. You want to specify a unique made-up page name. This can also be a directory, like in my example. The actual name or directory doesn’t need to exist. In fact it probably shouldn’t exist, since you don’t want it conflicting with an actual URL on your site.

For my purposes I track all outgoing links by prefixing them with /outgoing/. So to track the Twitter link I set the to _trackPageView(‘/outgoing/twitter’). This is so I can filter by ‘outgoing’ and see a report of all outbound traffic.

Now after you’ve had this in place for a day or two you can log into Google Analytics, go to the Top Content report and then filter by whatever your _TrackPageView is set to. In my example, I’d filter by ‘outbound’ and it would return a nice report of all my tracked outbound links. One could even set up a nice custom report to save themselves the steps of having to filter your content report.

Now this solution works for a few links, but wouldn’t be ideal if you wanted to track a large number of links. You could, in theory, cook something up in jQuery or straight-up JavaScript to automatically add in the onclick event to all your outbound links. I am sure something already exists that would handle this.

There is a helpful support page on the topic of manually tracking outbound links available from Google.

Trackbacks

Trackbacks are closed.

Comments

Comments are closed.