# Calculate campaign payback by cohort

> Tie acquisition campaigns to paid conversion, revenue, and retention so marketing and finance can see which campaigns pay back.

## Agent adaptation contract

- Canonical human page: https://agentry.sh/workflows/campaign-payback-by-cohort
- Execution mode: on_demand
- Immutable automation template: none
- Applies to: b2c-saas, b2b-saas, ecommerce, devtools-api
- Required example events: signup_completed, subscription_started
- Required Agentry resources: none declared
- Do not use when:
  - Do not use until the example events are mapped to observed project signals, the current onboarding state is verified, and live event/property reads prove the required data is present.
  - Do not recommend this for products without a real revenue lifecycle or an equivalent paid-account signal.
- Ask before using:
  - Which observed events map to signup_completed, subscription_started? Is the current onboarding state verified, and do live event/property reads show non-synthetic traffic for them?
  - Which live properties provide signup_completed.utm_campaign, subscription_started.utm_campaign, subscription_started.amount, and which stable user or account identifier joins the signals?

This is an adaptable workflow example, not an API recipe. Map event and property names to the project's saved signal map, require status: "verified" from GET /v1/projects/:project_id/onboarding, and confirm the required signals through live event/property metadata and rows. Fetch current OpenAPI or query-blueprint details before making calls. Do not infer unattended authority from this page.

## Why this matters

Campaign dashboards stop at leads. Product-led teams need to know which campaigns create activated, retained, paying users.

## What you get

- Campaign cohorts by signup week
- Paid conversion and revenue
- Retention by campaign
- Payback estimate when spend is available

## Walk through it

**You:**
> Which campaigns actually paid back?

**Agent:**
> I'll group signup cohorts by campaign and join revenue events.

```text
Endpoint: POST /v1/projects/:project_id/analytics/query
Exact shape: /v1/openapi.json?path=%2Fv1%2Fprojects%2F%7Bproject_id%7D%2Fanalytics%2Fquery&method=post
Custom HogQL goes in the OpenAPI-defined `query` field.
Concept fields:
  query: "SELECT properties.utm_campaign AS campaign, countIf(event = 'signup_completed') AS signups, countIf(event = 'subscription_started') AS paid, sumIf(toFloat(properties.amount), event = 'subscription_started') AS revenue FROM events WHERE event IN ('signup_completed','subscription_started') AND timestamp > now() - INTERVAL 90 DAY GROUP BY campaign ORDER BY revenue DESC"
```

## The output

The agent returns campaigns ranked by quality and revenue, not just signup count.

## Setting it up

Persist campaign attribution onto signup and revenue lifecycle events. If spend is not in Agentry, the agent can still rank revenue and conversion.

## Variations

- *"Only compare campaigns from last quarter."*
- *"Show campaigns with high signups but low paid conversion."*
- *"Publish this as a finance review dashboard."*
