Tracking outgoing links with Google Analytics

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

<a href="http://ww2db.com">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="http://ww2db.com" onClick="javascript: pageTracker._trackPageview('/outgoing/ww2db.com');">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.

Update

Updated code based on Google Analytics changes:

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

Leave a Reply

Your email address will not be published. Required fields are marked *