Skip to content

Commit

Permalink
Navigation: Send isNew flag in grafana_navigation_item_clicked events (
Browse files Browse the repository at this point in the history
  • Loading branch information
joshhunt authored Feb 25, 2025
1 parent 3aedb91 commit e78136c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions public/app/core/components/AppChrome/MegaMenu/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit e78136c

Please sign in to comment.