Google Analytics 4 数据 API 使用排序依据
Google Analytics 4 Data API use order by
我开始使用 Google Analytics 4 Data API 并下载了 PHP 库来创建请求。我一直在玩,到目前为止我的请求运行良好,但是当我需要对它进行排序时,我不知道如何传递这些数据,我已经尝试了很多方法但没有运气。
检查 "orderBys" 数据,我应该传递 orderType 和 dimensionName 以按维度日期过滤,因此它应该类似于 "ordertype" => ALPHANUMERIC and "dimensionName => "date"
任何提示将不胜感激:)
$response = $client->runReport([
'property' => 'properties/' . $property_id,
'dateRanges' => [
new DateRange([
'start_date' => '7daysAgo',
'end_date' => 'yesterday',
]),
],
'dimensions' => [new Dimension(
['name' => 'day']
),
],
'metrics' => [
new Metric(['name' => 'newUsers']),
new Metric(['name' => 'active7DayUsers']),
],
'orderBys' => [],
]);
这对我有用:
注意使用了 V1beta 包
use Google\Analytics\Data\V1beta\BetaAnalyticsDataClient;
$response = $client->runReport([
// ...
'orderBys' => [
new OrderBy([
'dimension' => new OrderBy\DimensionOrderBy([
'dimension_name' => 'month', // your dimension here
'order_type' => OrderBy\DimensionOrderBy\OrderType::ALPHANUMERIC
]),
'desc' => false,
]),
],
]);
我有过类似的挣扎,文档真的很糟糕。
我开始使用 Google Analytics 4 Data API 并下载了 PHP 库来创建请求。我一直在玩,到目前为止我的请求运行良好,但是当我需要对它进行排序时,我不知道如何传递这些数据,我已经尝试了很多方法但没有运气。
检查 "orderBys" 数据,我应该传递 orderType 和 dimensionName 以按维度日期过滤,因此它应该类似于 "ordertype" => ALPHANUMERIC and "dimensionName => "date"
任何提示将不胜感激:)
$response = $client->runReport([
'property' => 'properties/' . $property_id,
'dateRanges' => [
new DateRange([
'start_date' => '7daysAgo',
'end_date' => 'yesterday',
]),
],
'dimensions' => [new Dimension(
['name' => 'day']
),
],
'metrics' => [
new Metric(['name' => 'newUsers']),
new Metric(['name' => 'active7DayUsers']),
],
'orderBys' => [],
]);
这对我有用:
注意使用了 V1beta 包
use Google\Analytics\Data\V1beta\BetaAnalyticsDataClient;
$response = $client->runReport([
// ...
'orderBys' => [
new OrderBy([
'dimension' => new OrderBy\DimensionOrderBy([
'dimension_name' => 'month', // your dimension here
'order_type' => OrderBy\DimensionOrderBy\OrderType::ALPHANUMERIC
]),
'desc' => false,
]),
],
]);
我有过类似的挣扎,文档真的很糟糕。