Tracking outgoing links with Google Analytics

Normally, a link’s HTML code looks like the following.

<a href="">World War II History</a>

If you are using Google Analytics, you know that you can easily see what site is referring traffic to your site. But how do you use Google Analytics to track traffic flowing the other way? One way you can do so is by calling the ._trackPageview() method in Google Analytics’ pageTracker object. For example:

<a href="" onClick="javascript: pageTracker._trackPageview('/outgoing/');">World War II History</a>

Now whenever someone clicks on the World War II History link, it will be tracked as a normal visit to a particular content page. To see this data, log on to Google Analytics and go to Content, then Top Content, and finally search for all URLs containing the word “outgoing”. By the way, you can name these mock content URLs whatever you want. I chose to use the word “outgoing” because no other pages in my site contains the word “outgoing”, thus making it easy to distinguish between normal content and outgoing content.


Updated code based on Google Analytics changes:

onclick="javascript: ga('send','pageview','/outgoing/');"