Express apps often do three jobs at once: serve pages, run the API and create checkouts. Reveata plugs into all three with a script tag, two optional proxy routes, and two metadata keys.
What you get
- Every page tracked, whether Express renders views, serves static files or serves a single-page app's build.
- A first-party proxy in two routes, so the script and events go through your own domain and fewer visits are lost to ad blockers.
- Checkout payments credited to visits, from the route that creates the session.
- Your own billing posted to the Payments API.
Where the snippet goes
- A view engine (EJS, Pug, Handlebars): the layout or partial that renders
<head>, such asviews/partials/head.ejs. Express's view engines are covered in Express's template engine guide (opens in a new tab). - Static files with
express.static('public'): each HTML file, or the oneindex.htmlof a single-page app. - A front-end build (React, Vue, Svelte with Vite): that front end's
index.html(React analytics).
Page changes in a single-page app go through the History API, which the script follows.
The proxy routes
- Create a proxy secret in Settings → General → Tracking code and store it as
REVEATA_PROXY_SECRET. Never send it to the browser. - Add the two routes from Install on Express before your other routes (Node.js 18 or later).
- Point the snippet at them.
Set trust proxy to the number of proxies in front of your app. Without any proxy in front, remove the line, or anyone could set req.ip with an X-Forwarded-For header. To check, find the /dt/event request in the browser's Network tab: its x-reveata-proxy response header says trusted when the secret was accepted.
Linking payments to visits
const visitorId = req.body.reveata_visitor_id || trackerId(req.headers.cookie, '_dt_v');
const session = await stripe.checkout.sessions.create({
mode: 'payment',
line_items: [{ price: req.body.priceId, quantity: 1 }],
success_url: 'https://example.com/thanks',
metadata: { ...(visitorId && { reveata_visitor_id: visitorId }) },
});The trackerId cookie parser is in the Stripe Checkout guide. More in Stripe Checkout attribution.