From e78136c568a4deded4d954dfa04121e434e6b372 Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Tue, 25 Feb 2025 10:17:02 +0000 Subject: [PATCH] Navigation: Send isNew flag in grafana_navigation_item_clicked events (#101209) --- .../components/AppChrome/MegaMenu/utils.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/public/app/core/components/AppChrome/MegaMenu/utils.ts b/public/app/core/components/AppChrome/MegaMenu/utils.ts index abbcbc043c1..2afb61f8cc4 100644 --- a/public/app/core/components/AppChrome/MegaMenu/utils.ts +++ b/public/app/core/components/AppChrome/MegaMenu/utils.ts @@ -35,21 +35,36 @@ export const enrichHelpItem = (helpItem: NavModelItem) => { return helpItem; }; -export const enrichWithInteractionTracking = (item: NavModelItem, megaMenuDockedState: boolean) => { +export const enrichWithInteractionTracking = ( + item: NavModelItem, + megaMenuDockedState: boolean, + ancestorIsNew = false +) => { // creating a new object here to not mutate the original item object const newItem = { ...item }; const onClick = newItem.onClick; + + let isNew: 'item' | 'ancestor' | undefined = undefined; + if (newItem.isNew) { + isNew = 'item'; + } else if (ancestorIsNew) { + isNew = 'ancestor'; + } + newItem.onClick = () => { reportInteraction('grafana_navigation_item_clicked', { path: newItem.url ?? newItem.id, menuIsDocked: megaMenuDockedState, itemIsBookmarked: Boolean(config.featureToggles.pinNavItems && newItem?.parentItem?.id === 'bookmarks'), bookmarkToggleOn: Boolean(config.featureToggles.pinNavItems), + isNew, }); onClick?.(); }; if (newItem.children) { - newItem.children = newItem.children.map((item) => enrichWithInteractionTracking(item, megaMenuDockedState)); + newItem.children = newItem.children.map((item) => + enrichWithInteractionTracking(item, megaMenuDockedState, isNew !== undefined) + ); } return newItem; };