feat(sdk): 0.2.1——track补归属+business接线

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-18 23:47:44 +08:00
parent 7b670f274c
commit fea19c15cd
5 changed files with 132 additions and 15 deletions
+12 -2
View File
@@ -1,8 +1,9 @@
import { uuid } from "./util";
import { mergeConfig } from "./config";
import { Transport } from "./transport";
import { startPageSession } from "./page";
import { startPageSession, getPageSession } from "./page";
import { startStayTracking } from "./stay";
import { startBusinessTracking } from "./business";
import { buildEnvContext, collectHighEntropyHints, pageContext } from "./context";
import { SDK_VERSION, BUILD_ID, SCHEMA_VERSION, CONFIG_VERSION } from "./types";
import type { CtkConfig } from "./config";
@@ -65,8 +66,17 @@ function dispatch(cmd: string, arg?: unknown) {
...ps.attribution(),
});
startStayTracking(transport, ps);
// 0.2.1 接线(T5):业务事件自动监听(contact_click / form_* / product_view)。
// 必须在 startPageSession 之后——emit 经 getPageSession() 取归属,无会话时
// 守卫静默丢弃(business.test.ts 首例覆盖异常顺序)。幂等性依赖调用方守卫:
// init 的 !transport 条件已保证只调一次。product_view 的 init 判定读挂载时
// 同步的 location.pathname——置于 startStayTracking 之后无时序敏感(首帧判定)。
startBusinessTracking(transport);
} else if (cmd === "track" && transport) {
transport.push(arg as object);
// track 补当前段归属(T5):宿主字段展开在前、归属在后——归属键权威(宿主
// 伪造的 site_id 等被覆盖),其余宿主字段原样保留。PageSession 未启动时
// attribution() 为 undefined,展开为无操作——保持原样走兜底组路径。
transport.push({ ...(arg as object), ...getPageSession()?.attribution() });
} else if (cmd === "flush" && transport) {
transport.flush();
}
+1 -1
View File
@@ -9,7 +9,7 @@ export interface Attribution {
epoch?: null; // V1.1 预留
grant_ref?: null; // V1.1 预留
}
export const SDK_VERSION = "0.2.0"; // 与 package.json 同步手维护
export const SDK_VERSION = "0.2.1"; // 与 package.json 同步手维护
export const SCHEMA_VERSION = 2;
export const CONFIG_VERSION = "1";