alexeymosco
alexeymosco

Reputation: 311

R googleanalyticsR: strangely, data are not available

I set cron job at 5:00 AM to download page-view data for the past day.

For two days, though, I experience the lack of the data with this log:

2019-09-05 05:00:03> anti_sample set to TRUE. Mitigating sampling via multiple API calls. 2019-09-05 05:00:03> Finding how much sampling in data request... 2019-09-05 05:00:04> Downloaded [0] rows from a total of []. 2019-09-05 05:00:04> No sampling found, returning call 2019-09-05 05:00:04> Downloaded [0] rows from a total of [].

When I run the script manually later during the day I get the data...

Do you have any clues what is happening to cause this behaviour?

(I checked the timezone of our GA account, and it is exactly my city's.)

Update: I edited crontab to run every hour, looking for a possible time threshold when GA report data gets processed and available.

library(googleAuthR)
library(googleAnalyticsR)

service_token <- googleAuthR::gar_auth_service("My Project .......json")


        ## fetch data

        gaid <- .....

        recent_dat_ga <- google_analytics(
          viewId = gaid,    # replace this with your view ID
          date_range = c(
               as.character(Sys.Date()-1)
               , as.character(Sys.Date()-1)
          ),
          metrics = "pageviews"
          , dimensions = c("pagePath", "date")
          , anti_sample = T
        )

Upvotes: 1

Views: 106

Answers (1)

alexeymosco
alexeymosco

Reputation: 311

So, the problem was simple. Google prepares and process daily data with certain time lag. For example, I am in UTC+3 timezone, and I have to wait until 8 AM to get the data for the past day ready. The solution is to check for the fresh data once in a while, so that it does not get lost.

Upvotes: 1

Related Questions