FastAPI is often the backend behind a separate front end, sometimes the server of the pages themselves. Reveata works with both: the script lives in whichever HTML your visitors load, and FastAPI handles checkout ids and payments.
What you get
- Every page tracked, from Jinja2 templates or a built front end.
- First-party serving through two FastAPI routes with your proxy secret.
- Checkout payments credited to visits from the endpoint that creates the session.
- Payments from your own billing sent with
httpxto the Payments API.
Where the snippet goes
| How FastAPI serves pages | Where to paste |
|---|---|
Jinja2Templates(directory="templates") |
Before </head> in the base template, usually templates/base.html |
StaticFiles(directory="dist", html=True) |
The front end's index.html before you build (React, Vue) |
| API only, no pages | The front end that calls it, wherever it is hosted |
FastAPI's templating is documented in FastAPI's templates guide (opens in a new tab).
Linking payments to visits
From the browser, send the ids with the request that starts checkout:
body: JSON.stringify({ price_id, ...window.reveata.metadata() })On the server, put them in the Stripe Checkout Session's metadata as reveata_visitor_id and reveata_session_id (Stripe Checkout attribution). In a real app, check price_id against the prices you sell. With your own billing, post each payment to the Payments API with a website key.
Serving the script from your own domain
Proxy with FastAPI adds two routes that serve the script and pass events on with the visitor's address and your proxy secret. Behind a load balancer, run Uvicorn with --proxy-headers and --forwarded-allow-ips set to the load balancer, or request.client.host is the load balancer's address and request.base_url says http. NGINX or Caddy in front of Uvicorn can proxy instead (NGINX, Caddy).