Track (internal) affiliate links

I run a few websites I would like to move to Matomo On-Premise. One of the sites have quite a few affiliate links that all looks like this:<affiliate-id>

I am looking to add a goal in Matomo that tracks clicks to all links that contain*. Have tried setting this up with an expression, but I am doing something wrong as it does not work.



If someone know how to set this up properly I would really appreciate it.

Thank you.

What if you try:


(without escaping slashes)

It doesn’t seem to be working.

Maybe my options are wrong? I am using “Goal is triggered when visitors visit a given URL”.

For the URL I am using “matches the expression”.

The expression I’m using is:


Hi @naldy ,
are these links within your tracked pages or are links going to an external page?
Depending on this, you may have to select Outgoing Links.

Edit: And your pages with “/link/” contain the Matomo Tracking Code? With this goal option the measurement does not take place when you click, but only when you visit this page.

These links are most likely internal as is a URL on my site.

These links are set up with a plugin named ThirstyAffiliates in WordPress. When a link is clicked it redirects to the external affiliate site.

I have tried a lot but nothing that works yet. Any suggestions are welcome.

That sounds like a technical problem for any tracker.

You click on a link that is defined as internal in Matomo based on its domain. So the tracking for outgoing links does not work because of this.
However, the redirect “page” (simple 301-status request, I guess) does not load the tracker, so it cannot be tracked as a page impression either.

Since it’s a Wordpress plugin where you probably can’t make any code changes, the idea that comes to me, and if you’re familiar with writing own Javascript, is to attach event listeners to these links, which then call a Javascript-function with a tracking event or manually triggering the goal.
Your own script must parse the DOM and detect all affiliate links and add the listener with a function which tracks to Matomo.

Maybe there is another approach in Matomo, but I can’t think of one.


I forgot one possible approach for solving your constellation: the Matomo Tag Manager can measure clicks, so you can create a Trigger for the link clicks and Tags to track a goal manually.

For this you have to switch your tracking to the Tag manager.