andreaselia/analytics
Composer 安装命令:
composer require andreaselia/analytics
包简介
Analytics for the Laravel framework.
README 文档
README
Easily collect page view analytics with a beautifully simple to use dashboard.
Installation
Install the package:
composer require andreaselia/analytics
Publish the config file and assets:
php artisan vendor:publish --provider="AndreasElia\Analytics\AnalyticsServiceProvider"
Don't forget to run the migrations:
php artisan migrate
You can add the page view middleware to a specific route group, e.g. web.php like so:
Route::middleware('analytics')->group(function () { // ... });
Or add the page view to all middlewares/on an application level like so:
// app/Http/Kernel.php protected $middleware = [ // ... \AndreasElia\Analytics\Http\Middleware\Analytics::class, ];
Configuration
Disabling tracking
You can disable tracking by setting the environment variable ANALYTICS_ENABLED or the enabled property in the analytics.php config file to false.
Excluding routes
You can exclude certain routes from being tracked by adding them to the exclude array in the analytics.php config file.
Ignore robots
You can ignore requests from robots by setting the ignoreRobots property in the analytics.php config file.
Ignore specific IP addresses
You can ignore requests from specific IP addresses by adding them to the ignoreIps array in the analytics.php config file.
Masking routes
You can mask certain routes from being tracked by adding them to the mask array in the analytics.php config file.
This is useful if you want to track the same route with different parameters, e.g. /users/1 and /users/2 will be tracked as /users/∗︎.
Ignoring certain HTTP verbs/methods
You can ignore the tracking of some methods by adding them to the analytics.ignoreMethods config option. For example, if you don't want to track POST requests, you can configure it like so:
'ignoreMethods' => [ 'POST', ],
Changing how session_id is determined
By default, session_id in the page_views table is filled with the session ID of the current request. However, in certain scenarios (for example, for API and other requests not using cookies), the session is unavailable.
In these cases, you can create a custom session ID provider: create a class that implements the AndreasElia\Analytics\Contracts\SessionProvider interface and set its name as the provider option in the analytics.php config file. The configured class object is resolved from the container, therefore, dependency injection can be used via the __constructor.
One example of a custom way to generate the session ID in cookie-less environment is to hash IP address + User Agent + some other headers from the request.
Feel free to take a look at AndreasElia\Analytics\RequestSessionProvider for an example of implementing the SessionProvider interface.
Changing how the timezone for "today" and "yesterday" is determined
Since timestamps are stored using your application's timezone, you may get mixed results depending on when you check views for "today" and "yesterday" and your actual timezone. You can change the relative time for whatever "now" is by setting a callback in a service provider.
use AndreasElia\Analytics\Models\PageView; public function boot() { PageView::resolveTimezoneUsing(function () { return request()->user()?->timezone; }); }
You can return a dynamic value like the example above, or a static value. If one isn't determined, it will just fall back to the config('app.timezone') value.
Laravel Nova
The package comes with a dashboard and metrics for Laravel Nova.
Dashboard
You can add the dashboard to Laravel Nova by adding new \AndreasElia\Analytics\Nova\Dashboards\Analytics to dashboards array in your NovaServiceProvider:
protected function dashboards(): array { return [ new \AndreasElia\Analytics\Nova\Dashboards\Analytics, ]; }
Metrics
Alternatively, you can add the metrics to your own Laravel Nova dashboard by adding them to the cards array in your dashboard file.
protected function cards(): array { return [ new \AndreasElia\Analytics\Nova\Metrics\Devices, new \AndreasElia\Analytics\Nova\Metrics\PageViews, new \AndreasElia\Analytics\Nova\Metrics\UniqueUsers, ]; }
Contributing
You're more than welcome to submit a pull request, or if you're not feeling up to it - create an issue so someone else can pick it up.
andreaselia/analytics 适用场景与选型建议
andreaselia/analytics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22.58k 次下载、GitHub Stars 达 198, 最近一次更新时间为 2021 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「analytics」 「middleware」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 andreaselia/analytics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 andreaselia/analytics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 andreaselia/analytics 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Analytics chooser extensions for site settings.
A Laravel Nova Card to show Fathom Analytics stats.
Slim Framework 3 CSRF protection middleware utilities
Cloudflare Middleware For Guzzle
统计信息
- 总下载量: 22.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 198
- 点击次数: 16
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-09
