Data Collection

Track Internal Links with Google Analytics and GTM

Do *not*  use UTM tracking codes on internal links! I just wanted to get that out the way. And if you don’t read anything else in this post, that should be your main takeaway. But if you would like to know how to properly track internal links with Google Analytics, then read on!

Why track internal links?

Well, first: What are internal links? Internal links are just that. They are links on your website that point to other pages on your website. Those links are typically navigation links in menus, embedded links in text or call to action links (e.g. buttons). Also, it’s links in a sidebar pointing to related content. So basically, it can be any type of link.

You probably don’t want to track clicks on all internal links on your website. Most of all, you want to track clicks on links that matter. Link clicks that tell you something valuable. Like “Is this call to action getting any action?” or “Do we really need these 25 links in the mega dropdown menu?”. But to make those decisions, you need data.

Furthermore, you may want to be able to segment your data. For instance, do people – who clicked a specific link – have a significantly different behavior than those that didn’t? Do they convert better? Or worse? Do they view more pages, do they spend more time on the website? In that case, you can’t use the Navigation Summary reports (which you would use if just examining where people went to from one page).

So if you setup specific tracking on internal links, you can use that tracking to build segments. In turn, segments can be used to analyze acquisition, behavior and conversions. And finally, segments can be shared with AdWords to do very targeted, well, retargeting.

What not to do

First of all, don’t use UTM codes on your internal links and don’t use virtual pageviews.

UTM codes are only meant for tracking external, usually paid, campaigns. That’s one thing. Secondly, if anyone clicks an internal link that has UTM codes, a new session is started. Now, I won’t go into the technical details here (feel free to ask in the comments), but you’ll basically double count all users who click one of those links AND you will kind of overwrite the original traffic source information.

Next, don’t use virtual pageviews either. While they won’t destroy your session count and acquisition reports, this approach also will inflate your pageview count. And it’ll make your Navigation Summary reports a mess.

Things to know about links

So now that you know what not to do, let’s talk about what we should do. Basically, you want to use event tracking for internal link tracking. Events in Google Analytics are any interaction that can be tracked on a page. That could be a video play, an AJAX event, a file download – or a click on an internal link.

In order to track internal link clicks, you should know how a link looks like when talking HTML. So, while the navigation on my website might look like this:

Track internal links - rendered links

…the actual HTML behind those links looks like this (simplified):

<ul id="menu-nav-bar"">
  <li id="menu-item-129" class="menu-item">
    <a href="/">Home</a>
  </li>

  <li id="menu-item-409" class="menu-item">
    <a href="/category/data-collection/">Data Collection</a>
  </li>

  <li id="menu-item-410" class="menu-item">
    <a href="/category/data-quality/">Data Quality</a>
  </li>

  <li id="menu-item-411" class="menu-item">
    <a href="/category/data-analysis/">Data Analysis</a>
  </li>

  <li id="menu-item-412" class="menu-item">
    <a href="/category/inspiration/">Inspiration</a>
  </li>
</ul>

How to track internal links with GA & GTM

Now, depending on which link I want to track, there are multiple ways of setting up a trigger in Google Tag Manager. The basic premise in all cases is to set up a trigger of the Just Links type. This trigger is then configured to only fire on Some Link Clicks.

Let’s say I’d like to track clicks on any of those links. Looking at the css classes, any of those links can be captured in two ways using a css selector. The first matching css selector is #menu-nav-bar li a, and the second is .menu-item a. I prefer the last one, since it’s shorter. So, the trigger should look like this:

GTM trigger to track internal links

In turn, if I want to track clicks on a specific link, it’s just a matter of identifying the css selector that would match that specific link. So say I’d want to track clicks on the Data Analysis link, then the css selector for that link is #menu-item-411. We can use the same trigger configuration with one slight modification to the value of the Click Element condition:

GTM condition to track internal links

Finally, it’s all about setting up a Universal Analytics tag in Google Tag Manager:

Event tag to track internal links

In this example, the actual text of the clicked link is set as the Label. So, when triggered, this event appears in the Top Events report with the click text as the Event Label.

Next steps for tracking internal links

Because you can track any internal links, doesn’t mean you should. As I pointed out earlier, you should track clicks on links because you want to make better decisions. So it all begins with defining what you want to accomplish. And from there, you begin to map which internal links to track.

Also, take care to define a naming convention for you event categories, actions and labels. Maybe it’s a good idea to keep everything in one single Event Category and use the Event Action to ‘categorize’ different link types. As a result, you could have one action called ‘Navigation Links’, and another action called ‘CTA buttons’.

6 thoughts on “Track Internal Links with Google Analytics and GTM

    1. Hi Mick,

      To enable that feature, first go to the Variables section in GTM. Then click Configure under Built-in Variables. Enable the Click Element variable.

      After that, you should be able to select the Click Element variable in your trigger configuration.

  1. Thanks. Great article.

    1) Where do I find the css selector?

    2) If I want to track clicks on all of my CTAs, do you mean each of them will have their own css selector value? Or what would you recommend?

    1. Hi Warren,

      Thanks for the feedback :)

      1) In Chrome, right-click the element you’d like to track, click “Inspect Element” and simply read the css classes. You may need to look at the parent elements as well. If you’re not comfortable reading HTML and CSS, there’s this plugin for Chrome, which will generate the css selectors for you.

      2) On most modern websites, CTA buttons will share some of the same css classes. Let’s say that all of your CTA buttons have a classes called “btn”. Then you would just setup your trigger to trigger on clicks on elements where css classes matches “.btn” (without the quotes).

        1. That depends on your Tag configuration. In the example in this post, I’m using {{Click Text}} on the label field. This would push the actual text of the button to Google Analytics in the Event Label. So if texts on the CTA buttons are different, you can distinguish them from each other that way. You could also grab the {{Click URL}} if texts often are the same, but the URLs different. Or if URLs and texts are the same, you would have to add some information in the HTML such as an data attribute (e.g. data-button-identifier=”CTA button on homepage carousel #1″) and grab that via a custom variable. It’s a bit more advanced :)

Leave a Reply

Your email address will not be published. Required fields are marked *