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

Visitor Laravel Package

shetabit/visitor

Track and log Laravel visitor info (IP, browser, device, platform, languages, user agent) via request helper, and attach visit logs to models with a Visitable trait. Includes online user detection and visit counting/uniques by IP or user.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Laravel-native integration: Designed for Laravel’s ecosystem (Service Providers, Facades, Traits, Middleware), reducing friction with existing codebases.
    • Modularity: Decouples visitor parsing (UAParser), logging (database), and online detection into separate components, allowing selective adoption.
    • Trait-based extensibility: Visitable and Visitor traits enable model-specific tracking without bloating core logic.
    • Middleware-driven: LogVisits middleware automates tracking for routes with bound models, reducing manual instrumentation.
    • GeoIP extensibility: Optional GeoIP enrichment (v4.5.0+) supports location-based features without forcing a dependency.
    • Compliance-ready: Built-in controls for excluding sensitive routes (e.g., passwords) and anonymizing data (e.g., IP hashing).
  • Weaknesses:

    • Database dependency: All tracking requires writes to visit_logs table, which may not suit high-frequency or offline-first use cases.
    • Limited geolocation: GeoIP is optional and stubbed by default; advanced features (e.g., city-level targeting) require external services.
    • No event batching: Real-time writes may not scale for high-throughput systems (e.g., >10K RPS).
    • Session management: Online user detection relies on Laravel’s session store; distributed sessions (e.g., Redis) require additional configuration.

Integration Feasibility

  • Laravel Compatibility: Actively maintained for Laravel 11–13 (as of v4.5.6), with backward compatibility to 5.5+. Minimal risk for modern stacks.
  • Dependency Conflicts: Primary dependency is mobiledetectlib (for UA parsing), which is widely used and stable. No major conflicts expected.
  • Database Schema: Publishes migrations for visit_logs and visitors tables. Assumes MySQL/PostgreSQL; SQLite may need adjustments for online_at timestamps.
  • Testing Overhead: Requires unit tests for:
    • Visitor trait methods (e.g., isOnline()).
    • Middleware behavior (e.g., route exclusions).
    • GeoIP integration (if enabled).
  • Performance: Benchmark visit() method under load (e.g., 1K RPS) to validate database write throughput.

Technical Risk

Risk Area Severity Mitigation
Database bottlenecks High Optimize visit_logs indexes (e.g., ip, model_type, created_at).
GeoIP accuracy Medium Test with real user agents; consider MaxMind for production.
Online user detection Medium Validate session store compatibility (e.g., Redis, database).
Middleware route exclusions Low Document excluded routes in config/visitor.php.
PHP 8.4+ compatibility Low Already addressed in v4.5.4 (nullable type hints).
Migration conflicts Low Use --force cautiously; review schema changes in changelog.

Key Questions

  1. Use Case Alignment:
    • Are we tracking model-specific visits (e.g., blog posts, products) or just page views?
    • Do we need real-time online user counts (e.g., for live chat) or batch analytics?
  2. Scalability:
    • What’s our peak traffic volume? Can the database handle visit_logs writes?
    • Should we sample logs (e.g., 1% of requests) for high-scale use cases?
  3. Compliance:
    • Do we need IP anonymization (e.g., hashing) or log retention policies?
    • Are there GDPR/CCPA-specific requirements (e.g., right to erasure)?
  4. Extensibility:
    • Will we customize visitor attributes (e.g., add CRM data to logs)?
    • Do we need webhook notifications for visits (e.g., to a third-party analytics tool)?
  5. Alternatives:
    • Have we compared this to Laravel Scout, PostHog, or custom solutions?
    • Is client-side tracking (e.g., JavaScript) an option for some use cases?

Integration Approach

Stack Fit

  • Laravel Core: Seamless integration with:
    • Request Handling: $request->visitor() or visitor() helper.
    • Middleware: LogVisits for automatic tracking.
    • Eloquent: Visitable trait for model-specific logs.
    • Service Container: Facade (Visitor) for global access.
  • Database: Requires MySQL/PostgreSQL (or SQLite with adjustments). Supports:
    • Indexing: Optimize visit_logs(ip, model_type, created_at) for queries.
    • Partitioning: Consider table partitioning for large-scale deployments.
  • Caching: Online user lists (onlineVisitors()) can be cached (e.g., Redis) to reduce session checks.
  • Queueing: For high traffic, defer visit() writes to a queue (e.g., Laravel Queues).

Migration Path

  1. Evaluation Phase (1–2 days):
    • Install in a staging environment: composer require shetabit/visitor.
    • Publish config/migrations: php artisan vendor:publish --provider="Shetabit\Visitor\Provider\VisitorServiceProvider".
    • Run migrations: php artisan migrate.
    • Test core functionality:
      • $request->visitor()->browser().
      • visitor()->visit($model).
      • User::online()->get().
  2. Pilot Phase (3–5 days):
    • Enable LogVisits middleware for a subset of routes (e.g., /posts/*).
    • Monitor database impact (queries/sec, write latency).
    • Validate online user detection accuracy (e.g., compare with manual checks).
  3. Full Rollout (1 week):
    • Add Visitable trait to critical models (e.g., Post, Product).
    • Configure GeoIP (if needed) via config/visitor.php.
    • Exclude sensitive routes (e.g., /login, /password/reset) in middleware.
    • Document new APIs for the team (e.g., $model->visitLogs()->count()).

Compatibility

  • Laravel Versions: Tested on 11–13; may need adjustments for <11.
  • PHP Versions: Supports 8.1+ (PHP 8.4 fixes in v4.5.4).
  • Dependencies:
    • mobiledetectlib/mobiledetectlib (UA parsing).
    • geoip2/geoip2 (optional, for GeoIP).
  • Database: MySQL/PostgreSQL recommended; SQLite may need timestamp adjustments.
  • Session Drivers: Test with database, redis, and file session stores.

Sequencing

  1. Core Tracking:
    • Install package → Publish config → Run migrations.
    • Add LogVisits middleware to app/Http/Kernel.php.
  2. Model-Specific Tracking:
    • Use Visitable trait on Eloquent models (e.g., Post).
    • Test visit() and visitLogs() methods.
  3. Online Users:
    • Add Visitor trait to User model.
    • Test onlineVisitors() and isOnline().
  4. Advanced Features:
    • Enable GeoIP (if needed).
    • Customize middleware exclusions or visitor attributes.
    • Integrate with queues/caching for scalability.

Operational Impact

Maintenance

  • Dependencies:
    • Monitor mobiledetectlib and geoip2 for updates.
    • Watch for Laravel version drops (e.g., if package stops supporting Laravel 12).
  • Schema Changes:
    • Review changelog for migration updates (e.g., new columns in visit_logs).
    • Consider a visitors table backup strategy for compliance.
  • Logging:
    • Log visit() failures (e.g., database errors) for observability.
    • Set up alerts for abnormal visit_logs growth (e.g., >10% daily increase).

Support

  • Common Issues:
    • Bot Detection: Configure middleware to exclude known bots (e.g., LogVisits::except(['/robots.txt'])).
    • IP Anonymization: Use config/visitor.php to hash IPs if required.
    • Online User Staleness: Adjust session lifetime or use Redis pub/sub for real-time updates.
  • Debugging:
    • Enable debug mode for visitor data: visitor()->debug().
    • Check visit_logs for malformed entries (e.g., null ip).
  • Documentation:
    • Create internal docs for:
      • How to add Visitable to new models.
      • How to query visit logs (e.g., `Post::find
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.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
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