Reputation: 115
I'm trying to query the product sold the last week froma GA4 property with googleAnalyticsR package.
I can run multiple queries for other metrics and dimensions but I keep getting an error for this specific query:
top_products_sold_last_week <- googleAnalyticsR::ga_data(property_id,
date_range = c(last_monday, last_sunday),
metrics = c("itemPurchaseQuantity", "itemRevenue", "averagePurchaseRevenue"),
dimensions = c("nthWeek", "itemId"),limit = -1)
Request failed [500]. Retrying in 1.8 seconds...
Request failed [500]. Retrying in 2.4 seconds...
i 2022-08-08 10:43:33 > Request Status Code: 500
i 2022-08-08 10:43:33 > Trying again: 1 of 1
i 2022-08-08 10:43:36 > All attempts failed.
Error in `abort_http()`:
! http_500 Internal error encountered.
last_monday
and last sunday are dynamically generated and are both correct since in the other queries I get a correct response from the api.
I tried to manually query with the Query Explorer and I get a correct response, what am I missing?
This is the JSON request from the Query Explorer
{"dimensions":[{"name":"itemId"},{"name":"nthWeek"}],"metrics":[{"name":"averagePurchaseRevenue"},{"name":"itemPurchaseQuantity"},{"name":"itemRevenue"}],"dateRanges":[{"startDate":"2022-08-01","endDate":"2022-08-07"}]}
Upvotes: 1
Views: 340
Reputation: 2631
It does seem like a bug as I can replicate it, could you raise an issue on the project GitHub page? https://github.com/MarkEdmondson1234/googleAnalyticsR/issues
You can still progress if you have valid JSON by using the raw_json
parameter with your request e.g.
raw <- '{"dimensions":[{"name":"itemId"},{"name":"nthWeek"}],"metrics":[{"name":"averagePurchaseRevenue"},{"name":"itemPurchaseQuantity"},{"name":"itemRevenue"}],"dateRanges":[{"startDate":"2022-08-01","endDate":"2022-08-07"}]}
'
ga_data(propertyId = propety_id, raw_json = raw)
# Making API request with raw JSON: {"dimensions":[{"name":"itemId"},{"name":"nthWeek"}],"metric ...
# # A tibble: 10,000 × 5
itemId nthWeek averagePurchaseRevenue itemPurchaseQuantity itemRevenue
<chr> <chr> <dbl> <dbl> <dbl>
1 5016395 0000 15177. 2 3390.
2 5048751 0000 9378. 44 8798.
Upvotes: 2