# Which of Last Week's Email Campaigns Drove Unsubscribes? A Retention App Checks Each Store's Klaviyo Every Monday

A retention analytics app makes one agent per store, signed into its Klaviyo, that flags last week's campaigns with unusual unsubscribe or spam complaint rates.

[Run this on Rush](https://cloud.getrush.ai/run/find-campaigns-that-drove-unsubscribes/klaviyo/). Opens the console with this prompt ready to send. Connect Klaviyo there first.

## What the agent does

This is for a software company that sells a retention analytics app to online stores on Shopify: a candle maker, a pet treats brand, a cycling apparel label. Most of its customers send email campaigns from Klaviyo two or three times a week, and the campaign that costs them most is rarely the one with a low open rate. It is the one sent to the whole list, or with a subject line that felt like spam, that made a few hundred people unsubscribe or mark it as spam, shrinking the list and hurting how the store's mail is delivered. The app adds a Monday card for each store: last week's campaigns whose unsubscribe or spam complaint rate was well above that store's own normal, and the audience each one went to.

The company connects a Klaviyo account of its own, saves the agent once as a template with `POST /o/{org}/agents`, naming `klaviyo` in `connections` and instructions that allow reading only, and keeps its id. When a store turns the card on, the app's backend calls `POST /o/{org}/agents {"template": "<template id>", "name": "campaign-health-<store id>"}` and then `POST /o/{org}/agents/{agent}/connections {"type": "mcp", "name": "klaviyo"}`, and opens the `authorize_url` in a popup while the store owner is signed in to the app. The owner signs in on Klaviyo's own page. Klaviyo's docs say the MCP server needs an Owner, Admin or Manager role on the account, so the app tells staff with another role to ask their owner. The company registers no OAuth app and stores only the agent id against the store.

On a run the agent calls `get_metrics` to find the store's Placed Order metric, which Klaviyo's reporting requires as the `conversion_metric_id`, then `get_campaigns` for email campaigns sent in the last seven days. It calls `get_campaign_report` twice: once for last week and once for the 90 days before it, asking for the statistics `recipients`, `unsubscribes`, `unsubscribe_rate`, `spam_complaints`, `spam_complaint_rate`, `bounce_rate`, `open_rate` and `click_rate`. Klaviyo's docs recommend its Reporting API over aggregated metric queries because it matches what the store sees in Klaviyo's own reports, so the numbers on the card match the numbers the owner can check.

A campaign is flagged when its unsubscribe rate is at least twice the store's 90-day median and it reached at least 500 recipients, or when its spam complaint rate is above the store's 90-day highest. For each flagged campaign the agent calls `get_campaign_messages` and `get_audience_for_campaign_message` to name the lists and segments it was sent to and any it excluded, because a campaign sent to everyone who ever bought is the usual cause. It never creates, updates, schedules, sends or cancels a campaign, and changes no profile, list or segment.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "<agent id>",
  "input": "Monday campaign health check for this store. Last week: 2026-11-16 00:00 to 2026-11-22 23:59, time zone America/New_York. Baseline: the 90 days before that. Read only. 1) get_metrics; find the Placed Order metric id. 2) get_campaigns: email campaigns sent last week. 3) get_campaign_report for last week and for the baseline with statistics recipients, unsubscribes, unsubscribe_rate, spam_complaints, spam_complaint_rate, bounce_rate, open_rate, click_rate, conversion_metric_id the Placed Order metric. 4) Flag a campaign if unsubscribe_rate >= 2 x the baseline median and recipients >= 500, or spam_complaint_rate > the baseline maximum. 5) For each flagged campaign: get_campaign_messages and get_audience_for_campaign_message; name included and excluded lists and segments. Return JSON only: {week, baseline: {campaigns, median_unsubscribe_rate, max_spam_complaint_rate}, flagged: [{campaign_id, name, sent_at, recipients, unsubscribes, unsubscribe_rate, spam_complaints, spam_complaint_rate, open_rate, click_rate, included, excluded, reason}], other_campaigns: [{campaign_id, name, unsubscribe_rate}]}. Rates as decimals. Never create, edit, schedule, send or cancel a campaign, and never change a profile, list or segment."
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is the JSON in the session's `result`, which the `run.completed` webhook carries to the app's server: last week's flagged campaigns with their numbers, the audience each one went to, and why it was flagged, plus the store's baseline and a line for each campaign that was fine. The app renders it as the Monday card, so a store owner sees "Black Friday early access, sent to All Subscribers with no exclusions, unsubscribe rate three times your usual" rather than a table of rates.

What the store owner checks before changing anything: that the flagged campaign really went to the audience shown, by opening it in Klaviyo; whether the spike is a one-off, such as a first send to a list imported from a pop-up, rather than a pattern; and what to change next time, such as excluding people who have not opened in 90 days. The app shows the card; the owner decides what to send and to whom.

## Run it on every Monday morning

The app's scheduler sends `POST /o/{org}/sessions` with `{"agent": "<agent id>", "input": "…"}` for each store that has the card on, every Monday at 6:00 in the store's own time zone, with a fresh `request_id` per store and week so a retried call does not start a second run. The run's result arrives on the key's webhook, matched to the store by the agent id the app stored.

A store that has just sent a large campaign can press "Check now" in the app, which starts the same agent with last week's window replaced by "since yesterday".

## Why run it on Rush?

Each store's Klaviyo sign-in is held in Rush's connection under that store's own agent, so one store's run never sees another store's account or the company's own. The company never handles a Klaviyo token, and deleting a store's agent when it cancels disconnects that sign-in with it.

Each run has its own computer and a record of every report it requested, so when a store owner disputes a flagged campaign, the support team opens that Monday's session and reads exactly what Klaviyo returned. To bill stores for the card, the company lists each store's runs with `GET /o/{org}/sessions?agent=<agent id>` and adds up `total_cost_usd`.

## Frequently asked questions

### Why compare with the store's own baseline rather than an industry figure?

A store that mails a small, loyal list and a store that mails everyone who ever bought have very different normal rates. Comparing each campaign with that store's own last 90 days flags what is unusual for them, without the app claiming what a good rate is.

### What happens if the store owner's role is too low?

Klaviyo's docs say the MCP server needs an Owner, Admin or Manager role, so a staff member with another role cannot complete the connection. The agent's connections then show Klaviyo as missing, and the app asks the store's owner to connect instead.

### Can the agent fix the audience for the next campaign?

The instructions forbid it. Changing who receives the next campaign is a marketing decision, and the card gives the owner what they need to make it in Klaviyo.

## More Klaviyo jobs

- [Find the Klaviyo Coupons About to Run Out of Unique Codes Before Your Flows Do](https://getrush.ai/run/find-coupons-running-out-of-codes/klaviyo/)
- [Which Klaviyo Flows Quietly Stopped Sending? An Email Reporting App's Weekly Check of Each Store's Live Flows](https://getrush.ai/run/find-flows-that-stopped-sending/klaviyo/)
- [Audit Klaviyo Flows](https://getrush.ai/run/flow-audit/klaviyo/)

## More jobs like this: Run an agent per customer task

- [How Can a Tutoring Company Find Cancelled Lessons Nobody Rebooked? One Agent per Tutor, Reading Their Google Calendar Each Week](https://getrush.ai/run/find-cancelled-lessons-not-yet-rebooked/google-calendar/)
- [Which Candidates Emailed Us and Never Heard Back? A Recruiting App's Daily Check of Each Recruiter's Outlook](https://getrush.ai/run/find-candidates-waiting-on-a-reply/outlook/)
- [Find Personal-Training Clients With No Next Session Booked in Each Trainer's Google Calendar](https://getrush.ai/run/find-clients-without-a-next-session/google-calendar/)

## Keep reading

- [Connect Klaviyo to Rush once, then name it on any run](https://getrush.ai/integrations/klaviyo/)
- [Start your first run from the developer API quickstart](https://getrush.ai/docs/quickstart/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
