Menu
work at home • hustle • blog

Tracking Affiliate Clicks with Google Analytics 4

Last updated on: 06th Feb 2021
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 a lot of 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.

Fix-It Friday

Before we dive into this. I stopped using Fix-It Friday in my title as it holds no SEO value. And since I am not always fixing things, the title may be a little misleading. 

I will continue to keep the Friday for more technical articles.
And I will do that in a way I believe non-techies can understand.

Google Tag Manager

If you want to follow along then 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, unfortunatly.

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. You need to find an identifier in the link that was 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. 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 the way 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 something 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. 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

Testing

Now save it. To make sure that everything is in place before we release this new version of our tag configuration, we are going to 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.

Publish

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

Conclusion

Tracking affiliate clicks with Google Analytics 4 and Google Tag Manager takes quite a few steps to implement, but it is not hard if you 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 are wondering how affiliate marketing works, 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!

Tracking Affiliate Links with Google Analytics 4
Filed under:

Leave a Reply

Your email address will not be published. Required fields are marked *

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