Tracking Outbound Links in 4 Easy Steps

September 29, 2013

Adding event tracking Javascript code to outbound links is a nifty way of tracking outbound links to third party websites from your website. 


Ensure that your website is using the latest asynchronous Google Analytics tracking code.


Copy and paste the Javascript code below into the head section of your website HTML. The code may look a bit daunting but its function is fairly simple. It delays the new page load by a fraction of a second so that the click to the outbound link can be recorded. This delay will be imperceptible to your website visitors.

<script type="text/javascript">

function trackOutboundLink(link, category, action) { 

try { 

_gaq.push(['_trackEvent', category , action]); 

} catch(err){}

setTimeout(function() {

document.location.href = link.href;

}, 100);




Modify the HTML for your page to include the tracking method in the hyperlink tag.

For example, to log every click on a particular link to www.third-party-website.com, the altered link would look similar to this:

<a href="http://www.third-party-website.com" onClick="trackOutboundLink(this, 'Outbound Links', 'third-party-website.com'); return false;">

In Google Analytics, all clicks tracked with this link will show up under the head 'Outbound Links'. The 'return false' condition for the onClick handler gives the Google Analytics code time to track the link before the browser loads the new page. 


Test before launch! Assuming the event tracking was set up correctly, you should be able to see your events on the Standard Reporting -> Content -> Events screen in Google Analytics. Please note that it can take up to 24 hours for the tracked clicks to show up.

Add new comment


Partner Voices

Modern events accumulate huge amounts of data.  Turning that data into an understanding of your audience in order to build attendance can be overwhelming.  Fortunately, business analytics tools like CDS’ Data Sense® can do the heavy lifting, combining your different data sources for a detailed view of your event and audience.  Introducing the Persona Tree!