Skip to content

Instantly share code, notes, and snippets.

@wmcraver
Last active January 16, 2017 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmcraver/f90f4e8703e2d69eabab3e2356123db1 to your computer and use it in GitHub Desktop.
Save wmcraver/f90f4e8703e2d69eabab3e2356123db1 to your computer and use it in GitHub Desktop.
Use rSiteCatalyst to get the average revenue by day of week and hour of day for the last 30 days.
library(RSiteCatalyst)
library(lubridate)
library(dplyr)
# SCAuth Info -------------------------------------------------------------
SCAuth(key = "", #fill in with your own info
secret = "", #fill in with your own info
company = "" #fill in with your own info
)
# Pull report from Adobe Analytics ----------------------------------------
rs = 'myreportsuite'
# Run QueueOvertime report for revenue metrics for the last 30 days (not including today)
aaDat = QueueOvertime(
rs,
today() - 31,
today() - 1,
metrics = c("uniquevisitors", "orders", "revenue"),
date.granularity = "hour"
)
# Convert the datetime field to a better format
aaDat$datetime = as.Date(aaDat$datetime)
# Add the weekday to the data frame
aaDat$wday = wday(aaDat$datetime, label = T, abbr = T)
# Calculate the average revenue by weekday and hour of day
hourlyMetrics = aaDat %>%
group_by(wday, hour) %>%
summarize(
avgRevenue = round(mean(revenue), digits = 0),
avgOrders = round(mean(orders), digits = 0),
avgUniques = round(mean(uniquevisitors), digits = 0)
)
# Summary Questions -------------------------------------------------------
#Helps answer the question: If the site is taken down during x hour today, how will our revenue be impacted?
View(hourlyMetrics %>% filter(wday == wday(today(), label = T, abbr = T)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment