Tracking all outgoing links with Google Analytics

Track outbound links in Google Analytics

I wanted to try and find a way to track all of the outgoing links on my client website, without haven to modify the html of the link. What I found was that using javascript listeners would probably be the best solution.

With a bit of searching I found a script that you can place in the header file at the top of each of your pages (you might need to edit the templates if you run WordPress). The script tracks clicks to external links and reports them in Google Analytics.

Read more about Google Analytics: How to track all your outgoing links the easy way

 Step 1

Place the Google analytics code in head tag rather than body tag as follows:

Step 2

Custumize the Google code as follows:

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src='” + gaJsHost + “’ type=’text/javascript’%3E%3C/script%3E”));
function recordOutboundLink(link, category, action) {
try {
    var pageTracker=_gat._getTracker(“UA-XXXXXX-X”);
    pageTracker._trackEvent(category, action);
    setTimeout(‘“‘ + link.href + ‘”)’, 100);

Step 3

Add onclick attribute on outbound links which you wants to track as follows.

onClick=”recordOutboundLink(this, ‘Outbound Links’, ‘trackingname123);return false;”

<a href=”” rel=”nofollow” target=”_blank”>Reservations</a>

Step 4

Check the outbound links in Google analytics under left menu >> Content >> Event Tracking.

Srinivas Katam

Do you need help growing your business? Srinivas Katam is a Digital Marketing Strategist and Consultant with over 200 successful SEO and Social Media client engagements completed. I’ve worked with brands across the world as a digital marketing consultant to deliver revenue growth from content-focused inbound marketing campaigns. He is an Innovative Marketer who specializes in digital marketing, specifically in social media, SEO and online strategy.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInPinterestGoogle PlusDiggStumbleUponYouTubeRedditDelicious

Leave a Reply