PHP code example of moriony / ga-measurement-protocol-client

1. Go to this page and download the library: Download moriony/ga-measurement-protocol-client 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/ */

    

moriony / ga-measurement-protocol-client example snippets


use \Moriony\Google\Analytics\MeasurementProtocol\Client;

$client = new Client([
    Client::OPT_TRACKING_ID => 'UA-XXXXXXXXX-Y',
    Client::OPT_SSL => true,
]);

$response = $client->createEvent()
    ->setCustomerId(555)
    ->setCategory('video')
    ->setAction('play')
    ->setLabel('holiday')
    ->setValue(300)
    ->track();