Closed artemklevtsov closed 10 years ago
Seems I found more universal solution:
filters <- "ga:eventCategory == Purchase Button || ga:sessions > 10000"
# available operators
ops <- c("==", "!=", ">", "<", ">=", "<=", "=@", "!@", "=-", "!-", "\\|\\|", "&&", "OR", "AND")
# make pattern for gsub
opsw <- paste("(\\ )+(", paste(ops, collapse = "|"), ")(\\ )+", sep = "")
# remove whitespaces around operators
filters <- gsub(opsw, "\\2", filters)
# replace logical operators
filters <- gsub("OR|\\|\\|", ",", filters)
filters <- gsub("AND|&&", ";", filters)
filters
#> [1] "ga:eventCategory==Purchase Button,ga:sessions>10000"
Looks great, could you commit it?
It's a good feature to have, however, I'm pretty sure that the official GA API does not allow whitespace in filters, that does not mean that rga shouldn't support it though.
Ok. commit and push it now.
I also have some ideas for further development:
httr::oauth2.0_token
in .rga.getToken
and send this token with GET(url, config = config(token = token)) in
rga` methods...extend.*
functions and export rga
class with package load.rga$help("getData")
. Doc source example:rga$methods(
list(
getData = function(ids, start.date = format(Sys.Date() - 8, "%Y-%m-%d"),
end.date = format(Sys.Date() - 1, "%Y-%m-%d"), date.format = "%Y-%m-%d",
metrics = "ga:users,ga:sessions,ga:pageviews", dimensions = "ga:date",
sort = "", filters = "", segment = "", fields = "",
start = 1, max, messages = TRUE, batch, walk = FALSE,
output.raw, output.formats, return.url = FALSE, rbr = FALSE, envir = .GlobalEnv) {
'Description
This method provide query the Core Reporting API for Google Analytics report data.
Arguments
ids: Google Analytics profile ID. Can be character (with or without "ga:" prefix) or integer.
start.date: Start date for fetching Analytics data in YYYY-MM-DD format.
end.date: End date for fetching Analytics data in YYYY-MM-DD format.
metrics: A comma-separated list of Analytics metrics, such as ga:sessions,ga:bounces.
dimensions: A comma-separated list of Analytics dimensions, such as ga:browser,ga:city.
sort: A comma-separated list of dimensions or metrics that determine the sort order for Analytics data.
filters: A comma-separated list of dimension or metric filters to be applied to Analytics data
segment: An Analytics segment to be applied to data.
fields: Selector specifying which fields to include in a partial response.
start: An index of the first entity to retrieve.
max: The maximum number of entries to include in this feed.
messages: Show message during process data.
batch: Extracting more then 10000 observations per pull. Can be logical or integer.
walk: Get the data unsampled.
output.raw: Specify variable for a copy ouput raw data without processing.
output.formats: Specify variable for a copy ouput data formats.
return.url: return request URL only.'
I already tested points 2 and 3. What do you think?
Woa, good idea.
I've been wanting to update a lot of the core functions of this package for a while now, adding the help is a good idea!
The package is using the S4, which is not really documented, so I was thinking about downgrading it to S3. Which would make it more likely to be accepted by CRAN as well.
Your package based on R5 (refClass) as I inderstand. And it realy good choise. I'll make pull request with changes about I sayd to above.
On github there is package based on S4 - https://github.com/jdeboer/ganalytics. Although it has less functionality.
Also I think we should exract duplicated code in methods to separate funcitons (for example, mcf and core have some duplications).
Yet interesting thing for a tab completion within rga class (source - http://stackoverflow.com/a/12545344/1863950):
# Tab completions for rga clas
.DollarNames.rga <- function(x, pattern) {
grep(pattern, getRefClass(class(x))$methods(), value = TRUE)
}
Handling white spaces only around operators (issue #36).