Handle identity changes and keep SDK outages from interrupting pages

This commit is contained in:
2026-09-16 04:49:22 +08:00
parent 9d6ef1ec39
commit af5b797290
3 changed files with 36 additions and 12 deletions
+3 -1
View File
@@ -42,7 +42,9 @@ export function ServerStatus() {
`createClient(...).initialize()` 可用于非 Provider 接入,首次 track 也会自动初始化。提供 `autoInitialize={false}` 可延后 Provider 初始化;track 仍会初始化。
请求使用 credentials: include,匿名 token 默认保存在按 API 地址和应用隔离的 localStorage,可传入 storage: null 禁用或提供自定义存储。服务器仍提供 HttpOnly Cookie;不能靠设备指纹跨站识别。
`prepareEvent` 创建带固定 event_id / occurred_at 的可序列化请求,`sendEvent` 可重试同一请求;不要为同一次重试重新调用 track,否则会生成新 ID。本版没有自动重试、离线队列或批量发送。
服务器错误(未注册、参数错误、凭据错误)作为 Promise rejection 返回调用方。Provider 初始化失败抛出错误,可使用 React ErrorBoundary。
服务器错误(未注册、参数错误、凭据错误)作为 Promise rejection 返回调用方。Provider 初始化失败通过可选 onInitializationError 回调报告,不中断客户页面。
仅 collectionKey 可配置到 SDK;不得放入 server_key、management_key 或平台 SERVICE_TOKEN。客户端事件是行为信号,不作为付款、投递结果或广告计费的可信证据。
检查:`npm test` 包含 TypeScript 构建和初始化、身份恢复、幂等请求及应用隔离测试。
登录/身份缝合后,可把受控登录接口返回的新匿名身份传给 client.updateIdentity,更新 SDK 缓存;退出登录调用 client.resetIdentity,签发新匿名身份并覆盖本地存储。SDK 不持有身份管理接口的服务端凭据。