Install the tracking script in a React app
Add the snippet to index.html in Vite or Create React App. React Router navigation counts as pageviews, and goals can be sent from components.
Your snippet is in Settings → General of the website (the gear next to its name on the dashboard), with its id and domain filled in. The examples below use YOUR_WEBSITE_ID and yourdomain.com: replace them with yours.
Single-page React apps (Vite, Create React App, React Router) have one HTML file: paste the snippet in its <head>. Route changes made with history.pushState, which React Router uses, count as pageviews automatically.
<!doctype html>
<html lang="en">
<head>
<script
defer
supr-website-id="YOUR_WEBSITE_ID"
supr-domain="yourdomain.com"
src="https://supranalytics.app/js/script.js"
></script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html><head>
<script
defer
supr-website-id="YOUR_WEBSITE_ID"
supr-domain="yourdomain.com"
src="https://supranalytics.app/js/script.js"
></script>
</head>Goals from components:
<button onClick={() => window.supr?.("start_trial", { plan: "pro" })}>Start free trial</button>For TypeScript, declare it once: declare global { interface Window { supr?: (name: string, props?: Record<string, string | number | boolean>) => void } }.
Check it works
Open your website in a normal browser window, then the dashboard: the visit shows up within seconds, and the install card on a new website turns into the dashboard by itself. Nothing after a minute? See Not seeing any data.
AI agent or LLM? Read this page as Markdown