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

Until recently, the opportunity to have a celebrity attend an event, attach themselves to a name-brand or endorse a certain product or idea was untouchable. The thought of paying a person to promote a product was seen as something only Fortune 500 companies could afford. Social media has changed all that with brands and businesses utilizing celebrity influencers to connect directly with their demographics and increase sales and profits.