668f6a77
Alexey Boroda
-Analytics started
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<?php
use yii\helpers\VarDumper;
$client = new Google_Client();
$client->setAuthConfig(\Yii::getAlias('@common/config/Artbox-85b8559147bc.json'));
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
$analytics = new Google_Service_AnalyticsReporting($client);
$profile_id = "119240817";
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("30daysAgo");
$dateRange->setEndDate("today");
$sessions = new Google_Service_AnalyticsReporting_Metric();
|
73bbe131
Alexey Boroda
-Analytics in pro...
|
18
19
20
21
22
|
$sessions->setExpression('ga:sessions');
$sessions->setAlias('Сеансы');
$dimensions = new Google_Service_AnalyticsReporting_Dimension();
$dimensions->setName('ga:date');
|
668f6a77
Alexey Boroda
-Analytics started
|
23
24
25
26
|
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($profile_id);
$request->setDateRanges($dateRange);
|
73bbe131
Alexey Boroda
-Analytics in pro...
|
27
28
|
$request->setMetrics($sessions);
$request->setDimensions($dimensions);
|
668f6a77
Alexey Boroda
-Analytics started
|
29
30
31
32
33
34
|
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests([ $request ]);
$response = $analytics->reports->batchGet($body);
VarDumper::dump($response, 10, true);
|