Skip to content

Commit

Permalink
chore(telemetry): measure "Add/edit note" on collection items (#9850)
Browse files Browse the repository at this point in the history
- Adds measurement.
- Merges Collections-related constants into frozen PLUS_COLLECTIONS object.
  • Loading branch information
caugner authored Oct 19, 2023
1 parent 546f4fe commit 47d3686
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
13 changes: 11 additions & 2 deletions client/src/plus/collections/collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
FrequentlyViewedCollection,
useFrequentlyViewed,
} from "./frequently-viewed";
import { useGleanClick } from "../../telemetry/glean-context";
import { PLUS_COLLECTIONS } from "../../telemetry/constants";
dayjs.extend(relativeTime);

export function CollectionComponent() {
Expand Down Expand Up @@ -174,6 +176,7 @@ function ItemComponent({
const [note, setNote] = useState<string>();

const locale = useLocale();
const gleanClick = useGleanClick();

useEffect(() => {
const slicedNote = item.notes && charSlice(item.notes, 0, 180);
Expand Down Expand Up @@ -255,7 +258,10 @@ function ItemComponent({
<Button
icon="edit"
type="action"
onClickHandler={openBookmarkMenu}
onClickHandler={(e) => {
gleanClick(PLUS_COLLECTIONS.ACTIONS_NOTE_EDIT);
return openBookmarkMenu(e);
}}
>
<span className="visually-hidden">Edit note</span>
</Button>
Expand Down Expand Up @@ -294,7 +300,10 @@ function ItemComponent({
extraClasses="add-note"
icon="edit"
type="action"
onClickHandler={openBookmarkMenu}
onClickHandler={(e) => {
gleanClick(PLUS_COLLECTIONS.ACTIONS_NOTE_ADD);
return openBookmarkMenu(e);
}}
>
Add note
</Button>
Expand Down
11 changes: 4 additions & 7 deletions client/src/plus/collections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import Mandala from "../../ui/molecules/mandala";
import { useGleanClick } from "../../telemetry/glean-context";
import {
COLLECTIONS_BANNER_NEW_COLLECTION,
NEW_COLLECTION_MODAL_SUBMIT_COLLECTIONS_PAGE,
} from "../../telemetry/constants";
import { PLUS_COLLECTIONS } from "../../telemetry/constants";
import { camelWrap } from "../../utils";
import { useFrequentlyViewed } from "./frequently-viewed";
import { Icon } from "../../ui/atoms/icon";
Expand Down Expand Up @@ -89,7 +86,7 @@ function Overview() {
</p>
<Button
onClickHandler={() => {
gleanClick(COLLECTIONS_BANNER_NEW_COLLECTION);
gleanClick(PLUS_COLLECTIONS.BANNER_NEW);
setShowCreate(true);
}}
isDisabled={isLoading}
Expand All @@ -99,7 +96,7 @@ function Overview() {
<NewEditCollectionModal
show={showCreate}
setShow={setShowCreate}
source={NEW_COLLECTION_MODAL_SUBMIT_COLLECTIONS_PAGE}
source={PLUS_COLLECTIONS.NEW_MODAL_SUBMIT_COLLECTIONS_PAGE}
/>
</Container>
</header>
Expand Down Expand Up @@ -205,7 +202,7 @@ function CollectionCard({ collection }: { collection: Collection }) {
editingCollection={collection}
show={showEdit}
setShow={setShowEdit}
source={NEW_COLLECTION_MODAL_SUBMIT_COLLECTIONS_PAGE}
source={PLUS_COLLECTIONS.NEW_MODAL_SUBMIT_COLLECTIONS_PAGE}
/>
<MDNModal
isOpen={showDelete}
Expand Down
4 changes: 2 additions & 2 deletions client/src/plus/collections/new-edit-collection-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
useCollectionEdit,
useCollections,
} from "./api";
import { NEW_COLLECTION_MODAL_UPGRADE_LINK } from "../../telemetry/constants";
import { PLUS_COLLECTIONS } from "../../telemetry/constants";
import LimitedInput from "../../ui/atoms/form/limited-input";
import ExpandingTextarea from "../../ui/atoms/form/expanding-textarea";

Expand Down Expand Up @@ -105,7 +105,7 @@ export default function NewEditCollectionModal({
<div className="mdn-form-item is-button-row">
<SignUpLink
toPlans={true}
gleanContext={NEW_COLLECTION_MODAL_UPGRADE_LINK}
gleanContext={PLUS_COLLECTIONS.NEW_MODAL_UPGRADE_LINK}
/>
</div>
</div>
Expand Down
27 changes: 14 additions & 13 deletions client/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { ViewportBreakpoint } from "./glean-context";

export const ARTICLE_ACTIONS_COLLECTION_SELECT_OPENED =
"article_actions_collection_select_opened";
export const ARTICLE_ACTIONS_NEW_COLLECTION = "article_actions_new_collection";
export const ARTICLE_ACTIONS_COLLECTIONS_OPENED =
"article_actions_collections_opened";
export const COLLECTIONS_BANNER_NEW_COLLECTION =
"collections_banner_new_collection";
export const NEW_COLLECTION_MODAL_SUBMIT_ARTICLE_ACTIONS =
"new_collection_modal_submit_article_actions";
export const NEW_COLLECTION_MODAL_SUBMIT_COLLECTIONS_PAGE =
"new_collection_modal_submit_collections_page";
export const NEW_COLLECTION_MODAL_UPGRADE_LINK =
"new_collection_modal_upgrade_link";
export const OFFER_OVERVIEW_CLICK = "offer_overview_click";
export const SIDEBAR_CLICK = "sidebar_click";
export const SIDEBAR_CLICK_WITH_FILTER = "sidebar_click_with_filter";
Expand All @@ -31,6 +18,20 @@ export const BANNER_AI_HELP_CLICK = "banner_ai_help_click";
export const PLAYGROUND = "play_action";
export const AI_EXPLAIN = "ai_explain";

export const PLUS_COLLECTIONS = Object.freeze({
ACTIONS_NOTE_ADD: "collections_actions_note_add",
ACTIONS_NOTE_EDIT: "collections_actions_note_edit",
ARTICLE_ACTIONS_SELECT_OPENED: "article_actions_collection_select_opened",
ARTICLE_ACTIONS_NEW: "article_actions_new_collection",
ARTICLE_ACTIONS_OPENED: "article_actions_collections_opened",
BANNER_NEW: "collections_banner_new_collection",
NEW_MODAL_SUBMIT_ARTICLE_ACTIONS:
"new_collection_modal_submit_article_actions",
NEW_MODAL_SUBMIT_COLLECTIONS_PAGE:
"new_collection_modal_submit_collections_page",
NEW_MODAL_UPGRADE_LINK: "new_collection_modal_upgrade_link",
});

export const PLUS_UPDATES = Object.freeze({
EVENT_COLLAPSE: "plus_updates_event_collapse",
EVENT_EXPAND: "plus_updates_event_expand",
Expand Down
17 changes: 7 additions & 10 deletions client/src/ui/organisms/article-actions/bookmark-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ import { DropdownMenu, DropdownMenuWrapper } from "../../../molecules/dropdown";
import { Icon } from "../../../atoms/icon";
import NoteCard from "../../../molecules/notecards";
import { useGleanClick } from "../../../../telemetry/glean-context";
import {
ARTICLE_ACTIONS_COLLECTION_SELECT_OPENED,
ARTICLE_ACTIONS_NEW_COLLECTION,
ARTICLE_ACTIONS_COLLECTIONS_OPENED,
NEW_COLLECTION_MODAL_SUBMIT_ARTICLE_ACTIONS,
} from "../../../../telemetry/constants";
import { PLUS_COLLECTIONS } from "../../../../telemetry/constants";
import ExpandingTextarea from "../../../atoms/form/expanding-textarea";
import { KeyedMutator } from "swr";

Expand Down Expand Up @@ -71,7 +66,7 @@ export default function BookmarkMenu({
onClickHandler={() => {
setShow((v) => !v);
if (!show) {
gleanClick(ARTICLE_ACTIONS_COLLECTIONS_OPENED);
gleanClick(PLUS_COLLECTIONS.ARTICLE_ACTIONS_OPENED);
}
}}
>
Expand Down Expand Up @@ -158,7 +153,7 @@ function BookmarkMenuDropdown({
const collectionChangeHandler = (e: React.ChangeEvent<HTMLSelectElement>) => {
const { value } = e.target;
if (value === addValue) {
gleanClick(ARTICLE_ACTIONS_NEW_COLLECTION);
gleanClick(PLUS_COLLECTIONS.ARTICLE_ACTIONS_NEW);
setDisableAutoClose(true);
setShowNewCollection(true);
changeHandler(e);
Expand Down Expand Up @@ -276,7 +271,9 @@ function BookmarkMenuDropdown({
onChange={collectionChangeHandler}
onFocus={() => {
if (!focusEventTriggered) {
gleanClick(ARTICLE_ACTIONS_COLLECTION_SELECT_OPENED);
gleanClick(
PLUS_COLLECTIONS.ARTICLE_ACTIONS_SELECT_OPENED
);
setFocusEventTriggered(true);
}
}}
Expand Down Expand Up @@ -372,7 +369,7 @@ function BookmarkMenuDropdown({
collection_id: collection_id || collections[0].id,
});
}}
source={NEW_COLLECTION_MODAL_SUBMIT_ARTICLE_ACTIONS}
source={PLUS_COLLECTIONS.NEW_MODAL_SUBMIT_ARTICLE_ACTIONS}
/>
)}
</>
Expand Down

0 comments on commit 47d3686

Please sign in to comment.