Skip to content

Outbound Link Tracking

An outbound link click tells you when a user leaves your site to visit an external domain. For most sites, this means social media, affiliate links, partner sites, app store links, or competitor research. Knowing where your users go — and from which page — is worth having.

GA4 enhanced measurement (the free version)

Section titled “GA4 enhanced measurement (the free version)”

GA4 automatically tracks click events for outbound links when enhanced measurement is enabled in your GA4 data stream settings. It fires when a user clicks any link pointing to a different hostname than the current page.

You’ll see these events in GA4 with:

  • event_name: click
  • link_url: the destination URL
  • link_domain: the destination domain
  • outbound: true

The limitation: you can’t add custom parameters (like which marketing channel the link belongs to), you can’t exclude specific domains, and you can’t control the event name. If the default click event is good enough, use enhanced measurement and skip GTM entirely.

Section titled “GTM approach: Link Click trigger with hostname filter”

For custom parameters, domain exclusions, or a different event name, use GTM.

  1. Enable Link Click built-in variables. GTM Variables → Configure → enable: Click URL, Click Text, Click Element, Click Target.

  2. Create a Link Click trigger:

    • Trigger type: Click — Just Links
    • This trigger fires on: Some Link Clicks
    • Condition 1: Click URL — does not contain — yourdomain.com
    • Condition 2: Click URL — starts with — http (excludes mailto:, tel:, javascript:, and #anchor links)
    • Enable “Check Validation”: ON
    • Enable “Wait for Tags”: ON
  3. Create a GA4 Event tag with the outbound_click event.

Tag Configuration

GA4 - Event - Outbound Link Click

Type
Google Analytics: GA4 Event
Trigger
Click - Outbound Links
Variables
Click URLClick TextPage URL

Set event parameters:

  • link_url{{Click URL}}
  • link_text{{Click Text}}
  • outboundtrue
  • page_location{{Page URL}}

Some external links shouldn’t count as “outbound” — payment processors, authentication providers, CDN domains, or partner sites you own:

Add additional trigger conditions using “OR” logic isn’t possible directly, but you can use a Lookup Table or Regex Table to define a “is_excluded_domain” variable, then add a blocking condition:

Option 1: Multiple trigger conditions (simple case)

Add condition: Click URL — does not contain — trustedpartner.com Add condition: Click URL — does not contain — payments.stripe.com

This works for a small list. For larger lists, use the Custom JavaScript approach.

Option 2: Custom JavaScript variable for domain exclusion

// Custom JS Variable: "CJS - Is Excluded Outbound Domain"
function() {
var url = {{Click URL}};
if (!url) return true; // Exclude if no URL
var excludedDomains = [
'trustedpartner.com',
'stripe.com',
'paypal.com',
'accounts.google.com',
'auth0.com'
];
return excludedDomains.some(function(domain) {
return url.indexOf(domain) !== -1;
});
}

Then add a trigger condition: CJS - Is Excluded Outbound Domain equals false.

If you want to categorize outbound links by type, use a Regex Table variable:

Create a variable named Regex Table - Outbound Link Type:

  • Input Variable: {{Click URL}}
  • Rows:
    • twitter\.com|x\.comsocial_media
    • linkedin\.comsocial_media
    • instagram\.com|facebook\.comsocial_media
    • apps\.apple\.com|play\.google\.comapp_store
    • github\.comdeveloper
  • Default Value: external

Add link_type{{Regex Table - Outbound Link Type}} as an event parameter.

For affiliate links specifically, you often want to track the destination domain and the referring page together:

// dataLayer approach for affiliate links with structured tracking
document.querySelectorAll('a[data-affiliate]').forEach(function(link) {
link.addEventListener('click', function() {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'affiliate_click',
affiliate_partner: this.dataset.affiliate,
affiliate_destination: this.href,
link_text: this.textContent.trim(),
page_location: window.location.href,
content_block: this.closest('[data-block]')
? this.closest('[data-block]').dataset.block
: 'unknown'
});
});
});

Using data-affiliate attributes makes the intent explicit and removes guesswork from URL pattern matching.

Both of these options matter for outbound links:

Check Validation — Runs GTM’s own validation check on the link. It verifies the link isn’t prevented from navigating (e.g., by e.preventDefault()). This prevents false tracking of links that don’t actually navigate.

Wait for Tags — Pauses the link click response for up to 2000ms while GTM fires its tags. Without this, the browser may navigate before GA4 receives the hit, especially on slow connections. Set the timeout to 500ms. Going higher than 500ms creates a noticeable delay for the user.

If you forget to add a condition excluding your own hostname, every internal link fires as “outbound.” Your GA4 data fills with your own domain as the top outbound destination.

A pattern that catches this: build a constant variable with your domain name (yoursite.com), then use it in the trigger condition: Click URL — does not contain — {{Const - Site Hostname}}.

Links like mailto:info@example.com and tel:+12025551234 start with mailto: and tel:, not http. They will match a link click trigger but should typically be tracked separately. Add a condition: Click URL — starts with — http to exclude them from outbound tracking.

Forgetting to disable enhanced measurement after setting up GTM

Section titled “Forgetting to disable enhanced measurement after setting up GTM”

If you configure GTM to send click events for outbound links AND keep GA4 enhanced measurement enabled, you’ll get double events. Either disable enhanced measurement’s “Outbound clicks” option, or change your GTM event name to something like outbound_click to differentiate.