Skip to content

Install on React

View as Markdown

Add Reveata to a React app built with Vite or Create React App.

On this page

A React app is served from one HTML file, so the snippet goes in its <head> once and every route is counted.

Copy the snippet from your Reveata dashboard (it contains your website’s tracking id):

html
<script
  defer
  data-website-id="ws_your_tracking_id"
  src="https://reveata.com/js/script.js"
></script>

Add it to your app

  • Vite: open index.html at the root of the project (next to vite.config.ts) and paste the snippet before </head>.
  • Create React App: open public/index.html and paste the snippet before </head>.
html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>My app</title>
    <script defer data-website-id="ws_your_tracking_id" src="https://reveata.com/js/script.js"></script>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>

Build and deploy as usual. The tag is copied into the built index.html unchanged.

Route changes made by a router that uses the History API (React Router, TanStack Router, Wouter) are counted as pageviews by the script, with no code in your components. If your router puts routes after a # (/#/settings), add data-hash="true" to the tag. For Next.js, see Install on Next.js. For React Router in framework mode, see Install on React Router.

Check it works

Open your deployed app in a private window, then check that the visit appears in your Reveata dashboard. If it doesn’t, follow Verify your installation. The script ignores localhost by default, so visits to the development server stay out of your numbers. To test locally, add data-allow-localhost="true" and remove it before you deploy.

Goals

Call the script from an event handler. With TypeScript, declare it once:

tsx
// src/reveata.d.ts
declare global {
  interface Window {
    reveata?: (command: string, ...args: unknown[]) => void;
  }
}
export {};
tsx
<button onClick={() => window.reveata?.('goal', 'start_trial', { plan: 'pro' })}>
  Start free trial
</button>

Or skip the handler and add the attribute: <button data-reveata-goal="start_trial">. On a <form>, the goal counts when the form is submitted. See Custom goals.

Revenue

Connect your payment provider in Reveata: see Connect a payment provider. When your backend creates the checkout, send window.reveata.metadata() with the request and add it to the checkout metadata, so each payment is linked to the visit that led to it.

Was this helpful?