Yii 2.0: yii2-ga-measurement-protocol

Google Analytics Measurement Protocol for Yii2
3 followers

Interact with Google Analytics directly. No need of any JS code. Pure server-side.

Full support for all methods of the Google Analytics Measurement Protocol is provided.

Installation

  1. The preferred way to install this extension is through composer.

    To install, either run

    $ php composer.phar require baibaratsky/yii2-ga-measurement-protocol:1.1.*
    

    or add

    "baibaratsky/yii2-ga-measurement-protocol": "1.1.*"
    

    to the require section of your composer.json file.

  2. Add the component configuration in your main.php config file:

    '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) 
     ],
    ],

Usage

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

See the GitHub page for more usage cases.

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet