I need itemQuantity, itemRevenue, productName, transactionID. But when I am pulling all 4 together. Unable to get full data. So my approach is pulling transactionID first that is 37 000 something values saved that to data_frame_eight then running a for loop over those transactionIDs and then for that particular id pulling itemRevenue, productName and itemQuantity. Rbinding it to a data frame. In the end I need a final data frame with transactionID, itemRevenue, productName, itemQuantity together. This data frame will have multiple occurences of the transactionID as it going to be expanded by product name. Don't bother about the first for loop it is working perfectly fine. Logic - vise this approach is perfectly fine. help is needed in resolving the error
date_inputs <- read_excel("C:/Users/.../input_file.xlsx")
fetched_data_eight <- data.frame()
for (i in 1:nrow(date_inputs)) {
if(is.na(date_inputs$Status[i])){
# Get the start and end dates from the date_inputs data frame
view_id <- date_inputs$View_ID[i]
start_date <- as.Date(date_inputs$Start_Date[i])
end_date <- as.Date(date_inputs$End_Date[i])
# Query Google Analytics API for the specified date range and store the results
datanp <- google_analytics(view_id,
date_range = c(start_date, end_date),
metrics = c("ga:transactionRevenue"),
dimensions = c("ga:transactionId", "ga:date"),
anti_sample = TRUE,
)
str(datanp)
# Append the fetched data to the existing data frame
fetched_data_eight <- bind_rows(fetched_data_eight, datanp)
# Pause for a few seconds to avoid API rate limits
Sys.sleep(3)
date_inputs$Status[i] <- "Done"
writexl::write_xlsx(date_inputs, "input_file.xlsx")
}}
Help needed here in the second error
for (t in 1:length(fetched_data_eight$transactionId) ){
id <- fetched_data_eight$transactionId[t]
dimensions_filter <- list(dimension_name = "ga:transactionId",
operator = "EXACT",
expressions = id)
my_filter <- filter_clause_ga4(list(dimensions_filter))
datanpq <- google_analytics(view_id,
date_range = c("2018-10-01", "2023-05-24"),
metrics = c("ga:itemQuantity"),
dimensions = c("ga:productName"),
dim_filters = my_filter,
anti_sample = TRUE
)
}
Error in filter_clause_ga4(list(dimensions_filter)) : types[1] %in% c("dim_fil_ga4", "met_fil_ga4") is not TRUE