Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Request Analytics Laravel Package

me-shaon/laravel-request-analytics

Privacy-first web analytics for Laravel: track real-time page views, visitors, bounce rate, sessions, and performance in a built-in dashboard. Includes bot filtering, geo/device insights, data retention controls, IP anonymization, and a REST API—no third-party sharing.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel-Native Integration: The package leverages Laravel’s middleware, service providers, and event system, making it a seamless fit for Laravel 10+ applications. It aligns with Laravel’s conventions (e.g., artisan commands, config publishing, and migrations).
  • Modular Design: The package is modular, allowing granular control over features (e.g., geolocation, bot filtering, queue processing). This enables targeted adoption based on project needs.
  • Database Agnostic: Supports MySQL, PostgreSQL, and SQLite, reducing vendor lock-in and accommodating diverse infrastructure requirements.
  • Privacy-First: Built-in GDPR compliance (IP anonymization, data retention controls) aligns with modern regulatory requirements and user trust expectations.

Integration Feasibility

  • Low Friction: The interactive installer (php artisan request-analytics:install) simplifies setup, reducing onboarding complexity. Manual setup is also available for customization.
  • Middleware-Based Tracking: Uses Laravel’s middleware pipeline (web and api groups) to capture requests without modifying core application logic. This minimizes risk of breaking existing functionality.
  • Queue Support: Background processing via Laravel Queues (default or custom) mitigates performance impact on high-traffic applications.
  • API Access: REST API for analytics data enables integration with other systems (e.g., reporting tools, dashboards) without exposing the database directly.

Technical Risk

  • Database Schema Changes: Requires a new table (request_analytics) and migrations. In monolithic applications, this could introduce schema conflicts or deployment complexity.
  • Performance Overhead: Real-time tracking adds database writes per request. Mitigation strategies include:
    • Queue processing (queue.enabled = true).
    • Caching (cache.ttl configuration).
    • Pruning (pruning.enabled to auto-clean old data).
  • Geolocation Dependencies: External APIs (e.g., MaxMind, IPGeolocation) may introduce latency or cost. The default ipapi provider is free but rate-limited.
  • Bot Filtering Accuracy: False positives/negatives in bot detection could skew analytics. Customization via skip_ips/skip_referrers is possible but may require tuning.
  • Dashboard Dependency: The /analytics route introduces a new endpoint that must be secured (e.g., via middleware like auth or custom CanAccessAnalyticsDashboard).

Key Questions

  1. Data Retention vs. Storage Costs:
    • How will pruning (pruning.days) balance between analytics accuracy and database size? For high-traffic apps, consider tuning this or using a separate analytics database.
  2. Queue Configuration:
    • If enabling queue.enabled, ensure the queue worker (php artisan queue:work) is monitored to avoid job backlogs.
  3. Geolocation Provider:
    • For production, evaluate the trade-offs between free (rate-limited) and paid (high-accuracy) geolocation services.
  4. Middleware Conflicts:
    • Verify that request-analytics.access middleware doesn’t conflict with existing auth or rate-limiting middleware.
  5. Custom Analytics Needs:
    • Does the package’s default metrics (e.g., bounce rate, session duration) align with business KPIs? Extensions via the REST API may be needed.
  6. Multi-Tenant Support:
    • If the application is multi-tenant, ensure the request_analytics table includes tenant identifiers or use Laravel’s globalScopes.
  7. Dashboard Customization:
    • Will the default dashboard suffice, or will custom views (published via vendor:publish --tag="request-analytics-views") be required?

Integration Approach

Stack Fit

  • Laravel 10+: Fully compatible with Laravel’s latest features (e.g., app bindings, elixir, and console scheduling).
  • PHP 8.1+: Leverages modern PHP features (e.g., named arguments, attributes) for performance and maintainability.
  • Database Support: Works with Laravel’s Eloquent ORM, ensuring consistency with existing data access patterns.
  • Queue Systems: Integrates with Laravel Queues (database, Redis, etc.), enabling horizontal scaling for analytics processing.
  • Frontend Agnostic: Dashboard uses Blade templates, but can be adapted for Livewire, Inertia.js, or API-driven SPAs.

Migration Path

  1. Pilot Phase:
    • Install in a staging environment using the interactive installer.
    • Test with capture.web = false and capture.api = false to verify dashboard functionality without data collection.
  2. Gradual Rollout:
    • Enable tracking for non-critical routes first (e.g., public pages) before applying to API or authenticated routes.
    • Use ignore-paths to exclude high-traffic or sensitive endpoints during testing.
  3. Configuration Tuning:
    • Start with default settings, then adjust:
      • skip_ips to exclude internal/dev traffic.
      • pruning.days based on retention needs.
      • geolocation.provider based on accuracy/latency requirements.
  4. Queue Optimization:
    • Enable queue.enabled and monitor job processing times. Scale queue workers as needed.
  5. Dashboard Access:
    • Implement CanAccessAnalyticsDashboard to restrict access to authorized users (e.g., admins).
    • Customize the dashboard via published views if branding or additional metrics are required.

Compatibility

  • Laravel Ecosystem:
    • Compatible with Laravel’s authentication (e.g., Sanctum, Passport), Livewire, and API resources.
    • Works alongside other analytics tools (e.g., Sentry for errors, Laravel Debugbar) without conflicts.
  • Third-Party Services:
    • Geolocation providers (MaxMind, IPGeolocation) require separate accounts/API keys.
    • Bot filtering relies on user-agent parsing; custom lists (e.g., skip_referrers) may need maintenance.
  • Legacy Systems:
    • If using Laravel <10 or PHP <8.1, the package is not compatible. Consider feature flags or a migration plan.

Sequencing

  1. Pre-Installation:
    • Review database requirements (storage, backups) and allocate resources for the request_analytics table.
    • Plan for queue infrastructure if enabling background processing.
  2. Installation:
    • Run composer require me-shaon/laravel-request-analytics and php artisan request-analytics:install.
    • Publish migrations/configurations as needed.
  3. Testing:
    • Verify data collection with php artisan tinker:
      MeShaon\RequestAnalytics\Models\RequestAnalytics::latest()->take(5)->get();
      
    • Test the dashboard (/analytics) and API endpoints.
  4. Production Rollout:
    • Enable tracking incrementally (e.g., start with capture.web = true).
    • Schedule pruning jobs (e.g., monthly) via Laravel’s scheduler.
  5. Post-Launch:
    • Monitor database growth and queue performance.
    • Adjust configurations based on real-world usage (e.g., skip_ips, pruning.days).

Operational Impact

Maintenance

  • Configuration Management:
    • Centralized settings in config/request-analytics.php simplify updates. Use environment variables for sensitive values (e.g., REQUEST_ANALYTICS_GEO_API_KEY).
    • Document custom configurations (e.g., skip_ips, ignore-paths) for future maintainers.
  • Dependency Updates:
    • Monitor the package for updates (check GitHub releases) and test compatibility with Laravel minor versions.
    • Pin the package version in composer.json to avoid unexpected updates:
      "me-shaon/laravel-request-analytics": "^1.0"
      
  • Dashboard Updates:
    • The package may release dashboard UI improvements. Plan for periodic updates or customizations.

Support

  • Troubleshooting:
    • Common issues:
      • Missing Data: Verify middleware is registered in app/Http/Kernel.php and routes are not excluded via ignore-paths.
      • Queue Failures: Check failed_jobs table and queue worker logs.
      • Geolocation Errors: Validate API keys and provider configurations.
    • Enable debug mode temporarily to diagnose issues:
      'debug' => env('REQUEST_ANALYTICS_DEBUG', false),
      
  • Community Resources:
    • GitHub issues and discussions are active (215 stars, recent releases). Leverage the community for support.
    • The package includes a request-analytics:clear command for data cleanup.

Scaling

  • Database Scaling:
    • For high-traffic applications, consider:
      • Partitioning the request_analytics table by date.
      • Offloading analytics to a read replica.
      • Archiving old data to cold storage (e.g., S3) via custom pruning logic.
  • Queue Scaling:
    • Scale queue workers horizontally to handle increased load. Monitor job processing times and adjust worker count accordingly.
  • Caching:
    • Leverage Laravel’s cache (cache.ttl) to reduce database load for frequently accessed metrics.

Failure Modes

Failure Scenario Impact Mitigation
Database connection issues Data loss or incomplete analytics. Use Laravel’s
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium