Commit 130dffde58c73481811fe79d6bf1f382b31c5421
1 parent
3c03042d
ga
Showing
1 changed file
with
14 additions
and
7 deletions
Show diff stats
backend/views/report/index.php
... | ... | @@ -40,10 +40,17 @@ if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { |
40 | 40 | $analytics = new Google_Service_AnalyticsReporting($client); |
41 | 41 | |
42 | 42 | // Вызов the Analytics Reporting API V4. |
43 | - $response = getReport($analytics); | |
43 | + $metric_1 = 'ga:sessions'; | |
44 | + $metric_2 = 'ga:users'; | |
45 | + $metric_3 = 'ga:CTR'; | |
46 | + $response_1 = getReport($analytics, $metric_1); | |
47 | + $response_1 = getReport($analytics, $metric_2); | |
48 | + $response_1 = getReport($analytics, $metric_3); | |
44 | 49 | |
45 | 50 | // Вывод ответа. |
46 | - printResults($response); | |
51 | + printResults($response_1); | |
52 | + printResults($response_2); | |
53 | + printResults($response_3); | |
47 | 54 | |
48 | 55 | |
49 | 56 | } else { |
... | ... | @@ -52,20 +59,20 @@ if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { |
52 | 59 | } |
53 | 60 | |
54 | 61 | |
55 | -function getReport($analytics) { | |
62 | +function getReport($analytics, $metric) { | |
56 | 63 | |
57 | 64 | // Замена на свой идентификатор представления, напр. XXXX. |
58 | 65 | $VIEW_ID = "119240817"; |
59 | 66 | |
60 | 67 | // Создание объекта DateRange. |
61 | 68 | $dateRange = new Google_Service_AnalyticsReporting_DateRange(); |
62 | - $dateRange->setStartDate("7daysAgo"); | |
63 | - $dateRange->setEndDate("today"); | |
69 | + $dateRange->setStartDate("30daysAgo"); | |
70 | + $dateRange->setEndDate("yesterday"); | |
64 | 71 | |
65 | 72 | // Создание объекта Metrics. |
66 | 73 | $sessions = new Google_Service_AnalyticsReporting_Metric(); |
67 | - $sessions->setExpression("ga:sessions"); | |
68 | - $sessions->setAlias("sessions"); | |
74 | + $sessions->setExpression($metric); | |
75 | + $sessions->setAlias($metric); | |
69 | 76 | |
70 | 77 | |
71 | 78 | // Создание объекта ReportRequest. | ... | ... |