Last active
January 16, 2017 22:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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