Doug Digital | Digital Marketing Expert

Easy Process to Create GA4 Events to Track Affiliate Link Clicks

Introduction

Douglas

Douglas

I'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.


LATEST POSTS

Single-Page vs Multi-Page Checkout: A Comprehensive Comparison 23rd November, 2024

Reflect App Review 2024: A Detailed Review by Doug Digital 21st October, 2024

Tutorials & Guides

Easy Process to Create GA4 Events to Track Affiliate Link Clicks

Posted on .

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?

  1. A GA4 installation that is handled by Google Tag Manager
  2. Publishing rights to your Google Tag Manager Container
  3. 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…

  1. Log in to Google Tag Manager:
  2. Create a New Trigger:
    • Navigate to Triggers in the left sidebar.
    • Click on New.
    • Click on Trigger Configuration.
    • Select Just Links.
  3. 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.
  4. Name the Trigger:
    • Name your trigger (e.g., Affiliate Link Click) and click Save.

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.

  1. 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.
  2. 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

  1. Create a New Tag:
    • Navigate to Tags in the left sidebar.
    • Click on New.
    • Click on Tag Configuration and select Google Analytics: GA4 Event.
  2. 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}}.
  3. Set the Trigger:
    • Under Triggering, select the trigger you created earlier (e.g., Affiliate Link Click).
  4. Name the Tag:
    • Name your tag (e.g., GA4 Affiliate Link Click Event) and click Save.

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…

  1. Preview Your Container:
    • Click on the Preview button in GTM to enter Preview Mode.
    • Open your website in a new tab.
  2. 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

  1. 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

Douglas

https://dougdigital.co.uk

I'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.

There are no comments.
View Comments (0) ...
Navigation