artemklevtsov / RGA

A Google Analytics API client for R
http://cran.r-project.org/package=RGA
32 stars 13 forks source link

Bad request: Selected dimensions and metrics cannot be queried together. #51

Closed jburkhardt closed 6 years ago

jburkhardt commented 6 years ago

There is an issue with the ecommerce dimensions and metrics in get_ga. The combination of the metric ga:transactions with either one dimension of ga:productSku, ga:productName or ga:productCategoryleads to the following error:

Error: Client error: (400) Bad Request
Bad request: Selected dimensions and metrics cannot be queried together.

Example code:

get_ga(profileId = ***,
       token = ***,
       start.date = "2017-01-01",
       end.date = "2017-03-01",
       metrics = "ga:transactions",
       dimensions = "ga:productCategory",
       samplingLevel="HIGHER_PRECISION",
       fetch.by = "month")

Traceback

> traceback()
13: stop(res)
12: api_request(get_url(path, query), token)
11: get_data(path, query, token)
10: eval(expr, envir, enclos)
9: eval(expr, pf)
8: withVisible(eval(expr, pf))
7: evalVis(expr)
6: capture.output(pages[[i]] <- get_data(path, query, token))
5: withCallingHandlers(expr, message = function(c) invokeRestart("muffleMessage"))
4: suppressMessages(capture.output(pages[[i]] <- get_data(path, 
       query, token)))
3: fetch_by(path, query, by, token)
2: get_report("data/ga", query, token, fetch.by)
1: get_ga(profileId = ***, token = ***, 
       start.date = "2017-01-01", end.date = "2017-03-01", metrics = "ga:transactions", 
       dimensions = "ga:productCategory", samplingLevel = "HIGHER_PRECISION", 
       fetch.by = "month")

RGA Package:

> utils::bug.report(package = "RGA")
Package: RGA
 Version: 0.4.2
 Maintainer: Artem Klevtsov <a.a.klevtsov@gmail.com>
 Built: R 3.3.0; ; 2016-05-05 06:57:29 UTC; unix

R Version:
 platform = x86_64-apple-darwin13.4.0
 arch = x86_64
 os = darwin13.4.0
 system = x86_64, darwin13.4.0
 status = 
 major = 3
 minor = 3.2
 year = 2016
 month = 10
 day = 31
 svn rev = 71607
 language = R
 version.string = R version 3.3.2 (2016-10-31)
 nickname = Sincere Pumpkin Patch

Locale:
 en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

Search Path:
 .GlobalEnv, package:dplyr, package:RAdwords, package:RGA,
 tools:rstudio, package:stats, package:graphics,
 package:grDevices, package:utils, package:datasets,
 package:methods, Autoloads, package:base

Note: GA Ecommerce Tracking is implemented and data are available within the GA web interface.

jdeboer commented 6 years ago

That error is from the Google Analytics API server. As ga:productCategory is a product-level dimension, I would recommend using a product-level metric instead of a hit-level metric like transactions. Perhaps ga:uniquePurchases might give you what you're after.

artemklevtsov commented 6 years ago

Thank you for the report but as @jdeboer note it is not RGA package issue.

jburkhardt commented 6 years ago

@jdeboer Thank you for the explanation. You are totally right!