Skip to content
Frameworks

Flask analytics with Reveata

2 min read · Updated · By the Reveata team

Short answerPaste the Reveata snippet into the base Jinja template your Flask pages extend. Every page is tracked, two small Flask routes can serve the script from your own domain, and your checkout route can copy the visitor id into the payment's metadata.

Flask apps are small by design, and Reveata keeps it that way: one tag in a template, and, if you want first-party serving, two routes. No extension to install.

What you get

  • Every page rendered from your base template, tracked with source, campaign and device.
  • First-party serving through two Flask routes that pass the visitor's address with your proxy secret, so fewer visits are lost to ad blockers.
  • Revenue credited to visits from checkouts your routes create.
  • Your own billing sent to the Payments API from Python.

How to install it

  1. Open the base template in your templates folder, often templates/base.html or layout.html.
  2. Paste the snippet before </head> and deploy.
  3. Pages rendered from templates that don't extend the base need the snippet too.

Jinja inheritance in Flask is described in Flask's templating docs (opens in a new tab).

Linking payments to visits

Connect your payment provider, then add two hidden fields to the form with your buy button, filled from window.reveata.metadata(). In the route that creates the Stripe Checkout Session, copy them into its metadata:

python
metadata = {k: v for k, v in {
    "reveata_visitor_id": request.form.get("reveata_visitor_id"),
    "reveata_session_id": request.form.get("reveata_session_id"),
}.items() if v}

The route can also read the _dt_v and _dt_s cookies from request.cookies and keep the part before the first dot (Stripe Checkout attribution). If Reveata doesn't connect to your provider, post each payment to the Payments API with a website key, the transactionId, amount, currency, email and the saved visitorId.

Serving the script from your own domain

Setup Guide
Flask serves everything Proxy with Flask: two routes
NGINX or Caddy in front NGINX or Caddy
No server changes The managed proxy: one DNS record

Whatever you choose, the proxy must send the visitor's address with your website's proxy secret, or every visit looks as if it came from your server.

Frequently asked questions

Will a Content Security Policy block the script?

If your app sends one, allow the Reveata script and its endpoint, or use the proxy so 'self' covers both (Content Security Policy).

Can I connect Stripe and also use the Payments API?

Not for the same payments: they would be counted twice. Use the API only for a provider Reveata doesn't connect to.

Are development visits counted?

No. The script ignores localhost unless you add data-allow-localhost="true".

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?
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.IntegrationRevenue attribution for custom billing with the Payments APIIf your provider is not one Reveata connects to, or you bill customers yourself, post each payment to the Reveata Payments API with a website key. Include the visitor id, a user id or an email, and the payment is attributed like any connected provider's.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.