Last active
April 12, 2016 18:06
-
-
Save ryanpraski/1a2229b94909b8f323bf761bff6c681e to your computer and use it in GitHub Desktop.
Shiny app to visualize clicks, impressions, and position by week for Google Organic non brand keywords. Uses searchConsoleR library to pull Google Search Console data.
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(shiny) | |
library(ggvis) | |
runApp(shinyApp( | |
ui <- fluidPage( | |
sidebarLayout( | |
sidebarPanel( | |
uiOutput("choose_dataset") | |
), | |
mainPanel(ggvisOutput("plot1"), ggvisOutput("plot2"), ggvisOutput("plot3")) | |
) | |
), | |
server = function(input, output, session) { | |
output$choose_dataset <- renderUI({ | |
selectInput("dataset", "Keyword", unique(positionsmelt$query)) | |
}) | |
library(googleAuthR) | |
library(searchConsoleR) | |
library(Rmisc) | |
library(dplyr) | |
library(gdata) | |
library(ggplot2) | |
library(reshape) | |
website <- "http://www.ryanpraski.com" | |
download_dimensions <- 'query' | |
type <- c('web') | |
gar_auth() | |
rsd <- as.Date("2016-04-05") | |
x<- c(rsd-11*7,rsd-10*7,rsd-9*7,rsd-8*7,rsd-7*7,rsd-6*7,rsd-5*7,rsd-4*7,rsd-3*7,rsd-2*7,rsd-1*7,rsd) | |
as.character(x) -> x | |
k <-0 | |
for(i in x) { | |
j<-as.Date(i) | |
start <- j | |
end <- start + 7 | |
searchquery <- search_analytics(siteURL = website, | |
startDate = start, | |
endDate = end, | |
dimensions = download_dimensions, | |
searchType = type, | |
rowLimit = 5000) | |
k<-k+1 | |
week <- rep(k, length(searchquery$clicks)) | |
colnames(searchquery)[2:5] <-paste(colnames(searchquery)[2:5],k, sep="") | |
assign(paste("search", k , sep=""), searchquery) | |
} | |
report<-merge(search1,search2, by="query", suffixes=c(".1",".2")) | |
report<-merge(report,search3,by="query",suffixes = ".3") | |
report<-merge(report,search4,by="query") | |
report<-merge(report,search5,by="query") | |
report<-merge(report,search6,by="query") | |
report<-merge(report,search7,by="query") | |
report<-merge(report,search8,by="query") | |
report<-merge(report,search9,by="query") | |
report<-merge(report,search10,by="query") | |
report<-merge(report,search11,by="query") | |
report<-merge(report,search12,by="query") | |
report <- report %>% filter(!grepl("ryanpraski",query)) | |
report <- report %>% filter(!grepl("ryanpraski",query)) %>% arrange(desc(impressions1)) | |
report <- head(report, 30) | |
clicksCols<-c(colnames(report[1]), matchcols(report, with=c("clicks"))) | |
clicks <- subset(report, select=clicksCols) | |
imprCols<-c(colnames(report[1]), matchcols(report, with=c("impressions"))) | |
impressions <-subset(report, select=imprCols) | |
posCols <-c(colnames(report[1]), matchcols(report, with=c("position"))) | |
position <- subset(report, select=posCols) | |
clicksmelt <- melt(clicks, id.vars = "query") | |
clicksmelt$variable<-gsub("clicks", "", clicksmelt$variable) | |
impressionssmelt <- melt(impressions, id.vars = "query") | |
impressionssmelt$variable<-gsub("impressions", "", impressionssmelt$variable) | |
positionsmelt <- melt(position, id.vars = "query") | |
positionsmelt$variable<-gsub("position", "", positionsmelt$variable) | |
observeEvent(input$dataset, { | |
data1 <- filter(clicksmelt, clicksmelt$query == input$dataset) | |
data2 <- filter(positionsmelt, positionsmelt$query == input$dataset) | |
data3 <- filter(impressionssmelt, impressionssmelt$query == input$dataset) | |
data1 %>% | |
ggvis(~variable, ~value) %>% | |
layer_bars() %>% | |
add_axis("x", title = "Week") %>% | |
add_axis("y", title = "Clicks") %>% | |
set_options(width = 500, height = 300) %>% | |
bind_shiny("plot1") | |
data2 %>% | |
ggvis(~variable, ~value) %>% | |
layer_bars() %>% | |
add_axis("x", title = "Week") %>% | |
add_axis("y", title = "Position") %>% | |
set_options(width = 500, height = 300) %>% | |
bind_shiny("plot2") | |
data3 %>% | |
ggvis(~variable, ~value) %>% | |
layer_bars() %>% | |
add_axis("x", title = "Week") %>% | |
add_axis("y", title = "Impressions") %>% | |
set_options(width = 500, height = 300) %>% | |
bind_shiny("plot3") | |
}) | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment