Analytics: What are the impacts of taking the site down right now?

16. January 2017 analytics, data, programming, r 0
Analytics: What are the impacts of taking the site down right now?

Ever been asked how the company’s revenue would impacted if the site needed to be taken offline for an hour? I wrote a script that uses the rSiteCatalyst package for Adobe Analytics to answer this question.  

The script starts by requesting a report using the QueueOvertime() function that includes the following metrics: unique visitors, orders, and revenue.  I generally request additional metrics in the event that the focus of the analysis changes.

# SCAuth Info -------------------------------------------------------------

SCAuth(key = "",
       secret = "",
       company = "")

# Run QueueOvertime report for revenue metrics for the last 30 days (not including today)
aaDat = QueueOvertime(
 reportsuite.id = "myreportsuite",
 date.from = today() - 31,
 date.to = today() - 1,
 metrics = c("uniquevisitors", "orders", "revenue"),
 date.granularity = "hour")

 

After the report is received, the datetime field is converted to the YMD format.  This is a preference of mine and by no means affects the rest of the script–you can skip it if you prefer.  Next, we need to add a column to the data frame in order by which to group.  This is accomplished by using Lubridate’s wday() function.

# Convert the datetime field to a better format.  Not really necessary, but my preference.
aaDat$datetime = as.Date(aaDat$datetime)

# Add the weekday to the data frame
aaDat$wday = wday(aaDat$datetime, label = T, abbr = T)

 

Now that we have the data out of Adobe Analytics, into a data frame, and a categorical column added, we’ll use the dplyr package to group and summarize the data.  The end goal is to have a neatly summarized table of data that we can use to convey a general estimation of the impact.  We’ll summarize the data by taking an average of the observations, which are now grouped by weekday and hour.  This is accomplished easily by piping (%>%) the data into a few of dplyr functions.  I wrap each one of the averaged metrics with the round() function, so that only whole numbers are presented.

# 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))

 

The final line in the script filters the hourlyData data set we created, by using wday == wday(today(), label = T, abbr = T) inside of the filter() function.  We end up with a view of the data that has today’s averaged data from the last 4 weeks broken down by hour.  We can quickly see how many orders we could potentially be missing out on if the site was taken down for the 10 AM hour.

# 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)))

 

Full script

library(RSiteCatalyst)
library(lubridate)
library(dplyr)


# SCAuth Info -------------------------------------------------------------

SCAuth(key = "",
       secret = "",
       company = "")

       
# Pull report from Adobe Analytics ----------------------------------------

# Run QueueOvertime report for revenue metrics for the last 30 days (not including today)
aaDat = QueueOvertime(
 reportsuite.id = "myreportsuite",
 date.from = today() - 31,
 date.to = today() - 1,
 metrics = c("uniquevisitors", "orders", "revenue"),
 date.granularity = "hour"
)


# Convert the datetime field to a better format.  Not really necessary, but my preference.
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)))

 


Leave a Reply