0

我试图从 Google Analytics Report API v4 中获取会话、收入、交易、跳出率数据,并按 Chanel 分组:

  • 自然搜索
  • 电子邮件
  • 直接的
  • 品牌付费搜索
  • 社会的
  • 推荐
  • .. ETC

现在我正在编写一个带有测试请求的Java模块,它设置了以下参数:

方面:

ga:acquisitionTrafficChannel;

指标:

ga:会话

ga:percentNewSessions

ga:新用户

当我使用ga:acquisitionTrafficChannel + ga:sessionsGA Report api 返回值,但是当我尝试添加请求ga:percentNewSessions, ga:newUsers时,它返回错误:

{
  "domain": "global",
  "message": "Selected dimensions and metrics cannot be queried together.",
  "reason": "badRequest"
}

要在代码中执行请求,我执行以下操作:

DateRange dateRange = new DateRange();
            dateRange.setStartDate("2015-06-15");
            dateRange.setEndDate("2015-06-30");
            ReportRequest request = new ReportRequest()
                    .setViewId(context.getProperty(VIEW_ID).evaluateAttributeExpressions().getValue())
                    .setDateRanges(Arrays.asList(dateRange))
                    .setDimensions(Arrays.asList(
                            new Dimension().setName("ga:acquisitionTrafficChannel")
                    ))
                    .setMetrics(Arrays.asList(
                            new Metric().setExpression("ga:sessions"),
                            new Metric().setExpression("ga:percentNewSessions"),
                            new Metric().setExpression("ga:newUsers")
                    ));

            ArrayList<ReportRequest> requests = new ArrayList<>();
            requests.add(request);
            GetReportsRequest getReport = new GetReportsRequest().setReportRequests(requests);
            GetReportsResponse response = service.reports().batchGet(getReport).execute();

如何正确请求?我走的方向正确吗?

因为正如我所说,我需要对收入、跳出率做同样的事情。但我不完全理解如何将指标和维度结合起来而不会出错。

谢谢你的帮助

4

1 回答 1

1

About my question:

As solution for my needs I used following combination in code:

To get all Channel groups ("Organic Search, Email, Direct, etc") I used following dimension: ga:channelGrouping - it will return all

To get values for Sessions, Revenue, Transactions, Bounce Rate, etc I used following metrics:

ga:sessions
ga:transactionRevenue
ga:transactions
ga:bounceRate

Also here can be more metrics if it is needed.

Maybe it will be useful to somebody.

Actually, question about error with combination in question (with ga:acquisitionTrafficChannel) is still open :)

于 2017-04-13T14:52:17.100 回答