oleant / laravel-visit-analytics
Privacy-focused visit analytics for Laravel 10/11/12 with UTM and Referrer tracking.
Package info
github.com/Oleant-NET/laravel-visit-analytics
pkg:composer/oleant/laravel-visit-analytics
Requires
- php: ^8.2
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- jaybizzle/crawler-detect: ^1.2
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- pestphp/pest: ^2.0|^3.0
- pestphp/pest-plugin-laravel: ^2.0|^3.0
README
Lightweight, privacy-focused visit analytics for Laravel 10, 11, and 12. Track UTM parameters, referrers, and page views while automatically filtering out bots and respecting user privacy.
Features
- Bot Detection: Automatically skips crawlers using
jaybizzle/crawler-detect. - Privacy First: IP anonymization (masks the last octet) enabled by default.
- Cloudflare Ready: Automatically detects real visitor IP via
CF-Connecting-IPheader. - Zero Latency: Logging happens in the
terminatemiddleware after the response is sent to the user. - Flexible Exclusions: Easily ignore specific IPs, paths (like
/admin*), or bots.
Installation
Run this command in your terminal:
composer require oleant/laravel-visit-analytics
Database Setup
Create the necessary table by running migrations:
php artisan migrate
Configuration
Publish the config file to customize tracking rules (anonymization, whitelists, exclusions):
php artisan vendor:publish --tag="visit-analytics-config"
Key Config Options:
anonymize_ip: (bool) Mask the last digit of IPv4 addresses.exclude.ips: (array) List of IP addresses to ignore.exclude.paths: (array) URL patterns to skip (e.g.,['admin*', 'api/*']).track_bots: (bool) Whether to log search engine crawlers and bots.whitelist: (array) Only these GET parameters will be saved in thepayload(e.g.,['utm_source', 'utm_medium']).
Usage
For Laravel 11 & 12
Open bootstrap/app.php and register the middleware:
->withMiddleware(function (Middleware $middleware) { $middleware->web(append: [ \Oleant\VisitAnalytics\Http\Middleware\TrackVisits::class, ]); })
For Laravel 10
Open app/Http/Kernel.php and add the class to the $middlewareGroups array under web:
protected $middlewareGroups = [ 'web' => [ // ... \Oleant\VisitAnalytics\Http\Middleware\TrackVisits::class, ], ];
Cloudflare Setup & Security
Real IP Detection
The package automatically prioritizes the CF-Connecting-IP header. No extra configuration is needed to see real visitor IPs.
Avoid Self-Banning (WAF Rules)
If you are using Cloudflare WAF or Rate Limiting, ensure your server's IP is added to the IP Access Rules in the Cloudflare Dashboard:
- Go to Security > WAF > Tools.
- Add your Server IP to the whitelist with the action "Allow".
- This prevents Cloudflare from triggering security challenges when your server communicates with its own services or when you perform maintenance.
Data Retrieval
To get your stats, just use the Eloquent model:
use Oleant\VisitAnalytics\Models\VisitLog; // Get latest visits $visits = VisitLog::latest()->paginate(50);
License
The MIT License (MIT). Please see LICENSE.md for more information.
Built with ❤️ for Oleant Auditor.