Skip to content
Frameworks

React app analytics for Vite and Create React App

2 min read · Updated · By the Reveata team

Short answerPaste 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.

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-goal attribute on a button or form.
  • Revenue attribution by sending the visitor id to the endpoint that creates the checkout.
  • Development visits excluded: localhost is ignored unless you add data-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

tsx
<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:

ts
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.

Frequently asked questions

Do I need a React package?

No. The plain tag handles everything a single-page app needs. A typed npm tracker exists if you prefer imports (npm packages).

Do query string changes count as new pages?

Route changes through the History API are pageviews. For hash routes, turn on data-hash.

Why can't I see my local visits?

The script ignores localhost by default. Test the deployed app, or add data-allow-localhost="true" temporarily.

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 Router and Remix analyticsIn React Router framework mode, including Remix apps moved to it, add the Reveata tag to the Layout in app/root.tsx. In declarative or data mode, paste it into index.html. Route changes are counted automatically, and an action can put the visitor id into your checkout metadata.IntegrationNext.js analytics with revenue attributionAdd the Reveata script to your Next.js root layout with next/script, or use the typed Reveata component from @reveata/next. Client-side navigation is counted, and server helpers read the visitor id from Reveata's cookie so each checkout is credited to its visit.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.