【发布时间】:2021-07-16 11:33:00
【问题描述】:
我最近向网站添加了一个 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)
【问题讨论】:
-
请编辑您的问题并包含您的代码
-
我已经添加了相关代码sn-p。
标签: google-analytics google-analytics-api google-analytics-4