Erianna

Introducting yii2-analytics.js

October 10th, 2015 @ 13:51 Yii

Yii2 Analytics.js Integration

Today I'm happy to announce a new extension for Yii2 called yii2-analytics.js.

This extension provides Analytics.js integration for Yii Framework 2, and is the natural extension of EAnalytics which performs the same task for Yii1. This extension enables you to control and manage your analytics providers from within your Yii2 configuration, or in more complex examples, from a dynamic configuration.

Resources

yii2-analytics.js can be aquired from Github.

Installation

The preferred way to install this extension is through composer.

composer require --prefer-dist "charlesportwoodii/yii2-analytics.js"

or add the following to your composer.json's require-dev section.

"charlesportwoodii/yii2-analytics.js": "~1.0.0"

Configuration

To use this configuration, add the following to your config/web.php configuration file:

``` return [ // [...], 'components' => [ 'analyticsjs' => [ 'class' => 'charlesportwoodii\analytics\AnalyticsJs', 'providers' => [

        ]
    ]
]   

]; ```

A full list of providers and their arguments can be found on the Analytics.js integrations page. This extension directly passes the provider list and arguments to analytics.js.

Examples

Google Analytics

``` return [ // [...],

'components' => [
    // [...],

    'analyticsjs' => [
        'class' => 'charlesportwoodii\analytics\AnalyticsJs',
        'providers' => [
            // Google Analytics Provider
            'Google Analytics' => [
                'domain'                    => 'https://www.example.com',
                'doubleClick'               => false,
                'enhancedLinkAttribution'   => false,
                'trackingId'                => 'UA-XXXXXXXX',
                'universalClient'           => 1
            ],

            // Piwik provider
            'Piwik' => [
                'siteId'                    => 5,
                'url'                       => 'https://piwik.example.com'
            ]           
        ]
    ]
]   

]; ```