monishroy/visitor-tracking
Composer 安装命令:
composer require monishroy/visitor-tracking
包简介
A Laravel package for tracking website visitors
关键字:
README 文档
README
The monishroy/visitor-tracking package provides a simple way to track and analyze visitor data in your Laravel application, including total visitors, unique visitors, top visited pages, countries, operating systems, and devices.
Installation
-
Install the Package
Require the package via Composer:
composer require monishroy/visitor-tracking
-
Run Database Migrations
After installing the package, run the migrations to set up the necessary database tables:
php artisan migrate
Middleware
The package includes a middleware aliased as visitor_tracking to track visitor data for specific routes. To use it, apply the middleware to your routes.
Applying the Middleware
You can apply the visitor_tracking middleware to individual routes or route groups in your web.php or api.php files.
Example: Single Route
Route::get('/home', [HomeController::class, 'index'])->middleware('visitor_tracking');
Example: Route Group
Route::middleware(['visitor_tracking'])->group(function () { Route::get('/home', [HomeController::class, 'index']); Route::get('/about', [AboutController::class, 'index']); });
The middleware will automatically track visitor data for the routes it is applied to.
Usage
The package provides a Visitor facade to access visitor tracking data. You can use the following methods to retrieve analytics:
use Monishroy\VisitorTracking\Helpers\Visitor; Visitor::totalVisitors(), // Returns the total number of visitors Visitor::uniqueVisitors(), // Returns the count of unique visitors Visitor::topVisitedPages($limit), // Returns the most visited pages $limit = 5 default Visitor::countries(), // Returns visitor countries Visitor::os(), // Returns operating systems used by visitors Visitor::devices() // Returns devices used by visitors
Example Output
Running the above code will dump the visitor data, which might look like this (example):
[
"totalVisitors" => 1000,
"uniqueVisitors" => 750,
"topVisitedPages" => [
[
'page_title' => 'Home',
'url' => 'https://example.com'
],[
'page_title' => 'About',
'url' => 'https://example.com/about'
],[
'page_title' => 'Contact',
'url' => 'https://example.com/contact'
],
],
"countries" => [
"US" => 400,
"IN" => 300,
"BD" => 100
],
"os" => [
"Windows" => 600,
"MacOS" => 300,
"Linux" => 100
],
"devices" => [
"Desktop" => 700,
"Mobile" => 250,
"Tablet" => 50
]
]
Customization
Using the VisitorTable Model
The package includes a VisitorTable model that you can use to interact directly with the visitor tracking database table. This allows you to perform custom queries or extend the functionality.
Example: Querying Visitor Data
use Monishroy\VisitorTracking\Models\VisitorTable; $visitors = VisitorTable::where('country', 'US')->get(); foreach ($visitors as $visitor) { echo $visitor->page . ' visited from ' . $visitor->country; }
You can also extend the VisitorTable model to add custom methods or relationships.
Requirements
- PHP >= 7.4
- Laravel >= 8.0
License
This package is open-sourced software licensed under the MIT license.
Support
For issues or feature requests, please open an issue on the GitHub repository.
monishroy/visitor-tracking 适用场景与选型建议
monishroy/visitor-tracking 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 179 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「tracking」 「visitor tracking」 「laravel visitor tracking」 「visitor counter」 「user visitor tracking」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 monishroy/visitor-tracking 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 monishroy/visitor-tracking 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 monishroy/visitor-tracking 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP SDK for the Parcel Monkey UK API
Tracker package for Laravel.
Allow users to post public messages on other users' profile pages
Tracker package for ARCANESOFT/Foundation.
Audit changes of your Eloquent models in Laravel/Lumen
Alfabank REST API integration
统计信息
- 总下载量: 179
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-20