panphp/pan
Composer 安装命令:
composer require panphp/pan
包简介
A simple, lightweight, and privacy-focused product analytics php package.
关键字:
README 文档
README
Pan is a lightweight and privacy-focused PHP product analytics library. It’s designed as a very simple package that you can install via composer require and start tracking your pages or components with a simple data-pan attribute.
At the time of writing, Pan tracks only the following events: impressions, hovers, and clicks. It does not collect any personal information, such as IP addresses, user agents, or any data that could be used to identify a user.
Use cases:
- you have different tabs within a page with the same URL, and you want to know which one is the most viewed. By adding the
data-panattribute to your tabs, you can track this information. - you have different register buttons in your application, and you want to know which one is the most clicked. By adding the
data-panattribute to your buttons, you can track this information. - you have different "help" pop-hovers in your application, and you want to know which one is the most hovered. By adding the
data-panattribute to your pop-hovers, you can track this information. - and so on...
It works out-of-the-box with your favorite Laravel stack; updating a button color in your "react" won't trigger a new impression, but seeing that same button in a different Inertia page will. Using Livewire? No problem, Pan works seamlessly with it too.
Visualize your analytics is as simple as typing php artisan pan in your terminal. This command will show you a table with the different analytics you've been tracking, and hopefully, you can use this information to improve your application.
Get Started
Requires PHP 8.3+, and Laravel 11.0+.
You may use Composer to require Pan into your PHP project:
composer require panphp/pan
After, you may install Pan into your Laravel project using the following command:
php artisan install:pan
Finally, you may start tracking your pages or components adding the data-pan attribute to your HTML elements:
<div> - <button>Tab 1</button> + <button data-pan="tab-1">Tab 1</button> - <button>Tab 2</button> + <button data-pan="tab-2">Tab 2</button> </div>
Important
Event names must only contain letters, numbers, dashes, and underscores.
Filament integration
Pan works seamlessly with Filament. You can track any Filament action by passing the data-pan attribute via extraAttributes:
Action::make('subscribe') ->extraAttributes(['data-pan' => 'subscribe-button'])
To track all actions globally, add the following to a service provider's boot method:
use Filament\Actions\Action; public function boot(): void { Action::configureUsing(function (Action $action): void { $action->extraAttributes(fn () => ['data-pan' => $action->getLabel()]); }); }
Visualize your product analytics
To visualize your product analytics, you may use the pan Artisan command:
php artisan pan php artisan pan --filter=tab-profile
Whitelist your product analytics
By default, Pan tracks all the HTML elements with the data-pan attribute, so bad actors could alter your HTML and create unwanted analytics records in your database. To mitigate this, by default, Pan only allows 50 analytics records to be created.
For extra protection, you may use the PanConfiguration::allowedAnalytics method to whitelist the analytics you want to track. This way, only the analytics you've whitelisted will be stored in your database.
use Pan\PanConfiguration; public function register(): void { PanConfiguration::allowedAnalytics([ 'tab-profile', 'tab-settings', ]); }
Alternatively, if you want to allow dynamic analytics, you may use the PanConfiguration::maxAnalytics method and this way at least limit the number of analytics records created:
PanConfiguration::maxAnalytics(10000);
If you want to have unlimited analytics records, you may use the Pan::unlimitedAnalytics method:
PanConfiguration::unlimitedAnalytics();
Configure the route prefix
By default, Pan's route prefix is /pan, but you may change it by using the PanConfiguration::routePrefix method:
PanConfiguration::routePrefix('internal-analytics');
With that set the url to track the analytics will be /internal-analytics/events.
Flush your product analytics
To flush your product analytics, you may use the pan:flush Artisan command:
php artisan pan:flush
Delete an analytic
To delete a specific analytic record by its ID, use the pan:delete Artisan command:
php artisan pan:delete <id>
How does it work?
Via middleware, Pan injects a simple JavaScript library into your HTML pages. This library listens to events like viewed, clicked, or hovered and sends the data to your Laravel application. Note that this library does not collect any personal information; such as IP addresses, user agents, or any information that could be used to identify a user.
Also on the client-side, these events are collected in a very performant way and batched together to reduce the number of requests to your server.
On the server-side, Pan only stores: the analytic name, and a counter of how many times the different events were triggered. Via the pan Artisan command, you may visualize this data, and hopefully use this information to improve your application.
License
Pan is open-sourced software licensed under the MIT license.
panphp/pan 适用场景与选型建议
panphp/pan 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 108.31k 次下载、GitHub Stars 达 1.27k, 最近一次更新时间为 2024 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「library」 「analytics」 「laravel」 「pan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 panphp/pan 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 panphp/pan 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 panphp/pan 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Analytics chooser extensions for site settings.
Inbox pattern process implementation for your Laravel Applications
A Laravel Nova Card to show Fathom Analytics stats.
Core library that defines common interfaces used by the rest of the intahwebz..
Amqp classes
Provides command to manage a web library directory
统计信息
- 总下载量: 108.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1272
- 点击次数: 25
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-13
