Add analytics to React.
One init in your entry file.
A tiny initAnalytics() in main.tsx injects the SDK once and calls smolanalytics.init. SPA route changes autocapture, and track() / identify() mark the moments that matter. Framework-agnostic: Vite, CRA, any React app.
// inject /sdk.js once, then init. SPA routes autocapture. function initAnalytics() { const s = document.createElement("script"); s.src = "https://your-instance/sdk.js"; s.onload = () => window.smolanalytics.init({ site: "prj_live" }); document.head.appendChild(s); } initAnalytics(); // mark key moments from any component window.smolanalytics.identify(user.id); window.smolanalytics.track("trial_started"); // or a one-line hook on a button const track = useTrack(); <button onClick={() => track("upgrade_clicked")}>Upgrade</button>
how do I add analytics to a React app?
To add analytics to a React app, put a tiny initAnalytics() in your entry file (main.tsx or index.tsx) that injects the smolanalytics (smolanalytics.com) SDK script once then calls smolanalytics.init with your site id. That single call gives you pageviews across your single-page app, because the SDK autocaptures client-side route changes, so soft navigations count as real pageviews, plus visitors, referrers, funnels, retention, and paths. For key moments you call window.smolanalytics.track("signup_clicked") and window.smolanalytics.identify(userId) from anywhere in your component tree, and a tiny useTrack hook wraps that so a button's onClick is one line. Because identify keys off a stable distinct_id, a user's first pageview, their signup, and the server events you POST to /v1/events (payments, provisioning, webhooks) fuse into one funnel. It works the same in Vite, Create React App, or any React SPA, because the install is one script tag plus one init, framework-agnostic. It is an open-source single Go binary you self-host free forever, or a hosted instance from $9/month, and instead of building dashboards you ask it "where do users drop off?" in plain English and the answer is computed from your events, never guessed.
one script tag and one init, not a framework plugin
Honest pricing: 14-day full trial, no credit card. Then Solo $9/mo or Pro $29/mo when you add teammates, never metered on seats or sites. Overage is $5/million with an emailed receipt, the dashboard never locks, and self-hosting the single Go binary is free forever (MIT).
Paste initAnalytics() tonight.
One init in your entry file, SPA routes autocaptured, track() and identify() for the moments that matter. Tomorrow morning the verdict tells you which part of the funnel to fix.