Tutorials & Guides
Easy Process to Create GA4 Events to Track Affiliate Link Clicks
In this article, we’re going to be setting up a simple GA4 event using Google Tag Manager that will allow us to see how many of our affiliate links are being clicked.
Now, you could certainly track your affiliate links from the likes of Pretty Links, but Google Analytics will enable us to layer google behavioural data such as geo location, campaign attribution on your side, and model out behavioural journeys.
What do I need to implement these events?
- A GA4 installation that is handled by Google Tag Manager
- Publishing rights to your Google Tag Manager Container
- An existing GA4 config installed in Google Tag Manager
So, let’s get moving. The process should ideally take no more than 5 minutes.
Step 1: Create a Trigger for Affiliate Link Clicks
To begin, we’ll establish a trigger in Google Tag Manager (GTM) that determines when the Google Analytics event should be activated. We’ll utilise the ‘Link Clicks’ trigger for ‘some clicks’ and set specific criteria based on the target URL’s parameters. This approach necessitates a consistent URL structure for your affiliate links.
In the case of my website https://dougdigital.co.uk, all affiliate links (and only affiliate links) follow this pattern: https://dougdigital.co.uk/link/[vendorname]
The unique /link/
segment in the URL serves as an affiliate link identifier, allowing me to set up appropriate filters for tracking clicks on only these specific links.
I’d advise you briefly now to review your website and ensure that your affiliate links are consistent before moving forward. Then, anytime you see /link/
, just replace it with you own string. Here are some common URL parameters:
/aff/
/sp/
/go/
/affiliate/
/lnk/
Now, let’s get moving…
- Log in to Google Tag Manager:
- Go to Google Tag Manager and select your container.
- Create a New Trigger:
- Navigate to Triggers in the left sidebar.
- Click on New.
- Click on Trigger Configuration.
- Select Just Links.
- Configure the Trigger:
- Some people like to check the box for Wait for Tags and Check Validation. This ensures that the tag fires correctly when the link is clicked. I’ve personally found issues with the trigger firing. If enabling this, I would check diligently for errors.
- Under This trigger fires on, select Some Link Clicks.
- Set the condition to: “Click URL contains
/link/
‘ - This condition will ensure that the trigger only fires for your affiliate links.
- Name the Trigger:
- Name your trigger (e.g.,
Affiliate Link Click
) and click Save.
- Name your trigger (e.g.,
Step 2: Create Variables for Article Clicked and Vendor
You could call it a day, save your event and be done. But I’d suggest we add some variables. I’d encourage you to get into the habit of building variables into your events as the act is familiarising you with your GTM tags, and the data available to you, and it also provides great opportunities for data capture and analytics when analysing your events.
Common examples for use cases include products that were purchased in conjunction with a given coupon.
- Create a Variable for the Article Clicked:
- Navigate to Variables in the left sidebar.
- Click on New.
- Click on Variable Configuration and select Page URL.
- Name this variable (e.g.,
Article Clicked
) and click Save.
- Create a Variable for the Vendor:
- Click on New again.
- Click on Variable Configuration and select URL.
- Set the Component Type to Path.
- Name this variable (e.g.,
Vendor Name
). - In the Variable Configuration, set the following:
- Extract the vendor name by using a Regular Expression. Set the Regular Expression to:
^/link/(.+)$
- This will capture the vendor name from the URL.
- Click Save.
Step 3: Create the GA4 Event Tag
- Create a New Tag:
- Navigate to Tags in the left sidebar.
- Click on New.
- Click on Tag Configuration and select Google Analytics: GA4 Event.
- Configure the Tag:
- Select your GA4 Configuration Tag (if you haven’t set one up, you need to do that first).
- For Event Name, enter
click-afflink
. - In the Event Parameters section, add the following parameters:
- Parameter Name: article clicked
- Value: Select the variable
{{Article Clicked}}
. - Parameter Name: vendor
- Value: Select the variable
{{Vendor Name}}
.
- Set the Trigger:
- Under Triggering, select the trigger you created earlier (e.g.,
Affiliate Link Click
).
- Under Triggering, select the trigger you created earlier (e.g.,
- Name the Tag:
- Name your tag (e.g.,
GA4 Affiliate Link Click Event
) and click Save.
- Name your tag (e.g.,
Step 4: Test Your Implementation
As a general rule of thumb, you should always be testing any changes that you make with Google Tag Manager; a lot of resistance I’ve experienced when introducing Google Tag Manager to an organisation has been, ironically, GTM’s biggestselling point — no developer resource necessary.
GTM makes version control and testing changes extremely easy, and that’s what we’re going to do now…
- Preview Your Container:
- Click on the Preview button in GTM to enter Preview Mode.
- Open your website in a new tab.
- Test the Clicks:
- Click on an affiliate link and check the GTM Debug panel to ensure that your GA4 Affiliate Link Click Event fires correctly.
- Verify that the parameters article clicked and vendor are populated with the correct values.
Step 5: Publish Your Changes
- Submit Your Changes:
- Once you’ve confirmed that everything is working correctly, go back to GTM and click Submit to publish your changes.
You have successfully set up a GA4 event in Google Tag Manager to track clicks on affiliate links. This event will fire with the specified parameters whenever someone clicks an affiliate link on your blog.
Douglas
https://dougdigital.co.ukI'm a digital marketing expert with more than 10 years experience in the biz! When I'm not working, I'm enjoying video games, playing with my dog Shadow and fawning over all things technology.