我可能有一些误解,所以需要帮助来理解到底是什么错误。
在analytics.google.com,我有两个段,它们的事件标签不同,但都来自同一个事件。在分析界面中,段之间的差异是可见的:
当我尝试使用查询资源管理器之类的工具获取相同的数据时,结果也不同:
但是,当我使用报告 API v4 获取此数据时,段之间的所有值都是相同的。我也尝试过使用 API v3,得到了类似的结果。
这是我的代码:
googleapis.analyticsreporting('v4').reports.batchGet({
'headers': {'Content-Type': 'application/json'},
"auth": oauth2Client,
"resource":{
reportRequests:[
{
"viewId": "ga:"+Meteor.settings.admin.googleAPI.viewID,
"dateRanges":[{
"startDate": '2016-07-01',
"endDate": moment().format('YYYY-MM-DD'),
}],
"metrics": [{"expression":"ga:pageviews"},{"expression":"ga:avgtimeonpage"}],
"dimensions": [{"name":"ga:pagepath"},{"name":"ga:segment"}],
"segments": [{
"dynamicSegment":
{
"name": "version_bw",
"userSegment":
{
"segmentFilters": [
{
"simpleSegment":
{
"orFiltersForSegment": [
{
"segmentFilterClauses": [
{
"dimensionFilter":
{
"dimensionName": "ga:eventAction",
"operator": "EXACT",
"expressions": ["set-visual-code"]
}
},{
"dimensionFilter":
{
"dimensionName": "ga:eventLabel",
"operator": "EXACT",
"expressions": ["bw"]
}
}
]
}]
}
}]
}
}
},{
"dynamicSegment":
{
"name": "version_color",
"userSegment":
{
"segmentFilters": [
{
"simpleSegment":
{
"orFiltersForSegment": [
{
"segmentFilterClauses": [
{
"dimensionFilter":
{
"dimensionName": "ga:eventAction",
"operator": "EXACT",
"expressions": ["set-visual-code"]
}
},{
"dimensionFilter":
{
"dimensionName": "ga:eventLabel",
"operator": "EXACT",
"expressions": ["color"]
}
}
]
}]
}
}]
}
}
}]
}
]
}
}, function(err, response) {
if (err) {
console.log('API Error: '+ err);
return;
}
var rows = response.reports[0].data.rows;
for (var i = 0; i < rows.length; i++) {
console.log(rows[i].dimensions);
console.log(rows[i].metrics);
}
});
这导致以下输出:
I20160719-14:09:10.405(2)? [ '/', 'version_bw' ]
I20160719-14:09:10.406(2)? [ { values: [ '373', '174.11977715877438' ] } ]
I20160719-14:09:10.406(2)? [ '/', 'version_color' ]
I20160719-14:09:10.407(2)? [ { values: [ '373', '174.11977715877438' ] } ]
I20160719-14:09:10.407(2)? [ '/portfolio', 'version_bw' ]
I20160719-14:09:10.407(2)? [ { values: [ '468', '126.2876404494382' ] } ]
I20160719-14:09:10.407(2)? [ '/portfolio', 'version_color' ]
I20160719-14:09:10.408(2)? [ { values: [ '468', '126.2876404494382' ] } ]
I20160719-14:09:10.408(2)? [ '/portfolio/', 'version_bw' ]
I20160719-14:09:10.409(2)? [ { values: [ '22', '229.54545454545453' ] } ]
I20160719-14:09:10.410(2)? [ '/portfolio/', 'version_color' ]
I20160719-14:09:10.410(2)? [ { values: [ '22', '229.54545454545453' ] } ]
I20160719-14:09:10.410(2)? [ '/portfolio/graphics', 'version_bw' ]
I20160719-14:09:10.410(2)? [ { values: [ '84', '60.073170731707314' ] } ]
I20160719-14:09:10.410(2)? [ '/portfolio/graphics', 'version_color' ]
I20160719-14:09:10.410(2)? [ { values: [ '84', '60.073170731707314' ] } ]
I20160719-14:09:10.411(2)? [ '/portfolio/graphics/some-graphic', 'version_bw' ]
I20160719-14:09:10.411(2)? [ { values: [ '134', '42.02290076335878' ] } ]
I20160719-14:09:10.411(2)? [ '/portfolio/graphics/some-graphic', 'version_color' ]
I20160719-14:09:10.411(2)? [ { values: [ '134', '42.02290076335878' ] } ]