Reputation: 23
I am trying to pull Google analytics data using python google-api-client. But I need to mention the list of dimensions and metrics in the body of the request 'dimensions':[{'name' : 'ga:date'}]. But is there any way to get the full list of dimensions and metrics associated with a view ID. Can i get that list by API call?
sample_request = {
'viewId': 'xxxxxx',
'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
'metrics' : [{'expression' : 'ga:users'}],
'dimensions':[{'name' : 'ga:date'}]
}
response = api_client.reports().batchGet(
body={
'reportRequests': sample_request
}).execute()
Upvotes: 0
Views: 1939
Reputation: 61
There is an google analytics metadata api which provides an up-to-date list of all metrics and dimensions available in GA, if you really require a programmatic response.
Here's my example (using requests- there is a separate python metadata api that you can use, but as it doesn't require api keys in my experience it's easier to use requests- the reference for this & also how to use the python client library is here):
import requests
resp = requests.get("https://www.googleapis.com/analytics/v3/metadata/ga/columns?pp=1")
print(resp.json())
Unfortunately, the metadata API is limited in that you can't use it to identify which metrics and dimensions can be queried together in an Analytics API call. As mentioned by Michele you can use the dimensions and metrics explorer to explore which combinations of metrics and dimensions are possible to query by clicking the checkbox for the metric you are interested in, and seeing if this greys out the dimension.
Upvotes: 0
Reputation: 14197
Here you can find the list of all the metrics and dimensions that can be queried for any view in Analytics: https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/
Upvotes: 0