This guide walks you through integrating TRACIO into your application. You will install the client SDK, initialize it with your public key, and read your first visitor identification result.
Install the TRACIO SDK using your preferred package manager:
npm install @tracio/sdkOr with pnpm:
pnpm add @tracio/sdkOr with yarn:
yarn add @tracio/sdkIf you don't use a bundler, drop the edge script tag into your page. It auto-initializes with the public key in the k query parameter:
<script src="https://edge.tracio.ai/s.js?k=PUBLIC_KEY" async></script>Import Tracio and call Tracio.init() with your public key. This returns a TracioInstance immediately — the underlying agent loads in the background.
import { Tracio } from "@tracio/sdk"
const tracio = Tracio.init({ publicKey: "5ca175fc...",})Your public key is safe to ship in client-side code. You can find it in your dashboard under API Keys.
Tracio.init() accepts a TracioConfig object:
| Option | Type | Default | Description |
|---|---|---|---|
publicKey | string | required | Your public key. Copy it from your dashboard. |
region | "us" | "eu" | none | Optional data region. When unset, the SDK uses the generic https://edge.tracio.ai endpoint (no implied US data residency). Set it explicitly to pin us or eu. |
endpoint | string | auto | Custom API endpoint (for self-hosted deployments). |
scriptUrl | string | auto | Custom URL for the agent script (for self-hosted deployments). |
linkedId | string | none | Identifier linking this visitor to an entity in your system. |
tag | string | none | Free-form label attached to the request for later filtering. |
debug | boolean | false | Logs verbose diagnostics to the console. |
timeoutMs | number | 15000 | How long to wait for the result before timing out. |
Call tracio.getVisitorId() to receive a stable visitor identifier. This is an asynchronous operation.
const visitorId = await tracio.getVisitorId()
console.log(visitorId) // "X7fh2Hg9LkMn3pQr"Call tracio.getResult() to receive the full identification result, including bot detection.
const result = await tracio.getResult()
console.log(result.visitorId) // "X7fh2Hg9LkMn3pQr"
if (result.bot.detected) { console.warn("bot, confidence:", result.bot.confidence)}The result has the shape:
{ visitorId: "X7fh2Hg9LkMn3pQr", bot: { detected: false, confidence: 2, // 0-100 reasons: [], },}Use the lifecycle callbacks to react when the agent is ready or when something fails, and destroy() to tear down the instance:
const tracio = Tracio.init({ publicKey: "5ca175fc..." })
tracio.onReady((result) => { console.log("ready:", result.visitorId)})
tracio.onError((error) => { console.error("tracio error:", error.code, error.message)})
// later, when you no longer need ittracio.destroy()See Error Handling for the full list of error codes and retry helpers.
import { Tracio } from "@tracio/sdk"
const tracio = Tracio.init({ publicKey: "5ca175fc..." })
async function handleLogin(email: string, password: string) { const visitorId = await tracio.getVisitorId()
const response = await fetch("/api/login", { method: "POST", body: JSON.stringify({ email, password, visitorId }), })
return response.json()}import { Tracio } from "@tracio/sdk"
const tracio = Tracio.init({ publicKey: "5ca175fc...", tag: "payment",})
async function processPayment(paymentData: PaymentData) { const result = await tracio.getResult()
if (result.bot.detected) { throw new Error("Automated client detected") }
const response = await fetch("/api/payment", { method: "POST", body: JSON.stringify({ ...paymentData, visitorId: result.visitorId }), })
return response.json()}