How to track a goal in a wordpress hook


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 ,

Here you can get the whole HTTP API:

Thanks. Here is what I have so far:

$ch = curl_init("");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($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.