Skip to content

Commit

Permalink
enhance(telemetry): measure all external link clicks (#11981)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA authored Oct 21, 2024
1 parent 8d51b73 commit 2a79c01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions client/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ export const HOMEPAGE_ITEMS = Object.freeze({
CONTRIBUTION: "contribution",
CONTRIBUTION_REPO: "contribution_repo",
});

export const EXTERNAL_LINK = "external-link";
11 changes: 8 additions & 3 deletions client/src/telemetry/glean-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useEffect, useRef } from "react";
import { useLocation } from "react-router";
import { useUserData } from "../user-context";
import { handleSidebarClick } from "./sidebar-click";
import { VIEWPORT_BREAKPOINTS } from "./constants";
import { EXTERNAL_LINK, VIEWPORT_BREAKPOINTS } from "./constants";
import { Doc } from "../../../libs/types/document";

export type ViewportBreakpoint = "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
Expand Down Expand Up @@ -174,8 +174,13 @@ function handleLinkClick(ev: MouseEvent, click: (source: string) => void) {
if (anchor instanceof HTMLAnchorElement) {
if (anchor.dataset.glean) {
click(anchor.dataset.glean);
} else if (anchor.classList.contains("external")) {
click(`external-link: ${anchor.getAttribute("href") || ""}`);
}
if (
anchor.href &&
anchor.origin &&
anchor.origin !== document.location.origin
) {
click(`${EXTERNAL_LINK}: ${anchor.href}`);
}
}
}
Expand Down

0 comments on commit 2a79c01

Please sign in to comment.