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. 

STEP 1

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

STEP 2

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);

}

</script>

STEP 3

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. 

STEP 4

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

Image CAPTCHA

Partner Voices

Atlantic City is a hidden gem along the New Jersey shoreline, offering visitors much more than a seaside destination. As Atlantic City has gone through numerous transitions, the destination is in the midst of the dawn of a new era, drawing from its rich history to meet the demands of the future.