定制 palmans/tracker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

palmans/tracker

Composer 安装命令:

composer require palmans/tracker

包简介

Simple site visit/statistics tracker for Laravel

README 文档

README

Latest Version on Packagist

Simple site visit/statistics tracker for Laravel.

Tracker provides a simple way to track your site visits and their statistics. This is a fork of Arrtrust/Tracker - providing the same functionality, but modernized.

Features

  • Compatible with Laravel 11 and 12
  • Middleware for automatically recording the site view
  • Associate site views to Eloquent models to track their views
  • Persists unique views based on URL, method, and IP address
  • Helper method, Facade, and trait for easing access to services
  • Handy 'Cruncher' for number crunching needs
  • Flushing and selecting site views with given time spans
  • A phpunit test suite for easy development

Installation

Installing Tracker is simple.

  1. Pull this package in through Composer.

    composer require palmans/tracker
    {
        "require": {
            "palmans/tracker": "^4.0"
        }
    }
  2. You may configure the default behaviour of Tracker by publishing and modifying the configuration file. To do so, use the following command.

    php artisan vendor:publish --provider=Palmans\Tracker\TrackerServiceProvider

    Than, you will find the configuration file on the config/tracker.php path. Information about the options can be found in the comments of this file. All of the options in the config file are optional, and falls back to default if not specified; remove an option if you would like to use the default.

    This will also publish the migration file for the default SiteView model. Do not forget to migrate your database before using Tracker.

  3. You may now access Tracker either by the Facade or the helper function.

    tracker()->getCurrent();
    Tracker::saveCurrent();
    
    tracker()->isViewUnique();
    tracker()->isViewValid();
    
    tracker()->addTrackable($post);
    
    Tracker::flushAll();
    Tracker::flushOlderThan(Carbon::now());
    Tracker::flushOlderThenOrBetween(Carbon::now(), Carbon::now()->subYear());
  4. It is important to record views by using the supplied middleware to record correct app runtime and memory information. To do so register the middleware in app\Http\Kernel.

    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'guard' => \App\Http\Middleware\Guard::class,
        'track' => \Palmans\Tracker\TrackerMiddleware::class,
    ];

    It is better to register this middleware as a routeMiddleware instead of a global middleware and use it in routes or route groups definitions as it may not be necessary to persist all site view. This will persist and attach any Trackable that is added to stack to site views automatically when the request has been handled by Laravel.

  5. To attach views to any model or class, you should implement the Palmans\Tracker\TrackableInterface interface. Tracker provides Palmans\Tracker\Trackable trait to be used by Eloquent models.

        
        use Illuminate\Database\Eloquent\Model as Eloquent;
        use Palmans\Tracker\Trackable;
        use Palmans\Tracker\TrackableInterface;
        
        class Node extends Eloquent implements TrackableInterface
        {
            use Trackable;
    
            // ...            
        }

    The Trackable trait uses Eloquent's belongsToMany relationship which utilizes pivot tables. Here is a sample migration for the pivot table:

        <?php
        
        use Illuminate\Database\Schema\Blueprint;
        use Illuminate\Database\Migrations\Migration;
        
        return new class extends Migration {      
            /**
             * Run the migrations.
             *
             * @return void
             */
            public function up()
            {
                Schema::create('node_site_view', function (Blueprint $table)
                {
                    $table->unsignedBigInteger('node_id');
                    $table->unsignedBigInteger('site_view_id');
        
                    $table->foreign('node_id')
                        ->references('id')
                        ->on('nodes')
                        ->onDelete('cascade');
        
                    $table->foreign('site_view_id')
                        ->references('id')
                        ->on('site_views')
                        ->onDelete('cascade');
        
                    $table->primary(['node_id', 'site_view_id']);
                });
            }
        
            /**
             * Reverse the migrations.
             *
             * @return void
             */
            public function down()
            {
                Schema::drop('node_site_view');
            }
        };
  6. Check the Palmans\Tracker\Cruncher class and test for statistics number crunching. It is equipped with a number of methods for different types of statistics (mostly counts) in different time spans.

Please check the tests and source code for further documentation, as the source code of Tracker is well tested and documented.

License

Tracker is released under MIT License.

palmans/tracker 适用场景与选型建议

palmans/tracker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「analytics」 「laravel」 「statistics」 「visitor」 「tracker」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 palmans/tracker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 palmans/tracker 我们能提供哪些服务?
定制开发 / 二次开发

基于 palmans/tracker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-29