From d4703f6167dadcc58314f338411802db2f2544cf Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Mon, 4 Aug 2025 20:48:52 +0000 Subject: [PATCH] Improve video viewing experience and address issues with ad loading Fixes Google Ads initialization and video sharing, adds fallback for video playback. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 11420304-80a9-4ef2-adff-cbdaa418ffa8 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/11420304-80a9-4ef2-adff-cbdaa418ffa8/bVyBC8U --- client/src/components/video-modal.tsx | 41 ++++++++++++++++++--------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/client/src/components/video-modal.tsx b/client/src/components/video-modal.tsx index 9290c8f..9b2e4f6 100644 --- a/client/src/components/video-modal.tsx +++ b/client/src/components/video-modal.tsx @@ -175,18 +175,31 @@ export default function VideoModal({ video, isOpen, onClose }: VideoModalProps) if (isOpen && video && adContainerRef.current) { // Initialize Google Ads Manager const loadGoogleAdsManager = () => { - // Check if Google IMA SDK is loaded - if (window.google && window.google.ima) { - // Initialize ads display - const adsManager = new window.google.ima.AdsManager(); - // Configure ads for video content - console.log('Google Ads Manager initialized for video:', video.id); + // Check if Google IMA SDK is loaded and properly initialized + if (window.google && window.google.ima && window.google.ima.AdDisplayContainer) { + try { + // Create ad display container + const adDisplayContainer = new window.google.ima.AdDisplayContainer( + adContainerRef.current, + videoRef.current + ); + console.log('Google Ads Manager initialized for video:', video.id); + } catch (error) { + console.log('Google Ads Manager initialization skipped:', error); + } } else { - // Load Google IMA SDK - const script = document.createElement('script'); - script.src = 'https://imasdk.googleapis.com/js/sdkloader/ima3.js'; - script.onload = loadGoogleAdsManager; - document.head.appendChild(script); + // Load Google IMA SDK if not already loaded + if (!document.querySelector('script[src*="ima3.js"]')) { + const script = document.createElement('script'); + script.src = 'https://imasdk.googleapis.com/js/sdkloader/ima3.js'; + script.onload = () => { + setTimeout(loadGoogleAdsManager, 100); // Small delay to ensure full SDK load + }; + script.onerror = () => { + console.log('Google IMA SDK failed to load'); + }; + document.head.appendChild(script); + } } }; @@ -205,7 +218,8 @@ export default function VideoModal({ video, isOpen, onClose }: VideoModalProps) }; const getShareUrl = () => { - return `${window.location.origin}?video=${video?.id}`; + if (!video?.id) return window.location.origin; + return `${window.location.origin}?video=${video.id}`; }; const copyToClipboard = async () => { @@ -277,7 +291,6 @@ export default function VideoModal({ video, isOpen, onClose }: VideoModalProps)