PHP analytics without JavaScript
Track page views from PHP with no script in the browser: what you gain, what you lose, the options, working code and a mapping from matomo-php-tracker.
To get PHP analytics without JavaScript, your application reports the page view itself, over HTTP, once it has served the page. Matomo's PHP tracker and the Quiet Metrics php-metrics SDK both work this way. You count visitors whose browser blocks scripts; you lose what only a browser can see, such as window size, scrolling and clicks.
The facts about Matomo and Google Analytics on this page were checked against their own documentation in December 2026. Our own product is described from its documentation; theirs can change, so follow the links before you decide.
Why measure from the server
A browser-side tracker has three ways to fail: the script does not load, it does not run, or its request never reaches the network. Content blockers, strict privacy settings, a flaky mobile connection or a CSP that forgot one domain are each enough. With server-side tracking, the request leaves your code, so there is nothing on the client to block.
The second gain is page weight. No script to download, no work on the main thread, nothing in the critical rendering path. For a site that already fights for its Core Web Vitals, that is one less third-party resource.
The third is where the data goes first: from your infrastructure to your provider, instead of from your visitor's device to a third party. That can matter in your privacy assessment, but it settles nothing on its own (see below).
What you lose, honestly
The server only knows that a page was served. Everything that happens after that is invisible to it:
- Window size. Our browser script sends the window size, reduced to a class on arrival. A server-side page view has no such value.
- In-page interactions. Scrolls, clicks, a form abandoned halfway: none of them reaches your PHP code unless you send an event yourself when a request arrives.
- Cached pages. A page served by a full-page cache in front of your application never runs PHP, so its visit is not counted. Keep those pages out of the cache, or add the
qm.jsscript as well: both measurements coexist without double counting.
Two things it does not change. Server-side tracking is not automatically more private: your server sees the full IP address and user agent, and what protects a visitor is what the receiver keeps. Our side is published on How we count. And it does not remove the consent question: whether you need consent depends on your purposes and configuration, not on the transport. That decision stays with you as the site publisher. The server-side tracking page goes further on both points.
The options in PHP
Matomo PHP tracker
Matomo publishes matomo-php-tracker, a client for its HTTP Tracking API. According to its API reference, you create a MatomoTracker with a site ID and your Matomo URL, then call doTrackPageView(), doTrackEvent() or doTrackGoal(). It also covers ecommerce (addEcommerceItem(), doTrackEcommerceOrder()), bulk sending, and a visitor ID you can force with setVisitorId(). By default it reads and writes Matomo's first-party visitor cookies; disableCookieSupport() turns that off. Forcing the visitor IP with setIp() requires a token_auth.
It is a mature, complete client. If you self-host Matomo, need ecommerce reports, or want visitor-level journeys, it is the better fit. Our Matomo comparison covers the wider differences.
GA4 Measurement Protocol
Google's Measurement Protocol sends events to Google Analytics over HTTP. Google states that it is meant to augment automatic collection through gtag, Tag Manager or Firebase, not to replace it. It suits offline conversions on top of an existing GA4 setup; it is not a way to run GA4 without a tag.
Quiet Metrics php-metrics and the Symfony bundle
quiet-metrics/php-metrics is our core package: no dependencies, PHP 8.3 or later, shared hosting and CMSs included. The Symfony bundle and the Laravel middleware are built on it. It sends page views and events with no identifying or tracking cookies, and the visitor fingerprint uses a salt destroyed every night.
A plain PHP example
Install the SDK:
composer require quiet-metrics/php-metrics
Then, in a file every page goes through (a front controller or a common include):
use QuietMetrics\Client;
$qm = new Client('qm_pub_XXXXXXXXXXXXXXXXX', 'qm_sec_XXXXXXXXXXXXXXXX');
$qm->pageview(); // context inferred from the current request
$qm->event('purchase', ['amount' => 49]); // custom event
The URL, referrer, IP, User-Agent and language come from the current request's superglobals. Every field can be overridden:
$qm->pageview(['url' => 'https://mysite.com/thank-you', 'referrer' => null]);
The second argument is the secret key, and it matters. It signs each send with HMAC-SHA256; only a valid signature lets the service use the visitor's IP and browser from the payload. Without it, your server would be counted as the only visitor. Keep the secret key out of the browser and out of public repositories, and keep the server clock in sync: signatures more than five minutes off are rejected.
From a cron job or a worker there is no current request, so pass the URL, or the send is silently dropped:
$qm->event('invoice-generated', ['amount' => 99], [
'url' => 'https://mysite.com/invoices',
'ts' => time(),
]);
Before anything leaves your server, the SDK reduces the page address to its origin, path and campaign parameters (utm_source, utm_medium, utm_campaign, ref), and the referrer to its origin. A token or email address in a query string stays with you.
Symfony
The bundle sends page views automatically after the response, on kernel.terminate:
composer require quiet-metrics/symfony-metrics
# config/packages/quiet_metrics.yaml
quiet_metrics:
public_key: '%env(QUIET_METRICS_PUBLIC_KEY)%' # the site's public key (required)
secret_key: '%env(QUIET_METRICS_SECRET_KEY)%' # required for server-side sending: signs every send (HMAC)
# endpoint: 'https://quietmetrics.dev/api/v1/collect' # core SDK default
# auto_pageview: false # disables the automatic page view
It counts HTML documents served for a GET, including 404 and 500 pages, and skips redirects, JSON, files, AJAX, announced prefetches and opted-out visitors. For events, inject QuietMetrics\Tracker. Details in the Symfony docs; Laravel has its own middleware.
Shared hosting
The SDK first tries an outbound socket (fsockopen, fire-and-forget, about a millisecond perceived). If your host disables it, it falls back to a short cURL request. If neither is available, the send is dropped silently: your site never breaks because of analytics. The default send budget is 400 ms and can be lowered with timeout_ms. The PHP SDK docs list every option.
Coming from matomo-php-tracker
There is no conversion tool, and our docs describe no import of Matomo data: keep your Matomo reports for history. The code change itself is small, because the concepts map closely.
| matomo-php-tracker | php-metrics |
|---|---|
new MatomoTracker($idSite, $apiUrl) |
new Client($publicKey, $secretKey), endpoint as an option |
setTokenAuth() so that setIp() is accepted |
The secret key signs each send; the visitor's IP and browser count only with a valid signature |
setUrl(), setUrlReferrer(), setUserAgent() |
Inferred from the request; override with ['url' => …, 'referrer' => …] |
doTrackPageView($documentTitle) |
pageview(); pages are identified by their path, not their title |
doTrackEvent($category, $action, $name, $value) |
event($name, $props), up to 30 scalar properties |
doTrackGoal($idGoal) |
No call: goals are set in the dashboard (Sites → Goals), on an exact event name or a path with wildcards |
| Ecommerce methods | No dedicated API; send an event with properties |
setVisitorId(), visitor cookies |
No equivalent: no visitor ID, no identifying cookie |
enableBulkTracking(), doBulkTrack() |
No equivalent: each call sends at once, fire-and-forget |
Two habits to drop. Category and action pairs do not exist; fold them into the event name (newsletter-signup) or into properties. And there is no visitor ID to carry across visits: the fingerprint changes every day by design, so returning visitors cannot be followed over time.
Try it on your own site
Create a site, copy its two keys, add the three lines above, and the installation screen confirms the first page view live. A free plan exists; the pricing page shows what each plan includes, goals among them, and the conditions of the trial.