如何获取当前活跃用户数而不是 GA4 中的 30 分钟计数?

How to get the number of currently active users instead of the 30 minutes count in GA4?

我最近向网站添加了一个 Google Analytics GA4 标签,目的是计算当前活跃用户数。以前,我现在可以看到实时用户数(我认为它有一分钟的延迟,但我不确定)。

但是在新的GA4中,我只能看到30分钟对应的数字,这不是我需要的。

我环顾四周,找到了一个添加 1 分钟时间维度的选项,但它适用于旧的 google 分析,我觉得不合适。

不知道这个问题是否需要提供我的代码,但如果必须的话,我会添加它。

编辑:

#Run a realtime report to get desired metrics.
def run_realtime_report(property_id):
    #Runs a realtime report on a Google Analytics 4 property.
    client = BetaAnalyticsDataClient()
    #Run the request.
    request = RunRealtimeReportRequest(
        property=f"properties/{property_id}",
        metrics=[Metric(name="activeUsers")],
    )
    #Parse the response.
    response = client.run_realtime_report(request)
    ...
    return activeUsers

#Run the realtime report function.
def run_sample():
    global property_id
    return run_realtime_report(property_id)

GA4 中过去 30 分钟的用户数与 Universal Analytics (UA) 中的“现场活跃用户”相似。然而,在大约 5 分钟不活动后,UA 有时会评估用户在网站上不再活跃。此实时报告是根据过去 5 分钟内的综合浏览量生成的:

闲置 5 分钟后,网站上的活跃用户数变为零:

在 GA4 中,您可以通过在实时报告请求中指定 minutesRange 来重新创建该计算。此页面描述了 minuteRange parameter。作为 JSON 请求,此报告将只统计最近 5 分钟内活跃的用户:

{
  "metrics": [
    {
      "name": "activeUsers"
    }
  ],
  "minuteRanges": [
    {
      "startMinutesAgo": 5,
      "endMinutesAgo": 0
    }
  ]
}

此请求不同于 GA4 实时报告,后者将“过去 30 分钟内的用户”突出显示为主要实时指标: