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

Partner Voices
MGM Resorts is committed to fostering an inclusive and diverse culture, not just among employees and guests but also within its supply chain. The company prioritizes procuring goods and services from businesses owned by minorities, women, veterans, people with disabilities, LGBTQ individuals and those facing economic disadvantages. This commitment is integral to MGM Resorts' global procurement strategy.    Through its voluntary supplier diversity program, MGM Resorts actively identifies and connects certified diverse-owned suppliers to opportunities within its supply chain. The company is on track to spend at least 15% of its biddable procurement with diverse-owned businesses by 2025, demonstrating that supplier diversity is not only a social responsibility but also a strategic business imperative.    Supplier diversity isn’t just the right thing to do – it’s good for business. A diverse supply chain allows access to a broader range of perspectives and experience, helping to drive innovation, entrepreneurship and resilience, while strengthening communities. At MGM Resorts, engaging diverse suppliers ensures best-in-class experiences for guests and clients. Supplier diversity ensures a more resilient supply chain while supporting economic development in the communities in which it operates.   The impact of MGM Resorts' supplier diversity initiatives is significant. In 2023, these efforts supported over 3,500 jobs across more than 30 states, contributed over $214 million in income for diverse-owned businesses and generated more than $62 million in tax revenue. The story extends beyond the numbers – it reflects the tangible benefits brought to small and diverse-owned businesses, fostering economic empowerment in their communities.    MGM Resorts also supports the development and business skills of diverse-owned businesses through investment, mentorship and education. Through the MGM Resorts Supplier Diversity Mentorship Program, the company identifies, mentors and develops diverse-owned businesses to fill its future pipeline, while providing businesses with tools and resources to empower and uplift. Since 2017, the program has successfully graduated 105 diverse-owned businesses and is on track to achieve its goal of 150 graduates by 2025.     MGM Resorts’ commitment to supplier diversity not only enhances its business operations but also plays a crucial role in uplifting communities and fostering economic development. This approach reinforces the idea that diversity is a powerful driver of innovation and resilience, benefiting both the company and the wider community.