yiimaker/yii2-google-analytics

Google Analytics (Measurement Protocol)

Installs: 1 679

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 4

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.0 2016-12-04 14:45 UTC

This package is auto-updated.

Last update: 2024-12-14 03:59:09 UTC


README

Google Analytics (Measurement Protocol)

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiimaker/yii2-google-analytics "*"

or add

"yiimaker/yii2-google-analytics": "*"

to the require section of your composer.json file.

Example

Initialize

$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)
]);

Usage

/** @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.
]);

For more information, refer to the API official documentation.