:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(command-menu): capture item selections in command menu (#73287)
Rafael Audibert9e72789d4c5f
diff --git a/frontend/src/lib/components/Search/Search.tsx b/frontend/src/lib/components/Search/Search.tsxindex 7608456d6269..1b99a70b1332 100644--- a/frontend/src/lib/components/Search/Search.tsx+++ b/frontend/src/lib/components/Search/Search.tsx@@ -24,6 +24,7 @@ import { filterSearchItems } from 'lib/components/Search/utils'import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { TreeDataItem } from 'lib/lemon-ui/LemonTree/LemonTree'import { themeLogic } from 'lib/logic/themeLogic'+import posthog from 'lib/posthog-typed'import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuTrigger } from 'lib/ui/ContextMenu/ContextMenu'import { Label } from 'lib/ui/Label/Label'@@ -414,6 +415,9 @@ function SearchRoot({const inputRef = useRef<HTMLInputElement>(null!)const actionsRef = useRef<Autocomplete.Root.Actions>(null)const highlightedItemRef = useRef<SearchItem | null>(null)+ // Kept current with the flat, DOM-order item list so a click handler can report+ // the selected item's position without depending on it (it's computed further down).+ const orderedItemsRef = useRef<SearchItem[]>([])const allItems = useMemo(() => {const items: SearchItem[] = []@@ -501,6 +505,14 @@ function SearchRoot({if (item.disabledReason) {return}+ if (logicKey === 'command') {+ const position = orderedItemsRef.current.findIndex((i) => i.id === item.id)+ posthog.capture('command menu item selected', {+ category: item.category,+ item_type: item.itemType ?? null,+ result_position: position >= 0 ? position : null,+ })+ }if (item.id === SETTINGS_THEME_ITEM_ID) {const record = item.record as { themeMode?: UserTheme; toggleTheme?: boolean } | undefinedif (record?.themeMode) {@@ -522,7 +534,7 @@ function SearchRoot({router.actions.push(item.href)}},- [onItemSelect, onAskAiClick, updateUser, toggleTheme]+ [onItemSelect, onAskAiClick, updateUser, toggleTheme, logicKey])const groupedItems = useMemo(() => {@@ -589,6 +601,7 @@ function SearchRoot({// exactly matches the DOM render order. Without this, Base UI's keyboard navigation// breaks at group boundaries where the two orderings diverge.const orderedItems = useMemo(() => stableGroupedItems.flatMap((g) => g.items), [stableGroupedItems])+ orderedItemsRef.current = orderedItemsconst contextValue: SearchContextValue = useMemo(() => ({