A React single-page app loads one HTML file and changes routes in the browser. Many analytics setups then need a hook in every route. Reveata doesn't: it watches the History API, so one tag covers the whole app.
What you get
- Route changes counted as pageviews with no code in components, for any router that uses the History API.
- Goals from event handlers, or from a
data-reveata-goalattribute on a button or form. - Revenue attribution by sending the visitor id to the endpoint that creates the checkout.
- Development visits excluded:
localhostis ignored unless you adddata-allow-localhost="true".
Where the snippet goes
| Setup | File |
|---|---|
| Vite | index.html at the project root, next to vite.config.ts |
| Create React App | public/index.html |
| Next.js | The root layout: see Next.js analytics |
| React Router framework mode | app/root.tsx: see React Router analytics |
Paste it before </head>. The build copies the tag into the built index.html unchanged. If your router puts routes after a # (/#/settings), add data-hash="true".
Goals from components
<button onClick={() => window.reveata?.('goal', 'start_trial')}>Start trial</button>With TypeScript, declare reveata once on Window. Or skip the handler: <button data-reveata-goal="start_trial">. On a <form>, the goal counts when the form is submitted (custom goals). React itself is documented at react.dev (opens in a new tab).
Linking payments to visits
Connect your payment provider in Reveata, then send window.reveata.metadata() with the request that starts checkout:
await fetch('/api/checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ priceId, ...window.reveata.metadata() }),
});Your backend copies the two ids into the checkout metadata (Stripe Checkout attribution). With no backend, link to a Stripe Payment Link instead: the script adds the ids on click.