프로덕션에 배포하기 전에 통합이 올바르게 작동하는지 확인하세요.
무료 요금제에 가입하고 대시보드의 API Keys에서 공개 키를 가져오세요. 이 키는 즉시
작동하며 클라이언트 측 코드에 포함해 배포해도 안전합니다. 로컬 개발과 테스트에
사용하세요. 이 키를 Tracio.init()에 전달합니다:
import { Tracio } from "@tracio/sdk"
const tracio = Tracio.init({ publicKey: "YOUR_PUBLIC_KEY" })const result = await tracio.getResult()console.log(result.visitorId, result.bot.detected)빌드가 필요 없는 엣지 스니펫을 통해 에이전트를 로드하는 경우, 동일한 키를 k 쿼리 파라미터에 사용할 수 있습니다:
<script src="https://edge.tracio.ai/s.js?k=YOUR_PUBLIC_KEY" async></script>SDK가 로드된 페이지의 브라우저 콘솔에서 다음을 실행하여 SDK가 초기화되고 결과를 반환하는지 확인하세요:
import { Tracio } from "@tracio/sdk"
const tracio = Tracio.init({ publicKey: "YOUR_PUBLIC_KEY" })const result = await tracio.getResult()console.assert(typeof result.visitorId === "string", "visitorId should be a string")console.assert(typeof result.bot.detected === "boolean", "bot.detected should be a boolean")console.log("Integration verified:", result.visitorId)단위 테스트에서는 일반적으로 실제 네트워크 호출을 원하지 않습니다. Tracio 모듈을 목킹하고, 코드가 getResult()를 올바르게 사용하는지 검증하세요. Vitest를 사용하는 경우:
import { vi, test, expect } from "vitest"import { Tracio } from "@tracio/sdk"
vi.mock("@tracio/sdk", () => ({ Tracio: { init: () => ({ getResult: async () => ({ visitorId: "test-visitor-id", bot: { detected: false, confidence: 0 }, }), }), },}))
test("renders the visitor id", async () => { const tracio = Tracio.init({ publicKey: "YOUR_PUBLIC_KEY" }) const result = await tracio.getResult() expect(result.visitorId).toBe("test-visitor-id") expect(result.bot.detected).toBe(false)})목킹된 getResult()가 TracioError로 reject하도록 하여 오류 처리도 검증할 수 있습니다.
식별 결과를 자신의 서버에서 처리하려면, 서명된
webhook으로 결과를 수신하세요 — 각 이벤트는 검증할 수 있는
X-Tracio-Signature HMAC와 함께 엔드포인트로 전달됩니다.