Reputation: 1651
I am trying to get statisitcs on the top browsers used for my site using the analytics reporting api v3. I am using the Python version of the API. I am able to query the API and I do get a result. I query it using:
res = service.data().ga().get(ids='ga:' + profile_id, start_date='2014-01-01', end_date=t, metrics='ga:sessions', dimensions='ga:browser').execute()
But I do not know how to use the result data. My goal is to get the top 5 browsers. Can I somehow get this information directly or would I have to calculate it my self. How can I then access the rows in the result and the data in the rows?
Upvotes: 1
Views: 677
Reputation: 116968
This should work all I did was add a sort to so that your numbers are ordered highest first then set the max results to 5 this way you should only get 5 rows back.
res = service.data().ga().get(ids='ga:' + profile_id, start_date='2014-01-01', end_date=t, metrics='ga:sessions', dimensions='ga:browser',sort='-ga:sessions' , max_results='5' ).execute()
Note: It helps to test your querys you can check the sorting and the numbers that are retruned in the Google Analytics Query Explorer
Upvotes: 1
Reputation: 369
You should receive summary data along with the result set. Check this: https://developers.google.com/analytics/devguides/reporting/core/v3/reference#data_response
You can also apply sorting and limit which will give you only required data. i.e. apply sorting -ga:sessions (descending order) and limit by 5
Upvotes: 1