Google Analytics – How To Manually Track Clicks On External Links

There is a tutorial on Google which explains How do I manually track clicks on outbound links?

However that tutorial doesn’t help a lot for non-geeks.

This is my effort to simply the outbound link tracking.

Assuming that you are using Asynchronous Google Analytics Tracking Code follow these steps

Step 1

Add following code just before closing head </head>

<script type="text/javascript">
  function recordOutboundLink(link, category, action) {
    _gat._getTrackerByName()._trackEvent(category, action);
    setTimeout('document.location = "' + link.href + '"', 100);
  }
</script>

Step 2

For each external/outbound link which you want to track add the tracking information

<a onclick="recordOutboundLink(this, 'External Website', 'externalwebsite.com');return false;" href="http://www.externalwebsite.com">

Google Analytics Report

You can find this outbound link tracking report under Google Analytics Content->Even Tracking

Google Analytics Outbound Link Tracking

Google Analytics Outbound Link Tracking

You can see more details on this report from the menus in left.

Comments

9 Responses to “ Google Analytics – How To Manually Track Clicks On External Links ”
  1. Chris

    Do you know how to do this without having to add tracking code to every single link? Is there a way to track all outgoing links easily?

    • Ajay Kumar Singh

      Unfortunately yes, you have to add tracking code to each outgoing link.

      I don’t think there is any other easier way to track all outgoing links.

  2. Ashley Bryan

    At last! Someone has put it simply. Thank you!

  3. ganesh

    hai

  4. luis

    But that will not open a new page… What must be changed?

    • Ajay

      I think it is not possible to use _blank in the outbound link, so unfortunately you can’t open the link in a new window.

      • Christopher Regan

        Ajay: did you ever get your _blank to work with event tracking?

        Cheers,

        Christopher

        • Ajay

          Nop.
          AFAIK it is official that it doesn’t work. It is not possible.

  5. John

    You can retro-fit this to existing links in pages with Javascript. The example below uses jQuery. You’d need to add a script reference to jQuery (1.7 or above) and to the js file that includes the following code…

    $(“a”).each(function() {
    $(this).on(“click”, function() {
    recordOutboundLink(this, $(this).attr(“alt”), $(this).attr(“src”));
    });
    });

    Make sure you correctly set alt tags for each link.

Leave a Reply to John