Hi
In the code below, I used my actual domain instead of mydomain
Also, the token is indeed “123”. No error raised, and nothing happened! Is the PHP stuff broken? I couldn’t set userId neither
Thanks
try {
$matomoSiteId = 3; // Site ID
$matomoUrl = "https://www.mydomain.com"; // Your matomo URL
$matomoToken = "123"; // Your authentication token , created on personal->security
// Load object
//included in autoload in prepended file require_once("MatomoTracker.php");
// Matomo object
$matomoTracker = new MatomoTracker((int)$matomoSiteId, $matomoUrl);
// Set authentication token
$matomoTracker->setTokenAuth($matomoToken);
//https://forum.matomo.org/t/track-same-user-by-js-and-php/9525
//$matomoTracker->setVisitorId( $_COOKIE[$cookie_name] );
//get the visitorId to check in dashboard later
$theMatomoVisitorId = $matomoTracker->getVisitorId() ;
//let us get the userId to see if one exists:
$matomoUserId = $matomoTracker->getUserId();
if ($matomoUserId === false) {
$matomoTracker->setUserId($cookie_val); //setting it to the cookie value for the main cookie
echo "\r\n <h1>matomoUserId has been set to $cookie_val for $theMatomoVisitorId \r\n</h1>";
} else {
echo "\r\n <h1>matomoUserId = $matomoUserId for $theMatomoVisitorId \r\n</h1>";
}
} catch (\Throwable $th) {
//throw $th;
echo "<h1>Caught exception .... " . $th->getMessage() . "</h1>";
}