The preferred way to install this component is through composer.
php composer.phar require --prefer-dist gillbeits/yii2-google-api
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']
],
...
]
],
...
],
// 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"
]
)
;
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' ])?>