Matomo PHP Tracker

The official PHP client for the Matomo Analytics Tracking API, for server-side event and visit tracking.

SDK
Composer
v4.0.1
220stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
64/100Good
Development Activity60
Maintenance36
Community80
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture70
Code Quality72
Innovation65
Learning Curve85

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search