# Revenue in apps built with AI

> A ready-made prompt for Lovable, Bolt, v0, Replit or Cursor that finds your checkout code and passes the Reveata visitor id, so payments are credited to their visits.

Apps made with Lovable, Bolt, v0, Replit or Cursor usually take payments with Stripe or another provider. Two things are needed: the provider connected in Reveata, and the checkout code passing the Reveata visitor id. The builder's AI can write the second part for you with the prompt below.

## 1. Install the script and connect your provider

1. Add the Reveata snippet to your app's `index.html` or root layout (see the guides for [Lovable](https://reveata.com/docs/lovable), [Bolt](https://reveata.com/docs/bolt), [v0](https://reveata.com/docs/v0) and [Replit](https://reveata.com/docs/replit), or [Frameworks and site builders](https://reveata.com/docs/frameworks)), and publish.
2. In Reveata, open your website's **Settings → Payments** and connect Stripe, Polar or Dodo Payments (see [Connect a payment provider](https://reveata.com/docs/connect-a-payment-provider)). For anything else, use the [Payments API](https://reveata.com/docs/payments-api).

Payments now count as revenue. The next step credits them to visits.

## 2. Ask the builder to pass the visitor id

Paste this into the chat of your builder (or your editor's agent). It was written for Reveata and works with any of them:

```text
My app uses Reveata analytics. The Reveata script on every page exposes
window.reveata.metadata(), which returns { reveata_visitor_id, reveata_session_id }
(or {} when the visitor has no ids). I want every payment to carry these ids.

1. Find every place where this app starts a payment: checkout sessions, payment
   intents, subscriptions, checkout links or overlay checkouts, on the client and on
   the server (including edge or serverless functions). Tell me which payment
   provider and which method each one uses.
2. For each one, pass the ids as follows, and change nothing else:
   - Stripe Checkout Session: add them to `metadata` when the server creates the session.
   - Stripe PaymentIntent (Elements, Payment Element): add them to the PaymentIntent `metadata`.
   - Stripe Payment Links (buy.stripe.com), Buy Button or Pricing Table opened from a
     normal link or element: nothing to do, the Reveata script adds them itself.
     If the app sends the browser to a buy.stripe.com address in code, append
     `client_reference_id=dt_<visitor id>_<session id>` to that address.
   - Polar: in the checkout `metadata`.
   - Dodo Payments: in the checkout session or payment `metadata`.
   Read the ids in the browser with window.reveata.metadata() and send them to the
   server in the request that creates the checkout. Never fail a checkout when the
   ids are missing: send what exists.
3. If a signed-in user pays, also call
   window.reveata('identify', { userId: <the user's id>, email: <the user's email> })
   once after sign-in.
4. Show me a short list of the files you changed and what you added in each.
```

Review the changes, publish, and make one test purchase (below).

## When there is no checkout code to change

Some apps only link to a hosted checkout page, or take payments through a tool the builder can't edit. Then:

- **Links on your pages to Stripe Payment Links** are decorated by the script with no code: see [Stripe Payment Links and buy buttons](https://reveata.com/docs/stripe-payment-links).
- **Anything else** can still be linked by email: identify signed-in users (step 3 of the prompt), and Reveata matches payments to the visitor with the same email. Unattributed payments are retried every hour for 90 days, so identifying a user after they paid still links the payment.

## Check it works

1. Open your published app in a private window from a link ending in `?ref=test`.
2. Pay with your provider's test mode on a test website, or make a small real purchase and refund it afterwards. A free, fully discounted checkout is not a payment and does not show up.
3. In your provider's dashboard, the payment's metadata (or custom data) shows `reveata_visitor_id`.
4. In Reveata, the payment appears under **Revenue** with the source `test`.

If the ids are missing in step 3, paste the prompt again with the name of the file that creates the checkout.
