How to track external links in Google Analytics

Blog Topic: TechnologyThis is not going to be a very long post on the grounds that it has such a simple resolution, I’m mainly writing it just to spread the knowledge of how easy it is to track external links through using Google Analytics. This is especially important should you have *cough* agreements with other companies that rely on you supplying them with the number of click throughs on a monthly basis.

Google Analytics is not able to automatically track external links as the pages that you are linking to will not have the same tracking code installed as your site does, speaking of tracking code the first thing that you need to do is ensure that you have the newest version of the Analytics Javascript code installed for your website, it should look something like this;

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
</script>

Next identify the link in your HTML that you would like to track on your website, I assume you know what a link looks like in HTML but just in case here’s an example;

<a href="http://www.external-link.com/">External Link</a>

If you’ve ever tracked flash files on Google Analytics then this next part will look familiar to you as we’re going to use the pageTracker._trackPageview function. It’s a good idea to keep external links in a folder to make them easier to find when later checking google analytics. In the example below I’ve used /external/ but you can use whatever you think will be easy to remember. Replace the code above in your HTML with the code below.

<a href="http://www.example.com" onClick="javascript: pageTracker._trackPageview("/external/external-link.com")">External Link</a>

Using this code will now allow you to check numbers and form reports for external links in Google Analytics.

What do you think? Do you agree or disagree? let me know, leave feedback

You must be logged in to post a comment.



Blog Category List

computer themed blog entries

Technology

Wine

boxing themed blog entries

Sport

misc blog entries

Misc