Google Analytics API v4如何仅过滤目标> 0

问题描述 投票:0回答:1

我正在尝试查找“广告内容” UTM参数的目标完成情况。以下配置可以正常运行,但是,我希望对其进行过滤,以仅返回GOALS> 0的数据。即使目标= 0,它当前也会返回所有数据。

return analytics.reports().batchGet(
      body={
        'reportRequests': [
        {
          'viewId': VIEW_ID,
          'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
          'metrics': [{'expression': 'ga:sessions'}, {'expression': 'ga:goalCompletionsAll'}],
          'dimensions': [{'name': 'ga:adContent'}]
        }]
      }
  ).execute()
python python-3.x google-analytics google-analytics-api
1个回答
0
投票

您可以包含另一个参数-'includeEmptyRows':

return analytics.reports().batchGet(
      body={
        'reportRequests': [
        {
          'viewId': VIEW_ID,
          'includeEmptyRows' : True,
          'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
          'metrics': [{'expression': 'ga:sessions'}, {'expression': 'ga:goalCompletionsAll'}],
          'dimensions': [{'name': 'ga:adContent'}]
        }]
      }
  ).execute()

这将确保即使所有值均为0,API也会返回尺寸。文档的相关链接位于:

https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet#ReportRequest.FIELDS.include_empty_rows

© www.soinside.com 2019 - 2024. All rights reserved.