hirale/openmage-ga4-measurement
Composer 安装命令:
composer require hirale/openmage-ga4-measurement
包简介
Google Analytics 4 Measurement Protocol integration for OpenMage and Maho, built on hirale/queue.
README 文档
README
Server-side Google Analytics 4 events for OpenMage and Maho, delivered through the hirale/queue worker over your choice of transport:
- Measurement Protocol (default) — the classic GA4 MP API, authenticated by an API secret.
- Data Manager API — Google's strategic path for server-side integrations (overview), authenticated by an OAuth service account.
The transport is selectable per store view; observers and queued payloads are identical either way, so switching transports never loses in-flight events — each queued message is sent via the transport configured at the moment it is consumed.
This module can work with Mage_GoogleAnalytics module. For duplicate key events, you can consult this page https://support.google.com/analytics/answer/12313109?hl=en
Supported Events
page_viewbegin_checkoutadd_to_cartremove_from_cartview_cartpurchaserefundview_itemview_item_listadd_to_wishlistsign_uploginsearchview_search_results
You can check more events in the events section.
Install
Requires hirale/queue ^3.0 and
googleads/data-manager
(both pulled in automatically; the Data Manager client uses its REST
transport, so neither ext-grpc nor ext-protobuf is required).
Maho (26.5+):
composer require hirale/openmage-ga4-measurement
OpenMage (20.17+, PHP 8.3+) — one-time tweaks first; details in the hirale/queue README:
composer config platform.php 8.3
composer config allow-plugins.hirale/magento-module-installer true
composer require hirale/magento-module-installer hirale/openmage-ga4-measurement
Usage
Configuration lives in System > Configuration > Sales > Google API > GA4 Server-Side Events. Enable the module, pick the API Transport, and follow the matching setup below. The Measurement ID (G-XXXXXXX, from Admin > Data Streams > choose your stream) is needed by both transports.
Setup — Measurement Protocol (default)
- Generate an API SECRET in the Google Analytics UI:
Admin > Data Streams > choose your stream > Measurement Protocol > Create. - Enter the Measurement ID and API Secret, save.
Setup — Data Manager API
One-time Google-side setup (detailed in Google's guide):
- Create (or pick) a Google Cloud project and enable the Data Manager API in it.
- Create a service account in that project (no Cloud IAM roles needed for ingestion) and download a JSON key for it.
- In GA Admin, open the property's Access Management and add the service account's
client_emailas Editor. - Note the numeric Property ID (
Admin > Property Settings) — this is not theG-Measurement ID.
Then in the store admin:
- Set API Transport to Data Manager API (OAuth service account).
- Enter the Measurement ID, the GA4 Property ID, and paste the full JSON key file into Service Account Key (JSON). The key is validated at save time and stored encrypted.
- Click Validate Destination — it sends a validate-only test event with the values on screen (nothing is recorded in GA4) and reports the Google
requestIdon success.
Transport semantics
- The transport is store-view scoped: different stores can post to MP and Data Manager side by side from the same queue consumer.
- Queued events are transport-agnostic; the transport is chosen at consume time, so switching it also applies to messages already in the queue.
- Data Manager rejects GA events older than 72 hours — messages that aged past the window (e.g. a consumer outage) are dropped with a log entry instead of being retried forever.
- Data Manager item quantities are integers; fractional quantities (partial refunds) are rounded, while the monetary value stays exact.
- Permanent Data Manager errors (invalid argument, missing property access) fail the queue job immediately and show up in the queue's failure list; transient errors retry with backoff.
- Restart queue workers after credential or transport changes. Long-running consumers snapshot configuration (and cache the decoded service-account key plus its OAuth client) at boot. After rotating the service-account key — especially if the old key is revoked in Google Cloud — Data Manager messages fail as unrecoverable (
auth rejected) and land in the failure list until the workers are restarted with the new config.
Debug
Enable debug mode in the system config (gated by System > Developer > Developer Client Restrictions). Both transports log to the same file; Data Manager entries include the Google-assigned requestId.
2024-06-10T18:28:24+00:00 DEBUG (7): {"client_id":"2131884568.1715846325","timestamp_micros":1718044092903759,"non_personalized_ads":false,"user_id":"140","events":[{"name":"page_view","params":{"engagement_time_msec":1,"page_location":"https://example.com/customer/account/index/","page_title":"Create New Customer Account"}}]}
2024-06-10T18:28:24+00:00 DEBUG (7): {
"validationMessages": [ ]
}
Upgrading from v2.x
No action needed: the transport defaults to Measurement Protocol and the existing measurement_id/api_secret config keeps working unchanged. The 2.x branch remains the MP-only maintenance line.
License
The Open Software License v. 3.0 (OSL-3.0). Please see License File for more information.
hirale/openmage-ga4-measurement 适用场景与选型建议
hirale/openmage-ga4-measurement 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 85 次下载、GitHub Stars 达 7, 最近一次更新时间为 2024 年 06 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「analytics」 「magento1」 「openmage」 「ga4」 「maho」 「mahoecommerce」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hirale/openmage-ga4-measurement 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hirale/openmage-ga4-measurement 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hirale/openmage-ga4-measurement 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Free and open source ecommerce platform, created in 2024 on the M1 platform, PHP 8.3+
Analytics chooser extensions for site settings.
A Laravel Nova Card to show Fathom Analytics stats.
A Magento 1 extension to attach PDF documents to emails.
A queue module for OpenMage and Maho, built on Symfony Messenger. Backend-agnostic (Redis Streams in v3.0).
The vianetz AsyncQueue Magento 1 Extension.
统计信息
- 总下载量: 85
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: OSL-3.0
- 更新时间: 2024-06-04