How to Track Affiliate Links in Google Analytics

Cody Schneider9 min read

Tracking affiliate links is the only way to prove which content actually drives clicks and which pages are collecting dust. Instead of relying solely on your affiliate network’s dashboard, you can see exactly which links users click, on which pages, directly within Google Analytics. This guide will walk you through setting up affiliate link tracking in Google Analytics 4 with Google Tag Manager so you can stop guessing and start measuring what works.

Why Bother Tracking Affiliate Clicks?

Your affiliate programs will report sales and commissions, but they can't tell you the whole story. They don’t know which blog post, which call-to-action button, or which in-text link on your site generated that click. By tracking clicks as events in Google Analytics, you unlock far more powerful insights:

  • Attribute Clicks to Specific Content: Pinpoint the exact pages, blog posts, and articles on your site that successfully drive users to your partners' websites. Answering "Which post generated the most clicks to Amazon last month?" becomes simple.
  • Understand User Behavior: Do users click on the button at the top of the post or the text link near the bottom? You can compare the performance of different link placements to optimize your layouts.
  • Optimize Your Strategy: Discover which affiliate partners get the most clicks. If a partner gets lots of clicks but has a low conversion rate, you might want to reconsider the partnership or investigate their checkout process.
  • Identify Broken or Underperforming Links: A sudden drop-off in clicks from a popular page could signal a broken link you need to fix or a new campaign you need to run to generate new clicks.

By default, GA4 doesn’t track these outbound affiliate clicks. But with a one-time setup using Google Tag Manager, you can capture this valuable data automatically.

The UTM Parameter Trap for Affiliate Links

You may have heard of using UTM parameters to track campaigns. These are tags you add to a URL (e.g., ?utm_source=newsletter) to tell analytics where a user came from. It's tempting to add them to your affiliate links like this:

www.affiliate-product.com/trackingID?utm_source=my_blog&utm_campaign=winter_sale

Do not do this.

UTM parameters track traffic coming to a website. When you add them to an outbound affiliate link, you aren't sending tracking data to your Google Analytics account - you're sending it to the merchant's Google Analytics account. This clouds their data, provides zero value to you, and can even violate the terms of some affiliate programs.

UTM parameters have a role in your marketing toolkit, but using them for outbound affiliate tracking is the wrong tool for the job. The correct method is to track the click itself as an event on your website, right before the user leaves.

The Right Way: Event Tracking with Google Tag Manager

The industry-standard method for tracking outbound link clicks is to fire a custom "event" to GA4 when a user clicks an affiliate link. By far the easiest way to manage this is through Google Tag Manager (GTM), a free tool from Google that lets you add tracking code to your site without having to edit the code directly.

The process involves setting up a few simple components in GTM:

  1. Variables: These are placeholders that store information, like the specific URL a person clicked. We’ll need to make sure GTM’s click-related variables are turned on.
  2. A Trigger: This is the rule that tells GTM when to fire. Our rule will be: "When someone clicks a link, and that link contains our affiliate URL structure..."
  3. A Tag: This is the part that does the actual work. Our tag will be a GA4 Event Tag that sends the click data over to Google Analytics when the trigger fires.

It may sound a little technical, but it’s a straightforward, step-by-step process you only have to do once.

Step-by-Step Guide to Setting Up Tracking in GTM

Let's walk through building your affiliate tracking system in Google Tag Manager.

Step 1: Enable Click Variables in Google Tag Manager

First, you need to tell GTM to pay attention to link click information. Many of these helpful variables are turned off by default.

  1. Log into your Google Tag Manager account and select your website’s container.
  2. In the left-hand menu, click Variables.
  3. Under the "Built-In Variables" section, click Configure.
  4. A pane will slide out from the right. Scroll down to the "Clicks" section and check the boxes for all variables listed there (e.g., Click Element, Click Classes, Click ID, Click Target, Click URL and Click Text).

That's it. GTM will now begin listening for this data on every click. Now we can use it.

Step 2: Create a Trigger for Affiliate Link Clicks

Next, we’ll create a rule that lets GTM identify when a clicked link is an affiliate link and not just a regular link to another page on your site or a non-monetized external link.

A highly effective way to do this is to use a link cloaker plugin like Pretty Links or ThirstyAffiliates. These plugins transform long, ugly affiliate links into clean and short internal links, often with a common path like www.yoursite.com/recommends/product-name. This makes them incredibly easy to identify.

If you don't use a cloaker, you can set up the trigger to fire when the link's hostname matches a list of your affiliate domains (e.g., amazon.com, shareasale.com, etc.), but using a cloaked path is generally cleaner and easier to manage long-term.

Here’s how to set up the trigger using the recommended cloaking path method:

  1. In the left-hand side menu, go to Triggers and click New.
  2. Give your trigger a clear name, like "Affiliate Link Click Trigger."
  3. Click within the "Trigger Configuration" box and choose Just Links under the "Click" section type from the menu.
  4. Switch the trigger from "All Link Clicks" to Some Link Clicks.
  5. This is where you set the rule. Set it as follows: Click URL | contains | /recommends/ (Replace "/recommends/" with your actual cloaked path, e.g., "/go/".)
  6. Click Save.

Step 3: Create the GA4 Event Tag

With our variables enabled and our trigger ready, we can now create the tag that collects the data and pushes it over to GA4.

  1. Go to Tags in the left-hand menu and click New.
  2. Name your tag something descriptive, like "GA4 Event - Affiliate Click."
  3. Click inside the "Tag Configuration" box and select Google Analytics: GA4 Event.
  4. In the "Configuration Tag" field, choose your main GA4 tracking tag that should be installed. All of them use the same GA4 tracking ID.
  5. For the Event Name, use a unique and descriptive name. GA4 recommends using snake_case. Let's use affiliate_link_click. This is the new event you’ll see in your GA4 reporting dashboard when it starts running.
  6. Now, open the Event Parameters section. This is where we attach the useful click data. Click Add Row and add the following two parameters:

To add the values, simply click on the lego block icon and choose the corresponding variable from the list.

  1. Finally, click the Triggering box at the bottom. Choose your newly created "Affiliate Link Click Trigger". This "connects the dots" by telling GTM to listen for this tag and only to fire if the user clicks on a URL containing /recommends/.
  2. Click Save.

Step 4: Preview, Test, and Publish

Never publish changes without testing first. GTM has an excellent built-in Preview mode that lets you test everything works beforehand.

  1. In the top right corner of your Google Tag Manager Dashboard, click on Preview.
  2. Enter your website’s URL and hit "Connect." A page will pop up with a small Debugging overlay in the bottom-right corner. It will be "connected."
  3. Back in your previous GTM tab, the Tag Manager Assistant debugger should load. Go into the debugger on your left-hand menu.
  4. Now navigate through different website pages and some with clicks for affiliate links.
  5. Click one of your affiliate URLs. After your click, go to the debugger tab to see the Tag Assistant debugger. Your dashboard now shows "Link Click" and confirms the click event, and displays the tag in the "Tags Fired" section. This shows your setup is correct.
  6. While you're at it, go into your GA4 > Configure dashboard > DebugView to check in real-time that your newly-created affiliate clicks are firing too. This is a great troubleshooting tool.
  7. When everything is working right, click back to GTM and click Publish to go live.

Where to Find Your Affiliate Data in GA4

Once you’ve collected some click data (which can take 24-48 hours to fully populate), you need to know where to find and analyze it in GA4.

Register Custom Dimensions

This is a crucial step that many people miss. While GA4 now knows about your affiliate_link_click event, it doesn’t automatically make the parameters you sent (link_url and link_text) available in its standard reports. You have to tell GA4 to "register" or whitelist to a report.

  1. Inside your GA4 Dashboard, go to the Admin panel at the bottom.
  2. Under “Data display", there is a selection named Custom definitions.
  3. Click the Create custom dimensions button.
  4. Repeat for "Link Text", with parameter name link_text.
  5. Click Save, and you're finished.

Now, these dimensions will be available when creating reports, letting you see which exact link URLs and link texts were clicked.

Using Explorations for Deep Analysis

The best place to dig into this new affiliate data is in GA4’s Explorations tool. This provides a space for creating customized reports and filtering information.

Here’s how you can build an example report that shows which pages on your site have affiliate links and which links drive clicks:

  1. On the GA4 dashboard, go through the sidebar to Explore.
  2. Select Blank and choose Start from scratch.
  3. Name your exploration, e.g., "Affiliate Clicks Performance".
  4. In the Dimensions section, search for and import Page path, Link URL, and Link text.
  5. In the Metrics section, add Event count to show total clicks.
  6. Drag Page Path to rows, Link URL and Link text to columns, and Event count to values.

You can create a custom table showing which affiliate URLs were clicked, and the count of clicks.

Final Thoughts

Setting up affiliate link tracking in GA4 through Google Tag Manager takes your analysis miles beyond vague affiliate dashboard stats. It empowers you to see exactly which content is working, optimize your layouts based on real user behavior, and make data-informed decisions to grow your revenue.

We know manually building these kinds of reports in Google Analytics can be frustrating and difficult - it's one of the main reasons we built Graphed. We want you to build insights quickly with simple questions like "Which link on my blog had the most clicks last month?" without touching GA4, getting the report created for you immediately.

Related Articles

How to Connect Facebook to Google Data Studio: The Complete Guide for 2026

Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.

Appsflyer vs Mixpanel​: Complete 2026 Comparison Guide

The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.