GA4 it is impossible sort by metric ascending
- OS: MacOS BigSur, Ubuntu
- PHP version: 7.3
- Package name and version: googleapis/php-analytics-data 0.7.0 and 0.7.1
Code example
In GA4 it is impossible sort metric asc, I also tried sending array and others methods but nothing works
$order = new OrderBy();
$mOrder = new OrderBy\MetricOrderBy();
$mOrder->setMetricName('eventCount');
$order->setMetric($mOrder);
$order->setDesc(true);
dump($order->serializeToJsonString());
// {"metric": {"metricName": "eventCount"}}
and that made an descending report
$order = new OrderBy();
$mOrder = new OrderBy\MetricOrderBy();
$mOrder->setMetricName('eventCount');
$order->setMetric($mOrder);
$order->setDesc(false);
dump($order->serializeToJsonString());
// {"metric": {"metricName": "eventCount"}, "desc": true}
and that get an descending report
full example
$request = [
'property' => 'properties/' . $property_id,
'dateRanges' => [
new DateRange([
'start_date' => '2020-01-01',
'end_date' => '2020-12-31',
]),
],
'dimensions' => [
new Dimension([
'name' => 'eventName'
]),
new Dimension([
'name' => 'searchTerm'
])
],
'metrics' => [
new Metric([
'name' => 'eventCount',
]);
],
'limit' => 100,
];
$order = new OrderBy();
$mOrder = new OrderBy\MetricOrderBy();
$mOrder->setMetricName('eventCount');
$order->setMetric($mOrder);
$order->setDesc(false);
$request['orderBys'] = [$order];
$client->runReport($request);
using $order->setDesc(true); or $order->setDesc(false);
I receive the data sorted descending. I need sort data ascending.
Thanks in advance
@ikuleshov for vis
any news?
Thanks for filing this issue, @emimarz!
The description for the "desc" option is "If true, sorts by descending order.". This is interesting because it doesn't say that setting "desc" to false will sort ascending.
This seems to me like a support question (e.g. an API usage question). We don't have a lot of knowledge on the Analytics Data API on this team (we just work on the client libraries themselves). If you have found the answer to this question, please update the ticket and let us know!
Closing this issue due to inactivity. But please feel free to reopen this if there is more information on this, or if you need support on the client library front.
Thanks.