Easily build payloads for the Google Analytics measurement protocol.
composer require setono/google-analytics-measurement-protocol
<?php
require_once '../vendor/autoload.php';
use Setono\GoogleAnalyticsEvents\Event\AddToCartEvent;
use Setono\GoogleAnalyticsEvents\Event\Item\Item;
use Setono\GoogleAnalyticsMeasurementProtocol\Client\Client;
use Setono\GoogleAnalyticsMeasurementProtocol\Request\Body;
use Setono\GoogleAnalyticsMeasurementProtocol\Request\Request;
$client = new Client();
$request = (new Request(
'YOUR_SECRET',
'G-12341234',
'CLIENT_ID'
))
->addEvent(
AddToCartEvent::create()
->setCurrency('USD')
->setValue(123.45)
->addItem(Item::create()->setId('SKU1234')->setName('Blue t-shirt')),
)
->setTimestamp(1668509674013800)
;
$client->sendRequest($request);