PHPackages                             tomkyle/matomo-api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tomkyle/matomo-api-client

ActiveLibrary[API Development](/categories/api)

tomkyle/matomo-api-client
=========================

Client library for interacting with the Matomo API. Supports retry logic and PSR-6 caches.

1.1.3(12mo ago)040MITPHPPHP ^8.3CI passing

Since Nov 24Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/tomkyle/matomo-api-client)[ Packagist](https://packagist.org/packages/tomkyle/matomo-api-client)[ RSS](/packages/tomkyle-matomo-api-client/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (11)Versions (9)Used By (0)

Matomo API Client
=================

[](#matomo-api-client)

[![Packagist](https://camo.githubusercontent.com/35d99d320ac728e02d86bfd0b1f2120386884d0bf5199f65823f0e14a13319e4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6d6b796c652f6d61746f6d6f2d6170692d636c69656e742e7376673f7374796c653d666c6174)](https://packagist.org/packages/tomkyle/matomo-api-client)[![PHP version](https://camo.githubusercontent.com/e2fc71fb378c46d9058f2ecded01f6e48302cf4f366626eab5bb57e329cadf56/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f6d6b796c652f6d61746f6d6f2d6170692d636c69656e742e737667)](https://packagist.org/packages/tomkyle/matomo-api-client)[![PHP Composer](https://github.com/tomkyle/matomo-api-client/actions/workflows/php.yml/badge.svg)](https://github.com/tomkyle/matomo-api-client/actions/workflows/php.yml)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)

**A PHP client library for interacting with the Matomo API, providing robust and extensible functionality for managing and querying Matomo analytics data.**

Features
--------

[](#features)

- Supports retry logic with `RetryingMatomoApiClient` for handling transient failures.
- Caching with `Psr6CacheMatomoApiClient` to minimize API calls and improve performance.
- Fully PSR-compliant with PSR-6 (Caching), PSR-3 (Logging), PSR-17 (HTTP Factories), and PSR-18 (HTTP Client).
- Extensible via the `MatomoApiClientInterface` for standardized requests to the Matomo API.

Installation
------------

[](#installation)

Install via Composer:

```
composer require tomkyle/matomo-api-client
```

Usage
-----

[](#usage)

### Basic API Client

[](#basic-api-client)

Class **MatomoApiClient** is the primary client for sending requests to the Matomo API. The API response is returned as an associative array:

```
use tomkyle\MatomoApiClient\MatomoApiClient;
use GuzzleHttp\Psr7\Uri;

// Initialize the client
$uri = new Uri('https://your-matomo-domain.com');
$defaults = ['token_auth' => 'your-api-token'];
$client = new MatomoApiClient($uri, $defaults);

// Send a request
$params = ['idSite' => '1', 'period' => 'day', 'date' => 'today'];
$response = $client->request($params, 'VisitsSummary.get');

print_r($response);
```

### The Interface

[](#the-interface)

All classes in this package implement the **MatomoApiClientInterface** interface with a **request** method which returns the API response as an associative array. The method accepts the Matomo API parameters as well as an optional API method—See [Matomo docs](https://developer.matomo.org/api-reference/reporting-api) for more information:

```
/**
 * @param  array  $params API params
 * @return array API result
 */
public function request(array $params, string $method = null): array;
```

### Retrying Client

[](#retrying-client)

The **RetryingMatomoApiClient** wraps the above *MatomoApiClient* instance. When a request fails due to server load, it will retry the request up to a specified number of attempts.

```
use tomkyle\MatomoApiClient\RetryingMatomoApiClient;

// Maximum 3 attempts, 5 seconds wait
$retryingClient = new RetryingMatomoApiClient($client, 3, 5);

// Send a request
$params = ['idSite' => '1', 'period' => 'day', 'date' => 'today'];
$response = $retryingClient->request($params, 'VisitsSummary.get');
```

### Caching Client

[](#caching-client)

The **Psr6CacheMatomoApiClient** wraps any *MatomoApiClientInterface* instance and integrates with any PSR-6 compliant cache pool.

```
use tomkyle\MatomoApiClient\Psr6CacheMatomoApiClient;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$cachePool = new FilesystemAdapter();
$cachingClient = new Psr6CacheMatomoApiClient($cachePool, $client);

$response = $cachingClient->request($params, 'VisitsSummary.get');
```

Exceptions
----------

[](#exceptions)

- **MatomoApiClientException:** Thrown for errors during API requests or response handling.

---

License
-------

[](#license)

This library is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Contributing
------------

[](#contributing)

Contributions are welcome! Please open an issue or submit a pull request.

Links
-----

[](#links)

- [Matomo API Documentation](https://developer.matomo.org/api-reference/reporting-api)
- [GitHub Repository](https://github.com/tomkyle/matomo-api-client)

---

Development
-----------

[](#development)

Run `npm update` to install development helpers. Watch the file system for PHP code changes using `npm run watch` and see what *phpstan, phpcs, Rector,* and *PhpUnit* say. See [package.json](package.json) for a list of all watch and test tasks.

```
$ npm run watch
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance50

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~14 days

Total

8

Last Release

362d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/412560?v=4)[Carsten Witt](/maintainers/tomkyle)[@tomkyle](https://github.com/tomkyle)

---

Top Contributors

[![tomkyle](https://avatars.githubusercontent.com/u/412560?v=4)](https://github.com/tomkyle "tomkyle (14 commits)")

---

Tags

api-clientmatomomatomo-apiphp-libraryapiclientmatomo

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tomkyle-matomo-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/tomkyle-matomo-api-client/health.svg)](https://phpackages.com/packages/tomkyle-matomo-api-client)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.8M712](/packages/sylius-sylius)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6941.5M396](/packages/drupal-core-recommended)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M514](/packages/shopware-core)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.7k371.6k6](/packages/theodo-group-llphant)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69634.4M144](/packages/algolia-algoliasearch-client-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
