Skip to content

Commit

Permalink
chore(telemetry): measure top-level menu link clicks (#9938)
Browse files Browse the repository at this point in the history
* refactor(main-menu): extract TopMenuLink

* chore(telemetry): measure top-level menu link clicks
  • Loading branch information
caugner authored Nov 3, 2023
1 parent ee8a59d commit 9c176c0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions client/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const PLAYGROUND = "play_action";
export const AI_EXPLAIN = "ai_explain";

export const MENU = Object.freeze({
CLICK_LINK: "menu_click_link",
CLICK_MENU: "menu_click_menu",
CLICK_SUBMENU: "menu_click_submenu",
});
Expand Down
43 changes: 28 additions & 15 deletions client/src/ui/molecules/main-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { PlusMenu } from "../plus-menu";
import "./index.scss";
import { PLUS_IS_ENABLED } from "../../../env";
import { useLocale } from "../../../hooks";
import { useGleanClick } from "../../../telemetry/glean-context";
import { MENU } from "../../../telemetry/constants";

export default function MainMenu({ isOpenOnMobile }) {
const locale = useLocale();
Expand Down Expand Up @@ -79,22 +81,33 @@ export default function MainMenu({ isOpenOnMobile }) {
toggleMenu={toggleMenu}
/>
)}
<li className="top-level-entry-container">
<a className="top-level-entry menu-link" href="/en-US/blog/">
Blog
</a>
</li>
<li className="top-level-entry-container">
<a className="top-level-entry menu-link" href={`/${locale}/play`}>
Play
</a>
</li>
<li className="top-level-entry-container">
<a className="top-level-entry menu-link" href="/en-US/plus/ai-help/">
AI Help <sup className="new beta">Beta</sup>
</a>
</li>
<TopLevelMenuLink to="/en-US/blog/">Blog</TopLevelMenuLink>
<TopLevelMenuLink to={`/${locale}/play`}>Play</TopLevelMenuLink>
<TopLevelMenuLink to="/en-US/plus/ai-help/">
AI Help <sup className="new beta">Beta</sup>
</TopLevelMenuLink>
</ul>
</nav>
);
}

function TopLevelMenuLink({
to,
children,
}: {
to: string;
children: React.ReactNode;
}) {
const gleanClick = useGleanClick();
return (
<li className="top-level-entry-container">
<a
className="top-level-entry menu-link"
href={to}
onClick={() => gleanClick(`${MENU.CLICK_LINK}: top-level -> ${to}`)}
>
{children}
</a>
</li>
);
}

0 comments on commit 9c176c0

Please sign in to comment.