mattitjaab / matomo-proxy-laravel
This is my package matomo-proxy-laravel
Fund package maintenance!
MattitjaAB
Requires
- php: ^8.3
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- guzzlehttp/guzzle: ^7.8
- guzzlehttp/psr7: ^2.6
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^2.0||^3.0
- pestphp/pest-plugin-arch: ^2.5||^3.0
- pestphp/pest-plugin-laravel: ^2.0||^3.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
This package is not auto-updated.
Last update: 2025-08-21 13:42:46 UTC
README
This package provides a plug-and-play server-side Matomo tracking middleware for Laravel. Instead of embedding JavaScript trackers in your frontend, requests are tracked directly from your Laravel app to your Matomo instance, ensuring better privacy, ad-blocker resilience, and simplified integration.
Installation
Install the package via Composer:
composer require mattitjaab/matomo-proxy-laravel
Publish the config file:
php artisan vendor:publish --tag="matomo-proxy-laravel-config"
This will create a config/matomo-proxy-laravel.php
file. Example:
return [ 'enabled' => env('MATOMO_ENABLED', true), // Full Matomo tracking endpoint (must include /matomo.php) 'base_url' => env('MATOMO_BASE_URL', ''), // Matomo site ID 'site_id' => env('MATOMO_SITE_ID', null), // Optional token_auth (can be null for anonymous tracking) 'token' => env('MATOMO_TOKEN', null), // Paths that should never be tracked 'ignore' => [ 'telescope/*', 'horizon/*', 'health', '_debugbar/*', ], // HTTP client behavior 'timeout' => env('MATOMO_TIMEOUT', 2), 'retry' => [ 'times' => env('MATOMO_RETRY_TIMES', 0), 'sleep' => env('MATOMO_RETRY_SLEEP_MS', 100), // milliseconds ], ];
Usage
Register the middleware globally in your bootstrap/app.php
:
->withMiddleware(function (Middleware $middleware): void { $middleware->append(\MattitjaAB\MatomoProxyLaravel\Middleware\MatomoProxyLaravelMiddleware::class); })
- Configure your
.env
file:
MATOMO_ENABLED=true MATOMO_BASE_URL=https://analytics.example.com/matomo.php MATOMO_SITE_ID=1 MATOMO_TOKEN=null MATOMO_TIMEOUT=2 MATOMO_RETRY_TIMES=0 MATOMO_RETRY_SLEEP_MS=100
✅ That’s it. All requests will now be tracked server-side in Matomo without requiring any frontend JS snippet.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.