Skip to content
Frameworks

FastAPI analytics with Reveata

2 min read · Updated · By the Reveata team

Short answerPaste the Reveata snippet into the base Jinja2 template of your FastAPI app, or into the index.html of the front end FastAPI serves. Two FastAPI routes can serve the script from your own domain, and your checkout endpoint can put the visitor id into the payment's metadata.

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 httpx to 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:

js
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).

Frequently asked questions

My FastAPI app has no HTML. Can I still use Reveata?

Yes. Put the snippet in the front end that calls your API. FastAPI then only creates checkouts or posts payments.

Why does every visit show the same country through my proxy?

The proxy is sending the load balancer's address. Trust the proxy headers in Uvicorn and make sure the proxy secret is sent.

Will Stripe payments be counted twice if I also call the Payments API?

Yes, so don't. With Stripe connected, let Reveata read Stripe and use the API only for other billing.

See it with your own numbersReveata ties every visit and sale to the source that brought it. Add your website in a minute.
Get started
Was this page useful?
IntegrationReact app analytics for Vite and Create React AppPaste the Reveata snippet into the head of your React app's index.html, the root one for Vite or public/index.html for Create React App. The script counts route changes from React Router, TanStack Router or Wouter by itself, and window.reveata.metadata() passes the visitor id to your checkout.IntegrationStripe Checkout analytics and attributionAdd the Reveata visitor and session ids to the metadata of each Stripe Checkout Session your server creates. When Stripe reports the payment, Reveata reads the ids and credits the money to the exact visit that started the checkout.IntegrationAngular analytics with ReveataPaste the Reveata snippet before the closing head tag of src/index.html. ng build keeps it in the built page, server-side rendering included, and the Angular Router's History API navigation is counted automatically. HashLocationStrategy needs data-hash="true".IntegrationAstro analytics with revenue attributionPaste the Reveata snippet with is:inline into the Astro layout that renders the head of every page. Astro then leaves the tag as written, view transitions are tracked, and payment links or checkouts started from your pages are credited to the visit behind them.IntegrationDjango analytics with revenue attributionPaste the Reveata snippet before the closing head tag of the base template your Django templates extend. Every page is tracked, the Django admin is not, and two hidden form fields let your checkout view put the visitor id into the payment's metadata.IntegrationDocusaurus analytics for documentation sitesAdd the Reveata script to the scripts array in docusaurus.config.js, or build the entry with @reveata/next/snippet. Page changes inside the docs are tracked by the script, so every page a reader opens is counted.