topoff / laravel-user-logger
Laravel User Logger
Requires
- php: ^8.3
- illuminate/cache: *
- illuminate/database: *
- illuminate/log: *
- illuminate/support: *
- jaybizzle/crawler-detect: ^1.2
- laravel/pennant: ^1.0
- matomo/device-detector: ^6.3.0
- snowplow/referer-parser: ~0.2
Requires (Dev)
- driftingly/rector-laravel: ^2.0
- larastan/larastan: ^3.0
- laravel/boost: ^2.1
- laravel/pint: ^1.14
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^2.36
- phpunit/phpunit: ^10.0
- rector/rector: ^2.3
- dev-master
- v8.3.4
- v8.3.3
- v8.3.2
- v8.3.1
- v8.3.0
- v8.2.0
- v8.1.0
- v8.0.0
- v7.0.1
- v7.0.0
- v6.2
- v6.1.0
- v5.7
- v5.5
- 5.4
- v5.3
- v5.2
- v5.1.2
- v5.1.1
- v5.1.0
- v5.0.2
- v4.0.0
- v3.0.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.1.0
- v1.0.1
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15
- v0.14.0
- v0.13.1
- v0.13.0
- v0.12.0
- v0.11.1
- v0.11.0
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.1
- v0.4
- v0.3
- v0.2
- v0.1
- v0.0.1
This package is auto-updated.
Last update: 2026-03-03 20:54:21 UTC
README
Laravel User Logger with Pennant-based experiment measurement.
Requirements
- Laravel
laravel/pennant
Installation
Using Composer is currently the only supported way to install this package.
composer require topoff/laravel-user-logger
Getting started
Publish the package config:
php artisan vendor:publish --tag=config
If you want to, create a dedicated user-logger database connection in config/database.php:
'user-logger' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => 'userlogger', 'username' => env('DB_USERNAME', ''), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ],
Run migrations:
php artisan migrate
Set up Pennant (required for experiment variant storage/resolution):
php artisan vendor:publish --provider="Laravel\Pennant\PennantServiceProvider"
Then set the Pennant DB connection to your user-logger connection in config/pennant.php:
'stores' => [ 'database' => [ 'driver' => 'database', 'connection' => 'user-logger', 'table' => 'features', ], ],
Run migrations again so the Pennant features table is created:
php artisan migrate
Experiments
Experiment measurement uses laravel/pennant. Configure tracked features in config/user-logger.php:
'experiments' => [ 'enabled' => true, 'features' => [ 'landing-page-headline', 'checkout-flow', ], 'conversion_events' => [ 'conversion', ], 'conversion_entity_types' => [], 'nova' => [ 'enabled' => true, ], 'pennant' => [ 'store' => 'user-logger', 'connection' => 'user-logger', 'table' => 'pennant_features', 'auto_install' => true, 'scope' => 'session', ], ],
Pennant storage is installed by this package via migrations on the user-logger connection (pennant_features table).
This makes feature resolutions shareable across multiple apps that point to the same user-logger database.
With auto_install=true (default), the package also creates the Pennant table automatically at boot if it is missing.
Flush all measured experiment data:
php artisan user-logger:flush
Nova
When Nova is installed and experiments.nova.enabled is true, the package auto-registers the ExperimentMeasurement Nova resource.
If your app defines a fully custom Nova::mainMenu(...), you must also add the resource manually in that menu.
Testing
composer test
Performance Profiling
You can enable runtime profiling logs in config/user-logger.php:
'performance' => [ 'enabled' => true, 'log_queries' => true, 'slow_ms' => 500, ],
When enabled, the package logs:
- total request duration (
request_duration_ms) - server-side time until response - user-logger boot duration (
boot_duration_ms) - user-logger internal segment timings (
user_logger.segments) - optional query counters (
queries_total,queries_user_logger) - skip reason (
skip_reason) when logging is bypassed
Slow request warnings can be emitted with slow_ms (set 0 to disable warnings).
User-Agent Parsing Performance
matomo/device-detector supports cache-backed parsing:
'user_agent' => [ 'cache' => true, ],
cache: uses Laravel's default cache store to speed up parser internals.
The package automatically skips DeviceDetector bot matching when the request was already classified as a crawler via CrawlerDetect.
Update
This package uses https://github.com/snowplow-referer-parser/referer-parser. Use that repository to update the known referer list when needed.