React
Track route changes and product events in React applications.
Create a provider
Initialize the tracker once in a client component mounted near the application root. endpoint is the collector. apiHost is the web origin for flags.
useEffect(() => {
window.analytica?.push(["init", {
projectId: "prj_your_app",
endpoint: "https://collector.example.com/api/collect",
apiHost: "https://analytics.example.com"
}]);
}, []);Track navigation
Call pageview when your router changes location. The built-in tracker can also observe standard history changes.
Use path goals for important routes (for example /onboarding/done) and track() for button-level conversions that power Goals and Funnel steps.
window.analytica?.push(["track", "checkout_started", { cart_total: 49 }]);