me-shaon/laravel-request-analytics
Laravel Request Analytics adds privacy-minded web analytics to Laravel with a built-in dashboard and API. Track traffic, user behavior, and performance metrics with bot detection, IP geolocation, and GDPR-friendly data handling. Works with Laravel 10+ and PHP 8.1+.
composer require me-shaon/laravel-request-analytics
php artisan request-analytics:install
This handles config, migrations, assets, and views in one step./analytics (or your custom pathname from config).First use case: After installing, visit the dashboard, make a few test requests (e.g., browse pages or hit
/api/test), and observe real-time data like page views, unique visitors, and top referrers.
Traffic Segmentation
Filter what to capture using config:
'capture.api' => false'capture.bots' => falseskip_ips (e.g., ['127.0.0.1', '10.0.0.0/8'])Privacy-First Tracking
Enable IP anonymization ('anonymize_ip' => true) and configure data retention (pruning.days) to comply with GDPR/CCPA. Use skip_referrers to ignore spam or internal tools.
Scalability & Performance
'queue.enabled' => trueroutes/console.php (Laravel 11+) or Kernel.php (Laravel 10):
$schedule->command('model:prune', [
'--model' => \MeShaon\RequestAnalytics\Models\RequestAnalytics::class,
])->monthly();
Custom Access Control
Implement CanAccessAnalyticsDashboard in your User model to restrict dashboard access:
public function canAccessAnalyticsDashboard(): bool
{
return $this->role === 'admin' || $this->can('view-analytics');
}
Programmatic Data Access
Use the built-in /api/v1/analytics/* endpoints for integrations (e.g., dashboard widgets, internal reporting tools). Requires OAuth/Bearer token auth (configure via api middleware).
Middleware Conflicts
Ensure request-analytics.access is placed after authentication/auth middleware. If using custom middleware, add it before request-analytics.access.
Geolocation Provider Gotchas
license_key (web service) or the database file at database_path (requires manual download from MaxMind).Dashboard Auth Pitfalls
If the dashboard returns 403, confirm your User model implements CanAccessAnalyticsDashboard. Forgot to run migrations? Dashboard will show "No data" or 500 errors.
Caching & Stale Data
Cache TTL is 5 minutes by default (cache.ttl). For debugging, temporarily set to 0. Clear cache via Cache::forget('shaon.request-analytics.*').
Migration Pitfalls
If you change the table name via config after running migrations, re-publish the migration (don’t rename manually). The package uses a dedicated table (request_analytics), so don’t assume shared analytics tables.
Testing & Local Dev
Use skip_ips to avoid polluting analytics with local/dev traffic. Example:
'skip_ips' => [
'127.0.0.1',
'::1',
'192.168.1.0/24', // Local LAN
]
Extensibility
php artisan vendor:publish --tag="request-analytics-views"config/request-analytics.php → 'middleware.web', 'middleware.api'request-analytics.capture.How can I help you explore Laravel packages today?