Saturday, December 1, 2018

Tracking Outgoing Link Clicks

 This is to record events in Google Analytics whenever someone clicks an outbound link on our website.

  • Event Category: Outside Interactions
  • Event Action: Outbound Link Clicked
  • Event Label: [Click URL]
Google Tag Manager can detect DOM events triggered by the browser such as clicks on elements and form submissions. This is known as Auto-Event tracking, because we are listening for default events and not having to write any additional code on the website.
To accomplish our goal, we can listen for all clicks on <a> elements, where the HREF attribute does not contain our domain name.

Enable the Click URL variable

In order to determine if a link is an internal or outbound one, we need to know the value of the HREF attribute. GTM can automatically record this and set it in a variable.

Go to the Variables screen and then click the Configure button.


Check the Click URL checkbox and then close the popup window. After that, you’ll see the Click URL variable will be available under the Built-In Variables table.

Create a trigger

First, create a trigger which will only fire when an outbound link is clicked. Click the Triggers menu item and then the New button.
Name your trigger  Click - Outbound Link.
Click the ‘Choose a trigger type to begin…’ text and select Just Links in the menu that appears.


We need to have the trigger to fire on outbound link clicks, not all link clicks, so need to select the Some Link Clicks radio button. In the appeared boxes, add a condition where Click URL does not contain store.com. Then save the trigger. Now this created trigger can be used to fire any tags we only want to fire when outbound links are clicked.


Create a tag

Create a new Universal Analytics tag, giving it the name GA Outbound Link Click.
Then enter your Google Analytics property ID, and then change Track Type from Pageview to Event.
Set the event category to Outside Interactions.
Set event action to Outbound Link Clicked.
Set event label to the Click URL variable (click on the brick icon to the right of the input field for a list of available variables). Once inserted, the variable name is surrounded by double curly braces. This means this field will be replaced at run-time with the action value of the clicked URL.


Set the trigger

In the Triggering section, click the pencil icon and select the Click - Outbound Link trigger we created earlier. Then save the tag.


Now you can check that the GTM debugger which shows your tag firing when you click on the links other than store.com.