snowplow / snowplow-javascript-tracker

Snowplow event tracker for client-side and server-side JavaScript. Add analytics to your websites, web apps and servers.
http://snowplowanalytics.com
BSD 3-Clause "New" or "Revised" License
555 stars 222 forks source link

Support events on buttons/links/forms in ShadowDOMs #1351

Closed jethron closed 1 month ago

jethron commented 1 month ago

When DOM events on elements within Custom Components/ShadowRoots trigger against the document, the target is set to the Custom Element/shadow host rather than the actual element that caused the event.

This change adds support to the from/button/link tracking plugins to detect when this occurs, and use the first element from the Event's composedPath instead of the target. This enables them to see the actual even target and fire correctly in this scenario.

For the Form tracker, only focus events are considered composed, so change and submit events don't actually get reported outside the shadow DOM. As a workaround, when the focus events occur, if enabled the change/submit event listeners are bound directly to the form (or field if it has no associated form) rather than just the document.

bundlemon[bot] commented 1 month ago

BundleMon

Files added (6) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | trackers/javascript-tracker/dist/sp.js
| +24.32KB | 30KB / +10% :white_check_mark: | libraries/browser-tracker-core/dist/index.mod
ule.js
| +23.41KB | 25KB / +10% :white_check_mark: | libraries/tracker-core/dist/index.module.js
| +19.12KB | 20KB / +10% :white_check_mark: | trackers/browser-tracker/dist/index.umd.min.j
s
| +17.24KB | 20KB / +10% :white_check_mark: | trackers/javascript-tracker/dist/sp.lite.js
| +17.18KB | 20KB / +10% :white_check_mark: | trackers/browser-tracker/dist/index.module.js
| +3.49KB | 5KB / +10%

Total files change +104.75KB 0%

Final result: :white_check_mark:

View report in BundleMon website ➡️


Current branch size history