我正在使用 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)
但是,这会返回 34000 行,这与我在 GA 中看到的 45000 行不匹配。注意:我确实在搜索词中添加了另一个维度。
有趣的是,如果我删除
ga:searchKeywordRefinement
来自代码的维度以及在 GA 中,行数确实匹配。
最佳答案
这很可能是由数据采样引起的。我似乎无法找到有关如何访问它的文档,但文档清楚地表明它是可能的:
RGoogleAnalytics GitHub with Readme
In cases where queries are sampled, the output also returns the percentage of sessions that were used for the query
所以答案是访问返回用于查询的 session 百分比的输出,如果它小于 100%,那么您就发现了问题。
为了解决采样问题……有一些技巧。查看文档中有关将查询拆分为一天的部分,然后将所有日期合并在一起。
关于r - Google Analytics API 返回的行数少于 GA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47011587/