@ 剪贴板- 健康/ 分析
类型安全分析包 围绕我们的第三方分析提供者 用户识别和事件跟踪.
目录
安装
npm install @clipboard-health/analytics
使用量
基本分析跟踪
import { Analytics } from "@clipboard-health/analytics";
const logger = {
info: console.log,
warn: console.warn,
error: console.error,
};
{
// Basic usage with both features enabled
const analytics = new Analytics({
apiKey: "your-segment-write-key",
logger,
enabled: { identify: true, track: true },
});
// Identify a user
analytics.identify({
userId: "user-123",
traits: {
email: "[email protected]",
name: "John Doe",
createdAt: new Date("2023-01-01"),
type: "worker",
},
});
// Track an event
analytics.track({
userId: "user-123",
event: "Button Clicked",
traits: {
buttonName: "Apply",
page: "home",
plan: "worker",
},
});
}
{
// Disabled analytics example
const analytics = new Analytics({
apiKey: "your-segment-write-key",
logger,
enabled: { identify: false, track: false },
});
// These calls will be logged but not sent to Segment
analytics.identify({
userId: "user-789",
traits: { email: "[email protected]" },
});
analytics.track({
userId: "user-789",
event: "Page View",
traits: { page: "home" },
});
}
地方发展指挥部
见 package.json scripts 用于命令列表.