Behavioral cohort design

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Behavioral cohort design is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Source: PostHog cohorts + Amplitude behavioral cohorts + Mixpanel cohort spec

How to use this skill

Skill file

<!--

Source: PostHog cohorts + Amplitude behavioral cohorts + Mixpanel cohort spec

-->

Behavioral Cohort Design SKILL

Define, build, and activate behavioral cohorts (multi-attribute, time-windowed). Static vs dynamic. PostHog, Amplitude, Mixpanel APIs + Hightouch activation. Foundation for every downstream growth action.

When to use

Trigger phrases:

Pair: cdp-segment-rudderstack-mparticle (event source), reverse-etl-hightouch-census-growth (downstream activation), pql-product-qualified-leads-framework, win-back-campaigns (cohort-driven actions).

Setup

export POSTHOG_PERSONAL_API_KEY="phx_..."
export AMPLITUDE_OAUTH_TOKEN="amp_..."
export MIXPANEL_API_KEY="mx_..."
export HIGHTOUCH_API_KEY="ht_..."

Cohort design rules

1. Single-attribute cohorts are vanity ("Users from organic search")
2. Multi-attribute cohorts are actionable ("Users from organic + signed up Q1 + Pro plan + 3+ active days last week")
3. Always time-window — events without time bound are meaningless
4. Define dynamic vs static at creation
5. Document purpose + intended action per cohort

Cohort taxonomy

| Type | Example | When to use |

|---|---|---|

| Static | Signups week of Mar 6, 2026 | Historical analysis; retention |

| Dynamic | Users active in last 7 days | Ongoing campaigns; real-time |

| Acquisition-based | UTM source = google + medium = paid | Channel quality analysis |

| Behavioral | Used premium feature ≥ 2x in last 14 days | PQL handoff, upgrade prompt |

| Lifecycle stage | Signed up 30d ago + not activated | Win-back campaigns |

| Firmographic | Company size 100-500 + industry SaaS | ICP segmentation |

| Predictive | Churn risk > 60% per Cox PH | At-risk handoff (see churn-prediction-modeling) |

| Multi-event sequence | Did A → then B within 7d | Funnel analysis |

Common recipes

Recipe 1: PostHog dynamic cohort (HogQL)

mcp tool posthog.cohorts_create \
  --name "Power Users + Approaching Limit" \
  --is_static false \
  --filters '{
    "type": "AND",
    "conditions": [
      {
        "type": "event",
        "event": "core_action",
        "operator": ">=",
        "value": 10,
        "window_days": 14
      },
      {
        "type": "property",
        "property": "usage_pct",
        "operator": "gte",
        "value": 0.80
      },
      {
        "type": "event_not",
        "event": "Subscription Started",
        "window_days": null  // never
      }
    ]
  }'

Recipe 2: Amplitude behavioral cohort

await amplitude.create_cohort({
  name: "Activated + High Frequency + Multi-Seat",
  definition: {
    type: "AND",
    conditions: [
      {event: "activation_event", count: ">=", value: 1, time_window: "first_7_days_after_signup"},
      {event: "session_started", count: ">=", value: 5, time_window: "last_14_days"},
      {user_property: "team_size", operator: "gte", value: 3}
    ]
  },
  is_dynamic: true
});

Recipe 3: Mixpanel cohort definition

curl -X POST "https://mixpanel.com/api/2.0/cohort/create" \
  -u "$MIXPANEL_API_KEY:" \
  -d '{
    "project_id": "...",
    "name": "Win-back candidates",
    "behavioral_filters": [
      {
        "event": "Session Started",
        "operator": "<",
        "value": 1,
        "window": {"days": 30}
      },
      {
        "event": "Subscription Started",
        "operator": ">=",
        "value": 1,
        "window": "ever"
      }
    ]
  }'

Recipe 4: Static cohort (point-in-time snapshot)

-- Snapshot, then freeze
INSERT INTO cohorts (cohort_name, user_id, created_at)
SELECT
  'Q1 2026 Signups',
  user_id,
  now()
FROM users
WHERE signup_date BETWEEN '2026-01-01' AND '2026-03-31'
  AND signup_source = 'organic'

Static = doesn't change. Useful for cohort retention curves.

Recipe 5: Multi-event sequence cohort

-- Users who did A → then B within 7 days
SELECT DISTINCT a.person_id
FROM events a
JOIN events b ON b.person_id = a.person_id
WHERE a.event = 'Premium Feature Attempted'
  AND b.event = 'Subscription Started'
  AND b.timestamp BETWEEN a.timestamp AND a.timestamp + INTERVAL 7 DAY

PostHog HogQL handles this in cohort builder; Amplitude has "Cohorts > Sequence".

Recipe 6: Negative event cohort

"Users who signed up but did NOT activate within 14 days"

PostHog:
  - Event: User Signed Up >= 14 days ago
  - AND Event Not: activation_event in 14 days after signup

Amplitude:
  Same; supports "did not" predicate

Recipe 7: Cohort with firmographic enrichment

# 1. Behavioral cohort in PostHog/Amplitude
# 2. Sync to warehouse via reverse-PostHog (or just query PostHog API)
# 3. Join with Clearbit/Apollo firmographics
# 4. Re-filter by ICP fit

enriched = pd.merge(
    cohort_users,
    firmographics,
    on='email'
)
icp_fit = enriched[
    (enriched.employees >= 50) & (enriched.employees <= 500) &
    (enriched.industry.isin(['SaaS', 'Fintech', 'Marketing']))
]

Recipe 8: Tier the cohort by score

-- Quintile-tier the cohort by PQL score
SELECT
  user_id,
  pql_score,
  NTILE(5) OVER (ORDER BY pql_score DESC) AS pql_quintile,
  CASE WHEN pql_quintile = 1 THEN 'critical'
       WHEN pql_quintile = 2 THEN 'high'
       WHEN pql_quintile = 3 THEN 'medium'
       ELSE 'low' END AS tier
FROM cohort_pql_high

Different tier = different downstream action (Slack alert vs in-app vs email).

Recipe 9: Activate cohort to downstream tool

Via Hightouch:
  PostHog cohort export → warehouse view → Hightouch model → destination

Via Customer.io direct:
  Customer.io supports its own segment definitions; create cohort within CIO.

Via Klaviyo:
  Hightouch sync → Klaviyo list, OR
  Klaviyo's own segment definitions

Via Intercom:
  Sync user attributes → Intercom segments based on attributes

Recipe 10: Cohort intersection / union

-- Users in BOTH cohort A AND cohort B (intersection)
SELECT a.user_id
FROM cohort_a a
INNER JOIN cohort_b b ON a.user_id = b.user_id

-- Users in A OR B (union)
SELECT user_id FROM cohort_a
UNION
SELECT user_id FROM cohort_b

-- A NOT in B (exclusion)
SELECT user_id FROM cohort_a
WHERE user_id NOT IN (SELECT user_id FROM cohort_b)

Recipe 11: Cohort lifecycle (auto-archive)

Dynamic cohorts can grow infinitely. Strategies:

1. Cap at 90 days: members who don't qualify within 90d are removed
2. Auto-archive after action: once user gets the message, remove from cohort
3. Cool-down: re-include same user only after N days
4. Suppression list: never include unsubscribed

Recipe 12: Cohort doc template (Notion)

# Cohort: Power Users Approaching Limit

**Purpose:** Trigger upgrade prompt for users likely to convert.

**Definition (PostHog cohort_id: 12345):**
- AND
  - Did `core_action` ≥ 10 times in last 14 days
  - `usage_pct` ≥ 0.80
  - Did NOT `Subscription Started`

**Type:** Dynamic.

**Refresh:** Real-time.

**Size:** ~340 users at any moment (varies daily).

**Downstream actions:**
- Hightouch sync to Customer.io segment "approaching_limit" (every 15 min)
- Customer.io campaign "Upgrade prompt" auto-triggers
- Slack alert to AE if account ARR > $5K (Recipe 9 in PQL skill)

**Owner:** Growth lead.

**Review cadence:** Weekly metrics check.

**Success metric:** Upgrade rate within 14 days of entering cohort.

Examples

Example 1: PQL Cohort

Definition:

Action: per pql-product-qualified-leads-framework skill — sync to CRM + Slack AE.

Example 2: Win-back cohort

Definition:

Action: per win-back-campaigns skill — Customer.io sequence.

Example 3: Activated power-users for advocate program

Definition:

Action: ship advocate program invitation; tracked via referral-program-referralcandy-friendbuy-growsurf.

Edge cases / gotchas

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.