How to track outbound links with Google Analytics

When setting up goals in Google Analytics, many people fall astray when it comes to tracking links that take the user to an external website. A common wrong assumption is to act as if the link is internal, i.e.:

The wrong way to set up external links in Google Analytics

Unfortunately, you are only able to track internal links via a URL destination.

Good news is that Google has a neat way of getting results another way – via what is known as Event Tracking.

Geeky Code Stuff

To do this you will need to deal with some JavaScript code so if you aren’t that type of geek, you may want to contact your website developer. The below is following the traditional analytics code, but you can also use the newer Asynchronous Code shown here.

1. Set up Event Tracking in your Analytics Tracking code (if you don’t have it already).

Add the following line to the tracking code for your pages after the page tracking object is set up (replace XXXXX-X with your account ID #):

var pageTracker = _gat._getTracker(“UA-XXXXX-X’);

2. Add a JavaScript method in the head of your document.

Here’s what the JavaScript code in the <head> section should look like:

<script type=”text/javascript”>
function recordOutboundLink(link, category, action) {
var pageTracker = _gat._getTracker(“UA-XXXXX-X”);
pageTracker._trackEvent(category, action);
setTimeout(‘document.location = “‘ + link.href + ‘”‘, 100)
} catch(err) {}

3. Update your outbound links to call the new function without first following the link.

For example, to log every click on a particular link to, you would use the _trackEvent() method in every link’s <a> tag:

<a href=”” onClick=”recordOutboundLink(this, ‘Outbound Links’, ‘’, <youropt_label>, <youropt_value>);return false;”>

Where <youropt_label> and <youropt_value> are optional. The “label” is useful if you are wanting to target an individual link(s), and you need to distinguish it from other links. “Values” can help place priority (by assigning higher values to more important links).

Google Analytics Set Up

Let’s say you want to track clicks to from just your homepage. You simply add this to your <a> tag to any links on that page:

<a href=”” onClick=”recordOutboundLink(this, ‘Outbound Links’, ‘’, ‘From Home Page’, 5);return false;”>

Where ‘From Home Page’ acts as the unique “label” and 5 is the goal “value” you wish to assign this link.

Log in to analytics and find the goals within the admin section. When adding a goal, fill in the details as appropriate. In our example, this would be as thus:

Correct Tracking of Outbound links

This must match the text within your code.

Once set up, allow a few days for the tracking to take place before checking its progress. You can find this within Standard Reporting > Conversions > Goals.


1 comment

  1. Abhishek Dwivedi   •  

    Thanks a lot Ellen! I did have the Outbound Links setup but did not know how to setup a goal for a particular external url clicks. Thanks to your post I am able to configure now. As its configured just now, I don’t know what the results will be 🙂

    Thanks again!


Leave a Reply

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