我尝试使用下面的Python代码访问具有同类群组维度的数据:
return analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'metrics': [
{"expression": "ga:cohortActiveUsers"},
{"expression": "ga:cohortTotalUsers"}
],
"dimensions":
[
{
"name": "ga:segment"
},
{
"name": "ga:cohort"
},
{
"name": "ga:cohortNthDay"
}
],
"segments": [
{
"dynamicSegment":
{
"name": "Sessions from Poznan",
"userSegment":
{
"segmentFilters": [
{
"simpleSegment":
{
"orFiltersForSegment":
{
"segmentFilterClauses": [
{
"dimensionFilter":
{
"dimensionName": "ga:city",
"operator": "EXACT",
"expressions": ["Poznan"]
}
}]
}
}
}]
}
}
}],
"cohortGroup": {
"cohorts": [{
"name": "cohort 1",
"type": "FIRST_VISIT_DATE",
"dateRange": {"startDate": "2016-05-10", "endDate": "2016-05-10"}
}, {
"name": "cohort 2",
"type": "FIRST_VISIT_DATE",
"dateRange": {"startDate": "2016-05-10", "endDate": "2016-05-10"}
}]
}
}]
}
).execute()
执行此代码时,收到错误Selected dimensions and metrics cannot be queried together
。但是当删除segments
部分时,一切正常。
出现此类错误的原因是什么?我该如何正确地请求这些数据?
答案 0 :(得分:0)
在您的同类群组报告中,没有维度“ga:segment”用作维度。您应该将自己限制在群组和文档的文档中提到的维度和指标。终身报告。
希望这有帮助。