-
Optimizing Data Extraction from Google Analytics 4 API
Hey there, so here’s what’s happening. I’ve been pulling data from Google Analytics 4 API https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema?hl=en. Don’t know if you’ve noticed this as well but the data I get from GA4 and UA seems to be having a wild party ’cause they’re not matching, quite different in fact. I’m starting to wonder if this “sampling” thing is the culprit and I’m interested in knowing how to scoop up data without sampling. Like taking the ice-cream, and skipping the sprinkles, you know?
Here’s what I’ve been working with so far. I trail off after pulling 100,000 rows, let’s call ’em, “data nuggets” until the whole act flames out.
while True: print("offset: " + str(offset)) request = { "requests": [ { "dateRanges": [ { "startDate": "180daysAgo", "endDate": "today" } ], "dimensions": [{'name': name} for name in dimensions], "metrics": [{'name': name} for name in metrics], "offset": offset, "limit": 100000 } ] } # Make Request response = analytics_GA4.properties().batchRunReports(property=property_id, body=request).execute() #Stop Loop if response.get("reports")[0].get("rows") == : break; else: offset = offset + 100000
Log in to reply.