Title: | Advertisement Metrics Calculation |
---|---|
Description: | Calculations of the most common metrics of automated advertisement and plotting of them with trend and forecast. Calculations and description of metrics is taken from different RTB platforms support documentation. Plotting and forecasting is based on packages 'forecast', described in Rob J Hyndman and George Athanasopoulos (2021) "Forecasting: Principles and Practice" <https://otexts.com/fpp3/> and Rob J Hyndman et al "Documentation for 'forecast'" (2003) <https://pkg.robjhyndman.com/forecast/>, and 'ggplot2', described in Hadley Wickham et al "Documentation for 'ggplot2'" (2015) <https://ggplot2.tidyverse.org/>, and Hadley Wickham, Danielle Navarro, and Thomas Lin Pedersen (2015) "ggplot2: Elegant Graphics for Data Analysis" <https://ggplot2-book.org/>. |
Authors: | Ivan Nemtsev [aut, cre, cph] |
Maintainer: | Ivan Nemtsev <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-03-01 03:35:13 UTC |
Source: | https://github.com/cran/AutoAds |
A combination of functions view_percent, eCPM, CPMv, CTR, and fill_rate in one.
adstats(data)
adstats(data)
data |
A dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Requests', 'Impressions', 'Revenue', 'Viewable', and 'Clicks'. |
view_percent |
A percentage of viewable impressions among the total number of impressions. |
eCPM |
Cost per thousand impressions of an ad, shown in the currency the original file had for 'Revenue'. |
CPMv |
Cost per thousand viewable impressions of an ad, shown in the currency the original file had for 'Revenue'. |
CTR |
A ratio of clicks to impressions. |
fill_rate |
A ratio of impressions to requests as a percentage. |
Dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Requests', 'Impressions', 'Revenue', 'Viewable', and 'Clicks'.
Ivan Nemtsev
## The function is currently defined as adstats <- function(data){ data$ViewablePercent <- view_percent(data) data$eCPM <- eCPM(data) data$CPMv <- CPMv(data) data$CTR <- CTR(data) data$FillRate <- fill_rate(data) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data <- adstats(data)
## The function is currently defined as adstats <- function(data){ data$ViewablePercent <- view_percent(data) data$eCPM <- eCPM(data) data$CPMv <- CPMv(data) data$CTR <- CTR(data) data$FillRate <- fill_rate(data) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data <- adstats(data)
A ratio showing how much actual clicks on the ad cost.
CPC(data)
CPC(data)
data |
Dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Clicks' and 'Revenue'. |
A ratio of revenue to clicks - a cost of one click.
Dataset has to be named 'data' and include columns 'Clicks' and 'Revenue'.
Ivan Nemtsev
## The function is currently defined as CPC <- function(data){ x <- data$Clicks y <- data$Revenue round( y/x, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$CPC <- CPC(data)
## The function is currently defined as CPC <- function(data){ x <- data$Clicks y <- data$Revenue round( y/x, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$CPC <- CPC(data)
Calculating CPMv based on Viewable Impressions and Revenue data. The dataset has to be named 'data' and include columns 'Viewable' and 'Revenue'.
CPMv(data)
CPMv(data)
data |
Dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Viewable' and 'Revenue'. |
Cost per thousand viewable impressions of an ad, shown in the currency the original file had for 'Revenue'.
Dataset has to be named 'data' and include columns 'Viewable' and 'Revenue'.
Ivan Nemtsev
## The function is currently defined as CPMv <- function(data){ x <- data$Viewable y <- data$Revenue round( y/x*1000, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$CPMv <- CPMv(data)
## The function is currently defined as CPMv <- function(data){ x <- data$Viewable y <- data$Revenue round( y/x*1000, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$CPMv <- CPMv(data)
A ratio showing how often people who see your ad end up clicking on it.
CTR(data)
CTR(data)
data |
Dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Impressions' and 'Clicks'. |
A ratio of clicks to impressions.
Dataset has to be named 'data' and include columns 'Impressions' and 'Clicks'.
Ivan Nemtsev
## The function is currently defined as CTR <- function(data){ x <- data$Impressions y <- data$Clicks round( y/x, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$CTR <- CTR(data)
## The function is currently defined as CTR <- function(data){ x <- data$Impressions y <- data$Clicks round( y/x, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$CTR <- CTR(data)
Calculating eCPM based on Impressions and Revenue data. The dataset has to be named 'data' and include columns 'Impressions' and 'Revenue'.
eCPM(data)
eCPM(data)
data |
Dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Impressions' and 'Revenue'. |
Cost per thousand impressions of an ad, shown in the currency the original file had for 'Revenue'.
Dataset has to be named 'data' and include columns 'Impressions' and 'Revenue'.
Ivan Nemtsev
## The function is currently defined as eCPM <- function(data){ x <- data$Impressions y <- data$Revenue round( y/x*1000, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$eCPM <- eCPM(data)
## The function is currently defined as eCPM <- function(data){ x <- data$Impressions y <- data$Revenue round( y/x*1000, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$eCPM <- eCPM(data)
A percentage of returned ads that were displayed in the app to the user out of all requested ones.
fill_rate(data)
fill_rate(data)
data |
Dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Requests' and 'Impressions'. |
A ratio of impressions to requests as a percentage.
Dataset has to be named 'data' and include columns 'Requests' and 'Impressions'.
Ivan Nemtsev
## The function is currently defined as fill_rate <- function(data){ x <- data$Requests y <- data$Impressions round( y/x*100, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$FillRate <- fill_rate(data)
## The function is currently defined as fill_rate <- function(data){ x <- data$Requests y <- data$Impressions round( y/x*100, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$FillRate <- fill_rate(data)
Plotting metrics of the dataset with trend and forecast, splitting them by groups of different ad blocks.
plot_trend_and_forecast(data, x_col, y_col, group_col)
plot_trend_and_forecast(data, x_col, y_col, group_col)
data |
Dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Date', 'Block', and at least one with the data needed to plot ('Requests', 'Impressions', 'Revenue', 'Viewable', 'Clicks'). |
x_col |
Column of the dataset 'data' with the data required for the x-axis of the plot. Preferrably 'Date'. |
y_col |
Column of the dataset 'data' with the data required for the y-axis of the plot. Preferrably the one with the data needed to plot ('Requests', 'Impressions', 'Revenue', 'Viewable', 'Clicks'). |
group_col |
Column of the dataset 'data' with the data required for grouping the data. Preferrably 'Block'. |
A plot of the chosen data with trend and forecast.
This function also requires packages 'ggplot2', and 'forecast'. Dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Date', 'Block', and at least one with the data needed to plot ('Requests', 'Impressions', 'Revenue', 'Viewable', 'Clicks').
Ivan Nemtsev
Hyndman, R. J., & Athanasopoulos, G. (2018). "Forecasting: Principles and Practice" - https://otexts.com/fpp3/ Documentation for 'forecast' - https://pkg.robjhyndman.com/forecast/ Documentation for 'ggplot2' - https://ggplot2.tidyverse.org/ Wickham, H. (2016). "ggplot2: Elegant Graphics for Data Analysis" - https://ggplot2-book.org/
## The function is currently defined as plot_trend_and_forecast <- function(data, x_col, y_col, group_col) { data$Date <- as.Date(data$Date) data_groups <- split(data, data[[group_col]]) for (group in names(data_groups)) { group_data <- data_groups[[group]] time_series <- ts(group_data[[y_col]], frequency = 1, start = min(group_data[[x_col]])) arima_model <- auto.arima(time_series) forecast <- forecast(arima_model, h = 6) forecast_dates <- seq(max(group_data[[x_col]]) + 1, to = max(group_data[[x_col]]) + length(forecast$mean), by = "day") forecast_data <- data.frame(Date = forecast_dates, Forecast = forecast$mean) print(ggplot() + geom_line(data = group_data, aes(x = !!rlang::sym(x_col), y = !!rlang::sym(y_col))) + geom_line(data = forecast_data, aes(x = Date, y = Forecast), color = "blue") + geom_ribbon(data = forecast_data, aes(x = Date, ymin = forecast$lower[, 2], ymax = forecast$upper[, 2]), fill = "blue", alpha = 0.2) + labs(x = x_col, y = y_col, title = group) + theme_minimal()) } } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) plot_trend_and_forecast(data, "Date", "Impressions", "Block") #Any value instead of Impressions can be here
## The function is currently defined as plot_trend_and_forecast <- function(data, x_col, y_col, group_col) { data$Date <- as.Date(data$Date) data_groups <- split(data, data[[group_col]]) for (group in names(data_groups)) { group_data <- data_groups[[group]] time_series <- ts(group_data[[y_col]], frequency = 1, start = min(group_data[[x_col]])) arima_model <- auto.arima(time_series) forecast <- forecast(arima_model, h = 6) forecast_dates <- seq(max(group_data[[x_col]]) + 1, to = max(group_data[[x_col]]) + length(forecast$mean), by = "day") forecast_data <- data.frame(Date = forecast_dates, Forecast = forecast$mean) print(ggplot() + geom_line(data = group_data, aes(x = !!rlang::sym(x_col), y = !!rlang::sym(y_col))) + geom_line(data = forecast_data, aes(x = Date, y = Forecast), color = "blue") + geom_ribbon(data = forecast_data, aes(x = Date, ymin = forecast$lower[, 2], ymax = forecast$upper[, 2]), fill = "blue", alpha = 0.2) + labs(x = x_col, y = y_col, title = group) + theme_minimal()) } } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) plot_trend_and_forecast(data, "Date", "Impressions", "Block") #Any value instead of Impressions can be here
A ratio of viewable impressions to all impressions, shown as a percent.
view_percent(data)
view_percent(data)
data |
Dataset downloaded from excel file, has to be assigned to 'data' and include columns 'Impressions' and 'Viewable'. |
A percentage of viewable impressions among the total number of impressions.
Dataset has to be named 'data' and include columns 'Impressions' and 'Viewable'.
Ivan Nemtsev
## The function is currently defined as view_percent <- function(data){ x <- data$Impressions y <- data$Viewable round( y/x*100, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$ViewablePercent <- view_percent(data)
## The function is currently defined as view_percent <- function(data){ x <- data$Impressions y <- data$Viewable round( y/x*100, digits=2) } ## Example of use: data <- data.frame( Date = c("2022-07-01", "2022-07-02", "2022-07-03", "2022-07-29", "2022-07-30", "2022-07-31"), Block = c("1_234", "1_234", "1_234", "1_235", "1_235", "1_235"), Requests = c(372234, 268816, 291224, 1928854, 1928290, 786539), Impressions = c(18537, 12432, 13764, 2839269, 2682648, 1114773), Revenue = c(13.5, 9.13, 8.85, 1669.0, 1654.0, 739.0), Clicks = c(1167, 720, 856, 214451, 196657, 93178), Viewable = c(13320, 8214, 9768, 2446884, 2243865, 1063158) ) data$ViewablePercent <- view_percent(data)