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

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+.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package via Composer:
    composer require me-shaon/laravel-request-analytics
    
  2. Run the interactive installer for zero-config setup:
    php artisan request-analytics:install
    
    This handles config, migrations, assets, and views in one step.
  3. Access the dashboard at /analytics (or your custom pathname from config).
  4. Start tracking: By default, all web and API requests are captured—no middleware changes needed beyond auto-registered middleware.

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.

Implementation Patterns

  • Traffic Segmentation
    Filter what to capture using config:

    • Disable API tracking for performance-critical endpoints: 'capture.api' => false
    • Exclude bots to focus on human traffic: 'capture.bots' => false
    • Skip internal/dev traffic via skip_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

    • Enable queuing for high-traffic apps: 'queue.enabled' => true
    • Register the pruning job in routes/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).

Gotchas and Tips

  • 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

    • IP-API’s free tier throttles at 45 req/min—disable geolocation or use MaxMind if high volume.
    • MaxMind requires either a valid 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

    • Publish views to customize dashboard UI: php artisan vendor:publish --tag="request-analytics-views"
    • Override middleware via config/request-analytics.php'middleware.web', 'middleware.api'
    • Extend bot detection by implementing custom logic in middleware before request-analytics.capture.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport