trackGoal for specific visitor

Hello,

I am running an affiliate website with offers. On that affiliate website i am running Matomo Analytics.
What is do is this.

If a user is clicking on a affiliate link i send the visitor_id with this link.
example: https://www.externaldomain.com?ref=REFCODE&subid=MATOMO_VISITORID

When they purchase the offer the externaldomain gives on there thankyoupage an GET/POST to my url.
https://www.mydomain.com/tracking/tracking.php?commission=15.20&subid=MATOMO_VISITORID

What is do on this tracking.php in the Matomo trackingcode is this:
_paq.push([‘trackGoal’, 2, <?php echo $commission; ?>]);
_paq.push([‘visitor_id’, <?php echo $subid; ?>]); //this one seems it’s not working.

My question is: How can i trackGoal been set for a specific MATOMO_VISITORID

Since I don’t have a response yet, I’ll describe it differently.

The trackGoal goes through a server request. The information what I have is this:

Goal_ID
Commission
Visitor_ID

Which tracking code should I use to measure goals and connect it to a visitor.

Hi,
Your request is not very clear to me :wink:

Anyway, you can create a goal directly from the Matomo Console (when some requirements are met).

Or send a goal event through the HTTP API: https://developer.matomo.org/api-reference/tracking-api#optional-action-info-measure-page-view-outlink-download-site-search

Or through JS API: https://developer.matomo.org/guides/tracking-javascript-guide#manually-trigger-goal-conversions

Or through MTM:

Philippe thanks for your reply!

I’ve made a image to make the request clear.

The code i am using is

<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  window._paq.push(['trackGoal', 2, <?php echo $commission; ?>]);
  window._paq.push(['setUserId', <?php echo $subid; ?>]);
  (function() {
    var u="//matomo.domain.nl/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

ON tracking.php i need to setGoal and connect it to a userID

On page 1 (the one before going to awin.com), do you set the same user ID?
So do you have the code:

<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  _paq.push(['setUserId', <?php echo $subid; ?>]);
  (function() {
    var u="//matomo.domain.nl/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

No i am not doing that. $subid is the userID from the cookie (_pk_id.1.1763)

the userId should be constant. If not, Matomo won’t consider it is the same user…

The userId is constant now and this is working.

The tracking.php is requested by a server (from awin.com)

On tracking.php is this trackingcode:

<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  _paq.push(['trackGoal', 2, <?php echo $commission; ?>]);
  _paq.push(['setUserId', <?php echo $subid; ?>]);
  (function() {
    var u="//matomo.domain.nl/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

The conversions aren’t logged by Matomo. Doe i need to change anything because the request is from a server?

Do you have a screenshot of the detailed visit log of a user (who reached the goal)?

Goals are zero…Matomo doesn’t tracking these goals properly

If i do it manualy the goal has been tracked! It’s working with the right commission and the right user.
The problem is that the page is visited by a server. And then the goal isn’t tracked.

Is it a server call or a JavaScript-API call
On your code examples, there is only JavaScript -API calls…

Hi Philippe,

Thanks for your fast reply!

It is a server call that woud be the reason ithink. do you know what i need to change?

Are you sure the server reach your matomo server? (do you have a log somewhere?)
I suppose you use the HTTP API: Tracking HTTP API: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v4
Then try to use the url parameter.
Or else maybe you can configure the measurable:


(Note: there is also some excluded IPs in these settings)

Thanks! i need to wait for a conversion now :wink:

I watched this for HTTP API https://www.youtube.com/watch?v=bYly4q6VOkA