Skip to content

修复 Flutter PAGE 事件时间戳与 VIEW_CLICK pageShowTimestamp 不一致 - #50

Merged
YoloMao merged 1 commit into
masterfrom
fix/flutter-page-timestamp
Jul 6, 2026
Merged

修复 Flutter PAGE 事件时间戳与 VIEW_CLICK pageShowTimestamp 不一致#50
YoloMao merged 1 commit into
masterfrom
fix/flutter-page-timestamp

Conversation

@YoloMao

@YoloMao YoloMao commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

背景

CDP/SaaS 模式下,Flutter 页面的 PAGE 事件 timestamp 与同页 VIEW_CLICK 的 pageShowTimestamp 对不齐(实测偏差约几十 ms)。这会破坏 CDP 服务端「点击 → 页面浏览实例」的归因。

根因

Flutter(Dart)侧 GrowingPageEvent.toNativeMap() 已经把页面显示时间戳放进 timestamp 字段随 trackFlutterPage 上报,且该值与 click 的 pageShowTimestamp 同源(均取自 currentPage.pageEvent.timestamp)。

但 HarmonyOS 原生侧 Flutter.trackFlutterPage 未读取该字段PageInfo.timestamp 保持默认 0,随后被 EventBuilder.build 用原生 Date.now() 重新盖章——于是 PAGE 用的是「原生收到时刻」,click 用的是「Flutter 页面显示时刻」,两者相差一段跨 Platform Channel 的链路延迟。

改动

Flutter.trackFlutterPage 读取 argument['timestamp'] 并赋给 pageInfo.timestamp

  • 有效正整数 → 使用它,使 PAGE 与 click 的 pageShowTimestamp 同源;
  • 缺省时保持默认 0,由 EventBuilder 回退到 Date.now(),兼容不携带 timestamp 的旧版 Flutter SDK。

写法与同文件 ptm/title/path 的内联解析保持一致,仅 4 行。

影响范围

  • 仅影响 Flutter 桥接的 PAGE 事件时间戳来源;原生/Hybrid/UniApp 路径不受影响。
  • 对 NewSaaS 的 FlutterPageEvent 路径同样生效。

验证

  • GrowingAnalytics HAR 构建通过(BUILD SUCCESSFUL)。
  • ⏳ 建议在真机用 Flutter 示例复现,确认 PAGE.timestamp 与 VIEW_CLICK.pageShowTimestamp 一致。
  • ⏳ 待核对 iOS 端 trackFlutterPage 的 timestamp 取值口径,保证多端一致。

🤖 Generated with Claude Code

Flutter SDK reports the page-show timestamp via trackFlutterPage, but the
native side ignored it and let EventBuilder re-stamp the PAGE event with
Date.now(). This made the PAGE timestamp diverge from the VIEW_CLICK
pageShowTimestamp (which faithfully carries the same Flutter-side value),
breaking click-to-page attribution in CDP/SaaS.

Read the timestamp from the argument map and use it for the PageInfo; fall
back to the default 0 (EventBuilder Date.now()) when absent to stay
compatible with older Flutter SDKs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@YoloMao
YoloMao merged commit f0ef0f6 into master Jul 6, 2026
1 check passed
@YoloMao
YoloMao deleted the fix/flutter-page-timestamp branch July 6, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant