From 865a1d6002ac440c2a4ffae4af0f15e96ceb2553 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Thu, 14 Mar 2024 16:29:46 +0100 Subject: [PATCH] fix(telemetry): measure link/button clicks properly We assumed that the click happens on the element with data-glean, but this is not guaranteed if the link/button has children. --- 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);