diff --git a/app/library/App/Bootstrap/RouteBootstrap.php b/app/library/App/Bootstrap/RouteBootstrap.php index 3e3ab6e..b4cc931 100755 --- a/app/library/App/Bootstrap/RouteBootstrap.php +++ b/app/library/App/Bootstrap/RouteBootstrap.php @@ -7,8 +7,13 @@ use App\Constants\Services; use Phalcon\Config; use Phalcon\DiInterface; use PhalconRest\Api; + use Google_Client; use Google_Service_AnalyticsReporting; +use Google_Service_AnalyticsReporting_DateRange; +use Google_Service_AnalyticsReporting_Metric; +use Google_Service_AnalyticsReporting_ReportRequest; +use Google_Service_AnalyticsReporting_GetReportsRequest; class RouteBootstrap implements BootstrapInterface { @@ -52,7 +57,18 @@ class RouteBootstrap implements BootstrapInterface $client->setDeveloperKey($api_key); $analytics = new Google_Service_AnalyticsReporting($client); - $var_2 = var_dump($analytics); + $param[] = ['metric' => 'ga:sessions', 'alias' => 'Сессии']; + $param[] = ['metric' => 'ga:users', 'alias' => 'Пользователи']; + $param[] = ['metric' => 'ga:CTR', 'alias' => 'CTR']; + $param[] = ['metric' => 'ga:goal1Value', 'alias' => 'цель "Корзина"']; + + foreach ($param as $item) { + + $response = $this->getReport($analytics, $item['metric'], $item['alias']); + + } + + $var_2 = var_dump($response); $msg = "testing fine"; @@ -62,4 +78,31 @@ class RouteBootstrap implements BootstrapInterface ]); }); } + + function getReport($analytics, $metric, $alias) { + + // Замена на свой идентификатор представления, напр. XXXX. + $VIEW_ID = "119240817"; + + // Создание объекта DateRange. + $dateRange = new Google_Service_AnalyticsReporting_DateRange(); + $dateRange->setStartDate("30daysAgo"); + $dateRange->setEndDate("today"); + + // Создание объекта Metrics. + $sessions = new Google_Service_AnalyticsReporting_Metric(); + $sessions->setExpression($metric); + $sessions->setAlias($alias); + + + // Создание объекта ReportRequest. + $request = new Google_Service_AnalyticsReporting_ReportRequest(); + $request->setViewId($VIEW_ID); + $request->setDateRanges($dateRange); + $request->setMetrics(array($sessions)); + + $body = new Google_Service_AnalyticsReporting_GetReportsRequest(); + $body->setReportRequests( array( $request) ); + return $analytics->reports->batchGet( $body ); + } } \ No newline at end of file -- libgit2 0.21.4