analytic.php
1.19 KB
<?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:sessions');
$sessions->setAlias('Сеансы');
$dimensions = new Google_Service_AnalyticsReporting_Dimension();
$dimensions->setName('ga:date');
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($profile_id);
$request->setDateRanges($dateRange);
$request->setMetrics($sessions);
$request->setDimensions($dimensions);
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests([ $request ]);
$response = $analytics->reports->batchGet($body);
VarDumper::dump($response, 10, true);