承接 monishroy/visitor-tracking 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

monishroy/visitor-tracking

最新稳定版本:v1.1.1

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

  1. Install the Package

    Require the package via Composer:

    composer require monishroy/visitor-tracking
  2. 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.

统计信息

  • 总下载量: 150
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-20