/
HyperTalbot
/
CollabHub
Обзор
Документация
Войти
/
HyperTalbot
/
CollabHub
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
frontend/hooks/useViewTracking.ts
39 строк
1 KB
hypertalbot
v0.2.7: recomendation for posts, adds music
12 мар 2026, 19:28
12 мар 2026, 19:28
d7c09be
Код
Авторство
О чём код?
// frontend/hooks/useViewTracking.ts "use client"; import { useEffect, useRef } from 'react'; import { trackView, trackInteraction } from '@/lib/tracking'; interface UseViewTrackingProps { contentType: 'post' | 'video' | 'short' | 'stream' | 'music'; contentId: number; contentDuration?: number; } export function useViewTracking({ contentType, contentId, contentDuration = 0, }: UseViewTrackingProps) { const startTimeRef = useRef<number>(Date.now()); const trackedRef = useRef(false); useEffect(() => { startTimeRef.current = Date.now(); trackedRef.current = false; return () => { if (!trackedRef.current) { const watchTime = Math.floor((Date.now() - startTimeRef.current) / 1000); trackView({ contentType, contentId, watchTime, contentDuration }); trackedRef.current = true; } }; }, [contentId]); return { trackLike: () => trackInteraction({ contentType, contentId, interactionType: 'like' }), trackComment: () => trackInteraction({ contentType, contentId, interactionType: 'comment' }), trackShare: () => trackInteraction({ contentType, contentId, interactionType: 'share' }), }; }