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>

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

Step 2

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

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

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. 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?

    1. 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 Avatar
    Ashley Bryan

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

  3. ganesh Avatar

    hai

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

    1. 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.

      1. Christopher Regan Avatar
        Christopher Regan

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

        Cheers,

        Christopher

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

  5. 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 luis Cancel reply

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