Files
supabase/apps/studio/hooks/misc/useStudioCommandMenuTelemetry.ts
T
Francesco SansalvadoreandCharis af43adb9a4 chore: command events (#39775)
* add CommandMenuTriggerInput in ui-patterns
* optimize search input responsiveness
* add event on commandMenu opened
* add event on debounced commandMenu input submission
* add event on commandMenu command selection
* add commandMenu telemetry to studio, www and docs

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
2025-10-24 11:06:31 +02:00

41 lines
1.2 KiB
TypeScript

import { useCallback } from 'react'
import { useParams } from 'common'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import type {
CommandMenuOpenedEvent,
CommandMenuCommandSelectedEvent,
CommandMenuSearchSubmittedEvent,
} from 'common/telemetry-constants'
export function useStudioCommandMenuTelemetry() {
const { ref: projectRef } = useParams()
const { data: organization } = useSelectedOrganizationQuery()
const { mutate: sendEvent } = useSendEventMutation()
const onTelemetry = useCallback(
(
event:
| CommandMenuOpenedEvent
| CommandMenuCommandSelectedEvent
| CommandMenuSearchSubmittedEvent
) => {
// Add studio-specific groups (project and organization)
const eventWithGroups = {
...event,
groups: {
...event.groups,
...(projectRef && { project: projectRef }),
...(organization?.slug && { organization: organization.slug }),
},
}
sendEvent(eventWithGroups)
},
[projectRef, organization?.slug, sendEvent]
)
return { onTelemetry }
}