The @tracio/react package wraps the core @tracio/sdk and exposes idiomatic React primitives: a provider that mounts the agent, and hooks that hand you the visitor ID and identification result with loading and error state.
npm install @tracio/react @tracio/sdkreact (18 or 19) is a peer dependency and is expected to already be installed in your app.
Wrap your application with <TracioProvider>. It mounts the TRACIO agent on first render and calls tracio.destroy() automatically when the provider unmounts.
import { TracioProvider } from "@tracio/react"
function Root() { return ( <TracioProvider publicKey={process.env.NEXT_PUBLIC_TRACIO_KEY!}> <App /> </TracioProvider> )}| Prop | Type | Description |
|---|---|---|
publicKey | string | Your public key. Always starts with tracio_pk_. |
config | TracioConfig | Full config object. Takes precedence over the flat scalar props below. |
endpoint | string | Custom API endpoint (for self-hosted deployments). |
scriptUrl | string | Custom URL for the agent script (for self-hosted deployments). |
debug | boolean | Logs verbose diagnostics to the console. |
timeoutMs | number | How long to wait for the result before timing out (default 15000). |
children | ReactNode | Required — the React subtree to wrap. |
Pass either publicKey plus the flat scalars, or a complete config object. When both are supplied, config wins.
Returns the stable visitor identifier with loading and error state.
const { data, isLoading, error, isFetched, getId } = useVisitorId()// data: string | undefined — the visitorIdgetId() re-fetches the visitor ID imperatively.
Returns the full TracioResult (visitor ID plus bot detection).
const { data, isLoading, error, isFetched, getData } = useTracioResult()// data: TracioResult | undefinedopts.immediate defaults to true. Pass { immediate: false } to defer the fetch until you call getData() yourself — useful behind a consent gate:
const { data, getData } = useTracioResult({ immediate: false })
function onConsent() { getData() // identify only after the user opts in}Escape hatch that returns the underlying instance for advanced use.
const { tracio } = useTracio()import { TracioProvider, useVisitorId } from "@tracio/react"function App() { return ( <TracioProvider publicKey={process.env.NEXT_PUBLIC_TRACIO_KEY!}> <Page /> </TracioProvider> )}function Page() { const { data: visitorId, isLoading, error } = useVisitorId() if (isLoading) return <span>Loading…</span> if (error) return <span>Error: {error.message}</span> return <span>Visitor: {visitorId}</span>}@tracio/sdk API the hooks build on