How to track all Link Clicks using Google Tag Manager

In this post I’ll show a way for you to track all Link Clicks using Google Tag Manager. This allows you to track all internal and outbound link clicks using one tag.

Previous post on Tracking Internal and Outbound Link

In a previous post I discussed a method for tracking Internal and Outbound link clicks using two different tags in GTM. This approach works fine, but I’ve come to think it’s easier to have fewer tags in GTM and do more filtering in Google Data Studio.

So in this post I’ll show how to setup a single link click tag in Google Tag Manager, and then how you can filter internal and outbound link clicks in Google Data Studio.

Creating an all Link Clicks trigger in GTM

The first step is to create our trigger that will fire when a link is clicked. Click to create a new trigger.

Google Tag Manager create a trigger

Then choose the Click > Just Links trigger type from the list.

Trigger type just links in google tag manager

I’ve decided to name it ‘Click – All link clicks’. The firing setting should be ‘This trigger fires on > Some Link Clicks“.

I’ve included the following criteria for the link click trigger to fire: ‘Click URL > starts with > http‘. This prevents us from seeing “undefined” link clicks in our Google Analytics data.

I've decided to name it 'Click - All link clicks'. The firing setting should be 'This trigger fires on > Some Link Clicks". I've included the following criteria for the link click trigger to fire: 'Click URL > starts with > http'.

Now that we have our trigger, it’s time to create our Google Analytics tag.

Creating an all Link Clicks Google Analytics tag in GTM

The next step is to create our tag to send our link click data to Google Analytics. Click to create a tag and then choose the ‘Google Analytics: Universal Analytics’ tag type.

create a tag and then choose the 'Google Analytics: Universal Analytics' tag type in google tag manager GTM

We then set up our tag in the following way.

Track Type = Event
Category = Link click
Action = {{Click URL}}
Label = {{Click Text}}
Non-Interaction Hit = False
Google Analytics setting = Your GA tracking code variable

Google Analytics - all link clicks tag in google tag manager

And for our trigger we choose our ‘Click – All link clicks’ trigger we have previously created.

Google Analytics - all link clicks tag in google tag manager

Our trigger is now completed, so lets test if it’s working in Google Tag Manager’s Preview mode.

Testing our All Link Clicks trigger in GTM preview mode

Let’s turn on Google Tag Manager’s preview mode to take a look at if our link click tag is working correctly.

preview mode in GTM

If we click to open a link in a new tab on our website, then the tag should fire, as shown below. Below we can see that when we click the link to the blog posts our “GA – All link clicks” tag fires.

gif showing the google analytics all link clicks trigger going

Now that we’ve confirmed that the tag is working correctly in GTM, it is time to see whether the correct information is appearing in Google Analytics.

Testing whether the tag is working using Google Analytics Real-time report

To test whether the tag is sending the correct information to Google Analytics, open up the program and navigate to the Real-time > Events section.

Google Analytics - Real Time - Events

Make sure you view an unfiltered view of your website, so that your own clicks are included.

Google Analytics events in real time

If we click on the Event Category “Link click” we see a table showing Event Action and Event Label. The Event Action is the URL that was clicked. The Event Label was the Click Text. If there was no Click Text, for example a user clicked an image that linked to a new page the Event Label appears as (not set).

List of Event Actions and Event Labels in Google Analytics

So we can see our link click tag is working correctly and sending the information we want to Google Analytics.

How to differentiate between Internal and Outbound Link clicks in Google Data Studio

Now that we have our link clicks tracking using a single tag, let’s use a CASE statement in Google Data Studio to differentiate between the different types of clicks.

The CASE statement says that whenever an Event action contains the text “michaelhoweely.com” then it will categorize it as an “Internal Link”. If the clicked URL does not contain the site URL (“michaelhoweely.com”) then it should be listed as an “Outbound Link”

CASE
WHEN CONTAINS_TEXT(Event Action,"michaelhoweely.com") THEN "Internal Link"
ELSE "Outbound Link"
END

In Data Studio it should look something like this.

A CASE statement in google data studio. Allows you to have a tag that track all Link Clicks and differentiate in Data studio

Using our new “Internal or Outbound links” dimension, we can filter between the two types of link clicks in Google Data Studio. You can see that below in the Data Studio report.

You can also add in a Page table and filter by what pages the events occurred on. But I’ve chosen to keep the above Data Studio report simple just as an example report.

More Articles about Google Tag Manager

Here are some previous articles I’ve written about Google Tag Manager that you might find interesting.

Hope you found this post about how track all Link Clicks in Google Tag Manager useful!

If you liked this article you might like my other blog posts.

Or you can follow me on Twitter!

I’m Michael


I’m a South African digital analyst living in Toronto, Canada. I blog about digital marketing, web analytics and data visualization.

Get in touch with me!
LinkedIn
Twitter
Email

Michael Howe-Ely