Reputation: 529
After attempting to run this piece of code with Universal Analytics version 4, I encountered an error: code :
def get_ua_report(analytics):
"""Fetches the report data from Google Analytics UA."""
return analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': config['UA_INITIAL_FETCH_FROM_DATE'], 'endDate': config['UA_FETCH_TO_DATE']}],
'metrics': [{'expression': 'ga:users'}],
'dimensions': [{'name': 'ga:date'}, {'name': 'ga:acquisitionSource'},{'name': 'ga:acquisitionCampaign'},{'name': 'ga:acquisitionMedium'},],
'pageSize': 10000
}
]
}
).execute()
Error occurred: <HttpError 400 when requesting https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json returned "Selected dimensions and metrics cannot be queried together.". Details: "Selected dimensions and metrics cannot be queried together.">
I checked all documents and used Google's tool (https://ga-dev-tools.google/dimensions-metrics-explorer/). It confirmed that the metrics and dimensions are compatible. can anyone help me fix this issue?
Upvotes: 0
Views: 75
Reputation: 116868
Solution is to pick different dimensions and metrics.
The reason they are incompatible is that the data doesn't exist so you can't query them together
Upvotes: 0