How to track a goal in a wordpress hook

Hello,

I’m searching for a way to track a goal in a wordpress action hook, where _paq.push is not available.

I found the MatomoTracker, but it seems only for non-wordpress installations.
Would the Tracking HTTP API be suitable? How would a common _paq.push([‘trackGoal’, 1, 99]) query look like in PHP?

Hi @saddy001 ,
idgoal

Here you can get the whole HTTP API:
https://developer.matomo.org/api-reference/tracking-api

Thanks. Here is what I have so far:

$ch = curl_init("https://www.example.com/wp-admin/matomo.php?idsite=1&rec=1&idgoal=5&_id=??????");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);

To assign the goal to the visitor, it seems I need the unique visitor ID ( _id). In JS there is getVisitorId() from /api-reference/tracking-javascript.

How to get it in PHP?

Hi @saddy001
Sorry I didn’t read well your first message… :thinking:
In Matomo, it is possible to define a goal when the visitor visits a specific URL or Page Title, or when he sends a specific event. Maybe one of these options could allow you to get goals? For example you could create an event on your WP and Matomo will generate a goal from it.

Although that would be possible, the goal would still not be attributed to the correct visitor, would it?

If the event is attributed to the correct visitor, the goal would also. But if you do also without _paq, the result will be the same. There is no known possibility to get the visitor ID if you don’t work client side…
How you you track page views, events, etc?
There is some ways (3) to install Matomo with WP:

Yes, I have that installed. But the problem remains :wink:

Anyways, if it’s not possible it is not an answer that I like but it’s an answer. Thank you.