amjadiqbal/laravel-first-party-analytics
First-party analytics for Laravel: collect and store visitor and event data on your own infrastructure without third-party scripts, giving you privacy-friendly, self-hosted reporting and insights.
Analytics::track() calls to be designed into the feature spec.Login/Registered, Analytics::identify(), and cookie-mode retroactive linking of anonymous visits determines whether you can answer "which channel produced this paying user?" That is a decision with product consequences and a config flag (ANALYTICS_COOKIES), not an implementation detail.analytics:prune with retention_days forces an explicit answer to "how long do we keep behavioral data?" — a question legal and product should co-own, and one most teams defer until an audit.Adopt when most of the following hold:
web routes. This is a hard gate — the pageview layer is middleware on the web group.users and orders tables is the actual value, and it's something hosted tools make awkward.Look elsewhere when:
For executives: We can answer core product questions — what pages people land on, where they come from, what they do, and where they convert — without adding a third-party analytics vendor. That means no per-event bill that grows with traffic, no data leaving our infrastructure, and a materially simpler privacy story: no cookies by default, IPs hashed and never stored raw, Do-Not-Track and Global Privacy Control honored out of the box. It installs in two commands on a Laravel app. The honest caveat is maturity: this is a v0.1.0 first release from a single maintainer, so treat it as a low-risk experiment on an internal or non-critical property before making it the source of truth for revenue reporting. Ask for a two-sprint pilot with a defined success criterion, not a permanent platform commitment.
For engineering: It is a well-scoped Laravel package rather than a platform — middleware on the web group (or the analytics.track alias), three write modes (batched after the response by default, one queued job per request, or sync) with write failures reported and never thrown, so analytics cannot take down a request. It respects the framework's extension points: a swappable DetectsBots contract, Analytics::ignoreUsing(), config-driven exclude_paths, ignore_referrers, conversions, and funnels, plus a gated Blade dashboard that is local-only by default. Data model is visits plus events with property breakdowns, pruned in chunks via analytics:prune. The release notes are unusually candid about test coverage: queue write mode was verified in the suite (job dispatched and applied) but not against a real queue worker, and the browser test ran on SQLite while MySQL 8.4 and PostgreSQL 17 coverage came from CI integration runs. Local CI was green across PHP 8.3/8.4/8.5 × Laravel 12/13 with Pint and PHPStan level 6.
What to ask before adopting: Pin the version and expect breaking changes pre-1.0; validate queue mode on your actual worker and driver; run the dashboard against your production database engine rather than SQLite; confirm whether your CDN sets the header the country field depends on; and get a written answer from legal on whether no-cookie mode plus hashed IPs changes your consent-banner obligation in each market you ship to. Decide ANALYTICS_COOKIES and retention_days explicitly at kickoff — they change what questions the data can answer later, and retroactive attribution is only possible in cookie mode.
How can I help you explore Laravel packages today?