@tracio/react पैकेज कोर @tracio/sdk को रैप करता है और idiomatic React primitives उपलब्ध कराता है: एक provider जो agent को माउंट करता है, और hooks जो आपको loading तथा error state के साथ visitor ID और identification result देते हैं।
npm install @tracio/react @tracio/sdkreact (18 या 19) एक peer dependency है और यह अपेक्षित है कि यह आपके ऐप में पहले से इंस्टॉल हो।
अपने application को <TracioProvider> से रैप करें। यह पहले render पर TRACIO agent को माउंट करता है और provider के unmount होने पर स्वतः tracio.destroy() को कॉल करता है।
import { TracioProvider } from "@tracio/react"
function Root() { return ( <TracioProvider publicKey={process.env.NEXT_PUBLIC_TRACIO_KEY!}> <App /> </TracioProvider> )}| Prop | Type | Description |
|---|---|---|
publicKey | string | आपकी public key। इसे अपने dashboard से कॉपी करें। |
config | TracioConfig | पूरा config object। नीचे दिए flat scalar props पर वरीयता रखता है। |
endpoint | string | कस्टम API endpoint (first-party-proxied endpoint के लिए)। |
scriptUrl | string | agent script के लिए कस्टम URL (first-party-proxied endpoint के लिए)। |
debug | boolean | console में विस्तृत diagnostics लॉग करता है। |
timeoutMs | number | timeout होने से पहले result के लिए कितनी देर प्रतीक्षा करनी है (default 15000)। |
children | ReactNode | आवश्यक — रैप किया जाने वाला React subtree। |
या तो publicKey के साथ flat scalars पास करें, या एक पूर्ण config object। जब दोनों दिए जाते हैं, तो config जीतता है।
loading और error state के साथ स्थिर visitor identifier लौटाता है।
const { data, isLoading, error, isFetched, getId } = useVisitorId()// data: string | undefined — the visitorIdgetId() visitor ID को imperatively फिर से fetch करता है।
पूरा TracioResult लौटाता है (visitor ID के साथ bot detection)।
const { data, isLoading, error, isFetched, getData } = useTracioResult()// data: TracioResult | undefinedopts.immediate का default true है। fetch को तब तक टालने के लिए { immediate: false } पास करें जब तक आप स्वयं getData() को कॉल न करें — किसी consent gate के पीछे यह उपयोगी है:
const { data, getData } = useTracioResult({ immediate: false })
function onConsent() { getData() // identify only after the user opts in}Escape hatch जो उन्नत उपयोग के लिए अंतर्निहित instance लौटाता है।
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 जिस पर hooks आधारित हैं