tda/laravel-analytics-v4
Composer 安装命令:
composer require tda/laravel-analytics-v4
包简介
GA4 integration for laravel 8
README 文档
README
This package offers integration to GA4 properties with some out of the box methods. Inspired by Spatie integration for GA3 and originally forked from MyOutDeskLLC. Requires Laravel 8+.
Installation
You can install the package via composer:
composer require tda/laravel-analytics-v4
You can publish the config file with:
php artisan vendor:publish --tag="analytics-v4-config"
This is the contents of the published config file:
return [ 'property_id' => env('ANALYTICS_PROPERTY_ID', 'XXXXXXXXX'), 'service_account_credentials_json' => storage_path('app/analytics/service-account-credentials.json'), // This data is passed into the built-in cache mechanism for google's CredentialWrapper 'cache' => [ 'enableCaching' => env('ANALYTICS_CACHE',false), 'authCache' => null, 'authCacheOptions' => [ 'lifetime' => env('ANALYTICS_CACHE_LIFETIME', 60), // you may want to set this higher 'prefix' => env('ANALYTICS_CACHE_PREFIX', 'analytics_'), ] ] ];
Usage
Inside Laravel:
use Tda\LaravelAnalyticsV4\Period; use Tda\LaravelAnalyticsV4\PrebuiltRunConfigurations; $client = App::make('laravel-analytics-v4'); $lastMonth = Period::months(1); $results = $client->runReport(PrebuiltRunConfigurations::getMostVisitedPages($lastMonth));
You may configure your own report configuration, or use a pre-built report:
// Use this on the laravel side to get it from the container $analytics = App::make('laravel-analytics-v4'); // Prepare a filter $filter = new StringFilter(); $filter->setDimension('country')->exactlyMatches('United States'); // Prepare a report $reportConfig = (new RunReportConfiguration()) ->setStartDate('2022-09-01') ->setEndDate('2022-09-30') ->addDimensions(['country', 'landingPage', 'date']) ->addMetric('sessions') ->addFilter($filter); $analytics->convertResponseToArray()->runReport($reportConfig);
Yay, results:
[
"dimensions" => [
"country" => "United States",
"landingPage" => "/",
"date" => "20220903",
],
"metrics" => [
"sessions" => "113",
],
],
[
"dimensions" => [
"country" => "United States",
"landingPage" => "/services/",
"date" => "20220902",
],
"metrics" => [
"sessions" => "110",
],
],
Or Using Prebuilt Report Configurations:
$lastMonth = Period::months(1); $analytics->runReport(PrebuiltRunConfigurations::getMostVisitedPages($lastMonth));
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Submit a PR with passing tests.
Credits
License
The MIT License (MIT). Please see License File for more information.
tda/laravel-analytics-v4 适用场景与选型建议
tda/laravel-analytics-v4 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.22k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「ga4」 「laravel-analytics-v4」 「tda」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tda/laravel-analytics-v4 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tda/laravel-analytics-v4 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tda/laravel-analytics-v4 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A small client implementing the Measurement Protocol for Google Analytics 4.
Google Tag Manager with new Google Analytics 4 for OXID eShop v6
Google UA, GA4 and GTM integration
GA4 integration for laravel
Instant Analytics brings full Google GA4 server-side analytics support to your Twig templates and automatic Craft Commerce integration
Laravel package to easily send events to Google Analytics 4
统计信息
- 总下载量: 2.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-06