Matomo PHP Tracker
The official PHP client for the Matomo Analytics Tracking API, for server-side event and visit tracking.
Repository Health
Technical Analysis
Matomo PHP Tracker is the official server-side PHP client for the Matomo (formerly Piwik) Analytics Tracking API. It brings all the capabilities of the Matomo JavaScript tracker—page views, event tracking, ecommerce, custom variables, goals, and more—to the backend, so you can record analytics from PHP without relying on client-side scripts.
This is ideal for tracking that must happen server-side: API requests, background jobs, non-browser clients, or privacy-conscious setups that avoid JavaScript. You instantiate a MatomoTracker with your site ID and Matomo URL, optionally set an auth token, and call methods like doTrackPageView() or doTrackEcommerceOrder() to send tracking requests directly to your Matomo instance.
What You Get
- A MatomoTracker class covering page views, events, ecommerce, goals, and custom variables
- Server-side tracking that works without any client-side JavaScript
- Control over visitor attributes like IP, user ID, timestamps, and custom dimensions (with an auth token)
- A dependency-light client requiring only the JSON extension plus cURL or streams
Common Use Cases
- Recording analytics from API endpoints and non-browser clients
- Tracking background jobs, webhooks, or server events in Matomo
- Logging ecommerce orders and conversions server-side for accuracy
- Backfilling or importing historical visits with precise timestamps and user IDs
Under The Hood
Architecture The library is deliberately simple: a single MatomoTracker.php class (with a PiwikTracker.php backward-compatibility alias) that holds tracking state—site ID, base URL, visitor attributes, custom variables—and builds query strings for the Matomo Tracking API. Public methods such as doTrackPageView(), doTrackEvent(), and doTrackEcommerceOrder() assemble the request parameters and dispatch an HTTP call to the configured Matomo endpoint via cURL or PHP streams.
Tech Stack It is plain PHP with no runtime framework dependencies, requiring only the JSON extension and cURL or the stream extension, and supporting PHP 7.2 through 8.5. Autoloading is classmap-based, and PHPUnit (8.5/9/10) is the sole dev dependency.
Code Quality The project is mature and stable rather than actively developed. It ships a tests/ suite run via PHPUnit and run_tests.sh, and maintains a changelog. The single-class, classmap design is dated (no PSR-4 namespacing, one large class) but well understood and battle-tested across many years of Matomo deployments.
API Design The API is procedural and approachable—construct a tracker, optionally set a token, call clearly named do* methods—so getting started takes minutes and mirrors the familiar JavaScript tracker. The main friction is knowing which auth-token-gated attributes you need for accurate server-side attribution, but the developer documentation covers this well.
Used by 2 apps in this directory
matomo
Analytics
Open-source, privacy-first web and app analytics that puts you in complete control of your data.
Shlink
Developer Tools · Marketing
Self-hosted PHP URL shortener with a full REST API, dynamic redirect rules, and real-time visit analytics under your own domain.