Commit 668f6a77875455d2c2b2ff02d56336137bdb0d50
1 parent
cc865d87
-Analytics started
Showing
1 changed file
with
30 additions
and
0 deletions
Show diff stats
1 | +<?php | |
2 | + use yii\helpers\VarDumper; | |
3 | + | |
4 | + $client = new Google_Client(); | |
5 | + | |
6 | + $client->setAuthConfig(\Yii::getAlias('@common/config/Artbox-85b8559147bc.json')); | |
7 | + $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY); | |
8 | + | |
9 | + $analytics = new Google_Service_AnalyticsReporting($client); | |
10 | + | |
11 | + $profile_id = "119240817"; | |
12 | + | |
13 | + $dateRange = new Google_Service_AnalyticsReporting_DateRange(); | |
14 | + $dateRange->setStartDate("30daysAgo"); | |
15 | + $dateRange->setEndDate("today"); | |
16 | + | |
17 | + $sessions = new Google_Service_AnalyticsReporting_Metric(); | |
18 | + $sessions->setExpression('ga:users'); | |
19 | + $sessions->setAlias('Пользователи'); | |
20 | + | |
21 | + $request = new Google_Service_AnalyticsReporting_ReportRequest(); | |
22 | + $request->setViewId($profile_id); | |
23 | + $request->setDateRanges($dateRange); | |
24 | + $request->setMetrics([ $sessions ]); | |
25 | + | |
26 | + $body = new Google_Service_AnalyticsReporting_GetReportsRequest(); | |
27 | + $body->setReportRequests([ $request ]); | |
28 | + $response = $analytics->reports->batchGet($body); | |
29 | + | |
30 | + VarDumper::dump($response, 10, true); | |
0 | 31 | \ No newline at end of file | ... | ... |