erlancarreira/laravel-analytics
Composer 安装命令:
composer require erlancarreira/laravel-analytics
包简介
A Laravel package to retrieve Google Analytics (GA4) data.
README 文档
README
Using this package you can easily retrieve data from Google Analytics (GA4).
Here are a few examples of the provided methods:
$start = \Illuminate\Support\Carbon::now()->startOfDay(); $end = \Illuminate\Support\Carbon::now()->endOfDay(); $totalUsers = ErlanCarreira\Analytics\Facades\Analytics::setDateRanges($start, $end) ->setDimensions( [ 'hostName', ] ) ->setMetrics( [ 'totalUsers', ] ) ->runReport() ->toArray();
Installation
This package can be installed through Composer.
composer require erlancarreira/laravel-analytics
Add in your .env
GOOGLE_CLOUD_PROJECT=project_id_from_google_console GOOGLE_APPLICATION_CREDENTIALS=full_path_to_google_credentials_json ANALYTICS_PROPERTY_ID=analytics_property_id
Optionally, you can publish the config file of this package with this command:
php artisan vendor:publish --provider="ErlanCarreira\Analytics\AnalyticsServiceProvider"
The following config file will be published in config/analytics.php
return [ /* * The view id of which you want to display data. */ 'property_id' => env('ANALYTICS_PROPERTY_ID', null), /* * The amount of minutes the Google API responses will be cached. * If you set this to zero, the responses won't be cached at all. */ 'cache_lifetime_in_minutes' => 60 * 24, ];
How to obtain the credentials to communicate with Google Analytics
Getting credentials
The first thing you’ll need to do is to get some credentials to use Google API’s. I’m assuming that you’ve already created a Google account and are signed in. Head over to Google API’s site and click "Select a project" in the header.
Next up we must specify which API’s the project may consume. In the list of available API’s click "Google Analytics Data API". On the next screen click "Enable".
Now that you’ve created a project that has access to the Analytics API it’s time to download a file with these credentials. Click "Credentials" in the sidebar. You’ll want to create a "Service account key".
On the next screen you can give the service account a name. You can name it anything you’d like. In the service account id you’ll see an email address. We’ll use this email address later on in this guide. Select "JSON" as the key type and click "Create" to download the JSON file.
Save the json inside your Laravel project at the location specified in the service_account_credentials_json key of the config file of this package. Because the json file contains potentially sensitive information I don't recommend committing it to your git repository.
Granting permissions to your Analytics property
I'm assuming that you've already created a Analytics account on the Analytics site. Go to "User management" in the Admin-section of the property.
On this screen you can grant access to the email address found in the client_email key from the json file you download in the previous step. Read only access is enough.
Getting the property id
The last thing you'll have to do is fill in the property_id in the config file. You can get the right value on the Analytics site. Go to "Property Settings" in the Admin-section of the property.
You'll need the PROPERTY ID displayed there.
Usage
All other Google Analytics queries
To perform all other queries on the Google Analytics resource use runReport. Google Analytics Data API (GA4) provides more information on which metrics and dimensions might be used.
API Dimensions & Metrics that are available
You can get access to the underlying BetaAnalyticsDataClient object:
ErlanCarreira\Analytics\Facades\Analytics::getAnalyticsService();
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email erlancarreira@hotmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
erlancarreira/laravel-analytics 适用场景与选型建议
erlancarreira/laravel-analytics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 89 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 02 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「analytics」 「google」 「laravel」 「reports」 「retrieve」 「ga4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 erlancarreira/laravel-analytics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 erlancarreira/laravel-analytics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 erlancarreira/laravel-analytics 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Analytics chooser extensions for site settings.
A Laravel Nova Card to show Fathom Analytics stats.
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
Google Recaptcha Package For PHP front and backend.
统计信息
- 总下载量: 89
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-06