Skip to content

Laravel Visits

Self-hosted, first-party analytics for Laravel: visitor, session and page-view tracking, geo/device/bot detection, campaign attribution, conversions tied to your own Eloquent models, daily rollups and a built-in dashboard — all stored in your own database.

The package records three levels of data instead of one flat “visits” table:

Visitor one row per browser/device — durable identity (cookie or client-supplied id)
└─ Session one browsing session, closed after inactivity
└─ Event a page view or a custom action ("order.placed")
  • Async-first — the request only resolves the visitor id and dispatches RecordVisitJob; geo lookup, device/bot detection and all database writes run on the queue
  • Three entry points — automatic page views (TrackVisit middleware), a JSON endpoint for the JS beacon and mobile apps (POST /visits/collect), and Visits::track() from PHP
  • Identity — a long-lived cookie, a client-supplied X-Visitor-Id for SPAs and mobile apps, automatic reconnection of logged-in users on Bearer-token APIs, merge on Login or Visits::identify()
  • Attribution — UTM/ref first-touch on the visitor and last-touch on the session, ad click IDs (gclid, fbclid, …), organic search keywords from the referrer
  • Conversions on your models — Visits::track('order.placed', $order) writes a polymorphic eventable relation you can read back from the order
  • Geo, device, bot detection — stevebauman/location (HTTP providers or a local MaxMind database) and matomo/device-detector; bots are recorded but hidden from reads by default
  • Dashboard — Overview with a session map, Campaigns, Sessions, Visitors, per-session/visitor detail, Live activity map (polling or SSE), Whoami
  • Hooks — events for every recorded visit, conversion, new visitor, new session and identified visitor

Dashboard

Terminal window
composer require fomvasss/laravel-visits
php artisan migrate

Every GET request through the web middleware group is now tracked (a queue worker must be running), and the dashboard is at /visits.

Track a conversion from anywhere in your code:

use Fomvasss\Visits\Facades\Visits;
Visits::track('order.placed', $order, ['amount' => $order->total]);

Read it back from the order (the model uses the HasVisits trait):

$event = $order->latestVisitEvent('order.placed')->first();
$event->session->utm_source; // campaign that brought this order
$event->session->country_code; // where it was placed from

Getting started

  1. Installation
  2. Configuration

Usage

  1. How tracking works
  2. Page views
  3. Custom events & conversions
  4. JS beacon
  5. Visitor identity
  6. Reading data back
  7. Campaign attribution
  8. Geo, device & bot detection
  9. Consent
  10. Custom models & multi-tenancy
  11. Dashboard
  12. Whoami
  13. Rollups, sessions & retention

Guides

  1. Production checklist
  2. Client integration scenarios
  3. Security considerations
  4. When to use this package
  5. Architecture

Reference

  1. Visits facade
  2. Models & HasVisits
  3. Database tables
  4. Routes & middleware
  5. JavaScript API
  6. Events
  7. Artisan commands
  8. Contracts

Upgrading