This extension provides easy way to add Universal Analytics tracking in your Yii2 application.
The preferred way to install this extension is through composer.
Either run
$ php composer.phar require cybercog/yii2-google-analytics "*"
or add
"cybercog/yii2-google-analytics": "*"
to the require section of your composer.json
file.
In your /views/layouts/main.php
add
use cybercog\yii\googleanalytics\widgets\GATracking;
Then before </head>
add following code
<?= GATracking::widget(
[
'trackingId' => 'UA-XXXXXXXX-X',
'anonymizeIp' => '[true|false]', // string
'inPageAnalysis' => [true|false], // boolean
]
) ?>