Skip to content

feat(autocapture): element-path-v1 - #1847

Draft
jxiwang wants to merge 12 commits into
mainfrom
element-path-v1
Draft

feat(autocapture): element-path-v1#1847
jxiwang wants to merge 12 commits into
mainfrom
element-path-v1

Conversation

@jxiwang

@jxiwang jxiwang commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up PR stacked on #1842 (feat(autocapture): route Element Path through the element-selector engine). Adds operational debug logging, fixes the remote-config key path, and restores full test coverage after the debug-log changes.

Changes

  • Debug logging — Log when element-selector remote config is subscribed, delivered, and applied; log per-click Element Path when the engine is enabled. Manual test page (test-server/autocapture/element-selector.html) surfaces the emitted event path for QA.
  • Remote-config key fix — The element-selector payload lives under configs.analyticsSDK.browserSDK.autocapture.elementSelector, not configs.analyticsSDK.elementSelector.
  • Coverage — Restore 100% CI coverage: add debug/error mocks to frustration-plugin tests, simplify shared-engine update paths, and cover enabled-engine logging branches in data-extractor tests.

Stack

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No — additive debug logging and a config-key fix only.
Open in Web Open in Cursor 

…uting

Extracted from #1832.

- Move canonical legacyCssPath walker into @amplitude/element-selector
- Add generateSelector top-level helper for null-engine call sites
- Route engine.generate through kill-switch and safety-net fallbacks
- Publish package (remove private flag)
- Bump size-limit cap to absorb consolidated walker
…gine

Integrate @amplitude/element-selector into autocapture's DataExtractor, the
single point where every selector string ([Amplitude] Element Path and the
viewport Element Exposed paths) is produced.

- DataExtractor owns a SelectorEngine and getElementPath now calls
  engine.generate instead of the local cssPath walker. Ships dormant: the
  default config (enabled: false) routes through element-selector's
  byte-identical legacyCssPath, so selector output is unchanged until an org
  opts in.
- updateSelectorConfig applies an ElementSelectorRemoteConfig payload to the
  engine.
- subscribeToElementSelectorConfig wires the engine to remote config; both the
  autocapture and frustration plugins subscribe so all selector-bearing events
  (Element Clicked, Element Changed, Dead/Rage/Error Click, Viewport Content
  Updated) stay consistent when the engine is enabled.

This is the engine integration only; selector-config hashing is tracked
separately.
…or-datextractor-integration-7d25

# Conflicts:
#	.size-limit.js
#	packages/element-selector/src/engine.ts
#	packages/element-selector/src/generate-selector.ts
#	packages/element-selector/src/legacy-css-path.ts
#	packages/element-selector/test/generate-selector.test.ts
#	packages/element-selector/test/legacy-css-path.test.ts
Add a Playwright e2e spec + test page that click real elements and assert the
emitted [Amplitude] Element Path. Runs in a real browser, exercising
getElementPath -> engine.generate -> (dormant) legacy cssPath end to end —
including real CSS.escape and real sibling/layout structure that jsdom unit
tests cannot cover. Guards that the local cssPath -> engine swap did not change
production selectors:
- stable id anchors as 'button#cta-button'
- id-less element disambiguates positionally as
  'div#container > section > button:nth-child(2)'
Add a manual test-server playground under test-server/autocapture/ that renders,
for each clicked element, the selector with the engine disabled (legacy cssPath)
vs enabled (new strategy chain), highlighting differences. Covers stable ids,
autogenerated-looking ids, positional disambiguation, unstable/library state
classes, and the explicit tracking attribute. Opened via 'pnpm dev' for manual
QA of selector quality on a realistic DOM (not run in CI).
Pin the enabled-engine unit test to button#test-button instead of only
checking length > 0, so the test guards against strategy-chain regressions.
Both autocapture and frustration plugins create separate DataExtractor
instances that subscribe to remote config independently. Use a module-level
singleton SelectorEngine so whichever subscription fires first updates config
for all plugins, preventing mismatched Element Path values on the same click.
…ment Path

Add debug logging when element-selector remote config is subscribed,
delivered, and applied, plus per-click Element Path logs when the engine
is enabled. Enhance the manual test page to surface the emitted event path.
The element-selector payload lives under
configs.analyticsSDK.browserSDK.autocapture.elementSelector, not
configs.analyticsSDK.elementSelector.
- Add debug/error mocks to frustration-plugin test logger
- Simplify shared-engine update path and debug branches
- Cover enabled-engine logging paths in data-extractor tests
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 60.87 KB (+0.5% 🔺)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 133.2 KB (+0.02% 🔺)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 213.53 KB (+0.18% 🔺)
@amplitude/element-selector (gzipped esm) 2.67 KB (0%)

 - @amplitude/analytics-browser@2.44.2-element-path-v1.0
 - @amplitude/element-selector@0.2.0-element-path-v1.0
 - @amplitude/plugin-autocapture-browser@1.28.0-element-path-v1.0
 - @amplitude/plugin-session-replay-browser@1.32.2-element-path-v1.0
 - @amplitude/segment-session-replay-plugin@0.0.30-element-path-v1.0
 - @amplitude/session-replay-browser@1.46.1-element-path-v1.0
 - @amplitude/unified@1.1.17-element-path-v1.0
@github-actions

Copy link
Copy Markdown

Session Replay Browser E2E Results

passed  150 passed
flaky  1 flaky

Details

stats  151 tests across 17 suites
duration  4 minutes, 16 seconds
commit  3ab0062

Flaky tests

chromium › e2e/trc-url-rule.spec.ts › TRC URL rule — happy path › starts recording after SPA navigation to a matching URL

Base automatically changed from cursor/element-selector-datextractor-integration-7d25 to main June 24, 2026 18:39
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.

3 participants