PHP API: Page views tracked as visits in 2.1.0



I am currently trying to change my tracking api from JS to PHP. JS worked just fine, but for various reasons, I want to do it in PHP. Here’s the code I’m using:

function trackvisit () {
    $siteid = 1;
    $pwurl= "";
    $pwtoken = 'xxxxxxxx';
    $ssl = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true:false;
    $sp = strtolower($_SERVER['SERVER_PROTOCOL']);
    $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
    $port = $_SERVER['SERVER_PORT'];
    $port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port;
    $thisurl = urldecode($protocol.'://'.$_SERVER['HTTP_HOST'].$port.$_SERVER['REQUEST_URI']);

    require_once "includes/PiwikTracker.php";
    PiwikTracker::$URL = $pwurl;
    $pwtracker = new PiwikTracker( $idSite = $siteid, $pwurl);
    $pwtracker->setVisitorId( $pwtracker->getVisitorId());
    if ($_SERVER['HTTP_REFERER']) $pwtracker->setUrlReferrer($_SERVER['HTTP_REFERER']);
    if ($_SERVER['HTTP_ACCEPT_LANGUAGE']) $pwtracker->setBrowserLanguage($_SERVER['HTTP_ACCEPT_LANGUAGE']);
    if ($_SERVER['HTTP_USER_AGENT']) $pwtracker->setUserAgent($_SERVER['HTTP_USER_AGENT']);
    if ($userdata['session_logged_in']) $pwtracker->setCustomVariable( 1, 'Username', $userdata['username']);
    $pwtracker->setGenerationTime(round((microtime(TRUE)-$_SERVER['REQUEST_TIME_FLOAT']), 4));
    if ($piwik_goal != 0) $pwtracker->doTrackGoal($piwik_goal); 

The site to track would be in this case. All this works fine so far BUT:

Each and every tracked page shows up with a new, unique VisitID in Piwik. It doesn’t matter if I omit enableCookies() and/or set/getVisitorId() - the result is the same in all cases. Neither the cookies nor the heuristics seem to work.

I’m usinf the PiwikTracker-php from the current release I’m running.

What am I doing wrong?


(Matthieu Aubry) #2

Maybe try this setting:How do I track visits on my intranet? - Analytics Platform - Matomo

If it does not work, maybe you need: