【问题标题】:Google Analytics query for list of dimensions and metrics assosicated with a view谷歌分析查询与视图相关的维度和指标列表
【发布时间】:2019-11-25 07:55:24
【问题描述】:

我正在尝试使用 python google-api-client 提取 Google 分析数据。但我需要在请求正文中提及维度和指标列表 'dimensions':[{'name' : 'ga:date'}]。但是有没有办法获得与视图 ID 关联的维度和指标的完整列表。我可以通过 API 调用获取该列表吗?

sample_request = {
    'viewId': 'xxxxxx',
    'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
    'metrics' : [{'expression' : 'ga:users'}],
    'dimensions':[{'name' : 'ga:date'}]
    }

response = api_client.reports().batchGet(
                      body={
                    'reportRequests': sample_request
                            }).execute()

【问题讨论】:

    标签: python google-analytics google-api-client google-reporting-api


    【解决方案1】:

    您可以在此处找到可在 Analytics 中查询任何视图的所有指标和维度的列表:https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/

    【讨论】:

    • 那么任何给定的视图是否都具有资源管理器中提到的所有维度和指标?
    • 所有指标和维度均可查询。如果它们没有值并且被查询它们将不会返回结果。如果我在非电子商务视图中查询 ga:transactionsPerUser(每个用户的交易),我会得到 0。试试这个工具:ga-dev-tools.appspot.com/query-explorer
    【解决方案2】:

    如果您确实需要程序化响应,google analytics metadata api 会提供 GA 中可用的所有指标和维度的最新列表。

    这是我的示例(使用请求 - 有一个单独的 python 元数据 api 可供您使用,但根据我的经验,它不需要 api 键,因此使用请求更容易 - 此参考以及如何使用python客户端库是here):

    import requests
    
    resp = requests.get("https://www.googleapis.com/analytics/v3/metadata/ga/columns?pp=1")
    
    print(resp.json())
    
    

    很遗憾,元数据 API 的局限性在于您无法使用它来确定可以在 Analytics API 调用中同时查询哪些指标和维度。正如 Michele 所提到的,您可以使用dimensions and metrics explorer 来探索可以通过单击您感兴趣的指标的复选框来查询哪些指标和维度的组合,并查看这是否会使维度变灰。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-18
      • 2017-08-11
      • 1970-01-01
      相关资源
      最近更新 更多