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 visitors: browser, platform, device, IP, languages, user agent, and request data. Use visitor() helper or $request->visitor(). Record visits for any model via Visitable trait, count views/unique visitors, and detect online users.

View on GitHub
Deep Wiki
Context7

Laravel Visitor captures and exposes rich visitor details—including browser, platform, device, IP, languages, and user agent—directly from $request->visitor() or the global visitor() helper. It also helps you recognize online users and determine whether a given user is currently online.

  • Retrieve visitor metadata (device/platform/browser/IP/languages/request inputs)
  • Record visit logs globally or per Eloquent model via the Visitable trait
  • Attribute visits to a specific user with setVisitor($user)
  • Query visits through relations and count total/unique visits (by IP or visitor model)
  • Check user presence with isOnline()
Frequently asked questions about Visitor
How do I install and set up Laravel Visitor for my project?
Run `composer require shetabit/visitor`, publish the migrations with `php artisan vendor:publish`, and execute `php artisan migrate`. Laravel 5.5+ requires no additional provider/alias configuration.
Can I track visits for specific Eloquent models (e.g., Posts, Products)?
Yes. Use the `Visitable` trait on your model and call `visitor()->visit($model)` or `$model->createVisitLog()`. Visits are stored in a `visits` relation for querying.
How does Laravel Visitor detect online users in real-time?
The package tracks online users via visit logs and provides `isOnline()` and `onlineVisitors()` methods. It’s lightweight but not WebSocket-based—ideal for dashboards or collaborative tools.
Will this package work with Laravel 10 or older versions?
Laravel Visitor is actively maintained for Laravel 11–13. Laravel 10 support is deprecated; pin to a stable version or fork if needed. Check the GitHub repo for version-specific branches.
How do I exclude certain routes (e.g., API or admin) from visit logging?
Use the `LogVisits` middleware and configure exclusions in its `except` property. For example, add `except: ['admin/*', 'api/*']` to your middleware configuration.
Does Laravel Visitor support GDPR compliance (e.g., IP anonymization or log purging)?
The package uses IP-based deduplication, which may conflict with GDPR. Supplement with session tracking for authenticated users and implement `purgeLogs()` for data retention compliance.
Can I log visits asynchronously to avoid database performance issues?
Yes. Queue visit logs by modifying the `visit()` method to dispatch a job (e.g., `VisitLogJob`). Use rate limiting (e.g., log every 5th visit for anonymous users) for high-traffic apps.
How accurate is the device/browser detection (e.g., mobile vs. desktop)?
The package uses UAParser, which is highly accurate for common user agents. Edge cases (e.g., custom UAs) may require testing or a fallback service like WURFL for precision.
What’s the difference between `visitor()->visit()` and `$model->createVisitLog()`?
Both methods log visits, but `visitor()->visit($model)` is a global helper, while `$model->createVisitLog()` is model-specific. The latter is cleaner if you’re already working with a model instance.
Are there alternatives to Laravel Visitor for tracking user behavior?
Alternatives include Laravel Analytics (for basic tracking), Spatie’s Analytics (event-based), or third-party services like Google Analytics. Laravel Visitor stands out for its model-agnostic logging and online user detection.
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