Track outbound links

Find out when users click a link to leave your site.

You can use Google Analytics Events to track clicks on links that take users to a website other than your own.

In this article:

Using Google Tag Manager

If you use Google Tag Manager to manage your Google Analytics tracking, follow the instructions in Google Analytics Events to implement events.

Adding tracking directly to your site

If you have added the Google Analytics tracking code directly to your site, you can copy and paste the script below into your own pages to set up Event tracking for outbound links. You should add this script in your page header, but not within the basic Google Analytics tracking code snippet.

If you copy and paste this script exactly as it appears here, your outbound clicks will appear in your Google Analytics Events reports with a Category of "outbound" and an Action of "click". (In the snippet, these are shown in bold.) You can use these values, or change them and define your own values. Learn more about Event components.

This example assumes that you are using the analytics.js tracking code. See if you are using Classic Analytics (ga.js) or Universal Analytics (analytics.js).

* Function that tracks a click on an outbound link in Google Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label.
var trackOutboundLink = function(url) {
   ga('send', 'event', 'outbound', 'click', url, {'hitCallback':
     function () {
     document.location = url;

You'll also need to add (or modify) the onclick attribute to your links. Use this example as a model for your own links:

<a href="" onclick="trackOutboundLink(''); return false;">Check out</a>

Related resources



Google Analytics Events

Was this article helpful?