# Revenue

> Connect Stripe or Paddle with a read-only key, or send your own billing's subscriptions, and see MRR, ARR, churn and the traffic source of each paying customer beside your visits.

Source: https://mettr.app/docs/revenue

Traffic says who came. Revenue says who paid, and from where. mettr reads a site's billing and shows MRR, ARR, subscribers, revenue per subscriber, churn, MRR by day, its movements, and MRR by the source of the visit each customer first came on. Revenue comes with the Pro plan.

## Connect Stripe

mettr reads Stripe with a **restricted key** (`rk_live_…`), which can only read what you tick. A full secret key (`sk_live_…`) is refused: it could change your account, and mettr only reads.

**The key:**

1. In the Stripe Dashboard, open **Developers**, then **API keys**.
2. Choose **Create restricted key**. If Stripe asks how the key will be used, say it is for another application, and name it `mettr`.
3. Set these to **Read** and leave everything else at **None**:
   - Subscriptions
   - Invoices
   - Charges
   - Refunds
   - Products
4. Choose **Create key**, then copy it.
5. In mettr, open the site's settings, **Revenue**. Choose Stripe, paste the key into **API key**, and choose **Connect Stripe**.

mettr tries the key before it keeps it, and the error names any access that is missing. It reads at a pinned API version, whatever your account's default. For a test mode account, make the key in test mode (`rk_test_…`).

**The webhook**, for payments and changes the moment they happen (without it Stripe is read once a day):

1. Once Stripe is connected, the **Revenue** tab shows the webhook's address (`https://mettr.app/api/v1/revenue/…`). Copy it.
2. In the Stripe Dashboard, open **Developers**, then **Webhooks**, and add an endpoint (in Workbench: **Add destination**, then **Webhook endpoint**).
3. Pick these events:

   `customer.subscription.created`, `customer.subscription.updated`, `customer.subscription.deleted`, `customer.subscription.paused`, `customer.subscription.resumed`, `invoice.paid`, `charge.succeeded`, `charge.refunded`, `charge.refund.updated`

4. Paste the address as the endpoint URL and save.
5. Open the endpoint, reveal its **Signing secret** (`whsec_…`), and paste it into **Signing secret** on the **Revenue** tab.

## Connect Paddle

mettr reads Paddle Billing (not Paddle Classic) with an API key that may only read.

**The key:**

1. In Paddle, open **Developer tools**, then **Authentication**.
2. Create a new API key and name it `mettr`.
3. Give it read access to **Subscriptions**, **Transactions** and **Adjustments** (`subscription.read`, `transaction.read`, `adjustment.read`), and nothing else.
4. Save it, then copy the key (`pdl_live_apikey_…`).
5. In mettr, open the site's settings, **Revenue**. Choose Paddle, paste the key into **API key**, and choose **Connect Paddle**.

For a sandbox account, make the key at sandbox-vendors.paddle.com and tick **Sandbox account**.

**The webhook**, for payments and changes the moment they happen (without it Paddle is read once a day):

1. Once Paddle is connected, the **Revenue** tab shows the webhook's address. Copy it.
2. In Paddle, open **Developer tools**, then **Notifications**, and create a new destination.
3. Paste the address as its URL. Keep it a webhook and pick these events:

   `subscription.created`, `subscription.updated`, `subscription.activated`, `subscription.canceled`, `subscription.past_due`, `subscription.paused`, `subscription.resumed`, `subscription.trialing`, `subscription.imported`, `transaction.completed`, `adjustment.created`, `adjustment.updated`

4. Save it, open the destination again, and copy its **secret key** (`pdl_ntfset_…`) into **Webhook secret** on the **Revenue** tab.

## Any other billing

Your app sends its subscriptions, and one-off payments as [revenue events](/docs/events-api#revenue-events). Choose **Your own billing** on the **Revenue** tab to see the address and a sample. Then send them:

- from Laravel, with [`Mettr::subscription()`](/docs/laravel#subscriptions);
- from any PHP app, with [`$mettr->subscription()`](/docs/php#subscriptions);
- from any other language, to the [Subscriptions API](/docs/subscriptions-api) over HTTP.

The JavaScript package runs in the browser, where a secret key must never be, so it sends no subscriptions.

## How it is read

- On connecting, every night, and on **Read again**, each subscription's history is rebuilt from its billing cycles: the recurring price, not a trial's, less lasting discounts and prorations. One-off payments and refunds go to the feed.
- A webhook is checked by its signature before anything in it is read, and adds a movement at once and puts a payment in the live feed.
- Keys and secrets are encrypted at rest and never sent back to a page: the tab shows a key's last four characters.

## What counts as MRR

- Each subscription's monthly amount: a yearly plan of $228 is $19 a month. Only `active` and `past_due` subscriptions count.
- Stripe: licensed items' prices times their quantities, less a discount that lasts. Metered items are left out (what will be used is not known ahead), and paused collection counts as nothing.
- Movements: new, expansion, contraction, churn and reactivation, each with MRR before and after.
- One currency per site, converted at the European Central Bank's rate of each day. A currency the ECB has no rate for is left out and named, never guessed.

## Revenue by source

For **MRR by source**, mettr needs to know which of your users each subscription belongs to. Pass your user's id to the checkout, and send the same id as `user_id` with your events:

- Paddle: in the checkout's `customData`, as `{"user_id": "4821"}`;
- Stripe: in the subscription's `metadata` (or the invoice's or charge's), as `user_id`.

The key is `user_id` unless you set another under the site's **Revenue** settings. Each subscription is then credited to the source of the visit its customer's first event was in (first touch): a search engine, a newsletter, a campaign, or Direct. A customer whose id never came, or was never seen on the site, is Unknown.

## Disconnecting

**Disconnect** stops reading and deletes the subscriptions and MRR history read from the account; payments stay in the feed. Connecting again reads it all anew. Connecting, changing and disconnecting are recorded in mettr's audit log.
