R/reports_ranked.R

#' Get a ranked reports
#'
#' @param date_range A two length vector of start and end Date objects
#' @param metrics Metric to send
#' @param dimensions Dimension to send
#' @param num_rows How many rows
#' @param rsid Adobe report number
#'
#' @export
aa_ranked_report <- function(date_range,
                             metrics,
                             dimensions,
                             num_rows,
                             rsid = Sys.getenv("ADOBE_API_RSID")){

  timeframe <- make_timeframe(date_range[[1]], date_range[[2]])

  req_body <- list(
    rsid = rsid,
    globalFilters = list(
      type = "dateRange",
      dateRange = timeframe
    ),
    metricContainer = list(
      metrics = list(
        columnId = 0,
        id = sprintf("metrics/%s", metrics),
        sort = "desc"
      )
    ),
    dimension = sprintf("variables/%s", dimensions),
    settings = list(
      countRepeatInstances = TRUE,
      limit = num_rows,
      page = 0
    ),
    statistics = list(
      functions = c("col-max", "col-min")
    )
  )

  res <- aa_get_data("reports/ranked", body = req_body)

  # parse response here
  res
}
MarkEdmondson1234/adobeAnalyticsR documentation built on July 2, 2019, 8:43 p.m.