Before you start
Create a free Cool Analytics account and add your site. You'll get a site ID — replace YOUR_SITE_ID in the code below with it. The dashboard shows the snippet with your ID already filled in.
Install on React
- 1Open the HTML entry file — index.html in the project root for Vite, public/index.html for Create React App.
- 2Paste the snippet inside <head>.
- 3Build and deploy. Every React Router (or TanStack Router) navigation is recorded as a pageview.
<script defer src="https://coolanalytics.dev/hb.js" data-site="YOUR_SITE_ID"></script>
Check that it works
Open your live site in a new tab, then open your Cool Analytics dashboard. Your visit appears on the live map within seconds — with the page you're on, where you came from and your browser.
Nothing showing up? Make sure you're looking at the published site (not a preview or editor), that an ad blocker isn't blocking the script, and that you're not testing on localhost.
Track signups, purchases and clicks
Pageviews, sources, countries and outbound link clicks are tracked automatically. For the moments that matter to you, send a custom event. Events named like a signup show up as signups, and events with an amount show up as revenue — on the live map and per traffic source.
// anywhere in your React site's browser code
window.hb?.track("signup");
// with an amount, it shows up as revenue
window.hb?.track("purchase", { amount: 49 });React tips
- Client-side route changes are tracked automatically — the script listens to the browser history, so there's no router hook to wire up.
- Don't load the script from inside a component with useEffect — it would be added again on remounts. The HTML file is the right place.
- Visits from localhost are ignored so your own development doesn't count. To test locally, add data-dev="1" to the script tag for a moment — then remove it.
Want to keep your own visits out of the stats? Open your site once with #hb-ignore at the end of the URL. That browser is excluded until you visit with #hb-track.
React analytics FAQ
How do I track a button click in React?+
Call window.hb?.track('signup') in your onClick handler. The optional chaining keeps it safe if an ad blocker stopped the script.
Does it work with hash routing (#/page)?+
Path-based routing is tracked out of the box. Hash-only routers don't change the path, so use BrowserRouter for accurate page stats.
Is there an npm package?+
You don't need one. The script is about 3 KB and loads with defer, so it's lighter than most React analytics wrappers.