Merge pull request #29380 from overleaf/mj-layout-editing-sessions

[analytics+web] Add layout info to editing sessions

GitOrigin-RevId: d5f3161444718004aa722a6f413f6b5ff9c95aea
This commit is contained in:
Mathias Jakobsen
2025-10-30 11:15:53 +00:00
committed by Copybot
parent bfed1ac2ae
commit b0d05c0cf0

View File

@@ -7,14 +7,33 @@ import { useCallback, useEffect, useRef } from 'react'
import useEventListener from '@/shared/hooks/use-event-listener'
import useDomEventListener from '@/shared/hooks/use-dom-event-listener'
import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
import {
IdeLayout,
IdeView,
useLayoutContext,
} from '@/shared/context/layout-context'
import {
RailTabKey,
useRailContext,
} from '@/features/ide-redesign/contexts/rail-context'
function createEditingSessionHeartbeatData(
editorType: EditorType,
newEditor: boolean
newEditor: boolean,
view: IdeView | null,
layout: IdeLayout,
railOpen: boolean,
railTab: RailTabKey,
hasDetachedPdf: boolean
) {
const newEditorSegmentation = newEditor ? { railOpen, railTab } : {}
return {
editorType,
editorRedesign: newEditor,
editorView: view,
editorLayout: layout,
hasDetachedPdf,
...newEditorSegmentation,
}
}
@@ -31,6 +50,8 @@ export function useEditingSessionHeartbeat() {
const { projectId } = useIdeReactContext()
const { getEditorType } = useEditorManagerContext()
const newEditor = useIsNewEditorEnabled()
const { view, pdfLayout: layout, detachIsLinked } = useLayoutContext()
const { isOpen: railIsOpen, selectedTab: selectedRailTab } = useRailContext()
// Keep track of how many heartbeats we've sent so that we can calculate how
// long to wait until the next one
@@ -59,7 +80,12 @@ export function useEditingSessionHeartbeat() {
const segmentation = createEditingSessionHeartbeatData(
editorType,
newEditor
newEditor,
view,
layout,
railIsOpen,
selectedRailTab,
detachIsLinked
)
debugConsole.log('[Event] send heartbeat request', segmentation)
@@ -80,7 +106,16 @@ export function useEditingSessionHeartbeat() {
heartBeatResetTimerRef.current = window.setTimeout(() => {
heartBeatSentRecentlyRef.current = false
}, backoffSecs * 1000)
}, [getEditorType, projectId, newEditor])
}, [
getEditorType,
projectId,
newEditor,
view,
layout,
railIsOpen,
selectedRailTab,
detachIsLinked,
])
// Hook the heartbeat up to editor events
useEventListener('cursor:editor:update', editingSessionHeartbeat)