分析 API 与网络数据不匹配

Analytics API doesn't match web data

我知道这个问题已经在别处问过,但我还没有找到特别有用的答案。

我遇到的问题是常规 Web 版分析中的数据与我从 API 中提取的数据不匹配。

据我了解,这有时可能是所用查询类型的问题。这是我一直在使用的:

  var requiredArguments = {    
'dimensions':'ga:medium',
'metrics': 'ga:users, ga:sessions, ga:uniquePageviews, ga:newUsers',
'sort': 'ga:medium',
'start-index': '1',
'max-results': '1000',
'sampling-level': 'DEFAULT',

};

然后...

  var results = Analytics.Data.Ga.get(    
tableId,
startDate, 
finishDate,
'ga:users, ga:sessions, ga:uniquePageviews, ga:newUsers',
requiredArguments);

例如,一个月的会话有时会相差 1000 次。我尝试过使用不同的采样类型;我不认为是这样,因为我不会在一个查询中进行超过 50,000 个会话。

非常感谢任何帮助。

您需要检查结果 return 如果数据被采样,它会告诉您数据被采样。

"containsSampledData":false

samplingLevel

samplingLevel=DEFAULT Optional.
Use this parameter to set the sampling level (i.e. the number of sessions used to calculate the result) for a reporting query. The allowed values are consistent with the web interface and include:
DEFAULT — Returns response with a sample size that balances speed and accuracy.
FASTER — Returns a fast response with a smaller sample size.
HIGHER_PRECISION — Returns a more accurate response using a large sample size, but this may result in the response being slower.

If not supplied, the DEFAULT sampling level will be used. See the Sampling section for details on how to calculate the percentage of sessions that were used for a query.

抽样应该return 与网站接近但不完全相同的结果。从 API 中完全删除采样的唯一方法是使用 Premium Google Analytics Account

还记得考虑processing latency。如果您请求 48 小时内的数据,它也将与网站不同。