cshehadi / yii2-google-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google Api Component for Yii2


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'
    ])?>

About


Languages

Language:PHP 100.0%