Google Api 返回的数据不是最新的(实时)

Data returned by Google Api is not Up-to-date (real-time)

我有一个包含多个属性的帐户,我正在为每个属性查询 Google Analytics API to pull Sessions and Pageviews by Hour

目前是 8:45pm PST,我有 3 个房产截至第 20 小时(晚上 8 点)的数据,但另外两个房产只有第 13 小时(下午 1 点)的数据。查看 GA UI.

时,所有 5 个属性都有截至晚上 8 点的数据

我希望创建一个报告,每小时汇总所有 5 个属性的指标,但如果两个属性要晚几个小时,我就不能这样做了。

这是我用来查询 API:

的代码
# configure query details
dimensions = "ga:hour"
metrics = "ga:sessions,ga:pageviews"
samplingLevel = "HIGHER_PRECISION"

for site in sites:

    # Fetch data from API for yesterday
    data = service.data().ga().get(
                ids=site,
                start_date=YESTERDAY,
                end_date=YESTERDAY,
                metrics=metrics,
                dimensions=dimensions,
                samplingLevel=samplingLevel
            ).execute()

    # Fetch data from API for today
    data = service.data().ga().get(
                ids=site,
                start_date=TODAY,
                end_date=TODAY,
                metrics=metrics,
                dimensions=dimensions,
                samplingLevel=samplingLevel
            ).execute()

是否有一些setting/configuration我需要为落后于计划的属性启用?

Google Analytics 可能需要 24 到 48 小时才能完成数据处理。在此之前可用的数据不会 100% 正确,因为它尚未完成处理。也不能保证所有数据至少保留 24 小时。你将无法用 reporting api.

做你正在谈论的事情

虽然您的某些媒体资源可能会提前显示数据,但数据并不完整,并且不能保证明天它们仍会提前显示数据。

Data processing latency
Processing latency is 24-48 hours. Standard accounts that send more than 200,000 sessions per day to Google Analytics will result in the reports being refreshed only once a day. This can delay updates to reports and metrics for up to two days. To restore intra-day processing, reduce the number of sessions you send to < 200,000 per day. For Premium accounts, this limit is extended to 2 billion hits per month.

我建议您为此考虑使用 Real-time api,主要缺点是您可以通过实时 api 访问的维度和指标的数量非常有限.