Tracking clicks on links with Google Tag Manager helps to better understand how visitors are engaging with your site. 

A Link Click Trigger in GTM will fire when a link is clicked, and a Google Analytics Event Tag will help you collect that data. By customizing the trigger, you can fire events on specific types of link clicks, such as button clicks, emails, and PDF downloads.

Below you’ll find examples of how to correctly set up tracking on each type of link click.

Before You Begin

Before starting the tracking, you want to make sure you have everything below in place.

1. GTM has been added to your site:

Ensure the Google Tag Manager code has been added to every page of your site. This can be done by manually adding the code to every page, or by using a plugin/extension to add the code for you.

2. The Google Analytics Settings Variable has been created:

The Google Analytics Settings variable is going to help us pass the data into the right Google Analytics Account.

Add this variable by going to Variables > Scroll Down To User-Defined > Click +New

3. All Click Variables have been turned on:

The Click Variables will help us create rules for our triggers, so having them all turned on in advance will save additional steps in the future.

To turn on all click variables, go to Variables > Click “Configure” > Check All The Boxes Under “Clicks”

4. You’ve added a “Link Click – All” trigger:

To help GTM “listen” for Link Clicks, we can add a Link Click Trigger that fires on all links. This shouldn’t be used a as trigger for any tags and can be removed later in the process if needed.

To add this trigger, go to Triggers > Add New > Click On Link Clicks > Name It “Link Click – All” > Save

Tracking All Link Clicks

How To Track Link Clicks In Google Tag Manager

So to get started, you will just need to drag-n-drop the How-to Schema block in the Gutenberg editor. The How-to Schema block can be used on pages that contain a How-to in their title and describe steps to achieve certain requirements.

Follow these steps to start tracking link clicks:

Step 1: Click New Tag and choose Google Analytics – Universal

This step is going to create the Google Analytics Tag, so we can start pushing the event data after a link is clicked.

Step 2: Select “Event” from the drop-down menu

Change the Google Analytics Track Type to “Event,” which will allow us to send the data into GA.

Step 3: Name The Event “GA Event – All Link Clicks”

I recommend starting all Google Analytics Event Tags with “GA Event – ” followed by whatever the event being tracked is. In this case, “all link clicks” make sense, but it could also be “button clicks, file downloads, etc.”

Step 4: Add the following the Category, Action, and Label

By filling out these event fields, we can send more detailed information about the click.
Event Category = all link clicks
Event Action = {{Click Text}} (this will pass through the visible text to the user)
Event Label = {{Click URL}} (this will pass through the full URL of the link being clicked)

Step 5: Choose Google Analytics Settings from the drop-down

The Google Analytics Settings Variable should have been created in the “before you begin” section and helps to make sure any Google Analytics events or pageviews are sent to the correct Google Analytics Property.

Step 6: Add the “Link Click – All” Trigger

The “Link Click – All” trigger will fire on every single link. This is not recommended in normal tracking but is meant to serve as a basic example of how to track link clicks.

Step 7: Save The Tag

Click Save in the top right corner, so we can then start testing the link click trigger and event you created.

Step 8: Enter Preview Mode & Test The Link Click Event

Click “Preview” in the top right corner, and then go to your website and refresh the page. The next section goes into more detail into how you can test these link links using Preview Mode and Real-Time Reports in GA.

*This tag will fire on every link clicked on the site, which is not recommended. Use the examples below to fire on specific types of links (emails, outbound, file downloads, etc), as will provide actionable data inside of Google Analytics.

How To Test The Tracking

To ensure the click tracking is working correctly, we can put the GTM Container into preview mode and test the event is firing. We can also go into the Real-Time Reports of Google Analytics, and see the actual data being passed through.

Testing In Preview Mode

  1. Click Preview Mode in the top right corner.
  2. Go to your website and refresh the page. (or hit the F5-key)
  3. Click a link on your website.
    • *Hold the CTRL-Key when clicking, and the link will open a new window.
  4. Review the tags fired, and see if your link click event was triggered correctly.

Testing In Real-Time Reports

  1. Follow the steps 1-3 in the above example to fire the event
  2. Go to Google Analytics and Click Realtime > Events in the top left corner
  3. You should see the Event firing in the reports

Troubleshooting

  • The event isn’t showing in GTM Preview Mode after clicking the link
    • Do you see a Link Click Event?
      • Try changing the Link Click Trigger, to an Element Click Trigger
  • The event isn’t showing in Realtime Reports in Google Analytics
    • Ensure your IP isn’t filtered out of Analytics
    • Double-check the Analytics Settings Variable to ensure the UA-ID is the same

Ryan’s Tip:

Naming conventions are key when building out your GTM. Start every Google Analytics Event Tag’s Name with “GA Event – “ and every Link Click Trigger with “Link Click -”

Use lowercase text for events, as it keeps things consistent within Analytics.

Tracking Button Clicks

Tracking button clicks in GTM provides more detailed information about page performance and how visitors are interacting with your site. Buttons can be tracked with a Link Click Trigger and by matching the Click Classes which usually contain “button, bttn, or btn.”

Testing is recommended to ensure the button click tracking is working correctly, but the Link Click Trigger with the RegEx match type below works for me ~90% of the time.

  • Name: GA Event – button clicks
  • Category: button clicks
  • Action: {{Click Text}}
    • this will pass through the text that is on the button.
  • Label: {{Click URL}}
    • this will pass through the full link that was clicked by the user.
  • Name: Link Click – Buttons
  • Variable 1: {{Click URL}}
  • Match Type 1: matches RegEx (ignore case)
  • Match Value 1: button|bttn|btn

Ryan’s Tip:

Naming conventions are key when building out your GTM. Start every Google Analytics Event Tag’s Name with “GA Event – “ and every Link Click Trigger with “Link Click -”

Use lowercase text for events, as it keeps things consistent within Analytics.

Tracking Email Clicks

While we can’t track emails sent to you, we can use GTM to track clicks on linked email addresses as an indicator of someone trying to contact. Linked emails contain “mailto:” in the Click URL, so we can fire the event on all links containing mailto.

  • Name: GA Event – Email Clicks
  • Category: email address click
  • Action: {{Click Text}}
    • this will pass through the email
  • Label: {{Click URL}}
    • this will pass through the email link
  • Name: Link Click – Emails
  • Variable 1: {{Click URL}}
  • Match Type 1: contains
  • Match Value 1: mailto

Ryan’s Tip:

This tag will fire on all email clicks on the site, including emails that are linked directly and buttons that are linked to emails. Seeing what is most common on your site can help you decide if passing through another variable instead of {{Click Text}} could be valuable.

Tracking Phone Number Clicks

Clicks on phone numbers can be tracked in GTM by matching the “tel:” text that appears in the URL of a correctly tagged site. Matching Click URL contains “tel” AND Click URL does not contain “http” should provide accurate tracking without false positives.

  • Name: GA Event – Phone Number
  • Category: phone number click
  • Action: {{Click Text}}
    • this will pass through the text that is visible to the user on the link.
  • Label: {{Click URL}}
    • this will pass through the full link that was clicked by the user.
  • Name: Link Click – Phone Number
  • Variable 1: {{Click URL}}
  • Match Type 1: contains
  • Match Value 1: tel
  • Variable 2: {{Click URL}}
  • Match Type 2: does not contain
  • Match Value 2: http

Ryan’s Tip:

Ensure the phone numbers on your site include the “tel:” in the HTML, as this follows along with best practices and will provide the most accurate tracking on your site.

Most cell phones link phone numbers automatically, but the “tel” is still recommended.

For more advanced and accurate tracking, use a Call Tracking Software like CallRail.

Tracking Clicks On PDFs (File Downloads)

Tracking PDF and file downloads with GTM can give you a better idea of which assets are popular with your audience, and help to understand traffic performance. By matching Click URLs that contain PDF (or the file type), we can easily track the number of downloads.

  • Name: GA Event – File Download
  • Category: file download
  • Action: {{Click Text}}
    • this will pass through the text that is visible to the user on the link.
  • Label: {{Click URL}}
    • this will pass through the full link of the file location
  • Name: Link Click – PDF Download
  • Variable 1: {{Click URL}}
  • Match Type 1: contains
  • Match Value 1: pdf

Ryan’s Tip:

Some sites have CTA’s to download PDFs, while others link directly to the file. Seeing what’s most common on your site could help you determine if another variable could be more useful than {{Click Text}}.

Tracking Facebook & Social Media Clicks

Every site has social media links, but who clicks them? By tracking social media clicks with GTM, we can see what social sites are being clicked to most. Matching the Click URL to each of the social sites is the easiest way to track.

Social links on sites are often Icons, meaning the Click Text may not work on certain sites. To combat this, I created a new variable called “Clicked Domain.” This will pass through the same site as the Click URL, but will only pass through the domain.


How To Set Up The Clicked Domain Variable

To set up the clicked domain variable, go to Variables > Scroll Down To User-Defined > Click +New

  • Name: Clicked Domain
  • Variable Type: URL
  • Component Type: Host Name
  • Strip www: Yes
  • URL Source: {{Click URL}}
  • Name: GA Event – Social Clicks
  • Category: social media click
  • Action: {{Clicked Domain}}
    • this will pass through the social site
  • Label: {{Click URL}}
    • this will pass through the full link/page on the social site
  • Name: Link Click – Social Media
  • Variable 1: {{Click URL}}
  • Match Type 1: matches RegEx (ignore case)
  • Match Value 1: facebook|twitter|linkedin|instagram|pinterest|youtube|tiktok

Ryan’s Tip:

Make sure to test all social links, including footer/header icons, share features, embedded posts, and direct links.

Tracking Outbound Link Clicks

While people leaving your site may not be ideal, tracking the number of outbound link clicks with GTM can help you understand why. Tracking link clicks that do not contain your domain is the cleanest way to track these outbound links.

  • Name: GA Event – Outbound Links
  • Category: outbound link click
  • Action: {{Click Text}}
    • this will pass through the text that is visible to the user on the link.
  • Label: {{Click URL}}
    • this will pass through the full link that was clicked by the user.
  • Name: Link Click – Outbound
  • Variable 1: {{Click URL}}
  • Match Type 1: does not contain
  • Match Value 1: yoursite.com

Ryan’s Tip:

Use Trigger Exceptions to prevent double firing of events on clicks like social media, as that would fire both an Outbound Click and Social Media Click.

Watch out for images on your site, especially if you’re using a CDN. These will trigger an outbound link click, even though they’re assets on your site.

Turning Link Clicks Into Google Analytics Goals

Event reports in Google Analytics are helpful for digging into the data, as a lot of information can be passed through in a single hit. However, using Goals to see conversion data makes the data a lot more accessible in most of the reports.

The Difference Between Goals and Events

While there are many differences between the two, the main difference relevant to this article relates to how each is counted.

  • A Google Analytics Goal can only fire once per session (visit), regardless of the number of times the goal has been triggered.
  • An Event can fire multiple times per session, and each triggering will show in Analytics. Events allow you to see “Total Events” and “Unique Events” to better understand how many times each event has actually been triggered.

Setting Up An Event-Based Goal In Google Analytics

To add an Event-Based goal, navigate to Goals under the View Settings in Google Analytics. Name the goal, set the Goal Type to “event,” and then fill out the Goal Details to match the event that’s been set up.

This is the part that people tend to screw up. We need just enough detail to make the goal fire when it’s supposed to, and not fire when it’s not. So if an event was set up to fire on email clicks, I would set the Event Category equal to “email address click.”

There is no need to fill out the Event Action or the Event Label unless I’m only looking to fire on a specific email address. For most events, you can get away with only filling out the Event Category.

  1. Go to Google Analytics > Admin > View Settings > Goals
  2. Click “+ New Goal” (the big red button)
  3. Select “Custom” as the Goal Setup
  4. Name the goal something helpful, such as “Email Address Click” or “PDF Download”
  5. Select “Event” as the Goal Type
  6. Fill out the “Event Category” (assuming that is all you need)
  7. Click Save

*Goals are not retroactive, meaning they won’t show any data from before they were set up. Even if an event was firing previously, the goal will only start collecting data once being added. And make sure to Publish your GTM container to make your event tracking live on the site. More about goals here.

What’s Next

By implementing link click tracking on the key engagement and conversion points on your website, you can better understand how visitors interact with your site and improve the overall quality of your data.

Thank you for checking out my post!