Cohorts and actions over the API
Create dynamic cohorts and actions with the REST API: the criteria tree, windows and step shapes, with copy-paste examples.
Authenticate as in Queries and insights over the API. The request and response schemas are in GET /v1/openapi.json.
To read one person's current cohort memberships from your server on each request, use the Profile API (cohorts in the profile); the routes on this page are management routes.
Cohorts
POST /v1/projects/{project_id}/cohorts takes name, kind (dynamic needs filters; static is filled with POST .../cohorts/{id}/upload), optional description and realtime. An upload (and POST .../cohorts/{id}/members with {"keys": [...]}) answers {cohort, submitted, matched, unmatched, column}: matched is how many of the submitted ids or emails named an existing person, unmatched the rest, which were not added.
filters is a tree. The root must be {"type": "and", "values": [...]} or {"type": "or", "values": [...]}; children go in values and each has a type:
{
"name": "Activated users",
"kind": "dynamic",
"filters": {
"type": "and",
"values": [
{"type": "performed", "event": "created_project", "window": {"days": 14}},
{"type": "performed", "event": "invited_teammate", "count": {"op": "gte", "n": 2}, "window": {"days": 30}},
{"type": "person_property", "filters": {"and": [{"key": "plan", "type": "person", "op": "neq", "value": "free"}]}}
]
}
}
| Fields |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A window is {"days": 7}, {"amount": 2, "unit": "week"} (day, week, month, year) or a fixed {"from": "...", "to": "..."}. Dynamic cohorts recalculate every 15 minutes; realtime: true also adds members as events arrive, for simple performed and person_property trees only.
Actions
An action names a set of interactions you can use like an event in queries. POST /v1/projects/{project_id}/actions takes name, optional description and webhook_endpoint_id, and steps: 1 to 50 alternatives. The action matches when any step does; all fields set inside one step must match.
{
"name": "Clicked Buy",
"steps": [
{"event": "$autocapture", "selector": "button.buy", "text": "Buy", "text_match": "contains"},
{"event": "$pageview", "url": "/checkout/done", "url_match": "contains"}
]
}A step may set event, selector, tag_name, text (+ text_match: exact or contains), href (+ href_match), url (+ url_match: exact, contains, regex), screen_name (+ screen_name_match) and properties (an and/or filter group). If event is left out it is $autocapture when an element field is set, $pageview when only url is set and $screen when only screen_name is set. Use the action in a query with {"type": "action", "id": "<action id>"} as the source.