Tatvic / RGoogleAnalytics

R Library to easily extract data from the Google Analytics API into R
227 stars 147 forks source link

RGoogleAnalytics error message: Your query matched 0 results..... #34

Open arielp1 opened 8 years ago

arielp1 commented 8 years ago

I try to extract data from several accounts in one script. few account has data and few empty, the problem is when no data i get an error message and the script stop to run.

Error message: Your query matched 0 results. Please verify your query using the Query Feed Explorer and re-run it. Error in GetDataFeed(query.uri) : no loop for break/next, jumping to top level

How to fix it and skip the empty account without stop the script.

My script:

lastday <- Sys.Date() - 1 daystorun <- as.numeric(round(difftime(Sys.Date(), '2016-07-01'), digit=0))

for(i in 1:daystorun){ start.date <- as.character(lastday - daystorun + i) end.date <- start.date view.id <- paste("ga:",v,sep="") query.list <- Init(start.date = start.date, end.date = start.date, dimensions = "ga:date, ga:medium, ga:source, ga:campaign", metrics = "ga:users",

max.results = 10000,

               sort = "-ga:date",
               filters = "ga:medium==XXXXX;ga:campaign=@XXXXXX;ga:source==XXXXXX",
               table.id = view.id)

ga.query <- QueryBuilder(query.list) ga.data <- GetReportData(ga.query, oauth_token, paginatequery = F) ga.data["viewID"] <- paste(v) df<-rbind(df,ga.data) print(paste(start.date,"",view.id)) } }

andreifoldes commented 7 years ago

I have the same issue unfortunately.

dikesh commented 7 years ago

This issue is resolved. Please try installing RGoogleAnalytics package using devtools.

devtools::install_github("Tatvic/RGoogleAnalytics")

james-faulkes commented 6 years ago

Hi there, I am having a similar issue running queries in a loop based on arielp1's post https://github.com/Tatvic/RGoogleAnalytics/issues/34

for (v in idsvector){
  start.date <- "2018-04-01"
  end.date <- "2018-04-02"
  view.id <- paste("ga:",v,sep="") #the View ID parameter need to have "ga:" in front of the ID 

  sourcequery.list <- Init(
    start.date = start.date,
    end.date =  end.date,
    dimensions = "ga:channelGrouping,ga:campaign,ga:source,ga:medium,ga:date",
    metrics = "ga:sessions,ga:bounces",
    table.id = view.id,
    max.results = 9999999
  )
  ga.sourcequery <- QueryBuilder(sourcequery.list)
  data <- GetReportData(ga.sourcequery, token, paginate_query = F, split_daywise = F)
  data$Property <- view.id
  df<-rbind(df,data)

The first profile passes but the second errors and throws the script out Error message:

Status of Query:
The API returned 771 results
Error in rep(xi, length.out = nvar) : 
  attempt to replicate an object of type 'closure'
githubqqqqq commented 6 years ago

I still have this error after installing it using devtools. Below is my code. It works without the filter but when I include the filter, it generates the error: "Your query matched 0 results. Please verify your query using the Query Feed Explorer and re-run it.Error in GetDataFeed(query.uri) : no loop for break/next, jumping to top level"

I tried it with Query Feed Explorer and it returned correct results. I'm using R3.4.0 through RStudio. Is there anything else I need to try? Thank you!

##########Code############### startdt<-"2018-06-01" enddt<-"2018-06-01" dimensions<-"ga:eventCategory,ga:eventAction,ga:eventLabel" dimensions<-"ga:eventCategory,ga:eventAction" metrics<-"ga:totalEvents" viewID<-'ga:00000000' query.list <- Init(start.date = startdt, end.date = enddt, dimensions = dimensions, metrics = metrics, filters = "ga:eventCategory==XXXXXX", max.results = 1000, table.id = viewID) ga.query <- QueryBuilder(query.list) output<-GetReportData(ga.query, oauth_token)

jdeboer commented 6 years ago

I would recommend using try or tryCatch to wrap the call and handle the exception. try and tryCatch are functions built-in to base R and they straight-forward to use - please refer to the help pages in R on how to use these.