feat(autocapture): element-path-v1 - #1847
Draft
jxiwang wants to merge 12 commits into
Draft
Conversation
…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
size-limit report 📦
|
- @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
Session Replay Browser E2E ResultsDetails
Flaky testschromium › 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
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.
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
test-server/autocapture/element-selector.html) surfaces the emitted event path for QA.configs.analyticsSDK.browserSDK.autocapture.elementSelector, notconfigs.analyticsSDK.elementSelector.Stack
DataExtractor.getElementPath()Checklist