React
npm install @x3growth/sdk// src/main.tsx
import { createRoot } from "react-dom/client";
import { X3Provider } from "@x3growth/sdk/react";
import { App } from "./App";
createRoot(document.getElementById("root")!).render(
<X3Provider options={{ key: import.meta.env.VITE_X3_KEY, host: "/n3" }}>
<App />
</X3Provider>,
);// anywhere below the provider
import { useX3 } from "@x3growth/sdk/react";
export function PricingToggle() {
const x3 = useX3();
return <button onClick={() => x3.track("pricing_toggle", { period: "yearly" })}>Yearly</button>;
}X3Providercallsinitonce on mount. React StrictMode's unmount/remount in development does not split the pageview: stopping is deferred by a task and cancelled by the remount.- Routing needs no wiring: the History API patch reports React Router, TanStack Router and similar
navigations as
spapageviews. useX3()returns the same API as the npm package (SDK reference). The tracker is a singleton, so the hook also works outside a provider (calls beforeinitwait for the tracker to start).useTrackOnMount(name, props?)tracks one event when the component mounts (again only whennameor the props change) – for exampleuseTrackOnMount("quiz_view", { variant: "pricing-quiz" })on a quiz step.
Without the provider
Calling init in your entry file and importing track where needed works just as well; the
provider only adds lifecycle handling and the hook.
Next.js
Use the dedicated adapter: Next.js.