Closed cevaboyz closed 2 years ago
Thanks, as I mentioned in the SO answer you can always get around errors like this if you have valid json using raw_json
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.
When I compare the working vs bugged call I found it worked if I removed the metricAggregations that by default are added to each GA4 API call when using ga_data()
:
try <- '{"metrics":[{"name":"itemPurchaseQuantity"},{"name":"itemRevenue"},{"name":"averagePurchaseRevenue"}],"metricAggregations":["TOTAL","MAXIMUM","MINIMUM"],"dimensions":[{"name":"nthWeek"},{"name":"itemId"}],"dateRanges":[{"startDate":"2022-08-01","endDate":"2022-08-07"}],"keepEmptyRows":true,"limit":10}'
# errors
ga_data(propertyId = propety_id, raw_json = try)
Removing metricAggregations
fixes it
try <- '{"metrics":[{"name":"itemPurchaseQuantity"},{"name":"itemRevenue"},{"name":"averagePurchaseRevenue"}],"dimensions":[{"name":"nthWeek"},{"name":"itemId"}],"dateRanges":[{"startDate":"2022-08-01","endDate":"2022-08-07"}],"keepEmptyRows":true,"limit":10,"returnPropertyQuota":true}'
# works
ga_data(propertyId = propety_id, raw_json = try)
I'll change it to make metricAggregations
opt in rather than on every call, if it causes this behaviour it may be also affecting others.
thanks for the report :)
@MarkEdmondson1234 Thank you, it was an oversight on my part that I did not see that you could use the raw json to make the call. I'm glad my oversight could bring something positive and thank you for your work!
I'll keep this open to track the code change
What goes wrong
Getting a 500 error whit a specific query
Steps to reproduce the problem
Expected output
Actual output
Before you run your code, please run:
options(googleAuthR.verbose=2)
and copy-paste the console output here.Session Info