Google has recently provided an alternative method to tracking visits on your website with their new Asynchronous Tracking method. This allows the required JavaScript & tracking code to be loaded in after your web page loads, making your website faster and more responsive.
The method of tracking outgoing / outbound links has changed however which is causing some confusion for web developers. The fundamental difference between the new and the old method is that previously one would track an outgoing link as simply another page on your website, forcing a tracker on a link such as /outgoing/outgoinglink.com allowing the developer to group outbound links as if they were local pages on their website. Using the new Google Analytics Async method however, one effectively is tracking an event using self-defined keywords, and this does not get logged as URL's on your site.
A manual outbound link on your website should not look something like this:
<a href="http://outgoinglink.com"
onclick="_gaq.push(['_trackEvent','outgoing_links','outgoinglink.com'])">Link Text</a>
What this will do (when clicked) is track an event called "outgoing_links" as "outgoinglink.com". This means that in your Google Analytics account, which has an "Event Tracking" section, you now get a category called "outgoing_links" containing an action (and total recorded) of outgoing links.
Another method of "auto-tracking" outgoing links would be to automatically detect outbound links with JavaScript after the page has loaded, and automatically add the click event to each link.
To do this, you could simply add the following code to run after your page loads (at the bottom of your document, or in some onload() function)
var a = document.getElementsByTagName('a');
for(i = 0; i < a.length; i++){
if (a[i].href.indexOf(location.host) == -1 && a[i].href.match(/^http:///i)){
a[i].onclick = function(){_gaq.push(['_trackEvent', 'outgoing_links', this.href.replace(/^http:///i, '')]);}
}
}
Using this new method, you can theoretically track anything on your website, including downloads, videos, etc. You just need to assign an "onclick" event with your own category and "description" (action), such as:
<a href="/myfiles/mypdf.pdf"
onclick="_gaq.push(['_trackEvent','downloads','/myfiles/mypdf.pdf'])">Link Text</a>