PHP code example of yiimaker / yii2-google-analytics

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

    

yiimaker / yii2-google-analytics example snippets


$analytics = \Yii::createObject([
    'class' => \ymaker\google\analytics\mp\Analytics::className(),
    
    'v' => 1,                                       // Protocol version. Default value: 1
    'tid' => 'UA-XXXX-Y'                            // Tracking ID / Web Property ID
    'cid' => '35009a79-1a05-49d7-b876-2b884d0f825b' // Client ID. Random UUID (http://www.ietf.org/rfc/rfc4122.txt)
]);

/** @var yii\httpclient\Response $responce */
$responce = $analytics->send([
    't' => 'event',     // Hit Type.
    'ec' => 'video',    // Event Category.
    'ea' => 'play',     // Event Action.
    'el' => 'holiday',  // Event label.
    'ev' => 300,        // Event value.
]);

php composer.phar