Commit 9ba864b06d9e4346cd93436ca9766a299333741e
1 parent
129bec7c
ga output
Showing
1 changed file
with
12 additions
and
2 deletions
Show diff stats
app/library/App/Controllers/GaController.php
... | ... | @@ -10,6 +10,7 @@ namespace App\Controllers; |
10 | 10 | |
11 | 11 | |
12 | 12 | use App\Model\Project; |
13 | +use App\Model\User; | |
13 | 14 | use Google_Client; |
14 | 15 | use Google_Service_AnalyticsReporting; |
15 | 16 | use Google_Service_AnalyticsReporting_DateRange; |
... | ... | @@ -26,14 +27,23 @@ class GaController extends CrudResourceController { |
26 | 27 | |
27 | 28 | public function getAction() { |
28 | 29 | |
30 | + $user_id = $this->request->get('user_id') ?? '1'; | |
29 | 31 | $view_id = $this->request->get('view_id') ?? '119240817'; |
30 | 32 | $get_metrics = $this->request->get('metric') ?? 'users'; |
31 | 33 | $get_dimensions = $this->request->get('dimension'); |
32 | 34 | $get_start_date = $this->request->get('start') ?? '30daysAgo'; |
33 | 35 | $get_end_date = $this->request->get('end') ?? 'today'; |
34 | 36 | |
35 | - | |
36 | - return $this->sendGaRequest($view_id, $get_metrics, $get_dimensions, $get_start_date, $get_end_date); | |
37 | + if (empty($view_id)) { | |
38 | + $projects = Project::find(['user_id' => $user_id]); | |
39 | + foreach ($projects as $project) { | |
40 | + $result[] = $this->sendGaRequest($project->id, $get_metrics, $get_dimensions, $get_start_date, $get_end_date); | |
41 | + } | |
42 | + } | |
43 | + else { | |
44 | + $result = $this->sendGaRequest($view_id, $get_metrics, $get_dimensions, $get_start_date, $get_end_date); | |
45 | + } | |
46 | + return $result; | |
37 | 47 | |
38 | 48 | } |
39 | 49 | ... | ... |