This article is about Universal Analytics properties, which will stop processing data on July 1, 2023 (July 1, 2024 for Analytics 360 properties). If you haven't already, start using a Google Analytics 4 property.

Measure outbound links with gtag.js

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

To set up Analytics Event measurement, you'll need to be comfortable editing HTML and coding in JavaScript, or have help from an experienced web developer.

Learn more about setting up your basic Google Analytics code setup.

If you use gtag.js for your Google Analytics installation, you can copy and paste the script below into your own pages to measure outbound links.

If you copy and paste this script exactly as it appears here, your outbound clicks will appear in your Analytics Events reports with a Category of "outbound", an Action of "click", and a Label = the URL . (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.

* Function that registers a click on an outbound link in Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
var getOutboundLink = function(url) {
  gtag('event', 'click', {
    'event_category': 'outbound',
    'event_label': url,
    'transport_type': 'beacon',
    'event_callback': 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="getOutboundLink(''); return false;">Check out</a>

Related resources

Was this helpful?
How can we improve it?

Need more help?

Sign in for additional support options to quickly solve your issue

Clear search
Close search
Google apps
Main menu
Search Help Center