Track Internal Links in Google Tag Manager and Google Analytics

Content marketers often ask if the blog posts on websites are providing positive ROI. Another case is when the SEO team needs to check the internal links between pages to assess the internal link structure for SEO ranking. The purpose might be to decrease the page load or improve user experience.

Whatever the case may be, the question focuses on how to track internal links on websites.

There’s a way to do it correctly.

Note: You should know a little bit of HTML and CSS to know your way around. Knowing Google Tag Manager and a little bit of JavaScript can help as well. You should learn how to use Google Tag Manager first before diving into implementation.

How NOT to track internal links: UTM parameters

Other blogs have said time and time again that UTM parameters (utm_source=, etc.) are not ideal. Generating UTMs and adding them to internal links bloats the referral traffic. It floods the referral channel under the Acquisition reports. This often happens on blog posts.

It also goes against Google Analytics’ best practice to always include the website in the referral exclusion list. This self-referral exclusion will prevent any traffic from inside the domain to pass unwanted session count to itself and instead get data only from outside traffic.

In addition, Google themselves said that putting UTM codes can give mixed signals to SEO web crawlers.

How to track internal links properly? Use Google Tag Manager

Definition of terms: Internal links are what links a page from a domain going to another page on the same domain.

Google Tag Manager is a web analytics tracking powerhouse so it’s the most logical choice to track these internal links. I’ll focus on one type.

Track internal link clicks from an anchor tag

This is an example of an anchor text going to the homepage. This is just one of the many internal links to track.

  1. Go to a blog post
  2. Press right-click
  3. Click Inspect
consolie screenshot
The HTML Document

You can see the entire HTML element of a page here. You need to hover your mouse inside and look for the HTML element that houses your links.

internal link1

The body’s HTML element or CSS selector in this example is:

<div class ="post..."></div>

Important note: The HTML element or CSS selector will be different on your website. Heck, it might not even be there. Traverse the HTML document and spot what your HTML element/CSS selector is. Ask help from a web developer.

This HTML element/CSS selector is what houses the content. This information can be put in Google Tag Manager.

tmr aff banner2

Go to Google Tag Manager

Another note: Your Google Tag Manager should be set up already. Setting it from the ground up is beyond this blog post so I suggest looking into other resources. You should also already know how to navigate GTM. 🙂

The first thing to do is to enable 3 built-in Data Layer Variables. This returns the information of the click that will be tracked.

click elements
Built-In Data Layer Variables

Click Element -> This will return the HTML element of what will be clicked.
Click URL -> This will return the URL where the click will land on.
Click Text -> This will return the text on what will be clicked.

You may enable all Data Layer Variables since it’s normal to have them all enabled anyway. These three Variables will be enough.

Next is to select the Click Trigger. The Trigger will be an “All Elements” trigger type.

click trigger2
Click Trigger

Things will be tricky after…

You’ll put the HTML element/CSS selector that you acquired from the web page here. Follow the screenshot below and click Save.

click triggers

Name:
Anchor Text Click -> The name could be anything.

This trigger fires on:
Some Clicks

Fire this trigger when an Event occurs and all of these conditions are true:
{{Click Element}} -> The built-in Click Variable from before
matches CSS selector -> Will catch the HTML element/CSS selector.
.post a -> The HTML element/CSS selector from the web page. Again, yours will be different.

Put {{Click URL}} to catch anything that contains your domain name. This way, the Tag will Trigger only when the click is going to a web page in the same domain.

The magic happens here…

When you put the HTML element/CSS selector (in this case, it’s .post), you need to put a space then put letter a. This is saying, “Get all <a> tags on the body content.”

At this point, you’ve possibly caught all the anchor tags for all blog posts.

How? All internal links have the <a> tag going to different web pages. This references the <a> tags on the blog post INSIDE the body document, which is .post. Most likely that all your blog posts have the same HTML structure. BAM!

This is how HTML/CSS work. Again, ask a web developer to help you out.



Make a Google Tag Manager Event

Now it’s time to make a Google Tag Manager Event to send data from Google Tag Manager to Google Analytics.

Create the Tag the same as the screenshot below and click Save.

click tag 1

Name:
GA Event – Anchor Text Click -> This name could be anything.

Category:
Anchor Text Click

Action:
Click

Label:
{{Click Text}}

Non-interaction Hit:
True

The {{Click Text}} will be the text of the anchor tag users will click on.

Debug to see if the tag is working

Google Tag Manager has a way to debug if the Tags, Triggers, and Variables are functional. Go through your website and do a test by clicking an anchor tag. The tag should work if the tag is under “Tags Fired On This Event”

debug
Google Tag Manager Debug Mode

It’s possible that the Tag won’t fire. You can customize your targeting at this point. Try to target different HTML elements to get what you need to catch the correct anchor tags. You can also add {{Page URL}} to trigger the tag on specific pages only. It’s up to you how to trigger with more precision.

Publish the Google Tag Manager container and you’re done! Whew! 💪

Go to Google Analytics to see the anchor tag events

The Tag event data will go from Google Tag Manager to Google Analytics under the Events dashboard. In this example, the Label is {{Click Text}} in Google Tag Manager so the data will appear under Event Label in Google Analytics. This is how you track anchor tags in Google Analytics.

event label 1
Google Analytics Events dashboard

Analysts or content marketers can now use Google Analytics Segments to see the rest of the metrics.

click metrics
Google Analytics Segments

You’re now getting a bird’s-eye view impact of the internal links.

Bonus: Track internal links in Google Analytics as a Custom Dimension

Send the internal link Tag as a Dimension in Google Analytics. The Event tag in Google Tag Manager will display the anchor tag as a Primary Dimension and put them beside the standard Google Analytics metrics (Bounce Rate, Pages/Session, etc).

Go to your Google Analytics Property View and find Custom Dimensions under Custom Definitions.

Set the scope to User, set to Active, then click Save. Take note of the Index number. We’ll go back to Google Tag Manager to use this number.

custom dimension setting
Custom Dimensions in Google Analytics

Go back to Google Tag Manager and enable Custom Dimensions

Go back to the Anchor Text Click tag you created. Then tick the checkbox “Enable overriding settings in this tag”.

Under “More Settings”, you’ll see Custom Dimensions. Put the Index number from Google Analytics here. Then put {{Click Text}} as the Dimension Value. Then click Save.

click tag2
Custom Dimension settings in Google Tag Manager

Publish the Google Tag Manager container again.

The anchor text will be a Primary Dimension in Google Analytics. You’ll see it together with the standard Google Analytics metrics. Congratulations! 🎉

custom dimenson 1
Internal Links as Custom Dimensions

Conclusion – Track internal links today

Ask a web developer and show them these methods. Ask a google analytics consultant if you don’t have web developers to ask help from. If still none, well, good luck! You won’t move forward without the technical know-how. 🙂

If you want to do everything yourself and won’t spend on outsourcing this task, then you have no choice but to learn HTML/CSS and Google Tag Manager to grasp this.

Final note: The most important to consider is the type of data it will collect. Remember that Google does not allow users to store personally identifiable information in Google Analytics.

If you have private information that serves as an anchor tag, that could breach Google’s terms and conditions. It’s best not to use {{Click Text}} and instead, just use another Google Tag Manager variable as an alternative.

Google Tag Manager and Google Analytics are powerful tools to track user interactions. Tracking internal links is just a glimpse of what it can do. It becomes more powerful when combined with proper goals, KPIs, and analysis.


About The Author

Francis Angelo Reyes

Francis is the owner and runs Lupage Digital. With 5 years of experience, Francis writes everything he knows about digital marketing. There’s a large knowledge gap between developers and digital marketers. Francis is the middleman between where the non-technical and technical meet.