How to Track Internal Link Clicks in GA4 (With and Without Google Tag Manager)


How to Track Internal Link Clicks in GA4 (With and Without Google Tag Manager)

It’s important to note that GA4 doesn’t track internal link clicks by default. If you want to gather valuable data on how users are navigating your site, tracking internal link clicks is a must. Understanding which pages users are clicking on, where they go next, and which calls to action are the most effective can help improve your site’s performance.

In this post, we’ll walk through two approaches to tracking internal link clicks in GA4:

  1. Using Google Tag Manager (GTM).
  2. A simple JavaScript solution for those who prefer not to use GTM.

Option 1: Track Internal Link Clicks with Google Tag Manager

If you’re using Google Tag Manager, the process of tracking internal link clicks is pretty straightforward and doesn’t require much code. Here’s how to set it up:

Step 1: Create a Click Trigger

First, we need to create a trigger that fires when someone clicks on a link:

  • Go to your GTM account and create a new Click – Just Links trigger.
  • For the Trigger Configuration, choose Some Link Clicks.
  • Under “Enable this trigger when,” use the condition Click URL contains <your-domain-name>, so only internal links are tracked.

Step 2: Set Up a GA4 Event Tag

Next, we’ll configure a tag to send the event data to GA4:

  • Create a new GA4 Event Tag.
  • For the Event Name, use something simple like internal_link_click.
  • Add some important parameters:
    • link_url: Set this to Click URL (this is the destination of the link clicked).
    • link_text: Use Click Text to capture the text of the link.
    • link_classes: Capture the classes of the link using Click Classes.

Step 3: Test and Publish

After everything’s set up, use GTM’s Preview Mode to make sure your links are firing correctly. Once confirmed, publish the changes.

Now, when someone clicks on an internal link, you’ll start seeing events in GA4 with the details like the URL, link text, and class names.

Option 2: Track Internal Link Clicks Without Google Tag Manager

If you’re not using Google Tag Manager, you can still track internal link clicks with a simple JavaScript solution. This method works well if you’re comfortable adding a bit of custom code to your site.

JavaScript Code

Add the following JavaScript code to your site to capture clicks on internal links and send the data to GA4:


document.addEventListener('click', function(event) {
  // Check if the clicked element is a link
  let link = event.target.closest('a');
  if (link && link.href.includes(window.location.hostname)) {
    // Capture data-* attributes
    let dataAttributes = {};
    Array.from(link.attributes).forEach(attr => {
      if (attr.name.startsWith('data-')) {
        dataAttributes[attr.name.replace('data-', '')] = attr.value;
      }
    });

    // Send event to GA4
    gtag('event', 'internal_link_click', {
      'link_url': link.href,
      'link_text': link.innerText || link.title || link.id || 'unknown',
      'link_classes': link.className || 'no-classes',
      ...dataAttributes,
    });
  }
});

What’s Happening in the Code?

  • Event Listener: We’re adding a listener to detect clicks on all links on the page.
  • Internal Links Only: The script checks whether the link is pointing to an internal page (same domain).
  • Capturing Data: It grabs useful information like the link’s URL, text, CSS classes, and any custom data-* attributes you’ve added.
  • Sending to GA4: The gtag function sends this data to Google Analytics under the event name internal_link_click.

Comparing GTM vs. JavaScript

Feature GTM JavaScript
Ease of Use User-friendly interface Requires custom code
Setup Time Fast for GTM users Takes a bit longer to implement
Customization Limited by GTM’s capabilities Fully customizable with code
Data Tracking Basic (URL, text, classes) Advanced (e.g., data-* attributes)

Viewing the Data in GA4

Once you’ve set up either GTM or JavaScript to track internal link clicks, you can view the data in GA4:

  1. Go to Reports > Engagement > Events.
  2. Look for the event internal_link_click.
  3. You can drill down into the event parameters such as link_url, link_text, link_classes, and any custom data-* attributes you’re tracking.

Why Track Internal Links?

Tracking internal link clicks provides invaluable insights into how users interact with your website:

  • Optimize Navigation: See which pages people are clicking and how they move around the site.
  • Measure CTA Effectiveness: Understand which calls-to-action are driving clicks and conversions.
  • Improve User Flow: Analyze how users engage with different areas of your site and where they might be getting stuck.

By tracking internal link clicks, you can make data-driven decisions to improve your website’s user experience and conversion rates.

Next Steps

Whether you choose to use Google Tag Manager or JavaScript, implementing internal link tracking in GA4 is simple and highly beneficial. It gives you a clearer picture of user engagement, helping you make smarter decisions about site structure and content.

Got any questions or need help getting this set up? Contact me.

Related Resources:



Written by: Jake Lett
Jake Lett is a B2B marketing consultant with over 15 years of experience in the digital marketing industry. He specializes in SEO, HubSpot, and PPC campaign management. Jake has a proven track record of helping businesses increase their online visibility and drive more traffic, leads and sales. He is a Certified Google Ads Specialist and a Certified HubSpot Developer.

Related posts

Tags: ,

Want to Get Email Updates of New Articles?

Join My Email Newsletter