Skip to content

Utilize the Google Analytics measurement protocol in your PHP project

License

Notifications You must be signed in to change notification settings

Setono/google-analytics-measurement-protocol

Repository files navigation

Google Analytics measurement protocol library

Latest Version Software License Build Status Code Coverage Mutation testing

Easily build payloads for the Google Analytics measurement protocol.

Installation

composer require setono/google-analytics-measurement-protocol

Usage

<?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);

References

About

Utilize the Google Analytics measurement protocol in your PHP project

Resources

License

Stars

Watchers

Forks

Languages