setono / google-analytics-events
一个简化Google Analytics事件生成的库
v1.0.0-rc
2023-09-12 09:23 UTC
Requires
- php: >=7.4
- ext-json: *
Requires (Dev)
- infection/infection: ^0.26
- nyholm/psr7: ^1.5
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.18
- setono/code-quality-pack: ^2.4
This package is auto-updated.
Last update: 2024-09-12 11:34:59 UTC
README
安装
composer require setono/google-analytics-events
使用方法
use Setono\GoogleAnalyticsEvents\Event\PurchaseEvent; use Setono\GoogleAnalyticsEvents\Writer\GtagWriter; $event = PurchaseEvent::create('TRANS_1234') ->setCurrency('USD') ->setValue(123.45) ->setTax(10.45) ->setShipping(3.32) ->addItem(Item::create()->setId('SKU1234')->setName('Blue t-shirt')) ; $writer = new GtagWriter(); echo $writer->write($event); // output: gtag("event", "purchase", {"currency":"USD","transaction_id":"TRANS_1234","value":123.45,"shipping":3.32,"tax":10.45,"items":[{"item_id":"SKU1234","item_name":"Blue t-shirt","quantity":1}]});