Server-Side Tracking Fails when setTokenAuth is set

I am trying to implement server side tracking and can successfully see page views within Matomo, however, each visitor is showing the servers IP address.

After reading the docs, and to get around this, I am settings setTokenAuth, but I then lose all tracking. As soon as I comment out the setTokenAuth line, it all starts again.

Where could I be going wrong?

      $matomoTracker = new MatomoTracker($matomoSiteId, $matomoUrl );
      $matomoTracker->setRequestTimeout(2);
      $matomoTracker->setTokenAuth($authToken);
      $matomoTracker->setRequestMethodNonBulk('POST');
      if (is_user_logged_in()) {
        $matomoTracker->setUserId($display_name);
      }
      $matomoTracker->setIp($connecting_ip);
      $matomoTracker->doTrackPageView( $page_title );

(The variables all return the correct values)

1 Like

I have been doing some further testing and the setUserId is working correctly (but again without the setTokenAuth which shows the code is working but not when elevation is needed.

Any ideas?

2 Likes

Hi @nbwpuk
What are the rights associated to the tocken? Maybe the minimum right should be probably tracked site admin…

3 Likes

That was a good thought, but to make sure I have created it against a superadmin so should have full permissions.

1 Like