Google Analytics V4 API:获取最近30天的数据

时间:2016-11-12 16:55:30

标签: google-analytics analytics google-analytics-api universal-analytics

我正在玩谷歌分析报告api v4。我想在后端显示一个图表,其中显示了某些指标的最后30天。问题是,我只获得累积/总和值。

例如,这是我发送给api的正文

  body = {
    reportRequests: [{
      dateRanges: [
        {
          startDate: Date.parse('2016/10/01'),
          endDate: Date.parse('2016/10/31')
        }
      ],
      viewId: '12345',
      metrics: [{ expression: "ga:users" }],
      dimensions: [{ name: "ga:pagePath" }]
    }]
  }

然后我得到了很多网址(当然,我没有过滤输出),如下所示:

{"reports"=>
  [{"columnHeader"=>
     {"dimensions"=>["ga:pagePath"],
      "metricHeader"=>
       {"metricHeaderEntries"=>[{"name"=>"ga:users", "type"=>"INTEGER"}]}},
    "data"=>
     {"rows"=>
       [{"dimensions"=>["/"], "metrics"=>[{"values"=>["2854"]}]},
        {"dimensions"=>["/?extlink_img=0"], "metrics"=>[{"values"=>["113"]}]},
        {"dimensions"=>["/?v=338"], "metrics"=>[{"values"=>["12"]}]},
        ...

但是,当我想要特定路线的最近30天的用户数时,我应该如何查询api,例如/?这甚至可能吗?

1 个答案:

答案 0 :(得分:1)

我自己发现了这个问题:ga:date

  body = {
    reportRequests: [{
      dateRanges: [
        {
          startDate: Date.parse('2016/10/01'),
          endDate: Date.parse('2016/10/31')
        }
      ],
      viewId: '12345',
      metrics: [{ expression: "ga:users" }],
      dimensions: [{ name: "ga:pagePath" }, {name: 'ga:date'}]
    }]
  }

还有其他与时间相关的维度https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&group=time