Download the PHP package poldixd/laravel-matomo-ai-bot-tracking without Composer
On this page you can find all versions of the php package poldixd/laravel-matomo-ai-bot-tracking. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download poldixd/laravel-matomo-ai-bot-tracking
More information about poldixd/laravel-matomo-ai-bot-tracking
Files in poldixd/laravel-matomo-ai-bot-tracking
Package laravel-matomo-ai-bot-tracking
Short Description Track AI bot requests from Laravel in Matomo.
License MIT
Homepage https://github.com/poldixd/laravel-matomo-ai-bot-tracking
Informations about the package laravel-matomo-ai-bot-tracking
Laravel Matomo AI Bot Tracking
Track AI bot requests from a Laravel app in Matomo.
This package adds a middleware for Laravel. It uses
a fast user-agent string check to detect AI bots and sends these requests to
Matomo with recMode=1.
What It Does
The middleware tracks AI bot page requests on the server. It only tracks a request when all of these things are true:
- The request is a
GETrequest. - The request has a
User-Agentheader. - The user agent contains a known AI bot identifier.
- The request is not asking for JSON.
- The path is not for Livewire, Debugbar, or Telescope.
The request to Matomo contains these fields:
idsiterec=1recMode=1urlhttp_statusbw_bytespf_srvuasource
The middleware does not send cip or cdt. This means it does not override the
visitor IP or request time in Matomo.
Requirements
- PHP 8.2 or newer
- Laravel 11, 12, or 13
- Matomo with bot tracking support
Matomo bot tracking needs support for the recMode tracking parameter.
Installation
Install the package with Composer:
Laravel will auto-discover the service provider.
Configuration
The package reads its settings from Laravel's services config. Add this to
config/services.php:
Then add the values to your .env file:
MATOMO_TRACKING_URL is the base URL of your Matomo installation. Do not add
/matomo.php here. The middleware adds it for you.
Middleware Usage
Register the middleware on the routes where you want to track AI bots.
For a Laravel 11+ application, add it to the middleware configuration in
bootstrap/app.php:
For older Laravel applications that still use app/Http/Kernel.php, add it to
the web middleware group:
Behavior
When an AI bot request matches the rules above, the middleware waits until Laravel has created the response. Then it sends a form POST request to:
If Matomo tracking fails, the user response is still returned as normal. The error is reported through Laravel and logged with useful request details.
Testing
Run the tests with:
Run the code style check with:
License
MIT