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 ¶
0. 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.
0. 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
[php] \Yii::$app->ga->request()
->setClientId('12345678')
->setDocumentPath('/mypage')
->sendPageview();
See the [GitHub page](https://github.com/baibaratsky/yii2-ga-measurement-protocol#usage) for more usage cases.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.