簡體   English   中英

Google Analytics 數據上的自定義維度 API (GA4) Python

[英]Custom dimensions on Google Analytics Data API (GA4) Python

我正在嘗試使用此處描述的快速入門代碼制作報告,它運行良好,但是當我嘗試添加自定義維度時,我得到以下錯誤

google.api_core.exceptions.InvalidArgument:400 字段 uid 不是有效維度。 有關有效維度和指標的列表,請參閱https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema

我可以在谷歌分析中心使用這個自定義維度制作報告,所以我不明白為什么我會收到這個錯誤,這是代碼(自定義維度是 uid)

def sample_run_report(property_id):
    """Runs a simple report on a Google Analytics App+Web property."""

    # Using a default constructor instructs the client to use the credentials
    # specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = AlphaAnalyticsDataClient(credentials=credentials)
    request = RunReportRequest(
        entity=Entity(property_id=property_id),
        dimensions=[Dimension(name='uid')],
        metrics=[Metric(name='userEngagementDuration')],
        date_ranges=[DateRange(start_date='2020-07-01',end_date='today')])

    response = client.run_report(request)

    print("Report result:")
    
    for row in response.rows:
        print(row.dimension_values[0].value, row.metric_values[0].value)

def main():
  sample_run_report(xxxxxx)

if __name__ == '__main__':
  main()

編輯:我能夠使用 name="customUser:uid" 創建查詢

嘗試在您的請求中從uid更新為customEvent:uid 此處記錄了自定義維度的語法。

您可以查詢元數據 API 方法以列出此屬性的已注冊自定義維度。 請參閱查詢示例 元數據方法可能會返回類似於以下內容的維度:

"dimensions": [
...
    {
      "apiName": "customEvent:uid",
      "uiName": "uid",
      "description": "An event scoped custom dimension for your Analytics property."
    },
...
],

如果 Metadata 方法不返回自定義維度,則沒有為此屬性注冊。 因為您說“我可以在 Google Analytics Hub 中使用此自定義維度制作報告”,所以您可能已經注冊了此維度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM