我正在尝试使用 GA4 数据 API 获取不同转化的
sessionConversionRate
。sessionConversionRate:conversionName
这样的指标时,一切都很好。conversion with space
,因此我请求一个指标 sessionConversionRate:conversion with space
,但收到此错误:
Metric names must only contain letters, numbers, or _. Received a metric name = session_conversion_rate[conversion with space]
我尝试删除空格并替换为“_”并收到此错误:
Did you mean sessionConversionRate:conversion with space? Field sessionConversionRate:conversion_with_space is not a valid metric. For a list of valid dimensions and metrics, see https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema
这种情况有解决方法吗?
这仍然是一个问题。我正在通过拉出all的转换并按名称拉出我需要的行来解决这个问题。我无法告诉我的客户重命名数百个属性中的所有指标;做得更好,谷歌。
<?php
$response = $client->runReport([
'property' => 'properties/' . $gaPropertyId,
'dateRanges' => [
new DateRange([
'start_date' => '2023-07-01',
'end_date' => '2023-07-31',
]),
],
'dimensions' => [new Dimension(
[
'name' => 'eventName',
]
)
],
'metrics' => [new Metric(
[
'name' => 'conversions',
]
)
]
]);
$output = [];
foreach ($response->getRows() as $row)
{
$output[$row->getDimensionValues()[0]->getValue()] = $row->getMetricValues()[0]->getValue();
}
输出:
Array
(
[Phone Calls] => 53
[Appt Request] => 47
[Contact Us] => 4
)