The Side Gig Longlist
work at home • hustle • blog

Tracking Affiliate Clicks with Google Analytics 4

Last updated on: 16th May 2022
Advertiser Disclosure: Some of the links on The Side Gig Longlist are affiliate links.
This means that if you click on that link and purchase an item I will get a commission, at no extra cost to you!

Finally, I found time and a topic to write another Fix-It Friday post about. Today I want to implement tracking affiliate clicks with Google Analytics 4. 

There are many ways to track if visitors clicked your affiliate links, and plugins like ThirstyAffiliates make it very easy to do.

I want to have these reports appear in my Google Analytics dashboard without depending on the implementation of a third-party plugin, so I can switch plugins without losing information.

Google Tag Manager

If you want to follow along, you have to have Google Tag Manager installed and use Google Analytics 4. GA4 is a new version of Google Analytics.

To set up Google Tag Manager (GTM) on your website check this tutorial: Setup and install Tag Manager.

To implement GA4, check here: Add the Google Analytics tag for Google Analytics 4 properties to your site with gtag.js.

If you still find it hard to implement, let me know. If there are enough requests I will write a tutorial post about it.

Track Events

When you start a blog, you will find yourself wondering how it is performing and if the carefully selected affiliate links you use to monetize your blog are being found and clicked.

Google Analytics is a great way to keep track of your audience and performance, but it just can’t include all the specifics for every user. 
You can, however, add a lot of customizations!

What I want to accomplish is to get clicks on affiliate links registered in my Google Analytics dashboard.

At the moment, it looks like this:

It shows some basic metrics like session_start, clicks, scroll, first_visits, and page_views. As for all GA reports, you can filter them per date or period.
For our goal, tracking affiliate clicks with Google Analytics 4, there isn’t a standard solution, unfortunately.

To show this data, Google first needs to receive and recognize the right events and parameters.
We can add these in Google Tag Manager (GTM).

Creating a Trigger

We start with telling Tag Manager how to identify a click on an affiliate link. There are a couple of ways to do this, and I will explain two of them, but first:

Adding a Trigger

Open your Tag Manager dashboard and find the Triggers menu link on the left-hand side.

GA4 Triggers

You will find all triggers you have made in place here. If there are none, that’s ok, we will add one by clicking ‘New‘.

GA4 new trigger

In the next window, click on ‘Untitled’ and give the trigger a name. Pick one that identifies it, but it really doesn’t matter how you call it. If you want to name your triggers like rock stars, it’s fine.

GA4 name trigger

Now we will have to tell GTM what type of trigger it is.
Click somewhere in the ‘Trigger Configuration‘ panel. A list of trigger types to choose from will appear.

Pick ‘Just Links‘.

GA4 trigger type

This will fill the Trigger Configuration panel with the parameters and conditions form for the link clicks event.

I don’t want to trigger all link clicks, but just the ones that are affiliate links.
To do this, I have to select ‘Some Link Clicks’ instead of ‘All Link Clicks.’

A row will appear where we can define the conditions. Click in the first field and pick ‘Choose Built-In Variable‘.

GA4 trigger conditions

Selecting Trigger Conditions

The next step is important. It is important to use an identifier for the link that your visitor clicked, so GTM knows how to distinguish affiliate links from others.

One way to do this is to look at the URL. My affiliate links get a prefix from ThirstyAffiliates, and almost every link has ‘/gig/’ as part of the URL.

Option 1

I could choose ‘Click URL‘ as a variable and check if it contains ‘/gig/.’ This, however, would make it more difficult to detect uncloaked links or links that, for some reason, I am bypassing the ThirstyAffiliates prefix mechanism for.

It would look like this in GTM:

GA4 trigger regex
Option 2

Another way is to look for other identifiers.
I add a CSS class to every affiliate link. This will make it easy for me to customize how they look if I think it is necessary. I called this class ‘aflk’.

ThirstyAffiliates makes it easy for me to add a class automatically, but adding classes to links is a feature that almost every method of inserting links supports by default.

If I ever want to switch plugins or quit using ThirstyAffiliate, the tracking of affiliate clicks will still be working.

This condition would look as follows:

Identifying links for tracking affiliate links with Google Analytics 4

Adding a Tag

Now save your trigger and head over to the ‘Tags‘ section by clicking it in the menu on the left.

In it, find the ‘New‘ button and click it.
Name your tag and click in the ‘Tag Configuration‘ panel.

Select ‘Google Analytics: GA4 Event‘.

In the ‘Tag Configuration,’ you can select one of your configurations. There is probably just one or maybe two, but if there are more, you are most likely a little more advanced and know which one you need.

GA4 tag configuration

Select ‘Event Name‘ and click the icon.
A panel appears where you can select a variable. We are going to add on ourselves.

GA4 add variable

Name the variable and click in the ‘Variable Configuration‘ panel and select ‘Custom Event’.

GA4 custom event

Save it and open the ‘Event Parameters.’ We are going to add 2. One for the URL and one for the text that the clicked link contains.

Name them and take note of the names you are using here. You will need them later.

In the ‘Value‘ column, click the field and find the right variable from the list that appears. You will need ‘Click URL’ and ‘Click Text.’

Mine looks like this:

GA4 tag parameters complete

When you are done, scroll down to the ‘Triggering‘ panel. Click inside and find the trigger you made before.

Trigger tracking affiliate links with Google Analytics 4


Now save it. To make sure that everything is in place before we release this new version of our tag configuration, we will test it with the preview mode.

Find the ‘Preview‘ button in the upper right corner and click it.

You can probably leave all as-is in the ‘Start Tag Assistant‘ panel, but if you want to go straight to a certain page, you can adjust the URL. Click ‘Start‘ when you are ready.

Your website should appear in a new window. Browse to an affiliate link and click it. Maybe try a few more.

Return to the window that holds the GTM. Click the ‘Continue‘ button. 

If your tag has fired, you are good to go! If not, review the previous steps, and see if you haven’t missed one or made a spelling error.

GA4 preview test

Now close this window and head back to your GTM workspace.


It is time to submit and publish our new configuration. Click the Submit button. Give your version a name and a description. 

Did you write down the names of the Event Parameters?

If everything went well, we can close the GTM window and head back over to our Google Analytics window.

Configuring Google Analytics

Now we need to tell Google Analytics that we have new data to process.

Go to the ‘Events‘ tab, click on ‘Events‘ and find the button saying ‘Manage Custom Dimensions.’ Once clicked, you can add a custom dimension.

Add two—one for each event parameter (yep, the ones you wrote down). You can keep the Custom dimension name the same as the parameter name. I changed mine a little.

add parameters for tracking affiliate links with Google Analytics 4

And now… We wait. You won’t see them in your dashboard, nor can you create reports with them until the next day (which is why I had to wait to finish this post).

Once the data is collected, you will see them in your standard reports, and you can use the parameters for your custom ones.

Tracking affiliate links with Google Analytics 4


Tracking affiliate clicks with Google Analytics 4 and Google Tag Manager takes quite a few steps to implement, but it is not hard to follow the above steps.

Tracking your links this way makes you less dependent on the analytical dashboards and implementation of a plugin.

To do this in the ‘old’ Analytics is similar to this process, although some parameters and configurations are different. 

What’s Next

If you haven’t started using affiliate links in your blog and wonder how affiliate marketing works, then I highly recommend The Zero To Superhero Affiliate Marketing Training Bundle

I hope you enjoyed this post and found it helpful. If you did, then please share it among your social networks.

Don’t forget to subscribe to my email list to get updates on new posts!

Thank you for reading and as always: you are awesome!

Recommended Reading

Filed under:

3 comments on “Tracking Affiliate Clicks with Google Analytics 4

  • Luna Sanchez says:
    May 22, 2021 at 1:37 am

    Really helpful guide. Thankyou for taking the time to put this together! Much appreciated.

  • DMMBlitz says:
    January 24, 2022 at 3:21 pm

    Setup and running perfectly. Thanks for the guide, really helpful.

Comments are closed.


Hi there!

My name is Jip, and I created the Side Gig Longlist to learn all I can about blogging and making money online.
Having decades of experience in information technology, I decided to explore all the non-technical aspects of blogging, marketing, and promoting.
I also happen to like sharing the things I know and learn with others.
This blog is my platform to experiment, learn, and share.

Sign up, stay connected, and get updates and new gigs in your inbox. {subscription_form_1}