Google Analytics: Tracking outbound links

Recently I was exploring Google Analytics to track website visits on my clients website. Google Analytics (GA) is indeed a powerful tool yet simple to use, implement, and most of the things are pretty straight forward. Even developers like me who are not from the SEO or Analytics background can setup website tracking pretty easily without much learning curve and can have a detailed analysis reports about the site usage, user patterns, etc.

Most of the things Google Analytics appears to do on its own without any efforts from our side to make it happen except (and off course) the GA java script code that we need to embed on each pages on our website. Again, this is pretty simple if your website is well designed and programmed (include files are good) so that from one location or file you can have the GA code added on every page automatically.

Once your GA code is in place Google starts tracking almost everything about your website usage and soon you get useful reports inside your website profile in Google Analytics. All pages, All clicks are tracked automatically (or say automagically). Such a powerful tool!

However I noticed that Google was not able to track the clicks on outbound links. Outbound links are those links on your website that take or redirect your users from your website (domain) to some other website (domain). Google does not seem to do that automatically and here it requires us to put a small javascript code inside such links. Here is the example taken from GA tutorials. (Its a nice place to explore and learn more about GA)


<a href="http://www.example.com" onClick="javascript: pageTracker._trackPageview('/outgoing/example.com');">

Notice the onClick event added inside the <a> tag. The href attribute contains the URL of the external website and the pageTracker._trackPageview('/outgoing/example.com') contains the argument with which you want to tag your outbound link click as a page view. Once this is in place Google starts tracking clicks on your outbound links as well, and the top content reports would show the tag you have assigned (in above example: ‘/outgoing/example.com’) as a page view to external site. This will give you a useful information about how many users are clicking on such outbound links and taken to external websites. Also its wise to organize and tag such links in some logical directory structure so that you can distinguish from which outbound link and from which page your users are going to any external site.

This is just a brief description about it, you can learn more about this topic at GA Tutorials. The above code snippet is applicable to only the latest version of GA tracking code.