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

问题描述 投票:0回答:1

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

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

我环顾四周,找到了一个添加 1 分钟时间维度的选项,但它是针对旧的谷歌分析的,对我来说似乎不合适。

不确定是否需要为这个问题提供我的代码,但如果必须,那么我会添加它。

编辑:

#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)
google-analytics google-analytics-api google-analytics-4
1个回答
6
投票

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

闲置5分钟后,现场活跃用户归零:

在 GA4 中,您可以通过在实时报告请求中指定

minutesRange
来重新创建该计算。本页介绍了 minuteRange 参数。作为一个 JSON 请求,此报告将只计算最近 5 分钟内活跃的用户:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.