I trying to get Sessions, Revenue, Transactions, Bounce Rate data from Google Analytics Report API v4 with grouping by Chanel:
Right now I'm programming a Java module with test Request which has setted following parameters:
Dimensions:
ga:acquisitionTrafficChannel;
Metrics:
ga:sessions
ga:percentNewSessions
ga:newUsers
When I use ga:acquisitionTrafficChannel + ga:sessions
GA Report api returns values, but when I try to add in request ga:percentNewSessions, ga:newUsers , it returns error:
{
"domain": "global",
"message": "Selected dimensions and metrics cannot be queried together.",
"reason": "badRequest"
}
To perform request in code I do following:
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();
How to do request correctly? Is in the right direction do I go?
Because as I said, I will need to do same thing with Revenue, Bounce Rate.. but I not fully understand how to combine Metrics and Dimensions without errors.
Thanks for any help
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 :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.