Get 20% off all of our individual Pro themes or grab the entire club! Just use the coupon code CCTHEME20

Discover our superb new professional blogging WordPress theme, Jefferson Pro

Get the latest Create and Code updates and offers every month
Home Blog WooCommerce How to track WooCommerce external/affiliate product link clicks in Google Analytics

How to track WooCommerce external/affiliate product link clicks in Google Analytics

Leave a comment

How to track WooCommerce external/affiliate product link clicks in Google Analytics Leave a comment

Today we dive into exactly how to track WooCommerce external/affiliate product link clicks in Google Analytics. WooCommerce is a pretty kickass eCommerce platform for WordPress with full featured Add to Cart/Checkout functionality. But many WooCommerce users sell affiliate products via third party websites like Amazon. In this scenario WooCommerce gives us a great solution to managing our product catalog and when customers click on the “Buy now” button they’re redirected to whatever link you specify. In WooCommerce these are known as “External/Affiliate” products.

External/Affiliate Products in WooCommerce
External/Affiliate Products in WooCommerce

For products sold internally within WooCommerce there are a plethora of excellent Google Analytics plugins that give you tons of data about tracking conversion events. But what about tracking conversion for external/affiliate products?

How to track conversion events for External/Affiliate products in WooCommerce

It would be pretty tricky to actually track the sale of a product on the external site unless you have a close relationship with the external site and they’d be happy to add a tracking pixel/conversion code to their order confirmation page for you. This will be especially true of the eCommerce giants like Amazon. (Good luck convincing Jeff Bezos to add your conversion pixel on the Amazon order confirmation page!). Still, most big vendors will provide some good analytics about the amount of traffic you’re sending them and how well it’s converting. But if we can’t track the actual sale directly ourselves, can we at least track the click event? We sure can! Let’s walk through the process step by step and we’ll even go one step further and define an affiliate link click event as a Conversion event in Google Analytics. This will be especially useful as it will allow us to accurately measure how effective we at driving traffic to merchants – and keep them honest 🙂

Step 1 – Make sure you have Google Analytics installed and configured.

We’ll not go into how to do that in this post. There are plenty of excellent resources on how to do this. We recommend Google Analytics for WordPress by MonsterInsights.

Step 2 – Add some custom Javascript to track external/affiliate product links in WooCommerce

There’s a ton of ways to do this but the easiest way is to install the Code Snippets plugin and then add the following as a new snippet.

In summary, the script above will:

  • Look for any instances of a p element on your site with the css class cart – which is the default markup WooCommerce uses for the add to cart button

  • Next, our script will check to ensure that Google Analytics is installed and that the url is indeed an external link.
  • We then create a custom GA event where we’ve defined a few important values.
    • Event Category – you can call this whatever you want – I’ve called it External Affiliate Link
    • Event Action – this is the name for the actual event that has taken place – in this case I’ve called this clicked
    • Event Label – this is set to be the actual url that has been clicked

Step 3 – Setup your External/Affiliate product in WooCommerce

This might be stating the obvious but this script will only work on External/Affiliate product types so you’ll need at least one of those 🙂

Ensure you add your external product link to your External/Affiliate product in WooCommerce
Ensure you add your external product link to your External/Affiliate product in WooCommerce


Step 4 – Confirm your event is working correctly in Google Analytics

Open your External/Affiliate product in WooCommerce and click the external link. If you’ve followed all our steps so far this will be sending events to Google Analytics for you. Go ahead and the click the button a few times to trigger a few test events. Then, hop on over to Google Analytics and go to Real Time -> Events (Note: It’s important to confirm your test works via Real Time as Events don’t show up in Behaviour -> Events for a few hours).

You should see something like this.

Our affiliate link tracking event in Google Analytics
Our affiliate link tracking event in Google Analytics

Woo hoo it works! Just like that any time one of your users clicks on external product links from your catalog they will now appear in their own Event category in GA.

Bonus round – let’s track link clicks to External Affiliate links as Conversion events.

How to track affiliate link clicks as conversion events

Step 1 – Go to GA -> Admin



Step 2 – Click Goals

Step 3 – Create a new goal 


You will want to give your goal a name that makes sense to you. Then select Event as the goal type.


Step 4 – Configure your goal

Make sure to enter the exact same name for the Category and Action that we defined earlier. Label and Value can be left blank. You will see an option to check this goal against your traffic for the past week. As we’ve just defined this event don’t be surprised if you see that the goal has a 0% conversion rate even though we’ve just ran some test events. That’s just our good ‘ol data lag in GA rearing it’s head again. Hit Save.


Check that your Conversions are working.

Thankfully we can verify our conversions are working by heading back over to Real Time -> Conversions. You can see below that our external link clicks are now showing up as conversions!

And that’s it – you’re done!

Wrapping things up

Given how many people many of us rely on affiliate marketing as a source of income online, it’s vital that we make sure we know as much as possible about the amount of traffic we generate for merchant we choose to promote. As a result of implementing the tracking processes we’ve detailed here, you’ll now be in a much better position to understand how effective your promotional efforts are. Of course we’ve only scratched the surface of what you can do with Events in Google Analytics. This same approach could be deployed to other external links across your site with a few tweaks. There are also some excellent plugins available to allow you to do that without needing to get your hands dirty with Javascript such as WP Google Analytics Events and Gravitate Event Tracking which are both awesome.

New extra bonus script added!

James Winsoar over on the Advanced WooCommerce Facebook Group wanted to use this conversion tracking method with Google Adwords. Here’s an alternative code snippet to do exactly that 🙂 Just be sure to change the Adwords variables to match your account settings.


Follow us on Twitter and Facebook!

Stay connected – be the first to get interesting updates and new releases from Create and Code.

Colm has been building web stuff since the web was a wee lad. Colm built his first blog with WordPress around 2007 and has been hooked ever since. When not knee deep in hooks and filters you’ll probably find him running around a mountain or making pizza.

Leave a Reply

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

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match