gillbeits / yii2-google-api
Google Api Component for Yii2
Installs: 8 021
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 3
Requires
- php: >=5.4.0
- google/apiclient: ^2.0.0@RC
Requires (Dev)
- yiisoft/yii2: ^2.0
- yiisoft/yii2-bootstrap: ^2.0
Suggests
- yiisoft/yii2-bootstrap: Allow use widgets
This package is auto-updated.
Last update: 2024-10-26 05:06:20 UTC
README
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' ])?>