Files
patbond-flutter/lib/analytics/analytics_page_name.dart
T
lixi f501a959f3
CI / flutter-gates (push) Successful in 1m9s
修复:埋点接线与三处偏差(sessionId/eventId/设备信息)
- 生产接线修复:app.dart 组装时传 analytics 实例给 ApiAuthRepository(_buildRepository),修复 M1 遗留的「生产环境 _analytics 恒为 null、挂接点空转」问题
- sessionId 生命周期:新建 SessionTracker (WidgetsBindingObserver),冷启动生成 UUIDv7、后台超 30 分钟换新、未超阈值沿用原值,不再每事件随机生成
- eventId 改 UUIDv7:对齐 13 号规范(uuid 包已在依赖,直接用 v7()),保留插入时间局部性
- appVersion 动态注入:package_info_plus(新增依赖)异步读取后 setAppVersion,不再硬编码 '1.0.0+1'
- osVersion 动态读取:Platform.operatingSystemVersion 正则提取主版本(如 android-14),不再硬编码
- 队列顺手加固:上传失败批次重回队首而非整批丢弃(一行级缓解,分段持久化属 M2 第二波)

测试新增 9 例:session_tracker_test(5 例:冷启动/短后台/长后台/级联状态/连续幂等),analytics_service_test 补强 4 例(UUIDv7/sessionId 不再逐事件生成/appVersion 可注入/失败重回队列)。

验收对照(06 号报告 §5.1 六条):1✓ SessionTracker 新建、2✓ 三条语义、3✓ 同会话 sessionId 一致、4✓ sessionId 为 UUID 不持久化、5✓ 单测 3 例(实际 5 例)、6✓ 真机脚本(开发者手测)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-07 14:45:41 +08:00

37 lines
1.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/// page_viewed 的 pageName 编译期枚举(06 号报告 §5.2 字典 v2 + 03 号评估
/// §3.2 Tab 映射)。禁止自由路由字符串;带参数路由必须归一化,任何
/// UUID/ID 不得出现在 pageName 或 referrer 中(隐私红线第 5 条)。
///
/// 尚不存在的 M2 页面(petList/petDetail/petForm/recordForm/recordDetail
/// 先留枚举定义、不接线,待健康档案页面族落地时启用。
enum AnalyticsPageName {
// —— 字典 v2 初始集合(06 §5.2 验收 2)——
login('login'),
register('register'),
home('home'),
profile('profile'),
petList('pet_list'),
petDetail('pet_detail'),
petForm('pet_form'),
recordForm('record_form'),
recordDetail('record_detail'),
// —— 客户端现存页面/Tab 补充(03 §3.2 Tab 映射,需数据侧同步进字典)——
create('create'),
petArchive('pet_archive'),
services('services'),
postDetail('post_detail');
const AnalyticsPageName(this.pageName);
/// 上报值,snake_case,与 RouteSettings.name 一致。
final String pageName;
static final Map<String, AnalyticsPageName> _byName = {
for (final page in values) page.pageName: page,
};
/// 路由名 → 枚举;不在枚举内返回 null(调用方不上报,06 §5.2 验收 4)。
static AnalyticsPageName? fromRouteName(String? name) =>
name == null ? null : _byName[name];
}