Skip to content

Commit

Permalink
chore(telemetry): measure menu clicks (#9918)
Browse files Browse the repository at this point in the history
* chore(telemetry): measure Menu/Submenu clicks

* chore(glean): record menu/submenu id

* refactor(user-menu): change ID to "user-menu"

* fixup! chore(glean): record menu/submenu id

* Revert "refactor(user-menu): change ID to "user-menu""

This reverts commit 9184fa9.
  • Loading branch information
caugner authored Oct 31, 2023
1 parent 9867d52 commit c4c5d79
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions client/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const BANNER_AI_HELP_CLICK = "banner_ai_help_click";
export const PLAYGROUND = "play_action";
export const AI_EXPLAIN = "ai_explain";

export const MENU = Object.freeze({
CLICK_MENU: "menu_click_menu",
CLICK_SUBMENU: "menu_click_submenu",
});

export const PLUS_COLLECTIONS = Object.freeze({
ACTIONS_NOTE_ADD: "collections_actions_note_add",
ACTIONS_NOTE_EDIT: "collections_actions_note_edit",
Expand Down
11 changes: 9 additions & 2 deletions client/src/ui/molecules/menu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MENU } from "../../../telemetry/constants";
import { useGleanClick } from "../../../telemetry/glean-context";
import { MenuEntry, Submenu } from "../submenu";
import "./index.scss";

Expand All @@ -8,6 +10,8 @@ interface MenuProps {
}

export const Menu = ({ menu, isOpen, toggle }: MenuProps) => {
const gleanClick = useGleanClick();

const buttonId = `${menu.id}-button`;
const submenuId = `${menu.id}-menu`;

Expand Down Expand Up @@ -35,8 +39,11 @@ export const Menu = ({ menu, isOpen, toggle }: MenuProps) => {
<a
href={menu.to}
className="top-level-entry"
// @ts-ignore
onClick={() => document?.activeElement?.blur()}
onClick={() => {
gleanClick(`${MENU.CLICK_MENU}: ${menu.id} -> ${menu.to}`);
// @ts-ignore
document?.activeElement?.blur();
}}
>
{menu.label}
</a>
Expand Down
8 changes: 8 additions & 0 deletions client/src/ui/molecules/submenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MENU } from "../../../telemetry/constants";
import { useGleanClick } from "../../../telemetry/glean-context";
import "./index.scss";

export type SubmenuItem = {
Expand Down Expand Up @@ -32,6 +34,7 @@ export const Submenu = ({
submenuId?: string;
extraClasses?: string;
}) => {
const gleanClick = useGleanClick();
return (
<ul
id={submenuId}
Expand All @@ -58,6 +61,11 @@ export const Submenu = ({
className={`submenu-item ${
item.url.startsWith("https://") ? "external" : ""
}`}
onClick={() =>
gleanClick(
`${MENU.CLICK_SUBMENU}: ${menuEntry.id} -> ${item.url}`
)
}
>
{item.hasIcon && <div className={item.iconClasses} />}
{item.dot && (
Expand Down

0 comments on commit c4c5d79

Please sign in to comment.