mattitjaab/matomo-proxy-laravel

This is my package matomo-proxy-laravel

v1.0.0 2025-08-20 15:06 UTC

This package is not auto-updated.

Last update: 2025-08-21 13:42:46 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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);
})
  1. 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.