Google Analytics(分析数据API)有时会返回不完整数据
我正在使用RunReportrequest
呼叫来处理Python中Google Analytics GA4的数据。我面临的问题是,有时脚本返回具有所有值的完整数据,但有时尺寸为无效,主要是自定义的尺寸。顺便说一句,在所有API电话中,我仍然有配额。
我注意到这种行为甚至每天安排多次脚本执行,并且由于脚本条件几乎相同,因此无法确定可能是原因的。
我使用的脚本与此相似:
from google.analytics.data_v1beta import BetaAnalyticsDataClient, DateRange, RunReportRequest, Dimension, Metric
import os
client = BetaAnalyticsDataClient()
property_id = os.environ.get('PROPERTY_ID')
def download_ga_data(start_date, end_date, limit=int(1e6)):
request = RunReportRequest(property=f"properties/{property_id}",
dimensions=[Dimension(name=x) for x in ['customEvent:myCustomEvent', 'eventName']],
metrics=[Metric(name="averageSessionDuration")],
date_ranges=[DateRange(start_date=start_date, end_date=end_date)],
limit=limit,
return_property_quota=True,
keep_empty_rows=False)
response = client.run_report(request)
return response
谢谢
I'm working with data from Google analytics GA4 in python, using RunReportRequest
call. The issue I'm facing is that sometimes the script returns complete data with all values, but sometimes dimensions come null, mostly custom dimensions. BTW in all API calls I still had available quota.
I've noticed this behavior even scheduling the script execution multiple times a day, and haven't been able to pinpoint what could possible be the cause since the script conditions are pretty much the same.
The script I'm using is similar to this one:
from google.analytics.data_v1beta import BetaAnalyticsDataClient, DateRange, RunReportRequest, Dimension, Metric
import os
client = BetaAnalyticsDataClient()
property_id = os.environ.get('PROPERTY_ID')
def download_ga_data(start_date, end_date, limit=int(1e6)):
request = RunReportRequest(property=f"properties/{property_id}",
dimensions=[Dimension(name=x) for x in ['customEvent:myCustomEvent', 'eventName']],
metrics=[Metric(name="averageSessionDuration")],
date_ranges=[DateRange(start_date=start_date, end_date=end_date)],
limit=limit,
return_property_quota=True,
keep_empty_rows=False)
response = client.run_report(request)
return response
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论