levelweb/laravel-google-analytics-4-measurement-protocol
Composer 安装命令:
composer require levelweb/laravel-google-analytics-4-measurement-protocol
包简介
A Laravel package to use Measurement Protocol for Google Analytics 4
README 文档
README
Laravel Google Analytics 4 Measurement Protocol
A Laravel package to use Measurement Protocol for Google Analytics 4.
Introduction
This package allows you to post events to Google Analytics 4 from your Laravel backend.
Installation
- Install the package by running this command in your terminal/cmd:
composer require levelweb/laravel-google-analytics-4-measurement-protocol
-
Set
MEASUREMENT_IDandMEASUREMENT_PROTOCOL_API_SECRETin your .env file. You can get them from: Google Analytics > Admin > Data Streams > [Select Site] > Measurement Protocol API secrets -
Optional: You can publish the config file by running this command in your terminal/cmd:
php artisan vendor:publish --tag=google-analytics-4-measurement-protocol-config
client_idis required to post an event to Google Analytics. This package provides a Blade component which you can put in your layout file after the Google Analytics Code tracking code. It makes a POST request to the backend to store the client id in the session which is later used to post events to Google Analytics 4.
<!-- Google Analytics Code --> <x-google-analytics-client-id /> <!-- </head> -->
The other option is to call the setClientId($clientId) method on the GA4 facade everytime before calling the postEvent() method.
- You can set
user_idby callsetUserId($userId)method on theGA4facade everytime before calling thepostEvent()method.
Usage
You can simple call GA4::postEvent($eventData) from anywhere in your backend to post event to Google Analytics 4. $eventData contains the name and params of the event as per this reference page. For example:
GA4::postEvent([ 'name' => 'login', 'params' => [ 'method' => 'Google', ], ]);
postEvent() method will return an array with the status of the request.
Debugging Mode
You can also enable debugging mode by calling enableDebugging() method before calling the postEvent() method. Like so - GA4::enableDebugging()->postEvent($eventData). The postEvent() method will return the response (array) from Google Analytics request in that case.
Authors
- Gaurav Makhecha - Initial work
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details
Treeware
You're free to use this package, but if it makes it to your production environment I would highly appreciate you buying the world a tree.
It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you contribute to our forest you’ll be creating employment for local families and restoring wildlife habitats.
You can buy trees at for our forest here offset.earth/treeware
Read more about Treeware at treeware.earth
Special Thanks to
- Laravel Community
levelweb/laravel-google-analytics-4-measurement-protocol 适用场景与选型建议
levelweb/laravel-google-analytics-4-measurement-protocol 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 63 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel-google-analytics-4-measurement-protocol」 「levelweb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 levelweb/laravel-google-analytics-4-measurement-protocol 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 levelweb/laravel-google-analytics-4-measurement-protocol 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 63
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-03