mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-07-29 05:00:06 +02:00

[web] Introduce React hook wrapper around sendMB and friends GitOrigin-RevId: 3c693ae609c6d4e5ba280c45096692aca47975ca
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
|
|
import {
|
|
Segmentation,
|
|
sendMB,
|
|
sendMBOnce,
|
|
sendMBSampled,
|
|
} from '@/infrastructure/event-tracking'
|
|
import { useCallback } from 'react'
|
|
|
|
export const useEditorAnalytics = () => {
|
|
const editorRedesign = useIsNewEditorEnabled()
|
|
|
|
const populateSegmentation = useCallback(
|
|
(segmentation: Segmentation | undefined = {}): Segmentation => {
|
|
return editorRedesign
|
|
? { ...segmentation, 'editor-redesign': 'enabled' }
|
|
: segmentation
|
|
},
|
|
[editorRedesign]
|
|
)
|
|
|
|
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 }
|
|
}
|