ads / statistics
Tracks basic user information to generate statistical data on page usage. Also provides additional information to debug 500 errors
Requires
- php: ^7.3|^8.0
- ext-json: *
- ext-mbstring: *
- illuminate/support: ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^9.5|^10.0|^11.0|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 3.1.0
- 3.0.20
- 3.0.19
- 3.0.18
- 3.0.17
- 3.0.16
- 3.0.15
- 3.0.14
- 3.0.13
- 3.0.12
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- v2.x-dev
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0.1
- 2.1.0
- 2.0.5
- 2.0.4.3
- 2.0.4.2
- 2.0.4.1
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- v1.x-dev
- 1.0.2
- 1.0.1
This package is auto-updated.
Last update: 2026-10-19 15:52:32 UTC
README
Audit/Error Logging Module for Laravel
Records page views (URL, route, status code, user, filtered form input) and exceptions to a statistics table to help with usage reporting and debugging 500 errors.
Logging is designed to never break your app: every value is cleaned to valid UTF-8 and truncated to fit its column, and any failure while logging is written to the Laravel log and swallowed. Page views are written after the response has been sent (or queued), so they don't slow requests down.
Supports Laravel 7–13 on PHP 7.3+.
Installation
composer require ads/statistics
php artisan vendor:publish --provider="Ads\Statistics\StatisticsServiceProvider"
php artisan migrate
Upgrading? Publish and run migrations again; update_statistics_table widens ip_address for IPv6 and adds indexes. On Laravel 7–9 it requires composer require doctrine/dbal.
Log page views
Add the middleware to the web group.
Laravel 11+ (bootstrap/app.php):
->withMiddleware(function (Middleware $middleware) { $middleware->web(append: [ \Ads\Statistics\Http\Middleware\LogStatistics::class, ]); })
Laravel 7–10 (app/Http/Kernel.php):
protected $middlewareGroups = [ 'web' => [ // ... \Ads\Statistics\Http\Middleware\LogStatistics::class, ], ];
Registering \Ads\Statistics\Statistic::class as middleware still works but is deprecated; it writes synchronously before the response is sent.
Log exceptions
Laravel 11+ (bootstrap/app.php):
->withExceptions(function (Exceptions $exceptions) { $exceptions->report(function (Throwable $e) { \Ads\Statistics\Statistic::error($e); }); })
Laravel 8–10 (app/Exceptions/Handler.php):
public function register() { $this->reportable(function (Throwable $e) { \Ads\Statistics\Statistic::error($e); }); }
Statistic::error() never throws. Exceptions with their own status (e.g. HttpException) record that code; others record error_status_code (500).
Configuration
Edit config/statistics.php. The main options:
| Key | Default | Purpose |
|---|---|---|
enabled / log_errors / log_input |
true |
Toggle page views, exceptions, and input capture |
user_id, first_name, last_name |
null |
Attribute names on your User model, e.g. 'email' |
protected_fields |
passwords, tokens, card numbers… | Keys redacted at any depth, case-insensitive |
ignored_urls |
[] |
URIs to skip; supports wildcards like 'api/*' |
ignored_route_names |
['users.show'] |
Route names to skip |
queue |
false |
true or a queue name to write via a queued job |
connection |
null |
Separate database connection for the table |
retention_days |
180 |
Used by statistics:prune |
Most can be set via .env (STATISTICS_ENABLED, STATISTICS_QUEUE, STATISTICS_RETENTION_DAYS, …).
Pruning old rows
php artisan statistics:prune # uses retention_days
php artisan statistics:prune --days=30
Schedule it daily, e.g. Schedule::command('statistics:prune')->daily();.
Tests
composer install
composer test