Skip to main content

Get Cohort Analytics and Metrics

Enterprise

This endpoint is part of Countly Enterprise. To get access, contact sales or compare versions. Existing customers can reach the support portal with questions.

Endpoint

/o?method=get_cohort_metrics

Overview

Retrieves aggregated value counts for requested user property metrics within a cohort.

Authentication

Pass api_key or auth_token as a query parameter, or send countly-token as a header. See Authentication.

Permissions

  • Required permission: Read on the cohorts feature

Request Parameters

ParameterTypeRequiredDescription
api_keyStringYes (or auth_token)API key for authentication
auth_tokenStringYes (or api_key)Auth token for authentication
app_idStringYesApplication identifier
cohort_idStringYesID of the cohort to get metrics for
metricsJSON Array StringYesMetric fields array, for example ["up.cc","up.p"]

Examples

Example 1: Read cohort metrics

Request:

curl -X GET "https://your-server.com/o?method=get_cohort_metrics" \
-d "api_key=YOUR_API_KEY" \
-d "app_id=YOUR_APP_ID" \
-d "cohort_id=COHORT_ID" \
-d 'metrics=["up.cc","up.p"]'

Response

Success Response

{
"in_cohort": 1050,
"metrics": {
"up.cc": {
"US": 700,
"DE": 200
},
"up.p": {
"iPhone": 600,
"Android": 450
}
}
}

Response Fields

FieldTypeDescription
in_cohortNumberCount of users currently in the cohort.
metricsObjectMetric-keyed distribution map for requested metric names.
metrics.<metricName>ObjectTop values for metric with counts.

Error Responses

No explicit returnMessage(...) path in this branch. Missing/invalid metrics input can fail during JSON parse before callback.

Behavior

  • Validates read permission for cohorts feature.
  • Parses metrics JSON array from request.
  • Aggregates cohort users from app_users{appId} where chr.<cohortId>.in = "true".
  • Returns:
    • in_cohort: matched user count
    • metrics: top 3 values per requested metric with counts

Use Cases

  1. Dashboard display: Show cohort performance metrics
  2. Trend analysis: Analyze cohort growth and engagement over time
  3. Retention comparison: Compare retention curves across cohorts
  4. Revenue reporting: Track monetization performance by cohort
  5. Anomaly detection: Identify unusual patterns in cohort metrics
  6. Benchmarking: Compare metrics against cohort targets
Implementation details

Database Collections

CollectionUsed forData touched by this endpoint
countly.app_users{app_id}Per-app user profilesStores user-level properties and profile fields affected by this endpoint.
countly.cohortsEndpoint data sourceStores endpoint-related records this endpoint reads or modifies.