React
React (Vite, CRA, Remix client) + @millimetric/track.
Install
npm i @millimetric/trackInit at the root
// src/main.tsx (Vite)
import { StrictMode, useEffect } from "react";
import { createRoot } from "react-dom/client";
import { init } from "@millimetric/track";
import App from "./App";
function Analytics({ children }: { children: React.ReactNode }) {
useEffect(() => {
init({
key: import.meta.env.VITE_AOA_KEY!,
host: import.meta.env.VITE_AOA_HOST ?? "https://api.millimetric.ai"
});
}, []);
return <>{children}</>;
}
createRoot(document.getElementById("root")!).render(
<StrictMode>
<Analytics>
<App />
</Analytics>
</StrictMode>
);The SDK auto-fires $pageview on init and on every history.pushState / popstate, so React Router and Tanstack Router are handled without extra wiring.
Identify on login
Drop <IdentifyOnAuth /> once near the top of your tree — usually next to your auth provider.
Track on intent
A tiny custom hook (optional)
It's a one-liner — no global provider needed. The SDK is its own singleton.
React Router — manual page() if you turn off auto
Auto-pageviews handle most apps. Turn them off only if you need full control:
React Server Components / SSR
Don't call SDK functions in components rendered on the server — the SDK reads localStorage and navigator. Mark anything analytics-related "use client" (Next.js / RSC) or render it inside a client-only boundary (Remix ClientOnly).
For Next.js specifically, see the Next.js page.
Tracking errors / boundaries
Last updated
Was this helpful?