当我尝试使用自定义维度进行batchGet时,出现错误“未知维度:”
此代码可以正常工作
analyticsreporting.reports.batchGet({
requestBody: {
reportRequests: [
{
viewId: 'XXXXXXXXX',
dateRanges: [
{
startDate: '7daysAgo',
endDate: 'today',
},
],
dimensions: [
{
name: 'ga:eventCategory'
}
],
metrics: [
{
expression: 'ga:totalEvents',
},
],
},
],
},
}).then((res) => {
console.log(res);
})
但是当我使用自定义分析维度作为维度时,将ga:eventCategory替换为ga:store
dimensions: [
{
name: 'ga:store'
}
],
我收到错误消息:未知尺寸:ga:store
维度“商店”正在分析GUI上工作
答案 0 :(得分:1)
在报告API中,您需要通过索引而不是名称来引用维度。这是因为名称会随着时间而改变,但索引永远不会改变。
假设store
在索引2
中,那么您将使用以下代码:
dimensions: [
{
name: 'ga:dimension2'
}
]