Analytics
2.5K members online now
2.5K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Using Segments and Cohorts in Reporting API V4 results in 400 error

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello,

 

I have been attempting to use the Google Analytics Reporting API V4 with JSON to query cohort user retention data. The API works as expected for simple queries and returns day-by-day active users for a request like:

 

{

  "reportRequests" : [ {

    "viewId" : "xxxxxxxx",

    "dateRanges" : [ ],

    "metrics" : [ {

      "expression" : "ga:cohortActiveUsers",

      "formattingType" : "INTEGER"

    } ],

    "dimensions" : [ {

      "name" : "ga:cohort"

    }, {

      "name" : "ga:cohortNthDay"

    } ],

    "cohortGroup" : {

      "cohorts" : [ {

        "name" : "2016-06-07",

        "type" : "FIRST_VISIT_DATE",

        "dateRange" : {

          "startDate" : "2016-06-07",

          "endDate" : "2016-06-07"

        }

      } ]

    }

  } ]

}

 

A problem arises, however, when I attempt to filter the data using segments. A request with an added segment returns a 400 error. For example:

 

{

  "reportRequests" : [ {

    "viewId" : "xxxxxxxx",

    "dateRanges" : [ ],

    "metrics" : [ {

      "expression" : "ga:cohortActiveUsers",

      "formattingType" : "INTEGER"

    } ],

    "dimensions" : [ {

      "name" : "ga:segment"

    }, {

      "name" : "ga:cohort"

    }, {

      "name" : "ga:cohortNthDay"

    } ],

    "segments" : [ {

      "dynamicSegment" : {

        "name" : "USUsers",

        "sessionSegment" : {

          "segmentFilters" : [ {

            "simpleSegment" : {

              "orFiltersForSegment" : [ {

                "segmentFilterClauses" : [ {

                  "dimensionFilter" : {

                    "dimensionName" : "ga:country",

                    "operator" : "EXACT",

                    "expressions" : [ "United States" ]

                  }

                } ]

              } ]

            }

          } ]

        }

      }

    } ],

    "cohortGroup" : {

      "cohorts" : [ {

        "name" : "2016-06-07",

        "type" : "FIRST_VISIT_DATE",

        "dateRange" : {

          "startDate" : "2016-06-07",

          "endDate" : "2016-06-07"

        }

      } ]

    }

  } ]

}

 

The error that is returned:

 

400 - {
"error": {
"code": 400,
"message": "Selected dimensions and metrics cannot be queried together.",
"status": "INVALID_ARGUMENT"
}
}

 

I'm wondering if it is even possible to apply segments along with cohorts using the reporting API at this time.

 

Thank you,

Jesse

Using Segments and Cohorts in Reporting API V4 results in 400 error

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

Hi I am also trying to display cohort report. Please share the JSP example how to display cohort report using EmbedAPI v4.