Google Analytics API returns 行比 GA 少(不同数量)

Google Analytics API returns less (different amount) rows than GA

我使用 R 通过 RGoogleAnalytics 插件访问 GA 数据。

我编写了以下查询以从 10 月 16 日到 22 日的站点搜索中获取搜索词。

query <- Init(start.date = "2017-10-16",
                   end.date = "2017-10-22",
                   dimensions = "ga:searchKeyword,ga:searchKeywordRefinement",
                   metrics = "ga:searchUniques,ga:searchSessions,ga:searchExits,ga:searchRefinements",
                   max.results = 99999,
                   sort = "-ga:searchUniques",
                   table.id = "ga:my_view_id")

ga.query2 <- QueryBuilder(query)

ga.data.refined <- GetReportData(ga.query2, token, paginate_query = T)

但是,这个 returns 34000 行与我在 GA 中看到的 45000 行不匹配。注意:我确实为搜索词添加了另一个维度。

有趣的是,如果我从代码和 GA 中删除 ga:searchKeywordRefinement 维度,行数确实匹配。

这很可能是数据抽样造成的。我似乎无法找到有关如何访问它的文档,但文档清楚地表明这是可能的:

RGoogleAnalytics GitHub with Readme

In cases where queries are sampled, the output also returns the percentage of sessions that were used for the query

所以答案是访问 returns 用于查询的会话百分比的输出,如果它小于 100%,那么你就找到了你的问题。

要解决抽样...有一些技巧。查看文档中有关将查询拆分为一天的部分,然后将所有日期合并在一起。