Reputation: 11
I have getting an error like
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request { "code" : 400, "errors" : [ { "domain" : "global", "message" : "Selected dimensions and metrics cannot be queried together.", "reason" : "badRequest" } ], "message" : "Selected dimensions and metrics cannot be queried together."
Metrics are below: "ga:uniquePurchases,ga:itemRevenue,ga:transactionTax,ga:transactionShipping
Dimensions below: "ga:productName";
if (accessToken != null && refreshToken != null) {
JacksonFactory jacksonFactory = new JacksonFactory();
GoogleCredential credential =new GoogleCredential.Builder().setTransport(netHttpTransport)
.setJsonFactory(jacksonFactory).setClientSecrets(CLIENT_ID, CLIENT_SECRET).build();
credential.setAccessToken(accessToken);
credential.setRefreshToken(refreshToken);
analytics=new Analytics.Builder(netHttpTransport, jacksonFactory, credential).setApplicationName(APPLICATION_NAME).build();
try {
//AT a time we can get only 7 dimensions and 10 metrics
apiQuery = analytics.data().ga().get("ga:" + gleTokenInf.getProfileId(), TimeStamp1, TimeStamp2,getMetrics());
apiQuery.setDimensions(getDimensions());
gaData = apiQuery.execute();
log.info("Succesfully got the data for GA MOM Report from Analytics Interface ");
} catch (Exception ex) {
ex.printStackTrace();
}
}
Upvotes: 0
Views: 2329
Reputation: 136
You cannot query all combinations of dimensions and metrics in GA API. Your query will work if ga:productName is replaced with ga:transactionId.
Test API queries here here - https://ga-dev-tools.appspot.com/query-explorer/
Upvotes: 0