mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-24 17:51:51 +02:00
Add editor-redesign segmentation to a bunch of analytics events GitOrigin-RevId: e8d2091028dab09de06362c38c5a17f32253e7cc
54 lines
1.5 KiB
TypeScript
54 lines
1.5 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 function populateEditorRedesignSegmentation<
|
|
SegmentationType extends Segmentation,
|
|
>(
|
|
segmentation: SegmentationType | undefined = {} as SegmentationType,
|
|
editorRedesign: boolean
|
|
): SegmentationType & { 'editor-redesign'?: 'enabled' } {
|
|
return editorRedesign
|
|
? { ...segmentation, 'editor-redesign': 'enabled' }
|
|
: segmentation
|
|
}
|
|
|
|
export const useEditorAnalytics = () => {
|
|
const editorRedesign = useIsNewEditorEnabled()
|
|
|
|
const populateSegmentation = useCallback(
|
|
(segmentation: Segmentation | undefined = {}): Segmentation => {
|
|
return populateEditorRedesignSegmentation(segmentation, editorRedesign)
|
|
},
|
|
[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 }
|
|
}
|