修复 Flutter PAGE 事件时间戳与 VIEW_CLICK pageShowTimestamp 不一致 - #50
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
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:pageShowTimestamp同源;EventBuilder回退到Date.now(),兼容不携带 timestamp 的旧版 Flutter SDK。写法与同文件
ptm/title/path的内联解析保持一致,仅 4 行。影响范围
FlutterPageEvent路径同样生效。验证
GrowingAnalyticsHAR 构建通过(BUILD SUCCESSFUL)。trackFlutterPage的 timestamp 取值口径,保证多端一致。🤖 Generated with Claude Code