Add logs for video tracking

This commit is contained in:
austinkelsay 2024-11-26 14:56:54 -06:00
parent 89dd52ed8b
commit d36e61c4f7
No known key found for this signature in database
GPG Key ID: 44CB4EC6D9F2FA02

View File

@ -81,8 +81,13 @@ const useTrackVideoLesson = ({lessonId, videoDuration, courseId, videoPlayed, pa
const alreadyCompleted = await checkOrCreateUserLesson(); const alreadyCompleted = await checkOrCreateUserLesson();
if (!alreadyCompleted && videoDuration && !completedRef.current && videoPlayed && (paidCourse === false || (paidCourse && decryptionPerformed))) { if (!alreadyCompleted && videoDuration && !completedRef.current && videoPlayed && (paidCourse === false || (paidCourse && decryptionPerformed))) {
setIsTracking(true); setIsTracking(true);
console.log('🎥 Starting video tracking - Duration:', videoDuration);
timerRef.current = setInterval(() => { timerRef.current = setInterval(() => {
setTimeSpent(prevTime => prevTime + 1); setTimeSpent(prevTime => {
const newTime = prevTime + 1;
console.log(`⏱️ Time spent: ${newTime}s / ${videoDuration}s (${((newTime/videoDuration)*100).toFixed(1)}%)`);
return newTime;
});
}, 1000); }, 1000);
} }
}; };
@ -100,6 +105,7 @@ const useTrackVideoLesson = ({lessonId, videoDuration, courseId, videoPlayed, pa
if (isAdmin) return; if (isAdmin) return;
if (videoDuration && timeSpent >= Math.round(videoDuration * 0.9) && !completedRef.current) { if (videoDuration && timeSpent >= Math.round(videoDuration * 0.9) && !completedRef.current) {
console.log('🎯 Video reached 90% threshold - Marking as completed');
markLessonAsCompleted(); markLessonAsCompleted();
} }
}, [timeSpent, videoDuration, markLessonAsCompleted, isAdmin]); }, [timeSpent, videoDuration, markLessonAsCompleted, isAdmin]);
@ -107,4 +113,4 @@ const useTrackVideoLesson = ({lessonId, videoDuration, courseId, videoPlayed, pa
return { isCompleted, isTracking }; return { isCompleted, isTracking };
}; };
export default useTrackVideoLesson; export default useTrackVideoLesson;