How to Track External Links using Google Analytics?

google-analytics-logoGoogle Analytics allows you to track how often viewers on your website click particular links on your website. Links to internal pages are automatically tracked, however you must add JavaScript code to links that point to pages outside of your own website (Exit Links) in order to track them. There are couple of ways you can track an outbound link in Google Analytics (GA) Using _trackPageview or by utm method. Let us first see the difference between these two methods.

_trackPageview method

The _trackPageview JavaScript creates a fake pageview. This method is most commonly used to track outgoing links or downloads. The _trackPageview attribute is placed within the <a> tag and looks like this: onClick="javascript: pageTracker._trackPageview(’/example/some-blue-link’). The /example/some-blue-link becomes a new pageview and it is tracked in GA as a new pageview – so it will increase your pageview count. These fake pageviews will now show up in your “content” reports.

utm method

The utm method involves telling GA what the campaign name is (you define this), the source (typically something like Google), and the medium (typically something like PPC) – as well as a few other options. This method is most commonly used in tracking PPC campaigns (as Google AdWords does this automatically), email campaigns, and other external campaigns that link back to your site. If you choose to tag your links with utm, it erases all referral information. In other words, if someone arrived at your site via a Google organic search; but they then clicked on an internal link that had the utm tagging, you lose the insight that the visitor originally came from the Google organic search (the source and medium). Instead, you see the new source and medium information that you manually entered. For me, that’s not a good option. I need to know where the visitor came from as much as I need to know what internal links they’re clicking on. Lets track an exit link on a webpage using _trackPageview method.
  1. Open the web pages with the links in your web page editing software. Locate the link you would like to track.
  2. Add the following JavaScript into your “A HREF” tag, before any other code used by Google Analytics: onClick="javascript: pageTracker._trackPageview('/example/some-link.com');" Change the portion in the parentheses to the location you would like to have listed in your tracking report. Thus after adding the onclick event, the link might look like:
    <a href="/some/where/on/internet" onClick="javascript: pageTracker._trackPageview('/some/where/on/internet');">Check this</a>
    Code language: HTML, XML (xml)
  3. Save the web page file. Upload it to your website.
  4. Verify that your links are being tracked by checking your log in Google Analytics after a day or two. Your links appear in the “Top Content” report. The links you added tracking code to should now appear in the report.
With Google Analytics it is very simple and easy to track an outbound link.
Get our Articles via Email. Enter your email address.

You may also like...

10 Comments

  1. Thanks for the tip I have installed the code on my site http://www.ldfeeds.com
    That is also ware I found the link to your post.

  2. Hey Thanks a lot Scott for linking this site. I found lot of other useful links on your site too. Also saw that you have added Google Analytics external link tracking code too. Nice.. keep up the good work..

  3. mev says:

    with onClick you may lose some information. If you click the right button and select the context menu “Open in new tab” – event onClick does not work, Google Analytics will not count anything, you lose some visits or events. read about it here http://chenado.net/en/1040.html

  4. thanks for the tip. this is the first link i clicked on from google searching how to do this and i think it’ll work just fine.

    interesteing point from mev too.

  5. Ian says:

    Hi, would there be a way to track in GA an image uploaded to my site when it loads on an external site on a conversion page?
    Would it need some kind of JS on the image tag so it would record in my GA account, and if so, what would it be?
    Thanks for your time.

  6. There is now a new type of tracking code that uses a new method of tracking events.

    I demonstrate how to easily track external links using the new tracking code and jQuery in the following blog:
    http://stephenakins.blogspot.com/2010/12/link-tracking-using-jquery-and-google.html

  7. STB says:

    These data appears in Content -> Event Tracking in my ga account, not in Top Content. Thanks.

  8. Warriorz says:

    Good Tips..

    Thanks for the help.

  9. fawad says:

    Use this method to track outbound links

    http://support.google.com/analytics/bin/answer.py?hl=en&answer=1136920

  10. I appreciate you shared this. I was going through WP plug-ins for the same thing but no luck….

Leave a Reply

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