03Install guide
Add Metryo to a React app
Add the snippet to index.html and you are done. Navigation through React Router or any router built on the History API is picked up without a line of code.
- 01
Create the website in your dashboard
Choose Add website and enter its name and domain, without https://. You get a site ID that looks like site_k3v9x2m4q1. To try it on your own machine first, register localhost:3000 as the domain.
- 02
Add the snippet to index.html
index.htmlReplace site_xxxxx with your own site ID — everything else is copied as it is.
src/SignupButton.tsx - 03
Open your site
Load any page of your site in a browser. The dashboard's install screen checks every few seconds and unlocks the moment the first pageview arrives.
Do not report route changes yourself
React Router, TanStack Router and wouter all navigate with history.pushState, and the script already records a pageview each time that is called. An effect that also calls metryo.pageview() on every location change counts each page twice — and uses your monthly allowance twice as fast.
Hash routers
If your app routes with the URL fragment — HashRouter, or addresses like /#/settings — add data-hash="on" to the tag. Each fragment change then counts as a pageview. See script options.
TypeScript
Pasted it but nothing arrives?
- An extension is blocking it. Ad blockers and privacy extensions drop analytics requests. Check in a private window with extensions disabled.
- It is running on a different domain. A snippet only accepts events from the domain its website was registered with, and that domain's subdomains, so nobody else can send data in your name. Add a separate website for any other domain.
- You muted yourself earlier. Setting metryo_ignore in localStorage silences the script in that browser. Remove the key to start sending again.
- The monthly allowance ran out. Once an account passes its plan's allowance, new events stop being recorded until the next month. The allowance is shared across all of an account's websites.
Next: send custom events, turn on click tracking, or see every option the tag accepts.