[R] Referencing multiple lists in api loop call

Graeme Davidson gr@eme@r@d@v|d@on @end|ng |rom gm@||@com
Wed May 1 17:10:50 CEST 2019


Hi all, 

I am working with a google analytics api, and need to pull out data on multiple views (n = 11, basically different databases with the same data types and formats).  However, in addition to this I need to specify the beginning and end date separately, in to get each months data, and I need to do this over multiple months (n = 6). Longer date ranges are not suitable, as the data aggregates between the specified dates.

I am using the RGA package for this as I need to pull out multichannel data. 

My attempt pulls in the data but only for one month. I am not sure how to specify the lists of the start and end dates for each month. Happy to use a different approach if this is not optimal. 

install.packages(“RGA”)
library(RGA)


#get list of month dates for last 6 months
end_months <- ymd("2018-11-01")+ months(0:6)-days(1)
start_months <- ymd("2018-10-01")+ months(0:6)

#list of view ids required to make api call (pseudonymised)
viewId <- c(26494958, 477448251,
            47843527, 96382507,
            537821552, 67482819)

for (i in viewId) {
  ga_data_temp <-
    get_mcf(i, #=This is a (dynamic) ViewID parameter
            start.date = "2019-01-01", end.date = "2019-01-31",
                     dimensions=c('mcf:conversionGoalNumber', 'mcf:basicChannelGroupingPath'),
                     metrics=c('mcf:totalConversions', 'mcf:totalConversionValue'))
  ga_data_temp$viewId <- i
  ga_data_final <- rbind(ga_data_final, ga_data_temp)
}


Thanks for any support in advance. 

All the best

Graeme

Graeme R Davidson PhD

Data and Insight Analyst 


More information about the R-help mailing list