【问题标题】:Custom dimensions on Google Analytics Data API (GA4) PythonGoogle Analytics Data API (GA4) Python 上的自定义维度
【发布时间】:2021-02-23 16:03:15
【问题描述】:

我正在尝试使用Here 描述的快速入门代码制作报告,它运行良好,但是当我尝试添加自定义维度时,我收到以下错误

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" 创建查询

【问题讨论】:

    标签: python google-analytics google-analytics-api custom-dimensions google-analytics-data-api


    【解决方案1】:

    尝试在您的请求中将 uid 更新为 customEvent:uid。自定义维度的语法是documented here

    您可以查询元数据 API 方法以列出此属性的已注册自定义维度。请参阅example of the query。元数据方法可能会返回类似于以下内容的维度:

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

    如果 Metadata 方法不返回自定义维度,则没有为该属性注册一个维度。因为您说“我可以在 Google Analytics Hub 中使用此自定义维度制作报告”,所以您可能已经注册了此维度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 2021-09-18
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多