Skip to main content

Cohorts & Segmentation

Cohorts let you group subscribers into named segments for targeted notification delivery, performance tracking, and A/B comparisons. Create static cohorts with manually managed membership, or dynamic cohorts that automatically match subscribers based on rules.

Overview

FeatureDescription
Static CohortsManually add/remove members
Dynamic CohortsAuto-populate based on filter rules
MetricsTrack delivery, engagement, and conversion per cohort
SnapshotsCapture membership over time for trend analysis
ComparisonsA/B compare metrics between cohorts

Quick Start

Create a Cohort

curl -X POST https://api.zyphr.dev/v1/cohorts \
-H "X-API-Key: zy_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Power Users",
"slug": "power-users",
"type": "static",
"description": "Users with 10+ logins in the last 30 days"
}'
const cohort = await zyphr.cohorts.create({
name: 'Power Users',
slug: 'power-users',
type: 'static',
description: 'Users with 10+ logins in the last 30 days',
});

Add Members

curl -X POST https://api.zyphr.dev/v1/cohorts/power-users/members \
-H "X-API-Key: zy_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"subscriber_ids": ["user_123", "user_456", "user_789"]
}'

View Metrics

curl "https://api.zyphr.dev/v1/cohorts/power-users/metrics?start_date=2026-02-01&end_date=2026-02-28&channel=email" \
-H "X-API-Key: zy_live_your_api_key"

Creating Cohorts

Static Cohorts

Membership is explicitly managed — you add and remove subscribers:

curl -X POST https://api.zyphr.dev/v1/cohorts \
-H "X-API-Key: zy_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Beta Testers",
"slug": "beta-testers",
"type": "static"
}'

Dynamic Cohorts

Membership is automatically determined by filter rules:

curl -X POST https://api.zyphr.dev/v1/cohorts \
-H "X-API-Key: zy_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Enterprise Users",
"slug": "enterprise-users",
"type": "dynamic",
"rules": {
"operator": "and",
"conditions": [
{ "field": "metadata.plan", "operator": "eq", "value": "enterprise" },
{ "field": "metadata.status", "operator": "eq", "value": "active" }
]
}
}'

Cohort Parameters

ParameterTypeRequiredDescription
namestringYesHuman-readable name
slugstringNoURL-safe identifier (auto-generated from name if omitted)
typestringYesstatic or dynamic
descriptionstringNoDescription of the cohort's purpose
rulesobjectDynamic onlyFilter rules for automatic membership

List Cohorts

curl "https://api.zyphr.dev/v1/cohorts?status=active&page=1&per_page=25" \
-H "X-API-Key: zy_live_your_api_key"

Update a Cohort

curl -X PATCH https://api.zyphr.dev/v1/cohorts/COHORT_ID \
-H "X-API-Key: zy_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Name",
"description": "Updated description"
}'

Delete a Cohort

curl -X DELETE https://api.zyphr.dev/v1/cohorts/COHORT_ID \
-H "X-API-Key: zy_live_your_api_key"

Managing Members

Add Members (Static Cohorts)

curl -X POST https://api.zyphr.dev/v1/cohorts/COHORT_ID/members \
-H "X-API-Key: zy_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"subscriber_ids": ["user_123", "user_456"]
}'
await zyphr.cohorts.addMembers(cohortId, {
subscriberIds: ['user_123', 'user_456'],
});

Remove Members

curl -X DELETE https://api.zyphr.dev/v1/cohorts/COHORT_ID/members \
-H "X-API-Key: zy_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"subscriber_ids": ["user_123"]
}'

List Members

curl "https://api.zyphr.dev/v1/cohorts/COHORT_ID/members?page=1&per_page=25" \
-H "X-API-Key: zy_live_your_api_key"
note

For dynamic cohorts, the members endpoint returns the current matching subscribers based on the cohort's rules. You cannot add/remove members manually from dynamic cohorts.

Metrics & Analytics

Get Cohort Metrics

Track notification delivery and engagement metrics for a cohort:

curl "https://api.zyphr.dev/v1/cohorts/COHORT_ID/metrics?start_date=2026-02-01&end_date=2026-02-28&period_type=daily&channel=email" \
-H "X-API-Key: zy_live_your_api_key"

Query Parameters

ParameterTypeRequiredDescription
start_datestringYesStart date (YYYY-MM-DD)
end_datestringYesEnd date (YYYY-MM-DD)
period_typestringNoAggregation period: daily, weekly, monthly
channelstringNoFilter by channel: email, push, sms, in_app

Calculate Metrics

Trigger a metrics calculation over a date range:

curl -X POST https://api.zyphr.dev/v1/cohorts/COHORT_ID/metrics/calculate \
-H "X-API-Key: zy_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"start_date": "2026-02-01",
"end_date": "2026-02-28",
"period_type": "weekly"
}'

Snapshots

Capture a point-in-time record of cohort membership for trend analysis:

Create a Snapshot

curl -X POST https://api.zyphr.dev/v1/cohorts/COHORT_ID/snapshots \
-H "X-API-Key: zy_live_your_api_key"

View Snapshots Over Time

curl "https://api.zyphr.dev/v1/cohorts/COHORT_ID/snapshots?start_date=2026-01-01&end_date=2026-02-28" \
-H "X-API-Key: zy_live_your_api_key"

Returns an array of snapshots showing member count and composition at each point in time.

A/B Comparisons

Compare metrics between two or more cohorts side by side:

Create a Comparison

curl -X POST https://api.zyphr.dev/v1/cohorts/comparisons \
-H "X-API-Key: zy_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Free vs Pro Users",
"cohort_ids": ["cohort_free", "cohort_pro"]
}'
const comparison = await zyphr.cohorts.createComparison({
name: 'Free vs Pro Users',
cohortIds: ['cohort_free', 'cohort_pro'],
});

View Comparison Results

curl "https://api.zyphr.dev/v1/cohorts/comparisons/COMPARISON_ID?start_date=2026-02-01&end_date=2026-02-28" \
-H "X-API-Key: zy_live_your_api_key"

List Comparisons

curl "https://api.zyphr.dev/v1/cohorts/comparisons?page=1&per_page=10" \
-H "X-API-Key: zy_live_your_api_key"

Pin/Unpin Comparisons

Pin frequently used comparisons for quick access:

curl -X POST https://api.zyphr.dev/v1/cohorts/comparisons/COMPARISON_ID/pin \
-H "X-API-Key: zy_live_your_api_key"

Plan Limits

PlanMax CohortsComparisons
Free31
Starter105
Pro5025
ScaleUnlimitedUnlimited
EnterpriseUnlimitedUnlimited

API Reference

MethodEndpointDescription
POST/v1/cohortsCreate cohort
GET/v1/cohortsList cohorts
GET/v1/cohorts/:idGet cohort
PATCH/v1/cohorts/:idUpdate cohort
DELETE/v1/cohorts/:idDelete cohort
POST/v1/cohorts/:id/membersAdd members
DELETE/v1/cohorts/:id/membersRemove members
GET/v1/cohorts/:id/membersList members
GET/v1/cohorts/:id/metricsGet metrics
POST/v1/cohorts/:id/metrics/calculateCalculate metrics
POST/v1/cohorts/:id/snapshotsCreate snapshot
GET/v1/cohorts/:id/snapshotsView snapshots
POST/v1/cohorts/comparisonsCreate comparison
GET/v1/cohorts/comparisonsList comparisons
GET/v1/cohorts/comparisons/:idView comparison
DELETE/v1/cohorts/comparisons/:idDelete comparison
POST/v1/cohorts/comparisons/:id/pinToggle pin

Next Steps

  • Subscribers - Manage the subscribers that populate cohorts
  • Topics - Group subscribers by interest for fan-out delivery
  • Usage & Analytics - Track platform-wide usage metrics