diff --git a/client/src/components/adsense-ad.tsx b/client/src/components/adsense-ad.tsx index 6c66d16..961ba7e 100644 --- a/client/src/components/adsense-ad.tsx +++ b/client/src/components/adsense-ad.tsx @@ -18,25 +18,15 @@ export default function AdSenseAd({ const adRef = useRef(null); useEffect(() => { - const timer = setTimeout(() => { - try { - // Ensure adsbygoogle is loaded - if (typeof window !== 'undefined' && adRef.current) { - // Check if element has width before initializing ad - const elementWidth = adRef.current.offsetWidth; - if (elementWidth > 0) { - // @ts-ignore - (window.adsbygoogle = window.adsbygoogle || []).push({}); - } else { - console.warn('AdSense element has no width, skipping initialization'); - } - } - } catch (error) { - console.error('AdSense initialization error:', error); + try { + // Ensure adsbygoogle is loaded + if (typeof window !== 'undefined') { + // @ts-ignore + (window.adsbygoogle = window.adsbygoogle || []).push({}); } - }, 100); // Small delay to ensure DOM is rendered - - return () => clearTimeout(timer); + } catch (error) { + console.error('AdSense initialization error:', error); + } }, []); const adStyle: React.CSSProperties = { @@ -52,7 +42,7 @@ export default function AdSenseAd({ } return ( -
+
(