Google Analytics(分析数据API)有时会返回不完整数据

发布于 2025-01-26 08:05:28 字数 1102 浏览 3 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文