Tracking all outgoing links with Google Analytics

Posted on Posted in 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:

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

Step 3

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

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

E.g.
<a href=”http://www.ichotelsgroup.com” 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 has been partnering with companies like yours for more than 13+ years to provide more traffic with better results. 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

Your email address will not be published. Required fields are marked *