如何使用 analyticsreporting 获取 Google Analytics 页面的特定数据?

How to get Google Analytics's page specific data using analyticsreporting?

我正在尝试使用 google 的 analyticsreporting api v4.

获取个人分析报告

我有以下页面。

https://www.example.com/uiqueId1 https://www.example.com/uiqueId2 https://www.example.com/uiqueId3 https://www.example.com/uiqueId4

加载的每个页面我都在调用 ga set 方法。例如对于 uiqueId1 页面,

ga('send', 'pageview', uiqueId1);

现在我正在尝试使用 page-specific 获取数据 POST https://analyticsreporting.googleapis.com/v4/reports:batchGet 使用 nodejs 客户端。

和body

{
  "reportRequests": [
    {
      "dateRanges": [
        {
          "endDate": "yesterday",
          "startDate": "30daysAgo"
        }
      ],
      "viewId": "ga:[viewId]",
      "metrics": [
        {
          "expression": "ga:uniquePageviews"
        }
      ]
    }
  ]
}

这给了我 ga:uniquePageviews 的整体。我如何将它传递给各个页面?

谢谢你的到来。

您可以在 batchGet 中使用过滤器。阅读 here

最后你会得到这样的东西:

{
  "reportRequests": [
    {
      "dateRanges": [...],
      "viewId": "ga:[viewId]",
      "metrics": [...],
      "dimensions": [...],
      "dimensionFilterClauses": [ 
         'filters': [
           "dimension_name": "ga:pagepath",
           "operator": "EXACT",
           "expressions": [
             `${you_page_path}`
           ],
         ],
      ]
    }
  ]
}