Commit c9087298289acd0e0cbac93ded7fd18162463175
1 parent
1d97c107
ga output
Showing
1 changed file
with
11 additions
and
7 deletions
Show diff stats
app/library/App/Controllers/GaController.php
... | ... | @@ -24,17 +24,21 @@ class GaController extends CrudResourceController { |
24 | 24 | |
25 | 25 | const SECRET_JSON = 'ca4a1bd8aa14.json'; |
26 | 26 | const VIEW_ID = '119240817'; |
27 | + const SCOPE = 'https://www.googleapis.com/auth/analytics.readonly'; | |
27 | 28 | |
28 | 29 | public function getAction() { |
29 | 30 | |
31 | + /** user params **/ | |
30 | 32 | $user_id = $this->request->get('user_id')?? '1'; |
31 | - //$view_id= $this->request->get('view_id') ?? '119240817'; | |
32 | 33 | $view_id= $this->request->get('view_id'); |
34 | + $chart = $this->request->get('chart') ?? false; | |
35 | + | |
36 | + /** google params **/ | |
33 | 37 | $get_metrics = $this->request->get('metric') ?? 'users'; |
34 | 38 | $get_dimensions = $this->request->get('dimension'); |
35 | 39 | $get_start_date = $this->request->get('start') ?? '30daysAgo'; |
36 | 40 | $get_end_date = $this->request->get('end') ?? 'today'; |
37 | - $chart = $this->request->get('chart') ?? false; | |
41 | + | |
38 | 42 | |
39 | 43 | if (empty($view_id)) { |
40 | 44 | $result = []; |
... | ... | @@ -59,15 +63,15 @@ class GaController extends CrudResourceController { |
59 | 63 | putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/phalcon/'.self::SECRET_JSON); |
60 | 64 | $client = new Google_Client(); |
61 | 65 | $client->useApplicationDefaultCredentials(); |
62 | - $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']); | |
66 | + $client->setScopes([self::SCOPE]); | |
63 | 67 | $analytics = new Google_Service_AnalyticsReporting($client); |
64 | 68 | |
65 | - // Создание объекта DateRange. | |
69 | + /** Create the DateRange object. **/ | |
66 | 70 | $dateRange = new Google_Service_AnalyticsReporting_DateRange(); |
67 | 71 | $dateRange->setStartDate($start); |
68 | 72 | $dateRange->setEndDate($end); |
69 | 73 | |
70 | - // Создание объекта Metrics. | |
74 | + /** Create the Metrics object. **/ | |
71 | 75 | $metrics = []; |
72 | 76 | $get_metrics = explode(',', $get_metrics); |
73 | 77 | foreach ($get_metrics as $metric) { |
... | ... | @@ -77,7 +81,7 @@ class GaController extends CrudResourceController { |
77 | 81 | $metrics[] = $metrics_obj; |
78 | 82 | } |
79 | 83 | |
80 | - //Create the Dimensions object. | |
84 | + /** Create the Dimensions object. **/ | |
81 | 85 | if (!empty($get_dimensions)) { |
82 | 86 | $dimensions = []; |
83 | 87 | $get_dimensions = explode(',', $get_dimensions); |
... | ... | @@ -88,7 +92,7 @@ class GaController extends CrudResourceController { |
88 | 92 | } |
89 | 93 | } |
90 | 94 | |
91 | - // Создание объекта ReportRequest. | |
95 | + //Create the ReportRequest object. | |
92 | 96 | $request = new Google_Service_AnalyticsReporting_ReportRequest(); |
93 | 97 | $request->setViewId($view); |
94 | 98 | $request->setDateRanges($dateRange); | ... | ... |