diff --git a/app/library/App/Controllers/GaController.php b/app/library/App/Controllers/GaController.php index cbf6917..0c39e88 100644 --- a/app/library/App/Controllers/GaController.php +++ b/app/library/App/Controllers/GaController.php @@ -40,8 +40,7 @@ class GaController extends CrudResourceController { $projects = Project::find(['user_id' => $user_id]); foreach ($projects as $project) { $view_id = (string)$project->ga_view_id; - $result[] = ['name' => $project->name]; - $result[] = $this->sendGaRequest($view_id, $get_metrics, $get_dimensions, $get_start_date, $get_end_date); + $result[] = $this->sendGaRequest($project->name, $view_id, $get_metrics, $get_dimensions, $get_start_date, $get_end_date); } } else { @@ -83,7 +82,7 @@ class GaController extends CrudResourceController { return $res; } - public function sendGaRequest($view, $get_metrics, $get_dimensions, $start, $end) { + public function sendGaRequest($project_name, $view, $get_metrics, $get_dimensions, $start, $end) { putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/phalcon/'.self::SECRET_JSON); $client = new Google_Client(); @@ -142,6 +141,8 @@ class GaController extends CrudResourceController { $metric_val = $item['metrics'][0]['values']; $dimension_val = $item['dimensions'][0]; + $result['name'] = $project_name; + if (count($metric_val) > 1) { for ($i = 0; $i < count($metric_val); $i++) { $result[$dimension_val][] = $metric_val[$i]; -- libgit2 0.21.4