Dan*_*ett 10 php google-analytics google-analytics-api google-data-api
我开始使用 Google Analytics 4 Data API 并下载 PHP 库来创建请求。我已经玩了一点,到目前为止我的请求运行良好,但是当我需要对其进行排序时,我不知道如何传递该数据,我一直在尝试很多方法,但没有运气。
检查“orderBys”数据,我应该传递orderType和dimensionName以按维度日期进行过滤,因此它应该类似于“ordertype”=> ALPHANUMERIC和“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' => [],
]);
Run Code Online (Sandbox Code Playgroud)
btx*_*btx 16
这对我有用:
注意使用的是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,
]),
],
]);
Run Code Online (Sandbox Code Playgroud)
我也有类似的挣扎,文档真的很糟糕。