- How do I install Laravel Request Analytics in my Laravel 11 project?
- Run `composer require me-shaon/laravel-request-analytics` followed by `php artisan request-analytics:install`. The installer handles migrations, configuration, and dashboard setup automatically. Ensure your project uses PHP 8.1+ and Laravel 10/11.
- Does this package work with Laravel’s API routes (e.g., for SPAs or mobile apps)?
- Yes, the package supports API routes out-of-the-box. Exclude specific paths by adding them to the `ignore-paths` array in the config file. It also integrates with Livewire and Laravel Sanctum for authenticated API tracking.
- How does the bot filtering work, and can I customize it?
- The package uses a default list of known bots and crawlers (e.g., Googlebot, Slackbot) to filter out fake traffic. You can extend the list by publishing the config (`php artisan vendor:publish --tag=request-analytics-config`) and modifying the `bot-user-agents` array.
- What Laravel versions and databases are supported?
- The package supports Laravel 10 and 11, PHP 8.1+, and databases like MySQL 5.7+, PostgreSQL 10+, and SQLite 3.8+. No additional database-specific configurations are required beyond Laravel’s default setup.
- How do I reduce database overhead for high-traffic sites?
- Enable queue processing by setting `queue.enabled = true` in the config to offload analytics collection. Additionally, adjust `pruning.days` (default: 90) to a shorter retention period (e.g., 30 days) and schedule regular pruning via Laravel’s scheduler.
- Can I disable geolocation features to save costs or improve performance?
- Yes, geolocation is optional. Disable it entirely by setting `geolocation.enabled = false` in the config. If enabled, you can choose between providers like MaxMind (database file) or IPGeolocation (API-based), with fallback options for reliability.
- How do I restrict dashboard access to specific users (e.g., admins only)?
- Use Laravel’s built-in authorization. Publish the dashboard views (`php artisan vendor:publish --tag=request-analytics-views`) and implement middleware like `auth` or custom gates (e.g., `CanAccessAnalyticsDashboard`) to control access.
- Does the package support testing (e.g., unit/feature tests) for analytics data?
- Yes, the package includes test helpers. Use `RequestAnalytics::fake()` to mock analytics events in your tests. For database testing, leverage Laravel’s `RefreshDatabase` trait to reset analytics data between tests.
- What alternatives exist for Laravel analytics if I need more advanced features?
- For simpler setups, consider `spatie/laravel-analytics` (basic tracking). For enterprise needs, integrate third-party tools like Google Analytics via `laravel-google-analytics` or self-hosted solutions like Matomo with `laravel-matomo`. This package stands out for its privacy-first, no-third-party approach.
- How do I integrate the REST API with external tools like Grafana or DataDog?
- The package includes a REST API endpoint at `/api/analytics`. Use Laravel Passport or Sanctum for authentication. Fetch data via HTTP requests (e.g., `GET /api/analytics/metrics`) and transform it for your external dashboard using tools like Laravel’s `Http` client or Guzzle.