使用你偏好的包管理器将 SDK 添加到你的项目。
npm install wrangleryarn add wranglerpnpm add wrangler以最简配置快速上手运行。
// Cloudflare Workerexport default { async fetch(request, env) { const url = new URL(request.url) if (url.pathname.startsWith('/tracio/')) { return fetch('https://edge.tracio.ai' + url.pathname) } return fetch(request) }}包含错误处理、加载状态和高级配置的生产级模式。
// Cloudflare Worker — production proxyexport default { async fetch(request: Request, env: Env): Promise<Response> { const url = new URL(request.url) if (!url.pathname.startsWith('/tracio/')) { return fetch(request) } // Strip the /fp prefix and proxy to your tracio.ai server const targetPath = url.pathname.replace(/^\/tracio/, '') const target = `https://${env.TRACIO_ORIGIN}${targetPath}${url.search}` const headers = new Headers(request.headers) headers.set('X-Forwarded-For', request.headers.get('CF-Connecting-IP') || '') headers.set('X-Real-IP', request.headers.get('CF-Connecting-IP') || '') const response = await fetch(target, { method: request.method, headers, body: request.method !== 'GET' ? request.body : undefined, }) // Cache static agent script for 1 hour const res = new Response(response.body, response) if (targetPath.includes('/agent')) { res.headers.set('Cache-Control', 'public, max-age=3600') } return res },}用于初始化和配置 SDK 的所有可用选项。
publicKeystring来自仪表盘的公钥 — 可安全地随浏览器代码发布endpointstring用于代理路由部署的自定义端点 URL — 显式 URL 优先于 regionregionstring数据区域:us 或 eutimeoutMsnumber整个 getResult() 调用的超时时间(毫秒)linkedIdstring已登录用户在您系统内的账户 ID,用于关联共享同一设备的访问tagstring附加到识别请求上的自由格式标签,例如 checkout 或 logindebugboolean将脚本生命周期和网络活动输出到浏览器控制台scriptUrlstring完全覆盖 agent 脚本 URL — 用于自托管或 Subresource Integrity通过完整的 API 参考、webhook 配置和高级指南深入了解。