Strongly recommended: HTTP Api if you want full control of data

Hello All

I strongly recommend the http API over javascript or PHP API as one will have much more control and flexibility on what’s happening, and also prevent flooding or people playing around with the javascript to push junk into your stats. This is a distinct possibility

This will also make your campaigns a lot more reliable (For info on marketing campaigns, see https://plugins.matomo.org/MarketingCampaignsReporting ). For example, if you use the marketing campaign keywords mtm_, someone can easily spam your URLs to confuse and pollute your stats, even by using proxies, etc.

It is best if you are in control. For example, you could have a unique id that maps to a bunch of marketing info and just have that in the GET request

The downside is that even for javascript interactions, you will need to do a server call, and a user can still try to flood you, but the control is with your backend php to see how you handle it before it gets tracked.

Also, in case of outgoing links, if you wish to “hide” your URL as the referer URL, this can be quite helpful. This is what google and others do to “hide” the http_referer . Just do a 302 redirect after tracking

There could be another challenge where an additional http call on the server side, in order to use the http api, may add to some lag. A simple solution is to use Guzzle PHP library and not wait for a response

Just set the timeout value in Guzzle to be very low, and don’t do anything with the exception that is raised

    //https://www.geeksforgeeks.org/how-to-make-asynchronous-http-requests-in-php/
    /*
    //https://stackoverflow.com/questions/35956516/send-asynchronous-request-without-waiting-the-response-using-guzzle
    try {
        $this->guzzle->post('https://www.myDomain.com/matomo.php', ['timeout' => 1]);
    } catch (\GuzzleHttp\Exception\ConnectException $e) {
        // do nothing, the timeout exception is intended
    }

Of course, implement your own logic for the visitorID, and userID based on cookies, or sessions, or whatever else you may use to track visitors and users

Hope this helps someone

1 Like