Files
overleaf-cep/services/web/frontend/js/shared/hooks/use-editor-analytics.ts
Davinder Singh d6e745c156 Merge pull request #31909 from overleaf/ds-removing-useIsNewEditorEnabled-2
[Part 2] Removing the usage of `useIsNewEditorEnabled` for editor tear down

GitOrigin-RevId: 864652da0edcedab4f3b1ba47d8d42fb65260118
2026-03-06 09:15:30 +00:00

48 lines
1.2 KiB
TypeScript

import {
Segmentation,
sendMB,
sendMBOnce,
sendMBSampled,
} from '@/infrastructure/event-tracking'
import { useCallback } from 'react'
export function populateEditorRedesignSegmentation<
SegmentationType extends Segmentation,
>(
segmentation: SegmentationType | undefined = {} as SegmentationType
): SegmentationType & { 'editor-redesign'?: 'enabled' } {
return { ...segmentation, 'editor-redesign': 'enabled' }
}
export const useEditorAnalytics = () => {
const populateSegmentation = useCallback(
(segmentation: Segmentation | undefined = {}): Segmentation => {
return populateEditorRedesignSegmentation(segmentation)
},
[]
)
const sendEvent: typeof sendMB = useCallback(
(key, segmentation) => {
sendMB(key, populateSegmentation(segmentation))
},
[populateSegmentation]
)
const sendEventOnce: typeof sendMBOnce = useCallback(
(key, segmentation) => {
sendMBOnce(key, populateSegmentation(segmentation))
},
[populateSegmentation]
)
const sendEventSampled: typeof sendMBSampled = useCallback(
(key, segmentation, rate) => {
sendMBSampled(key, populateSegmentation(segmentation), rate)
},
[populateSegmentation]
)
return { sendEvent, sendEventOnce, sendEventSampled }
}