From 5407f0bbb05e0db065ceacc2950bfe0115a7a97a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 9 Feb 2017 16:39:14 +0200 Subject: [PATCH] test google lib --- app/library/App/Bootstrap/RouteBootstrap.php | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/app/library/App/Bootstrap/RouteBootstrap.php b/app/library/App/Bootstrap/RouteBootstrap.php index 4b41e3f..6fdd938 100755 --- a/app/library/App/Bootstrap/RouteBootstrap.php +++ b/app/library/App/Bootstrap/RouteBootstrap.php @@ -9,6 +9,13 @@ 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 { @@ -54,13 +61,40 @@ class RouteBootstrap implements BootstrapInterface $client->setDeveloperKey($api_key); $analytics = new Google_Service_AnalyticsReporting($client); + $param[] = ['metric' => 'ga:sessions', 'alias' => 'Сессии']; + $param[] = ['metric' => 'ga:users', 'alias' => 'Пользователи']; + $param[] = ['metric' => 'ga:CTR', 'alias' => 'CTR']; + $param[] = ['metric' => 'ga:goal1Value', 'alias' => 'цель "Корзина"']; + + $VIEW_ID = "119240817"; + + foreach ($param as $item) { + + // Создание объекта DateRange. + $dateRange = new Google_Service_AnalyticsReporting_DateRange(); + $dateRange->setStartDate("30daysAgo"); + $dateRange->setEndDate("today"); + + // Создание объекта Metrics. + $sessions = new Google_Service_AnalyticsReporting_Metric(); + $sessions->setExpression($item['metric']); + $sessions->setAlias($item['alias']); - //$response = $this->getReport($analytics, '', ''); - //$this->setViewId('119240817'); - $test = $this->setViewId(); + // Создание объекта ReportRequest. + $request = new Google_Service_AnalyticsReporting_ReportRequest(); + $request->setViewId($VIEW_ID); + $request->setDateRanges($dateRange); + $request->setMetrics(array($sessions)); - $var_2 = var_dump($test); + $body = new Google_Service_AnalyticsReporting_GetReportsRequest(); + $body->setReportRequests( array( $request) ); + + $response = $analytics->reports->batchGet( $body ); + } + + + $var_2 = var_dump($response); $msg = "testing fine"; @@ -71,15 +105,5 @@ class RouteBootstrap implements BootstrapInterface }); } - public function getReport($analytics, $metric, $alias) { - - // Замена на свой идентификатор представления, напр. XXXX. - $VIEW_ID = "119240817"; - return $VIEW_ID; - } - - public function setViewId() { - return '123'; - } } \ No newline at end of file -- libgit2 0.21.4