Affiliate Tracking Through Google Tag Manager

It’s often the bane of many a website publisher’s life, and the question that we get asked a lot, “I’m generating lots of visits and spending money for visitors, but I’m not exactly sure what they are doing when they get there. How can I track what happens on my website as goals, so I can make the most out of my advertising pounds or dollars?”

Many of these publishers we speak to either work for or own an affiliate site, where the key is, of course, to take users through their own journey but ultimately to direct them away and spend money through partner websites. In most cases, this would include retailers, travel agents or sports betting agencies. The question is, how do you track any users who move away from your website? Well, the answer is quite simply, through event tracking, or auto event tracking, done through Google Tag Manager.

Let’s use a specific example to illustrate the tracking of users who click away from your domain, and some strange quirks that you may encounter along the way.

Event Tracking

Tracking events on Google Analytics is something that most website owners seem to get spooked by, and therefore, shy away from. They often don’t fully integrate this great tool into their data. What is a straightforward process can be made significantly more complicated by over-excited bloggers, and even Google themselves. However, providing you have access to the HTML on the page/button/link you are trying to track, then creating events is a piece of cake.

Essentially, to track a click as an event on your website you will need to insert the following code within your destination URL:

onClick=”ga(‘send’, ‘event’, { eventCategory: ‘Category’, eventAction: ‘Action’, eventLabel: ‘Label’, eventValue: Value});”

Within the inverted commas inside the brackets is what you will set to display within your reporting on Analytics, and this can be anything you choose. Let’s say if you have a link on your home page directing to, the code would then look like this:

onClick=”ga(‘send’, ‘event’, { eventCategory: ‘Affiliate_Link’, eventAction: ‘Amazon’});”

In this example I have only used the ‘Category’ and ‘Action’ ID’s, as the ‘Label’ and ‘Value’ ID’s are optional and can be used if required. Now let’s say for argument’s sake that the external link is ‘’ and the anchor text link is ‘’ then your final piece of code would look like the below:

If you’re using WordPress or a similar CMS, then choose the HTML (or ‘Text’ on WordPress) option and paste the code into the editor as per the example below:

wordpress HTML

Once you’ve published the page, your event should start to track in both the ‘Real Time’ and ‘Behavior’ sections of Analytics.

One of the snags that a lot of publishers come across – especially when using WordPress, and those who aren’t especially ‘au fait’ with high level coding – is that widgets and plugins often limit the opportunities to edit the HTML, in particular when linking from images or links that get pulled in from other areas of the CMS.

So what’s the alternative to getting ‘knee-deep’ in website code and pulling your hair out? We think the best solution is auto-event tracking via Google Tag Manager.

Auto-Event Tracking

If you’re not using Google Tag Manager on your website by now, you should be! It’s perfect for the non-coder and allows marketers and developers the ability to put cool tags on their website without the need for a code release. If you don’t have tag manager in place on your website, you can read about it here, then ask your development team to implement the container tag on your website.

In order to implement auto-event tracking, you will need to set up 3 tags on your website:

  • A Universal Google Analytics Page View Tag
  • A Link Click Listener Tag
  • An Event Tag
  1. First, implement the page view tag, which is basically a universal analytics page view tracker, and set it up as per the image below (obviously using your own Google Analytics UA number). Set the tag to fire on all pages.

GA page view

  1. Secondly you will need to set up a ‘Link Click Listener’, select new tag, and you will find this under the option ‘Event Listener’. As with the first tag, set the tag to fire on all pages.

link click listener

  1. Lastly, you will need to create an ‘Event Tag’, which is slightly more complex than the first two tags. The tag type is a ‘Universal Analytics’ tag, and you will need to select the track type as ‘Event’. This is the section where you would have created the event tag manually if you were using a simple HTML event tracking tag. The firing rules are slightly different here; essentially, you are telling tag manager to notify Analytics when an event happens that you specify. The firing rules are outlined in the image below:

event rule

So what we are saying is, fire an event to GA when a link is clicked that does not contain your own domain, simple.

Once you have defined the rules of the tag, you will need to assign the ‘Category’ and ‘Action’ of the Event. As discussed previously, the Category can be named anything you wish, however the beauty of GTM is that you can assign a macro to the action ID which tells GA what the resulting URL was, a handy tool for an affiliate, as it will tell you exactly which links have been clicked without editing every single affiliate link on your website. The final tag should look like the image below:

event tag

Not all websites are the same, and often you will need to test and learn with GTM, depending on how your website is structured. For example, we recently worked with a client whose external links directed to a site within their own domain for a split second then redirected to the advertiser’s website. In this case, we set the rule to fire when the url starts with ‘’.

If you’re an affiliate, or you have your own blog, auto-event tracking via Google Tag Manager is the perfect tool to track your outbound links, and ultimately give you a better idea of where to invest your marketing budget.

For help or advice on tracking through your website then contact Digital Fuel today on how we can help your business.

Author: Digital Fuel

Words by the Digital Fuel team members