2017 © Pedro Peláez
 

yii2-extension yii2-google-analytics

Google Analytics Widget for the Yii2 framework

image

cybercog/yii2-google-analytics

Google Analytics Widget for the Yii2 framework

  • Saturday, September 9, 2017
  • by a-komarev
  • Repository
  • 3 Watchers
  • 13 Stars
  • 29,712 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 9 Forks
  • 6 Open issues
  • 8 Versions
  • 3 % Grown

The README.md

Yii2 Google Analytics Tracking

Gitter chat at https://gitter.im/cybercog/yii2-google-analytics Latest Stable Version License, (*1)

This extension provides easy way to add Universal Analytics tracking in your Yii2 application., (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Run in console, (*4)

php composer.phar require cybercog/yii2-google-analytics

Usage

In your /views/layouts/main.php add, (*5)

use cybercog\yii\googleanalytics\widgets\GATracking;

Then before </head> add following code, (*6)

<?= GATracking::widget([
    'trackingId' => 'UA-XXXXXXXX-X',
]) ?>

Advanced usage

Omit script tag

By default this script generated output:, (*7)

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', "auto");
ga('send', 'pageview');
ga('set', 'anonymizeIp', true);
</script>

But sometimes we need the output without script tag to combined with registerJs or registerJsFile as renderPartial to add dependency or positioning configuration, you can use omitScriptTag true to disable script tag, example:, (*8)

<?= $this->registerJs(
    GATracking::widget([
        'trackingId' => 'UA-XXXXXXXX-X',
        'omitScriptTag' => true,
    ]), \yii\web\View::POS_END
); ?>

Example of advanced usage

You can configure tracking script for your needs:, (*9)

<?= GATracking::widget([
    'trackingId' => 'UA-XXXXXXXX-X',
    'trackingConfig' => [
        'name' => 'myTracker',
        'allowAnchor' => false,
    ],
    'omitScriptTag' => false,
    'debug' => true,
    'debugTrace' => true,
    'anonymizeIp' => true,
    'plugins' => [
        'linkid' => [
            'cookieName' => '_ccli',
            'duration' => 45,
            'levels' => 5,
        ],
    ],
]) ?>

Available fields (parameters)

Field Name Value Type Default Value
anonymizeIp boolean true
debug boolean false
debugTrace boolean false

Official field reference

Available plugins

Option Name Default Value Description
cookieName _gali Cookie name
duration 30 Cookie duration (seconds)
levels 3 Max DOM levels from link to look for element ID

Creating your own plugins

The Versions

09/09 2017

dev-master

9999999-dev

Google Analytics Widget for the Yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

analytics yii2 google

23/06 2016

v0.3.2

0.3.2.0

Google Analytics Widget for the Yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

analytics yii2 google

30/07 2015

0.3.1

0.3.1.0

Google Analytics extension for the Yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

analytics yii2 google

29/07 2015

0.3

0.3.0.0

Google Analytics extension for the Yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

analytics yii2 google

20/04 2015

v0.2

0.2.0.0

Google Analytics extension for the Yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

analytics yii2 google

20/04 2015

dev-develop

dev-develop

Google Analytics extension for the Yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

analytics yii2 google

19/03 2015

v0.1.1

0.1.1.0

Google Analytics extension for the Yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

analytics yii2 google

24/01 2015

v0.1

0.1.0.0

Google Analytics extension for the Yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

analytics yii2 google