> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt

# What do customers do right before they cancel? – Context Warehouse pocket guide

[](/pocket-guides.md)Aa

[](/pocket-guides/context-warehouse/upsell-ready-accounts.md)[](/pocket-guides/context-warehouse/support-tickets-churn.md)

# What do customers do right before they cancel? – Context Warehouse pocket guide

The warning signs were probably visible weeks before a customer cancels their subscription. This skill pulls cancellation dates from Stripe or Chargebee and examines the roughly 30 days of activity before each one, looking for a pattern that's shared across churned accounts.

## Example data and how to read it

The Skill looks for patterns like Fig. 1: engagement doesn't fall off a cliff, it erodes, roughly halving every week for a month before cancellation. That decay curve is the early-warning signal so you can start re-engaging users when their engagement first begins to dip.

| Weeks before cancellation | Avg. events / account |
| --- | --- |
| −4 | 210 |
| −3 | 175 |
| −2 | 96 |
| −1 | 41 |
| 0 (final week) | 12 |

Fig. 1 – Example data: engagement in the weeks before cancellation, averaged across churned accounts.

## Doing this by hand

1.  **Connect [Stripe](/docs/cdp/sources/stripe.md) or [Chargebee](/docs/cdp/sources/chargebee.md)** via [Data pipeline > Sources](/docs/data-warehouse/sources.md) for cancellation dates.
2.  **Pick a handful of recently churned accounts** and open each one in PostHog's [Persons](/docs/data/persons.md) (or Groups) explorer to read their activity timeline in the weeks before they left.
3.  **Look for the shared pattern**: Use the [SQL editor](/docs/data-warehouse/sql.md) or ask PostHog AI to average the number of weeks-to-churn across the accounts you've selected.

## Get an agent to do the work

Copy the Skill below and add it to your agent. The agent finds each account's cancellation timestamp (Stripe's `canceled_at`, or the Chargebee equivalent), then indexes that account's activity to weeks-before-cancellation and averages across every churned account to reveal the shared decline. It offers two readings: the trend line itself, and a ranking of each account's *last* action before they left.

This is behavioral churn prediction with no support data. If the question is specifically about support tickets predicting churn, that's [Tickets & churn](/pocket-guides/context-warehouse/support-tickets-churn.md) instead.

posthog-pre-cancellation-behavior/SKILL.md

```markdown
# What do customers do right before they cancel?
**Question:** How does account activity change in the ~30 days before a customer cancels?
**For:** CS & Product · **Difficulty:** Intermediate · **Shape:** a window query
**Data sources:** PostHog events (activity timeline per account) + Stripe / Chargebee (cancellation dates)
## What this produces
A saved PostHog insight showing the shared pre-churn pattern — how engagement trends downward (or which last
actions occur) in the weeks before cancellation — giving the user an early-warning signal.
## Workflow
First read `references/posthog-workflow.md` for the shared setup: confirm the PostHog MCP is connected, ensure the
churn source (Stripe or Chargebee) exists (secure connect-link flow if not), and learn the real schema. Then the
question-specific part:
### 1. Identify the pieces in this project
- **Cancellation dates.** From Stripe: `stripe_subscription` with `status = 'canceled'` and its `canceled_at` (or
  `ended_at`) timestamp per customer. Chargebee has an equivalent subscription cancellation field. Confirm which
  system holds the source of truth for churn.
- **Activity timeline.** The events that represent meaningful engagement (`event-definitions-list`).
- **Account key.** Map the churned Stripe/Chargebee customer to PostHog people/groups (email or customer id — see
  join gotchas in the shared reference).
### 2. Build and validate the query
The idea: for each churned account, index activity to weeks-before-cancellation, then average across accounts to
reveal the shared decline. Adapt names and validate with `query-run`.
```sql
-- Average weekly activity in the 30 days before cancellation, aligned by weeks-to-churn.
-- Adapt: the cancellation source/fields, activity events, and the email join key.
WITH cancels AS (
    SELECT lower(email) AS email, max(canceled_at) AS churn_ts
    FROM stripe_subscription
    WHERE status = 'canceled'
      AND canceled_at >= now() - INTERVAL 90 DAY       -- "last quarter" churners
    GROUP BY lower(email)
),
activity AS (
    SELECT
        c.email AS email,
        -- how many days before cancellation each event happened, bucketed into weeks
        intDiv(dateDiff('day', e.timestamp, c.churn_ts), 7) AS weeks_before_churn,
        count() AS events
    FROM events AS e
    INNER JOIN cancels AS c ON lower(e.person.properties.email) = c.email
    WHERE e.timestamp >= c.churn_ts - INTERVAL 30 DAY
      AND e.timestamp <= c.churn_ts
    GROUP BY c.email, weeks_before_churn
)
SELECT
    weeks_before_churn,                                -- 0 = final week before churn
    round(avg(events), 1) AS avg_events_per_account,
    count(DISTINCT email) AS accounts
FROM activity
GROUP BY weeks_before_churn
ORDER BY weeks_before_churn DESC
```
For "what was the last action", instead select each account's final event before `churn_ts` and rank those events
by frequency. Offer both readings to the user.
### 3. Save the insight
Save as a SQL/HogQL insight named "Activity before cancellation" — a line/bar over weeks-to-churn works well for
the trend; a table for the last-action ranking. Return the URL and tell the user the pattern you see (e.g.
"engagement roughly halves in the final two weeks").
## Self-driving development (offer this)
With an early-warning signal, the user can spot at-risk accounts before they leave. Offer to help turn the pattern
into a cohort or alert (e.g. "activity down >50% week-over-week") that triggers a save flow or CS outreach —
cutting churn automatically.
```

Show full example

Fig. 2 – The Skill itself, copy and paste this into your agent to answer the question.

See also: [Tickets & churn](/pocket-guides/context-warehouse/support-tickets-churn.md) · [ARR vs engagement](/pocket-guides/context-warehouse/value-vs-engagement.md)

[‹ Which accounts are ready to upsell?](/pocket-guides/context-warehouse/upsell-ready-accounts.md)[All guides](/pocket-guides.md)p. 4 of 15[Do support tickets predict churn? ›](/pocket-guides/context-warehouse/support-tickets-churn.md)