Skip to content

Instantly share code, notes, and snippets.

@matt-bernhardt
Created December 9, 2013 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-bernhardt/7874720 to your computer and use it in GitHub Desktop.
Save matt-bernhardt/7874720 to your computer and use it in GitHub Desktop.
An R script to pull search activity from Google Analytics
pullSearchesGA <- function(GAprofile,startDate,endDate) {
# taken from http://stackoverflow.com/questions/6434663/r-why-does-looping-over-a-date-object-result-in-a-numeric-iterator
days <- seq(from=as.Date(startDate), to=as.Date(endDate),by='days')
result <- data.frame()
master <- data.frame()
for ( i in seq_along(days) )
{
print(i)
print(days[i])
result <- ga$getData(GAprofile, start.date = days[i], end.date = days[i], metrics=("ga:visits,ga:visitsWithEvent,ga:totalEvents,ga:eventValue"), dimensions = "ga:date,ga:eventCategory,ga:eventAction,ga:eventLabel", sort = "", filters = "ga:eventCategory==Discovery", segment = "")
print(" Bind to master")
master <- rbind(master,result)
}
return(master)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment