PHP code example of setono / google-analytics-measurement-protocol
1. Go to this page and download the library: Download setono/google-analytics-measurement-protocol library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
setono / google-analytics-measurement-protocol example snippets
etono\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);