Lens
@tripo3d/lens· 前端数据采集内核 —— 把归因、埋点、错误、性能四套采集能力统一到一个内核,标准化加工后发往后端网关;基于@tripo3d/fingerprint提供稳定 device id。
lens 在浏览器侧采集数据、统一加工、本地缓冲,再发往后端网关;配置可经 CDN 远程控制。它默认只装归因 + 身份模块,行为 / 错误 / 性能模块按需引入。
一分钟上手
ts
import { TripoLens } from '@tripo3d/lens';
// 构造(务必在任何 URL 操作之前);app / configUrl / endpoint 三项必传
const trace = new TripoLens({ app: 'tripo', configUrl: '...', endpoint: '...' });
// 初始化:解析 device id + 装配插件 + 自动触发首访归因
await trace.init();
trace.deviceId; // 初始化后可取稳定设备 id
trace.entryUrl; // 构造时快照的完整入口 URL,不随后续路由变化这就是最小接入。各参数的含义与校验规则见 构造参数;想端到端跑通并看到第一条上报,跟着 快速开始 走一遍;需要行为埋点 / 错误 / 性能监控时,再按需 装配对应插件。
能力矩阵
lens 默认只装归因与身份两个插件;行为、错误、性能为 opt-in(构造时经 plugins 显式装配),并各自受权限 Consent 管控。
| 能力 | 产出事件类型 | 装配方式 | 受控 Consent |
|---|---|---|---|
| 渠道归因 | landing | 默认装(AttributionPlugin) | 不受管控,始终采集 |
| 身份绑定 | identity | 默认装(IdentityPlugin) | 不受管控 |
| 行为埋点 | click expo pageview hide show leave track | opt-in new TrackingPlugin(...) | tracking |
| 错误监控 | js promise resource white-screen api ssr | opt-in new ErrorPlugin(...) | errors |
| 性能监控 | performance | opt-in new PerformancePlugin(...) | performance |
ts
import { TripoLens, TrackingPlugin, ErrorPlugin, PerformancePlugin } from '@tripo3d/lens';
// 装配方式
const trace = new TripoLens({
app: 'tripo',
configUrl: '...',
endpoint: '...',
plugins: [
new TrackingPlugin({ autoTrack: true }),
new ErrorPlugin({ captureApi: true }),
new PerformancePlugin(),
],
});架构一览(六层 L1–L6)
L1 公共 API TripoLens —— 业务唯一接触面,稳定契约
L2 Core 内核 Identity · Session · Consent · Registry ·
EventBus · RemoteConfig · Breadcrumb
L3 Plugin 业务 Attribution(默认) · Identity(默认) ·
│ Tracking/Error/Performance(opt-in)
│ RawEvent(仅经 ctx.emit)
L4 Pipeline 加工 Enricher → killSwitch → Sampler →
│ Schema → PII → beforeEmit → Serializer
│ WireItem
L5 Transport 传输 单队列三级优先级 · OfflineStore · fetch keepalive
L6 Platform 适配 storage · url · dom · lifecycle ·
│ ssr · performance …(所有平台访问必经此层)
▼
后端网关(单 endpoint,X-DeviceId + 微服务路由头)前端职责边界
前端只做「采集 → 丰富上下文 → 本地缓冲 → 发到网关」。归因模型计算、Source Map 符号化、停留时长计算、ID 合并一概归后端——理解这条边界能避免很多「为什么前端拿不到 XX」的疑问。逐层拆解与这条边界见 架构总览。