User Tools

Site Tools


3._event_analysis.r
library(bigrquery)
library(dplyr)
 
project <- "panda-premium-analytics"
 
sql <- "select *
from adjust.03path_analysis
where event_country = 'IN'
group by id, log_date, network, event, timestamp, order, bundle_id, fb_campaign, campaign, event_country, ip
order by id, timestamp
"
 
data <- query_exec(sql, project = project, max_pages = Inf)
data_install <- data
data_path <- data
 
 
 
data$network <- as.factor(data$network)
data$event <- as.factor(data$event)
 
# global installs
global_installs <- data %>%
  group_by(network) %>%
  filter((event)=='install') %>%
  filter(n() > 50) %>%
  summarise(installs=n()) %>% 
  arrange(desc(installs)) %>%
  as.data.frame()
 
global_installs$installs <- as.numeric(global_installs$installs)
global_installs$network <- factor(global_installs$network,
                                  levels = global_installs$network[order(global_installs$installs,
                                                                         decreasing = TRUE)])
 
ggplot(global_installs, aes(x=network, y=installs)) + geom_bar(stat = "identity")
 
# global sales
global_sales <- data %>%
  group_by(network) %>%
  filter((event)=='sale') %>%
  filter(n() > 10) %>%
  summarise(sales=n()) %>% 
  arrange(desc(sales)) %>%
  as.data.frame()
 
global_sales$sales <- as.numeric(global_sales$sales)
global_sales$network <- factor(global_sales$network, 
                               levels = global_sales$network[order(global_sales$sales, 
                                                                   decreasing = TRUE)])
 
ggplot(global_sales, aes(x=network, y=sales)) + geom_bar(stat = "identity")
 
# 1st_sale-to-install ratio
 
 
count_installs <- data %>%
  group_by(network) %>%
  filter((event)=='install') %>%
  summarise(installs=n())
count_sales <- data %>%
  group_by(network) %>%
  filter((event)=='sale') %>%
  summarise(sales=n())
 
count_global <- count_installs %>%
  left_join(count_sales)
count_global[is.na(count_global)] <- 0
 
no_sales <- count_global %>%
  filter((sales) =='0') %>%
  arrange(desc(installs)) 
 
count_global <- count_global %>%
  filter((sales) > 0) %>%
  mutate(ratio = sales / installs * 100)
 
# to rescale
 
count_global$network <- factor(count_global$network, levels = count_global$network[order(count_global$ratio, decreasing = TRUE)])
ggplot(count_global, aes(x=network, y=ratio)) + geom_bar(stat = "identity")
 
 
 
# conversion paths frequency (to repeat with clicks too)
paths <- data_path %>%
  group_by(id) %>%
  filter(first(event)=='click' & event[2L] == 'sale') %>%
  filter(first(network) != network[2L])  %>%
  slice(1:2) %>%
  as.data.frame()
 
paths_grouped <- paths %>%
  group_by(id) %>%
  summarise(path = paste(network, collapse = '-'))
 
path_grouped_count <- paths_grouped %>%
  group_by(path) %>%
  summarise(count = n())
 
write.csv(path_grouped_count, file = '/Users/vincenzo/Desktop/1.install_sale_analysis/ios/IN/3.\ Event\ Analysis/conv_path.csv')
3._event_analysis.r.txt · Last modified: 2015/12/16 13:00 by vincenzo