GA: How to access Cohort Analysis through the Google Analytics API?

Cohort presents indicators and indicators here . However, when I try to query it using the API (e.g. using Query Explorer ), a 400 error occurs.

One of the queries I tried: metrics = ga:cohortActiveUsers and dimensions = ga:cohortNthDay .

Can I request a Cohort Analysis report through the API?

+5
source share
1 answer

The problem you are facing is that Query explorer uses the v3 Google Analytics API. If you look at Dimensions and Metrics Explorer , you will notice that these dimensions have been added to the Google Analytics Reporting API .

The error message you receive is incorrect and should be fixed as soon as possible. It should specify something more like This metric cannot be used in Version 3 of the API . You caught this while we are in the process of deploying a new API. Which is now officially published, see Change log

To use these new dimensions and metrics, you must create a V4 code proposal :

 POST https://analyticsreporting.googleapis.com/v4/reports:batchGet { "reportRequests": [{ "viewId": "XXXX", # No date range is required in the request "dimensions": [{"name": "ga:cohort" },{"name": "ga:cohortNthDay" }], "metrics": [ {"expression": "ga:cohortActiveUsers" }, {"expression": "ga:cohortTotalUsers"} ], "cohortGroup": { "cohorts": [{ "name": "cohort 1", "type": "FIRST_VISIT_DATE", "dateRange": { "startDate": "2015-08-01", "endDate": "2015-08-01"} },{ "name": "cohort 2", "type": "FIRST_VISIT_DATE", "dateRange": {"startDate": "2015-07-01", "endDate": "2015-07-01"} }] } }] } 
0
source

Source: https://habr.com/ru/post/1246633/


All Articles