gillbeits/yii2-google-api

Google Api Component for Yii2

dev-master 2016-03-03 09:57 UTC

This package is auto-updated.

Last update: 2024-10-26 05:06:20 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

The preferred way to install this component is through composer.

php composer.phar require --prefer-dist gillbeits/yii2-google-api

###Configuration

in your app and/or console configuration file, add

'components' => [
    // Google Api Configuration
    'google-api'   => [
        'class'             => 'gillbeits\Yii2GoogleApi\GoogleApi',
        'credentials' => '@common/config/google-api-server-key.json',
        'services' => [
            'analytics' => [
                'class' => '\Google_Service_Analytics',
                'scopes' => ['https://www.googleapis.com/auth/analytics.readonly']
            ],
            ...
        ]
    ],
    ...
],

Usage

// Get Sessions by user gender dimension
$data = \Yii::$app->{'google-api'}
        ->analytics
            ->data_ga
                ->get(
                    "ga:<AnalyticsViewID>", 
                    "2015-01-01", 
                    "today", 
                    "ga:sessions", 
                    [
                       "dimensions" => "ga:userGender"
                    ]
                )
;

Widgets

For usage widgets in Yii2 install yiisoft/yii2-bootstrap library:

php composer.phar require yiisoft/yii2-bootstrap
  • Google Analytics widget usage

    <?= gillbeits\Yii2GoogleApi\Widgets\AnalyticsGAData::widget([
        'viewId' => <AnalyticsViewID>,
        'startDate' => '2015-01-01',
        'endDate' => 'today',
        'metrics' => 'ga:sessions',
        'dimensions' => 'ga:userGender',
        'templateFile' => '//analytics/widgets/AnalyticsGenderGA'
    ])?>