From 2e03be005ca29178498412446bb01ee3a455eb58 Mon Sep 17 00:00:00 2001 From: Leo McArdle Date: Thu, 11 Sep 2025 17:38:56 +0100 Subject: [PATCH 1/2] Record clicks on elements in Shadow DOM --- .../src/content/docs/automatic_instrumentation/click_events.md | 2 +- glean/src/core/glean_metrics.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/src/content/docs/automatic_instrumentation/click_events.md b/documentation/src/content/docs/automatic_instrumentation/click_events.md index bbbcad7c4..88481f875 100644 --- a/documentation/src/content/docs/automatic_instrumentation/click_events.md +++ b/documentation/src/content/docs/automatic_instrumentation/click_events.md @@ -16,7 +16,7 @@ Glean.initialize("app-name", true, { }); ``` -Glean.js will create a global click listener to catch all clicks for +Glean.js will create a global click listener to catch all clicks (including in Shadow DOMs) for elements that include one of the following data attributes: - `data-glean-id` diff --git a/glean/src/core/glean_metrics.ts b/glean/src/core/glean_metrics.ts index b2578e256..25a93ca04 100644 --- a/glean/src/core/glean_metrics.ts +++ b/glean/src/core/glean_metrics.ts @@ -157,7 +157,7 @@ namespace GleanMetrics { * @param event Event object. */ export function handleClickEvent(event: Event) { - const clickedElement = event.target as Element; + const clickedElement = (event.composedPath()?.[0] || event.target) as Element; const closestElementWithClickAttributes: Element | null = clickedElement.closest("[data-glean-id], [data-glean-type], [data-glean-label]"); if (!closestElementWithClickAttributes) { From 4b0176d66f1ea5ca57828842c9acdebe8b7b2d40 Mon Sep 17 00:00:00 2001 From: Leo McArdle Date: Thu, 11 Sep 2025 17:59:05 +0100 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index accc0bffb..0f4c9e00f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ [Full changelog](https://github.com/mozilla/glean.js/compare/v5.0.5...main) +* [#2013](https://github.com/mozilla/glean.js/pull/2011): Bug 1988206 - Record clicks on elements in Shadow DOM. * [#2011](https://github.com/mozilla/glean.js/pull/2011): Bug 1987158 - Capture page `url`/`referrer`/`title` with `recordElementClick()`. # v5.0.5 (2025-07-17)