To add Obsidesk to a React app built with Vite or Create React App, paste the script tag into index.html. It tracks page views as the route changes, detects form signups and, with a revenue source connected, shows revenue by channel.
What you get
- Page views for every client-side route change
- Signups from forms with an email field
- Custom events and identify calls from any component
- Revenue by channel with a connected revenue source
- Cookieless tracking
Set it up
- 1Create your account and add your domain
Sign up, add the domain you want to track and copy your site ID from Settings. Every plan has a 14-day money-back guarantee; there is no free trial.
- 2Paste the script into index.html
Vite keeps it at the project root, Create React App in
public/index.html. Put it inside<head>.<script defer src="https://obsidesk.com/script.js" data-site="YOUR_SITE_ID"></script>
- 3Build and open your deployed site
Open your site in a normal browser window and check that the visit appears in the live view. Visits on localhost are not counted unless you add
data-allow-localhost, and your own visits can be excluded by opening#obsidesk-ignoreonce. - 4Identify users after sign-in
If you sign users in with OAuth or a magic link rather than a form, call identify once the user is known.
window.obsidesk?.identify(user.email, user.name);
- 5Track key actions
Call track from event handlers.
window.obsidesk?.track("Upgrade clicked", { plan: "pro" });
Single-page navigation
The script follows history changes, so route changes made by React Router or any router count as page views without extra code. You can also use the npm package (@obsidesk/analytics/react), but the script tag works without it.
A note on TypeScript
window.obsidesk is not typed. Use optional chaining as above, or declare it once in a global.d.ts file.
FAQ
How do I add analytics to a Vite React app?
Paste the Obsidesk script tag in index.html, inside <head>, with your site ID. Deploy and visit your site.
Does it track React Router navigation?
Yes. The script follows history changes, so client-side route changes are recorded as page views.
How do I track signups in React?
Form submissions with an email field are detected automatically. For other flows, call window.obsidesk?.identify(email, name).
Do I need the npm package?
No. The script tag works everywhere. The package @obsidesk/analytics is also available if you prefer a component.
Works with
Connect React in about a minute.
14-day money-back guarantee. Installed in 30 seconds. Read-only revenue connections.