From 2c27a78bcfbc0ba1d818c9928328770eae32fabd Mon Sep 17 00:00:00 2001 From: Claas Augner <495429+caugner@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:04:21 +0100 Subject: [PATCH] fix(telemetry): measure link/button clicks properly (#10707) We assumed that the click happens on the element with data-glean, but this is not the case if the click happens on a child of the link/button. --- client/src/telemetry/glean-context.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/telemetry/glean-context.tsx b/client/src/telemetry/glean-context.tsx index b7ea335467ed..b72e278a8211 100644 --- a/client/src/telemetry/glean-context.tsx +++ b/client/src/telemetry/glean-context.tsx @@ -172,14 +172,14 @@ const gleanAnalytics = glean(); const GleanContext = React.createContext(gleanAnalytics); function handleButtonClick(ev: MouseEvent, click: (source: string) => void) { - const button = ev?.target; + const button = (ev?.target as HTMLElement | null)?.closest("button"); if (button instanceof HTMLButtonElement && button.dataset.glean) { click(button.dataset.glean); } } function handleLinkClick(ev: MouseEvent, click: (source: string) => void) { - const anchor = ev?.target; + const anchor = (ev?.target as HTMLElement | null)?.closest("a"); if (anchor instanceof HTMLAnchorElement) { if (anchor.dataset.glean) { click(anchor.dataset.glean);