Php tracking code

Exist a php tracking code?


I had also seen him, but he had me a little confused …

Talk about piwik, the guide is a bit strange, send to download other files, I wasn’t sure it was the right one.

To get started I started in the simplest way, I just added these:

// -- Matomo Tracking API init -- 
require_once "/path/to/PiwikTracker.php";
PiwikTracker::$URL = '';

$piwikTracker = new PiwikTracker( $idSite = {$IDSITE} );

on all my sites, is that correct? It’s working? Will I need anything else?

I think doesn’t work…

what’s wrong?

Please someone answer… I had to restore the javascript code, but I would really like to use php tracking code on my sites.

no one… :sleepy:


Please check out Method 2 on this page:

You only created the tracker object, but didn’t tell it to send any data to Matomo:

$piwikTracker->doTrackPageView('Document title of current page view');

Thank you,
I added the new line of code and seems to work now.

I thought it was used to pass a page title different from that in the html to matomo … but actually “doTrackPageView” could be a clue :thinking::flushed: sorry.

One last question, can ‘Document title of current page view’ be left blank?
I have several sites, with different structures, but I use a single file for tracking that is included in all the pages of my sites, I struggle to pass the page title to it …
Otherwise I have to add a function in php that goes to read the title of the page, just to not go back to using javascript …


It should be possible to use a blank string for page title. Of course then reports in Matomo could be a bit more confusing (but you can still see the URL).

no problem for me, I know every single url of my sites.

I added the tracking code in php on all my sites (about 40) and … it destroyed my server …

With horrifically frightening errors like these:

[Wed Jan 22 22:53:20.956312 2020] [proxy:error] [pid 5873:tid 140225909090048] (2)No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /run/php/php7.3-fpm.sock (*) failed
[Wed Jan 22 22:53:20.956338 2020] [proxy_fcgi:error] [pid 5873:tid 140225909090048] [client] AH01079: failed to make connection to backend: httpd-UDS
AH01075: Error dispatching request to : (polling)
AH00484: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting

2 hours of panic before thinking about the tracking code of matomo …
I think something doesn’t work with php code, it sucks all the server …

For 24 hours yesterday I put the code on one site and everything worked without problems, with all the sites after 10 minutes the server exploded …