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, the altered link would look similar to this:

<a href="" onClick="trackOutboundLink(this, 'Outbound Links', ''); 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

One of the most distinctive and spectacular entertainment destinations in southern New England is none other than Mohegan Sun, situated on 185 acres along the Thames River.  Home to 1,600 deluxe hotel rooms, two Mandara Spas, a champion golf course, over 90 shops, restaurants and bars as well as three award – winning entertainment venues including the 10,000 – seat Mohegan Sun Arena. EXPO & CONVENTIONS