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.

Embed
Preview of the card
<a href="https://lucidace.com/help/cohorts-actions-api"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/9506ae47-dcec-4a72-881a-3c3a6d01f307/social-card.svg?v=3e7ae33eec8b" alt="Cohorts and actions over the API" width="600" height="315"></a>

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"}]}}
    ]
  }
}

type

Fields

performed / not_performed

event (or action_id), window; performed also takes count ({"op": "gte", "n": 3}; ops eq, gte, lte, gt, lt); both take filters

sequence / not_sequence

steps ([{"event": "a"}, {"event": "b"}]), window, within ({"amount": 1, "unit": "day"}; units minute, hour, day)

person_property

filters: an and/or group of person property tests

in_cohort / not_in_cohort

cohort_id

lifecycle

state (new, returning, dormant), window, optional event

stopped / started

event, previous and recent windows

regular

event, times, period, periods, min_periods

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.

Updated