I am using Google API V4 https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php
I am having issue with setAlias function. When there are multiple metrics selected, all the returned headers are same.
Code:
<?php
$metrices = {FORM ARRY WITH MULTIPLE METRICES}
$nmetrices = array();
if(is_array($metrices) && count($metrices) > 0){
$i=0;
foreach($metrices as $metric){
$nmetrices[$i] = new Google_Service_AnalyticsReporting_Metric();
$nmetrices[$i]->setExpression($metric);
$nmetrices[$i]->setAlias($metric);
$i+=1;
}
}?>
Example:
I have selected "ga:users" and "ga:percentNewSessions", but the returned results have title: "ga:users" for both metrics.
ga:medium: (none)
ga:date: 20150810
Metric type: INTEGER
**ga:users: 764
ga:users: 97.38219895287958**
ga:medium: (none)
ga:date: 20150811
Metric type: INTEGER
**ga:users: 2495
ga:users: 85.50284629981024**