How to track cloaked affiliate links in goals?


I have search high and low in the forums and in google but I still can’t find an answer to what I’m looking for.

I have a review site (eg., and use a plugin to cloak my affiliate links going to merchant sites like to a “pretty link” like

I want to be able to track the cloaked affiliate link --> in goals so I can see how many times my affiliate links gets clicked on.

In creating a goal, when goal is triggered when visitors --> do I choose:
Option 1 --> Visit a given URL (page or group of pages)
where the URL (it says Page Title by the way which I think is wrong) contains “” or just “visit/” is enough?
Option 4 --> Click on a Link to an external website
where the external website URL contains

I am confused as to which above mentioned option is the correct one to use. The cloaked link is obviously for an external website, but the cloaking plugin uses my site’s URL to mask the affiliate link.

Any help with this would be greatly appreciated.

In this case, it’s a bit different, because the link is neither external (option 4 will not work), and it is not a “Page view” as such, because the JS tracker is not executed in your cloacked page (option 1 will not work).

2 options:

  1. In your cloaking page, instead of redirecting directly to the URL, have a HTML page load, with the Piwik JS code in it, and redirect the visitor after 1 second to your affiliate URL

  2. In your cloacking page (for example doing the redirect in PHP), you can use the tracking API and trigger the goal manually: Tracking API - Analytics Platform - Matomo

Hi Matt,

Thanks for your response, but I am having difficulty understanding the jargon…
What do you mean by “cloaking page”?
How do you do a HTML page load with the Piwik JS code in it?

Do both the solutions you provided above stop me from using the plugin on my wordpress site?

I just tried to read the Piwik Tracking API page you directed me to, and it is way over my head to understand…

Do you know of any other analytics solutions that can track cloaked affiliate links?
Will this feature be added into piwik in the future?

Currently, what is the code source of your page that redirects to amazon?

you could write something like

<meta http-equiv="refresh" content="1;url="> 



Hello, great post thank you for the input.

My question, is there a way to avoid the 1 sec delay? Maybe insert client side redirect using javascript ? WHat if 1 sec is too long or not enough to track what piwik needs?

(location.href = ? Maybe )

Does option 1 (Visit a given URL) have to be an Internal website where Piwik has stats pages on it?

Also, anyway to hijack the stats from Google Adwords Javascript or other 3rd party banner servers? They decide on the image and the URL, so don’t think you can track this? Maybe track external clicks going to who they farm it out too. ( I think won’t work because its a javascript induced link as below

And option 4 (external website) will not work unless its a normal hyperlink part of the DOM , and not part of any javascript induced URL click?

You can also use the tracking api to avoid using javascript and therefore the delay: Tracking API - Analytics Platform - Matomo