PHP code example of baibaratsky / yii2-ga-measurement-protocol

1. Go to this page and download the library: Download baibaratsky/yii2-ga-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/ */

    

baibaratsky / yii2-ga-measurement-protocol example snippets


   'components' => [
       'ga' => [
           'class' => 'baibaratsky\yii\google\analytics\MeasurementProtocol',
           'trackingId' => 'UA-XXXX-Y', // Put your real tracking ID here

           // These parameters are optional:
           'useSsl' => true, // If you’d like to use a secure connection to Google servers
           'overrideIp' => false, // By default, IP is overridden by the user’s one, but you can disable this
           'anonymizeIp' => true, // If you want to anonymize the sender’s IP address
           'asyncMode' => true, // Enables the asynchronous mode (see below)
           'autoSetClientId' => true, // Try to set ClientId automatically from the “_ga” cookie (disabled by default)
       ],
   ],
   

\Yii::$app->ga->request()
    ->setClientId('12345678')
    ->setDocumentPath('/mypage')
    ->sendPageview();

$request = \Yii::$app->ga->request();

// Build the order data programmatically, each product of the order included in the payload
// First, general and iliation('THE ICONIC')
    ->setRevenue(250.0)
    ->setTax(25.0)
    ->setShipping(15.0)
    ->setCouponCode('MY_COUPON');

// Include a product, the only roductData1);

// You can set the product action, which is PURCHASE in the example below
$request->setProductActionToPurchase();

// Finally, you need to send a hit; in this example, we are sending an Event
$request->setEventCategory('Checkout')
    ->setEventAction('Purchase')
    ->sendEvent();

'asyncMode' => true,

\Yii::$app->ga->request()
    ->setClientId('12345678')
    ->setDocumentPath('/mypage')
    ->setAsyncRequest(true)
    ->sendPageview();

'components' => [
    'request' => [
        'enableCookieValidation' => false,
    ],
]

   $ php composer.phar