Skip to content

feat(saas): SaaS 无埋点采集与可视化圈选支持 - #41

Merged
YoloMao merged 23 commits into
masterfrom
feat/saas_autotrack
Jun 24, 2026
Merged

feat(saas): SaaS 无埋点采集与可视化圈选支持#41
YoloMao merged 23 commits into
masterfrom
feat/saas_autotrack

Conversation

@YoloMao

@YoloMao YoloMao commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

概述

本 PR 为 SaaS 模式补齐两大能力:无埋点采集(原生 + Hybrid 的点击 / 输入变更 / 页面浏览)与可视化圈选(扫码圈选原生页面 + Hybrid 页面)。完成后 SaaS 模式在采集与圈选层面与 New SaaS / CDP 对齐,并与 iOS / Android SaaS SDK 的协议保持一致。

说明:本描述以最终交付结果为准,不逐条对应中间 commit。


一、SaaS 无埋点采集

原生采集

  • SaaS 模式下启用无埋点点击(clck)、输入变更(chng)、页面浏览(PAGE)采集,xpath / page 生成逻辑复用 CDP(PATH_SEPARATOR + node[xcontent] 格式)。
  • 上报走新增的 SaaS_OTHER 发送通道(/harmonyos/other),事件按 MeasurementProtocol V2 序列化为 clck / chng
  • 同页面(t/u/s/d/p/ptm/r 一致)的多条点击事件在 JSON 序列化阶段合并为一条(mergeSaaSClick):公共字段提升至顶层,元素专属字段(x/v/idx/h/gesid/esid)收入 e 数组,降低上报体积,与 iOS SaaS 行为一致。

Hybrid 采集

  • WebView 内的 clck / chng 事件经 _vds_bridge 上报后,由 SDK 解析元素信息(xpath、textValue、index、hyperlink)并拼接原生页面路径前缀后入库上报。

接入方使用方式(README_SaaS)

  • 新增配置项 autotrackEnabled(默认 false)、autotrackAllPages(默认 false)。
  • 无埋点监听需在 onWindowStageCreate 中调用 GrowingAnalytics.onWindowStageCreate(...);仅配置开关而不注册监听不会产生事件。
  • 支持通过 growing_alias / growing_title / growing_attributes 设置页面别名 / 标题 / 属性(Navigation 与 @ohos.router 两种导航方式)。

二、SaaS 可视化圈选

圈选入口(URL Scheme 回跳)

  • 接入方在 module.json5 配置 URL Scheme,并在 EntryAbilityonCreate / onNewWant 中调用 GrowingAnalytics.handleOpenURL(uri)
  • SaaS 模式下解析回跳参数 circleType / wsHost / circleRoomNumber,由 wsHost + accountId + circleRoomNumber 拼接圈选 wss 地址并建连。

连接签名

  • SaaS 圈选 wss 连接追加 timestamp 查询参数,并附带 Authorization: Sign SHA1 <sig> 头,其中 sig = SHA1("<path>:<timestamp>") 的小写 hex。New SaaS / CDP 与 MobileDebugger 连接不受影响。

圈选数据上报

  • SaaS 圈选采用独立的 UserAction 协议(refresh / click / page),携带页面信息、截图、impress 元素列表及命中的 targets,相关模型集中在新增的 mobileDebugger/SaaSModel.ets

Hybrid 圈选

  • 新增公开 API GrowingAnalytics.onPageEnd(controller, webviewId?),接入方在 WebView onPageEnd 回调中调用。圈选激活时动态注入圈选脚本(vds_web_circle_plugin.min.js),并通过 runJavaScript 把 WebView 所在的原生 xpath 写入 window._vds_hybrid_native_info,供 Web 侧定位。
  • createHybridProxy 增加可选 webviewId 参数,配合 Web 控件 .id(webviewId) 支持多 WebView 圈选。
  • 服务端下发圈选指令时:携带坐标则通过 FrameNode 布局矩形命中目标 WebView 并做坐标系转换(server vp → device px)后定向转发,无坐标则广播给所有已注册 WebView,最终转发给 Web 侧 _vds_hybrid.helper.handleWebEvent()
  • 新增插件回调 PluginsInterface.onWebViewSaaSCircleEvent(message, webviewId?),由核心模块内的 Circle 圈选插件消费(Hybrid 收到 Web 侧圈选事件 → Plugins 广播 → Circle 转发给服务端)。

三、配套修复与改动

  • 混淆:将 Hybrid JS Bridge 方法名(New SaaS 的 GrowingWebViewJavascriptBridge、SaaS 的 _vds_bridge)加入 consumer-rules.txt / obfuscation-rules.txt-keep-property-name,修复 release 包属性混淆导致原生桥方法不可达(webview FindMethod fail)、Hybrid 页面零事件的问题。
  • ViewElementEvent:新增 query / hyperlink 字段;SaaS 模式补齐 pageShowTimestamp;index 在非 New SaaS 模式下允许 0
  • Context:SaaS 模式初始化 3 个 EventSender(PV + CSTM + OTHER)。

四、公开 API / 配置变更(接入方可见)

变更 说明
GrowingAnalytics.onPageEnd(controller, webviewId?) 新增 API,WebView onPageEnd 时调用
createHybridProxy(controller, webviewId?) 新增可选 webviewId 参数
config.autotrackEnabled 新增,开启无埋点点击 / 变更采集
config.autotrackAllPages 新增,开启页面浏览自动采集
PluginsInterface.onWebViewSaaSCircleEvent 新增插件回调

Test Plan

  • SaaS 模式点击 Button / Text / ListItem,上报 clck,xpath 格式正确
  • SaaS 模式输入变更上报 chng;页面浏览上报 PAGE
  • autotrackAllPages=true 时全页面自动上报;growing_alias/title/attributes 生效
  • SaaS + Hybrid:WebView 内点击 / 变更上报,路径含原生页面前缀
  • mergeSaaSClick:同页面多条点击合并为单条 JSON,e 数组元素个数正确
  • 扫码 → URL Scheme 回跳 → handleOpenURL 正确解析并建立圈选 wss 连接
  • wss 连接携带 timestampAuthorization: Sign SHA1 头,服务端验签通过
  • 圈选过程正确上报 refresh / click / page UserAction 及截图、impress 元素
  • SaaS + Hybrid 圈选:onPageEnd 后圈选脚本成功注入,native xpath 写入正确
  • 多 WebView:带坐标指令只转发命中 WebView,坐标偏移正确;无坐标广播
  • release 包下 Hybrid 桥方法可达,Hybrid 页面正常上报事件
  • dataCollectionEnabled=false 时上述事件均不上报

🤖 Generated with Claude Code

@YoloMao
YoloMao force-pushed the feat/saas_autotrack branch 3 times, most recently from ff80a8a to 1595d53 Compare April 3, 2026 03:40
@YoloMao
YoloMao force-pushed the feat/saas_autotrack branch from 1595d53 to c804c54 Compare April 9, 2026 07:50
@YoloMao
YoloMao force-pushed the feat/saas_autotrack branch from 4258f0f to 34604a8 Compare April 22, 2026 08:48
@YoloMao YoloMao changed the title feat: SaaS autotrack and hybrid circle support feat(saas): SaaS 无埋点采集与可视化圈选支持 Jun 11, 2026
YoloMao and others added 23 commits June 24, 2026 15:58
- Enable autotrack for SaaS mode (remove early return, add to xpath/page logic)
- Add SaaS_OTHER event sender for VIEW_CLICK/VIEW_CHANGE events via /harmonyos/other
- Merge click/change events by page context (t/u/s/d/p/ptm/r) before sending, consistent with iOS SaaS SDK behavior
- Add VIEW_CLICK/VIEW_CHANGE serialization in MeasurementProtocol V2 format (clck/chng)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Handle clck/chng events in SaaSHybridEventHandler, forwarding hybrid
  autotrack click/change events from _vds_bridge to SaaS_OTHER sender
- Add query/hyperlink fields to ViewElementEvent for SaaS serialization
- Add native page path (p) to _vds_hybrid_native_info injection, aligned with iOS SaaS SDK

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add Hybrid.saasCircleEnabled flag, managed by Circle on WebSocket open/close
- Add Hybrid.onPageEnd to inject vds_web_circle_plugin.min.js when circle active
- Compute and inject _vds_hybrid_native_info.x (WebView native XPath) via getAttachedFrameNodeById + AutotrackClick.getXpathInfo
- Add GrowingAnalytics.onPageEnd public API
- Add Plugins.onWebViewSaaSCircleEvent dispatch for SaaS circle events

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…DME_SaaS

- Hybrid.onPageEnd now checks hybridAutotrackEnabled before injecting circle plugin
- README_SaaS: add autotrackEnabled/autotrackAllPages config items
- README_SaaS: update createHybridProxy signature with webviewId param
- README_SaaS: add onPageEnd API and update Hybrid examples with webviewId

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e changes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SourceTree uses system Python 3.9 which doesn't support `X | Y`
union type syntax in annotations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ViewElementEvent: SaaS mode now sets pageShowTimestamp (same as CDP)
- Context: SaaS mode now creates 3 EventSenders (PV + CSTM + OTHER)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Util.test.ets: add 19 cases for VIEW_CLICK/VIEW_CHANGE branch in
  toSerializeByMeasurementProtocolV2 (clck/chng t field, q/h/idx/v
  optional field omission, lat/lng, r network state, base fields)
- ViewElementEvent.test.ets: add query/hyperlink field tests; fix
  stale comment (pageShowTimestamp now covers SaaS in addition to CDP)
- Network.test.ets: add SaaS OTHER (/harmonyos/other) URL path test

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Context.md: SaaS now initializes 3 EventSenders (PV/CSTM/OTHER)
- Network.md: add mergeSaaSClick param to generateRequest/processEvents
  signatures; add /harmonyos/other to URL path table
- AnalyticsCore.md: add onPageEnd() to SaaS special methods section
- Event.md: add SaaS_OTHER to EventSenderType; add /harmonyos/other URL;
  add query/hyperlink fields to ViewElementEvent; document click merge format
- GrowingAnalytics.md: add onPageEnd() API to Hybrid section
- Plugins.md: add onWebViewSaaSCircleEvent to PluginsInterface and callback table
- Utils.md: expand toSerializeByMeasurementProtocolV2 field mapping to cover
  VIEW_CLICK/VIEW_CHANGE branch with all output fields

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
删除与 CLAUDE.md 重复的"产品与使命"、无可行动信息的"持续积累的知识域"、
与核心职责高度重叠的"进阶能力"及 agent 自指注释,减少约 46% token 消耗。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- correct SaaS Hybrid WebView circle coordinate transform
  (server vp → device physical px via vp2px / px2vp)
- add SaaSDemo.html and entry Hybrid demo wiring
- add unit tests for circle protocol/elements and ViewElementEvent
- review and sync module docs with SaaS autotrack changes
  (fix Snappy/XOR, SaaS circle pipeline, mergeSaaSClick, dead links)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Release builds enable property obfuscation. With byteCodeHar=true the
property obfuscation is deferred to the consumer (entry) build, so the
hybrid JavaScriptProxy method names (registerJavaScriptProxy methodList)
were renamed while the methodList string literals and the web SDK calls
kept the original names. The mismatch made the native bridge methods
unreachable (webview "FindMethod fail"), so the hybrid page sent zero
events in release.

Add the NewSaaS (GrowingWebViewJavascriptBridge) and SaaS (_vds_bridge)
bridge method names to -keep-property-name in both consumer-rules.txt
(the file that actually governs the entry release build) and
obfuscation-rules.txt (kept in sync).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Append a timestamp query param to the circle wss URL and attach an
`Authorization: Sign SHA1 <sig>` header in SaaS mode, where the
signature is SHA1("<path>:<ts>") as a lowercase hex string. NewSaaS /
CDP and MobileDebugger connections are unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- parse circle回跳 URL params by mode (circleType/wsHost/circleRoomNumber for SaaS)
- build wsUrl from wsHost + accountId + circleRoomNumber in SaaS mode
- fix sha1 input encoding via TextEncoder
- allow list index 0 in CircleElement
- document URL Scheme setup and et 指令类型

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Authorization (signed WSS header) and _SaaSEventData fields x/v/p/tl are
renamed by property obfuscation, breaking SaaS circle auth and click/page
snapshot triggering. Add them to keep rules and extend the obfuscation
checker to monitor Circle/SaaSModel/WebSocket via JSON.parse-cast and
known-header extractors.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@YoloMao
YoloMao force-pushed the feat/saas_autotrack branch from d62687c to afa3dcb Compare June 24, 2026 08:01
@YoloMao
YoloMao merged commit 054508f into master Jun 24, 2026
1 check passed
@YoloMao
YoloMao deleted the feat/saas_autotrack branch June 24, 2026 08:01
@YoloMao YoloMao mentioned this pull request Jun 24, 2026
3 tasks
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