【问题标题】:Google Analytics Reporting API v4 sort resultsGoogle Analytics Reporting API v4 排序结果
【发布时间】:2017-11-09 14:01:51
【问题描述】:

基于此处的示例:https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py

我正在尝试在公共图书馆目录中查找搜索结果信息。我可以通过填写适当的指标和维度来获得结果,但我不知道如何将“排序”集成到

def get_report(analytics):
  """Queries the Analytics Reporting API V4.
  Args:
    analytics: An authorized Analytics Reporting API V4 service object.
  Returns:
    The Analytics Reporting API V4 response.
  """
  return analytics.reports().batchGet(
      body={
        'reportRequests': [
        {
          'viewId': VIEW_ID,
          'dateRanges': [{'startDate': '1daysAgo', 'endDate': 'today'}],
          'metrics': [{'expression': 'ga:avgSearchResultViews'}],
          'dimensions': [{'name': 'ga:searchKeyword'}],
        }]          

      }
  ).execute()

有谁知道我如何在上面的代码块中集成排序和可能的 maxResults 限制器?谷歌在这里有关于排序的信息:https://developers.google.com/analytics/devguides/reporting/core/v3/reference#sort。我已经尝试在指标表达式中添加“-”,甚至为“排序”添加一个全新的行,但它还不能帮助我。

【问题讨论】:

    标签: python sorting google-analytics google-analytics-firebase


    【解决方案1】:

    这里是如何。 Zeloslaw 的答案没有“orderType”,但您必须使用它。

    {
        "reportRequests": [
          {
            "viewId": "<your_view_id>",
            "dateRanges": [
              {
                "startDate": "30daysAgo",
                "endDate": "yesterday"
              }
            ],
            "metrics": [
                {
                  "formattingType": "METRIC_TYPE_UNSPECIFIED",
                  "expression": "ga:searchUniques"
                }
              ],
              "dimensions": [
                {
                  "name": "ga:searchKeyword"
                }
              ],
              "orderBys": [
                {
                  "orderType": "VALUE",
                  "sortOrder": "DESCENDING",
                  "fieldName": "ga:searchUniques"
                }
              ],
              "samplingLevel": "DEFAULT"
          }
        ]
      }
    

    您可以在此处找到批处理的其他详细信息https://developers.google.com/analytics/devguides/reporting/core/v4/basics

    【讨论】:

      【解决方案2】:

      例子:

      {
        "reportRequests":[
        {
          ...
          "orderBys": [
          {
            "fieldName": "ga:users",
            "sortOrder": "DESCENDING"
          },{
            "fieldName": "ga:source"
          }],
        }]
      }
      

      来源:GA API migration

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-08
        • 1970-01-01
        • 2016-11-22
        • 1970-01-01
        • 1970-01-01
        • 2021-03-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多