Skip to main content

Retention Segments - Read

Endpoint

/o?method=retention

Enterprise Only
This API is available exclusively in Countly Enterprise.

Overview

Returns retention data for selected period and event scope.

Authentication

Authentication methods:

  • API Key (parameter): api_key=YOUR_API_KEY
  • Auth Token (parameter): auth_token=YOUR_AUTH_TOKEN
  • Auth Token (header): countly-token: YOUR_AUTH_TOKEN

Permissions

  • Retention Segments: Read permission.

Request Parameters

ParameterTypeRequiredDescription
api_keyStringYes (or auth_token)API key authentication
auth_tokenStringYes (or api_key)Auth token authentication
app_idStringYesApp ID
methodStringYesMust be retention
periodStringYesadaily, aweekly, or amonthly
rettypeStringNofull, classic, or unbounded; default full
evtStringNoEvent key; default [CLY]_session
rangeString (JSON Array)NoTimestamp range [from,to] in milliseconds
spanNumberNoLast N units when range is not provided
queryString (JSON Object)NoUser filter query
save_reportBoolean/StringNoEnables long report workflow
no_cacheBoolean/StringNoBypass retention cache

Configuration Impact

SettingDefaultAffectsUser-visible impact
retention_segments.span10Default span when request omits span and rangeChanges default number of returned retention buckets

Response

Success Response

[
{
"_id": "20260210",
"tu": 152,
"1": 58,
"2": 37,
"3": 30
},
{
"_id": "20260211",
"tu": 167,
"1": 63,
"2": 35,
"3": 22
}
]

Response Fields

FieldTypeDescription
_idStringCohort start date in yyyymmdd format
tuNumberTotal users in the cohort
1, 2, 3, ...NumberReturning users at offset day/week/month

Error Responses

  • HTTP 400 - Missing auth:
{
"result": "Missing parameter \"api_key\" or \"auth_token\""
}
  • HTTP 401 - Invalid auth:
{
"result": "User does not exist"
}

Behavior/Processing

  • Applies defaults: rettype=full, evt=[CLY]_session.
  • Uses retention cache first unless no_cache=true.
  • Calculates cohort retention from event stream and optional user filter.
  • Supports long-running report mode with save_report.

Retention Type Differences

TypeUse CaseDefinition
fullStandard retentionUsers active on date X, returns on X+N
classicCohort analysisUsers first seen on X, returns on X+N
unboundedBroad analysisAny active user in range, then returns

Database Collections

CollectionUsed forData touched by this endpoint
countly.retention_cacheEndpoint data sourceStores endpoint-related records this endpoint reads or modifies.
countly_drill.drill_eventsDrill event recordsStores granular event rows queried or updated by this endpoint.
countly.app_users{appId}Per-app user profilesStores user-level properties and profile fields affected by this endpoint.

Examples

/o?api_key=YOUR_API_KEY&app_id=YOUR_APP_ID&method=retention&period=adaily&span=14
/o?api_key=YOUR_API_KEY&app_id=YOUR_APP_ID&method=retention&period=aweekly&rettype=classic&evt=purchase
/o?api_key=YOUR_API_KEY&app_id=YOUR_APP_ID&method=retention&period=adaily&range=[1738368000000,1739145599000]&query={"up.cc":"US"}

Limitations

  • Large spans and complex filters can take longer.
  • Cache is TTL-based and may lag latest writes.

Ⓔ Enterprise

This feature is part of Countly Enterprise.

Get Access:

Already a Customer? Use support portal if you have any questions.


Last Updated

2026-02-16