Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/xi.web/src/pages/(app)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
RoomProvider,
useCallStore,
ModeSyncProvider,
useUmamiActivityHeartbeat,
} from 'modules.calls';
import { useCurrentUser, useUpdateProfile, useMarkNotificationAsRead } from 'common.services';
import { OnboardingStageT } from 'common.api';
Expand All @@ -25,6 +26,8 @@ function LayoutComponent() {
const router = useRouter();
const updateStore = useCallStore((state) => state.updateStore);

useUmamiActivityHeartbeat();

useEffect(() => {
const pathname = router.state.location.pathname;
const search = router.state.location.search;
Expand Down
1 change: 1 addition & 0 deletions packages/modules.calls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { LiveKitProvider } from './src/providers/LiveKitProvider';
export { RoomProvider } from './src/providers/RoomProvider';
export { useCallStore } from './src/store/callStore';
export { useStartCall } from './src/hooks';
export { useUmamiActivityHeartbeat } from './src';
1 change: 1 addition & 0 deletions packages/modules.calls/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export { useVideoSecurity } from './useVideoSecurity';
export { useScreenShareCleanup } from './useScreenShareCleanup';
export { useVideoBlur } from './useVideoBlur';
export { useParticipantJoinSync } from './useParticipantJoinSync';
export { useUmamiActivityHeartbeat } from './useUmamiActivityHeartbeat';
54 changes: 54 additions & 0 deletions packages/modules.calls/src/hooks/useUmamiActivityHeartbeat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useLocation } from '@tanstack/react-router';
import { useEffect, useRef } from 'react';
import { useCallStore } from '../store/callStore';

const HEARTBEAT_INTERVAL_MS = 5 * 60 * 1000; // 5 минут

/** Проверяет, находится ли пользователь на странице доски по pathname */
function isBoardPath(pathname: string): boolean {
return (
/^\/board\/[^/]+$/.test(pathname) ||
/\/classrooms\/[^/]+\/boards\/[^/]+/.test(pathname) ||
/\/materials\/[^/]+\/board\/?$/.test(pathname)
);
}

/**
* Раз в 5 минут вызывает umami.track(), если пользователь
* в активной ВКС или на странице доски.
*/
export function useUmamiActivityHeartbeat() {
const pathname = useLocation().pathname;
const isStarted = useCallStore((s) => s.isStarted);
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);

const isOnBoard = isBoardPath(pathname);
const shouldTrack = Boolean(isStarted || isOnBoard);

useEffect(() => {
if (!shouldTrack) {
if (intervalRef.current) {
clearInterval(intervalRef.current);
intervalRef.current = null;
}
return;
}

const track = () => {
const win = window as Window & { umami?: { track: (name?: string) => void } };
if (typeof window !== 'undefined' && win.umami) {
win.umami.track();
}
};

intervalRef.current = setInterval(track, HEARTBEAT_INTERVAL_MS);
return () => {
if (intervalRef.current) {
clearInterval(intervalRef.current);
intervalRef.current = null;
}
};
}, [shouldTrack]);

return null;
}
1 change: 1 addition & 0 deletions packages/modules.calls/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export {
useRaisedHands,
useHandFocus,
useSpeakingParticipant,
useUmamiActivityHeartbeat,
} from './hooks';
export { useCallStore } from './store';
Loading