Outbound Link Tracking
For tagging links that lead the user away from the current page within the current window, it is recommended to add a small delay to the click event and/or to use a hit callback to ensure that the browser has enough time to load the tracking code before the user is navigated away.
In addition, setting the transport field to
beacon will allow browsers that support the
navigator.sendBeacon method to transmit the Event data even if the user navigates away from your page or closes the browser before the request has completed. For example, links using a
_blank target attribute or otherwise loaded in a new window, the new window opens in a separate tab, and the current page (where the click originates) is not closed. Since this functionality should give Google Analytics enough time to track the event, no delay or callback would be necessary.
Deployment via GTM
Import container configuration file
Import the container file into your Tag Manager container. If your Tag Manager container already has existing configurations, you can opt to merge the import into your existing container -- if so, you should remove any duplicate Analytics tags from your existing container.
Adjust Tag Manager container variables
The following variables have been provided in the Tag Manager configuration file and require personalized adjustment. You will find them in your container with names preceded by
2_. It is recommended that you rename them without this prefix once you have edited them.
Ensure that the settings variable used in the configuration file is compatible with any settings used by your existing container.
It is required to place your Google Analytics property id into the
0_GA property constant variable with the Tag Manager container.
GA cross domains
To implement Outbound Link tracking it is required that GTM know which domains are considered outbound. While this may be a single domain or multiple domains, it is required that you modify the GTM variable,
1_GA cross domains with the list of domains that should not be considered outbound (i.e. all domains that contain your tracking code).
Test & Publish
Test the container (preferably on a non-production environment) to ensure that it functions as expected and does not impact any of your site's functionality (it is recommended to use the Chrome extension for tag injection for testing containers).
Publish the container to see the changes go live.
Deployment via on-page code
In order to deploy outbound link tracking via on-page deployment, you'll have to execute code that
- listens for clicks on links
- evaluates if the target is on a domain outside of your own, and when it is, send an event to Google Analytics (shown below).
- ensures that the traffic does not proceed until either the evaluation is determined to be within your domain or until the event is sent to GA, if the traffic is headed outside of your domain.
The resulting events will be tracked with the following data model:
- label: target URL