Loading...
Loading...
Compare original and translation side by side
@databuddy/sdk@databuddy/sdk| Import Path | Environment | Description |
|---|---|---|
| Browser (Core) | Core tracking utilities and types |
| React/Next.js | React component and hooks |
| Node.js/Server | Server-side tracking with batching |
| Vue.js | Vue plugin and composables |
| AI/LLM | Vercel AI SDK middleware for LLM analytics |
| 导入路径 | 运行环境 | 描述 |
|---|---|---|
| 浏览器(核心) | 核心追踪工具与类型定义 |
| React/Next.js | React组件与钩子 |
| Node.js/服务端 | 支持批量处理的服务端追踪 |
| Vue.js | Vue插件与组合式函数 |
| AI/LLM | 用于LLM分析的Vercel AI SDK中间件 |
import { Databuddy } from "@databuddy/sdk/react";
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<Databuddy
clientId={process.env.NEXT_PUBLIC_DATABUDDY_CLIENT_ID}
trackWebVitals
trackErrors
trackPerformance
/>
</body>
</html>
);
}import { Databuddy } from "@databuddy/sdk/react";
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<Databuddy
clientId={process.env.NEXT_PUBLIC_DATABUDDY_CLIENT_ID}
trackWebVitals
trackErrors
trackPerformance
/>
</body>
</html>
);
}import { Databuddy } from "@databuddy/sdk/node";
const client = new Databuddy({
clientId: process.env.DATABUDDY_CLIENT_ID,
enableBatching: true,
});
await client.track({
name: "api_call",
properties: { endpoint: "/users", method: "GET" },
});
// Important: flush before process exit in serverless
await client.flush();import { Databuddy } from "@databuddy/sdk/node";
const client = new Databuddy({
clientId: process.env.DATABUDDY_CLIENT_ID,
enableBatching: true,
});
await client.track({
name: "api_call",
properties: { endpoint: "/users", method: "GET" },
});
// 重要提示:在无服务器环境中,进程退出前需调用flush
await client.flush();import { FlagsProvider, useFlag, useFeature } from "@databuddy/sdk/react";
// Wrap your app
<FlagsProvider clientId="..." user={{ userId: "123" }}>
<App />
</FlagsProvider>
// In components
function MyComponent() {
const { on, loading } = useFeature("dark-mode");
if (loading) return <Skeleton />;
return on ? <DarkTheme /> : <LightTheme />;
}import { FlagsProvider, useFlag, useFeature } from "@databuddy/sdk/react";
// 包裹你的应用
<FlagsProvider clientId="..." user={{ userId: "123" }}>
<App />
</FlagsProvider>
// 在组件中使用
function MyComponent() {
const { on, loading } = useFeature("dark-mode");
if (loading) return <Skeleton />;
return on ? <DarkTheme /> : <LightTheme />;
}import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
import { openai } from "@ai-sdk/openai";
const { track } = databuddyLLM({
apiKey: process.env.DATABUDDY_API_KEY,
});
const model = track(openai("gpt-4o"));
// All LLM calls are now automatically trackedimport { databuddyLLM } from "@databuddy/sdk/ai/vercel";
import { openai } from "@ai-sdk/openai";
const { track } = databuddyLLM({
apiKey: process.env.DATABUDDY_API_KEY,
});
const model = track(openai("gpt-4o"));
// 所有LLM调用现在会被自动追踪| Option | Type | Default | Description |
|---|---|---|---|
| | Auto-detect | Project client ID |
| | | Disable all tracking |
| | | Track Web Vitals metrics |
| | | Track JavaScript errors |
| | | Track performance metrics |
| | | Enable event batching |
| | | Sampling rate (0.0-1.0) |
| | — | Glob patterns to skip tracking |
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| | 自动检测 | 项目客户端ID |
| | | 禁用所有追踪功能 |
| | | 追踪Web Vitals指标 |
| | | 追踪JavaScript错误 |
| | | 追踪性能指标 |
| | | 启用事件批量处理 |
| | | 采样率(0.0-1.0) |
| | — | 跳过追踪的Glob模式 |
<Databuddy
disabled={process.env.NODE_ENV === "development"}
clientId="..."
/><Databuddy
disabled={process.env.NODE_ENV === "development"}
clientId="..."
/><Databuddy
clientId="..."
skipPatterns={["/admin/**", "/internal/**"]}
maskPatterns={["/users/*", "/orders/*"]}
/><Databuddy
clientId="..."
skipPatterns={["/admin/**", "/internal/**"]}
maskPatterns={["/users/*", "/orders/*"]}
/>// Browser
import { track } from "@databuddy/sdk/react";
track("purchase", {
product_id: "sku-123",
amount: 99.99,
currency: "USD",
});
// Node.js
await client.track({
name: "subscription_renewed",
properties: { plan: "pro", amount: 29.99 },
});// 浏览器环境
import { track } from "@databuddy/sdk/react";
track("purchase", {
product_id: "sku-123",
amount: 99.99,
currency: "USD",
});
// Node.js环境
await client.track({
name: "subscription_renewed",
properties: { plan: "pro", amount: 29.99 },
});// Browser
window.databuddy?.setGlobalProperties({
plan: "enterprise",
abVariant: "checkout-v2",
});
// Node.js
client.setGlobalProperties({
environment: "production",
version: "1.0.0",
});// 浏览器环境
window.databuddy?.setGlobalProperties({
plan: "enterprise",
abVariant: "checkout-v2",
});
// Node.js环境
client.setGlobalProperties({
environment: "production",
version: "1.0.0",
});| Service | URL | Purpose |
|---|---|---|
| Analytics API | | Query analytics data |
| Event Tracking | | Send custom events |
| 服务 | URL | 用途 |
|---|---|---|
| 分析API | | 查询分析数据 |
| 事件追踪 | | 发送自定义事件 |
x-api-keycurl -H "x-api-key: dbdy_your_api_key" \
https://api.databuddy.cc/v1/query/websitesx-api-keycurl -H "x-api-key: dbdy_your_api_key" \
https://api.databuddy.cc/v1/query/websitescurl -X POST -H "x-api-key: dbdy_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"parameters": ["summary", "pages"],
"preset": "last_30d"
}' \
"https://api.databuddy.cc/v1/query?website_id=web_123"| Type | Description |
|---|---|
| Overall website metrics and KPIs |
| Page views and performance by URL |
| Traffic sources and referrers |
| Browser usage breakdown |
| Device category breakdown |
| Visitors by country |
| JavaScript errors |
| Web vitals and load times |
| Custom event data |
todayyesterdaylast_7dlast_30dlast_90dthis_monthlast_monthcurl -X POST -H "x-api-key: dbdy_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"parameters": ["summary", "pages"],
"preset": "last_30d"
}' \
"https://api.databuddy.cc/v1/query?website_id=web_123"| 类型 | 描述 |
|---|---|
| 网站整体指标与关键绩效指标(KPI) |
| 按URL统计的页面浏览量与性能数据 |
| 流量来源与引荐网站 |
| 浏览器使用情况细分 |
| 设备类别细分 |
| 访客所在国家/地区 |
| JavaScript错误信息 |
| Web Vitals与加载时间 |
| 自定义事件数据 |
todayyesterdaylast_7dlast_30dlast_90dthis_monthlast_monthcurl -X POST \
-H "Content-Type: application/json" \
-d '{
"type": "custom",
"name": "purchase",
"properties": {
"value": 99.99,
"currency": "USD"
}
}' \
"https://basket.databuddy.cc/?client_id=web_123"curl -X POST \
-H "Content-Type: application/json" \
-d '{
"type": "custom",
"name": "purchase",
"properties": {
"value": 99.99,
"currency": "USD"
}
}' \
"https://basket.databuddy.cc/?client_id=web_123"curl -X POST \
-H "Content-Type: application/json" \
-d '[
{"type": "custom", "name": "event1", "properties": {...}},
{"type": "custom", "name": "event2", "properties": {...}}
]' \
"https://basket.databuddy.cc/batch?client_id=web_123"curl -X POST \
-H "Content-Type: application/json" \
-d '[
{"type": "custom", "name": "event1", "properties": {...}},
{"type": "custom", "name": "event2", "properties": {...}}
]' \
"https://basket.databuddy.cc/batch?client_id=web_123"