Blame view

backend/views/site/analytic.php 1.05 KB
668f6a77   Alexey Boroda   -Analytics started
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  <?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();
      $sessions->setExpression('ga:users');
      $sessions->setAlias('Пользователи');
      
      $request = new Google_Service_AnalyticsReporting_ReportRequest();
      $request->setViewId($profile_id);
      $request->setDateRanges($dateRange);
      $request->setMetrics([ $sessions ]);
      
      $body = new Google_Service_AnalyticsReporting_GetReportsRequest();
      $body->setReportRequests([ $request ]);
      $response = $analytics->reports->batchGet($body);
      
      VarDumper::dump($response, 10, true);