
October 18, 2023
Track Affiliate Link Clicks with Google Analytics 4 (2 methods)
This article was written by Rick Beijen, who was kind to share his tips with Analytics Mania’s readers
If you’re generating revenue from affiliate marketing and want to monitor which links are clicked the most or which pages generate the most clicks, Google Analytics can help, but some configuration is required.
In this blog post, I’ll show you two options for setting up affiliate link click tracking. One without coding within Google Analytics 4 and the other using Google Tag Manager, where I will track two affiliate links on a website. After that, I will show you a way to use that data in a report.
Video tutorial
If you prefer video content, here’s a tutorial from the Analytics Mania YouTube Channel.
Note: some things have changed in Google Tag Manager since this video was recorded, so you might need to adapt a bit.
Table of contents
Here’s what you will learn in this article
- What are affiliate links?
- Method #1 – Using only Google Analytics 4
- Method #2 – Using Google Tag Manager
- How to see the affiliate data in GA4
- Final Words
What are affiliate links?
Affiliate links are links from your website to another website, for example, an e-commerce website, containing an identifier in the URL that is connected to you. So, when the person who clicked that link makes a purchase on the affiliate website, you will get a commission.
It is possible to track which affiliate links are clicked the most and where those clicks happened using GA4.
Method #1 – Using only Google Analytics 4
For this method to work, you must ensure that Google Analytics 4 is installed on your website. If you haven’t done that yet, here is the article that explains how to do that.
Enable Outbound Clicks in Enhanced Measurement
First, you need to ensure that Enhanced Measurement is enabled and that you are tracking outbound clicks. Go to your GA4 property, then Admin > Data Streams.
Select your web data stream.
Make sure that Enhanced measurement is enabled and click the gear icon.
Make sure that Outbound Click tracking is enabled in the Enhanced Measurement.
The affiliate links are (mostly) links that are linked to a domain that is not your own. This is what we call an outbound click. For GA4 to track this, outbound clicks need to be enabled.
Install the GA debugger browser extension
Now that everything is enabled, you can test your data in the DebugView. But, to get the data to show, you need to install a Google Chrome browser extension called Google Analytics Debugger.
Install the extension here, and then click its icon (so that you can see the ON ribbon). From this moment, you will start seeing your events coming into the DebugView.

Track the affiliate link clicks
Navigate to the DebugView in GA4. You can find the DebugView in Admin > DebugView.
With the analytics debugger extension enabled, click on the affiliate links you want to track and check the DebugView to see if the events come in. You should see ‘click’ events on the timeline.
And because I clicked two outbound links I want to track, I will see two events:
These are the events that are measured by the enhanced measurement. You can verify if these are the clicks that you need by clicking on one of them and checking the value of the link_url parameter. This should contain your affiliate link.
Create the custom events
Now that GA4 is tracking your outbound clicks, you can create your new affiliate link click events using the create event feature in the Events section of GA4. Navigate to the Events in Admin > Events.
Click on Create event.
Click Create to create your new affiliate events.
Now, you can create your new affiliate link click event based on the parameters of the click event. First, you need to give your new event a name, for example, affiliate_link_click. Then, it’s time to set the conditions for when affiliate_link_click needs to fire.
Remember that GA4 is tracking the outbound clicks as click, so you can set the first condition to Event Name equals click.
Now, it will fire on all the outbound clicks, but you don’t want that. So, you need to add another condition based on the link_url you saw earlier in the DebugView. For example, link_url contains amazon.com.
This will fire an affiliate_link_click event every time GA4 registers a click event where the link_url contains amazon.com.
Awesome!
But what if you have multiple affiliate links on your website to multiple domains? Can you capture all of those events in one custom event?
Yes! You can by using Regular Expressions.
Regular Expressions allows you to add multiple conditions into one field. Let’s look at the condition in GA4 where I add amazon.com and example.com into one field:
With Regular Expressions, you can separate all your affiliate domains in one field using the pipe operator (|). So you could do something like this:
link_url Matches Regex (ignore case) yourfirstdomain.com|2nddomain.com|xyz.com
This would match either of those three domains and fire the event.
Alright, let’s click on Create. You will now see your new custom event.
Test the setup
Now you have everything configured in GA4, it is time to test the setup.
Go back to the DebugView and (still with the Google Analytics debugger extension enabled) click again on the affiliate links on your website. You should now see your shiny new affiliate_link_clicks in the DebugView next to the other click events!
And because I added example.com and amazon.com in my conditions, I see two affiliate_link_clicks.
If you don’t see the events, but you do see the click events, then you’ll need to wait a couple more minutes and try again. After that, they should appear in the DebugView. These new events contain the same parameters as the click event, like the link_url parameter.
Method #2 – Using Google Tag Manager
The second method for tracking the affiliate link clicks is with Google Tag Manager. Using Google Tag Manager over the create events feature in GA4 has multiple advantages.
For example, GA4 has a limit of 50 custom event rules in the event creation feature. With Google Tag Manager, there is no limit.
Let’s take a look at how we track the affiliate links with Google Tag Manager. For this to work, you need to have Google Tag Manager installed on the website. If you don’t know how to install Google Tag Manager, take a look at this blog post.
Next to that, you should have the Google Tag installed as a tag in Google Tag Manager.
If you don’t have it installed or if you want to learn more about the Google Tag, read this article.

Configure the Click variables
To get started with the affiliate link click tracking, you will first need to configure the variables you will need to create your trigger. In Google Tag Manager, go to Variables and check if you see Click variables (e.g., Click ID, Click Text, etc.) enabled.
If not, click Configure next to that list and enable all variables that start with “Click”.
The most important variable we need is the Click URL.
Create the trigger
Now that you have the variables enabled, you can create the trigger for the affiliate links. Go to Triggers > New and create a new Trigger.
Click on Trigger Configuration and choose ‘Just Links’.
Here you can add the conditions for your link trigger to fire. So let’s say you have one domain you want to track (let’s take amazon.com again), you can set the trigger like this:
This trigger will fire on all the link clicks where the link contains the domain amazon.com.
But again, what if we have multiple domains? Can we also add them all into one trigger with Regular Expressions?
Yes! You can.
Let’s look at a trigger example where we again track amazon.com and example.com but this time all in the same trigger.
Here we also use the pipe operator (|) to separate the domains we want to track in the trigger condition.
Now that you have your trigger created, you can give it a name and save it.
Create the tag and link the trigger
Now the trigger is created, you can start sending the information to GA4. For this, you need to create a new tag in Tags > New and create a new Tag.
Click on Tag Configuration, choose Google Analytics, and select Google Analytics: GA4 Event.
Add your GA4 measurement ID. You can find your measurement ID in GA4 in Admin > Data Streams > Your data stream.
Also, add the Event name affiliate_link_click.
The green checkmark next to the measurement ID should appear. That means that the measurement ID matches the ID that is in the Google Tag. This is what you want (and if you want to do it even better, enter your measurement ID as a constant variable).
Next, you want to add an event parameter where you send the URL that is clicked to be able to know for example that the user clicked on a link to amazon.com or example.com. Click on Add parameter to add a new event parameter.
Add link_url and add the Click URL variable to the value field.
Select Click URL.
This will send the affiliate_link_click event with the actual value of the clicked link in the link_url parameter to Google Analytics 4.
Now, you can add the trigger to the tag. You can do that by clicking on the trigger field that is below the tag field.
Here, you select the trigger that you have just created.
The last thing to do is to give the tag a name and click Save.
And that is it! Now, you are ready to test your new affiliate event.
Test the setup
To test our new tag, we need to test it in the Preview Mode. Click on Preview in Google Tag Manager.
Add the URL you want to test with your affiliate links and click connect.
Now, you should see the preview box on your page.
Now, you click the links that contain your affiliate links. After you have clicked the URLs, go to the Google Tag Assistant page. Then, you should see your new tag fired on the link clicks.
And in my case, it also fired a second time on the second link.
The last thing you need to check is if the events are also in the DebugView of Google Analytics. Navigate to the DebugView in GA4. You can find the DebugView in Admin > DebugView.
And voila! Here, you will find your new affiliate_link_click events.
If you click on one of the events, you can check if it contains the link_url parameter, which should look like this:
And that’s it! You are now tracking your affiliate links with Google Tag Manager.
Important: You should only use one of the methods to track the affiliate links, not both at the same time. So only use the build-in events feature of GA4 or use Google Tag Manager. If you use both, you will get duplicate data.
How to see the affiliate data in GA4
So now you are tracking your affiliate links with one of the methods from above. Awesome.
But where can you find your new affiliate data in GA4?
Let’s take a look at an example using the Explorations reports.
But, before we can get started, it’s important to wait at least 24 hours after you have set up the tracking. Only after that time you will be able to find the data in GA4.
Create the Report
Let’s say we want to create a report that shows how many affiliate_link_click events we’ve had, and we want to break it down on the link URLs.
Go to the Explore section and create a new blank report.
Click on the + sign to import dimensions.
And import the Event Name and Link URL dimension.
And import Event Count as a metric.
Now you can add the Link URL dimension and Event Count to the report. You can do this by double-clicking or by dragging and dropping. Your report will look something like this:
This report shows a breakdown of the link URL for all events. But you don’t want that. You only want to look at the link URLs of the affiliate events. So, you have to add a filter on the Event name exactly matches affiliate_link_click.
Now, your report should look something like this:
Here, you can see the amount of affiliate_link_click events broken down by the link URL.
See the pages where the events happened
If you want to see which pages of your website generated the most affiliate link clicks, you can add a page parameter to the report. For example, Page Location (full URL) or Page path and screen class (the part that goes after the domain).
Let’s say you want to see the Page path and screen class. Then you have got to import that as a dimension.
Now, you can replace the Link URL dimension in the report with the new Page path and screen class dimension.
If you want, you can even combine both parameters into one report, which will show you which Link URL is clicked on which page like this:
Unfortunately, the Free-form reports get a bit messy with long URLs. So you can export the report to Google Sheets or a CSV and analyze the data there.
Track Affiliate Link Clicks with Google Analytics 4: Final Words
Tracking affiliate link clicks in Google Analytics 4 can provide valuable insights into your affiliate marketing efforts. And tracking them is relatively simple.
It’s important that you choose either the Google Analytics 4 setup or the Google Tag Manager method, not both, to avoid duplicate data.
With the right configuration and reports, you can gain a better understanding of which affiliate links and pages are performing best. Which, in the end, can help you drive more revenue out of your commissions.
0 COMMENTS