diff --git a/attached_assets/image_1759062761808.png b/attached_assets/image_1759062761808.png new file mode 100644 index 0000000..17ae43d Binary files /dev/null and b/attached_assets/image_1759062761808.png differ diff --git a/client/src/components/adsense-ad.tsx b/client/src/components/adsense-ad.tsx index 0627db5..413d2b4 100644 --- a/client/src/components/adsense-ad.tsx +++ b/client/src/components/adsense-ad.tsx @@ -24,16 +24,24 @@ export default function AdSenseAd({ const adRef = useRef(null); useEffect(() => { - const initializeAd = () => { - const insElement = adRef.current?.querySelector('ins'); - if (!insElement || insElement.dataset.adsbygoogleStatus === 'done') return; + const initializeAds = () => { + const insElements = adRef.current?.querySelectorAll('ins'); + if (!insElements) return; - try { - // @ts-ignore - (window.adsbygoogle = window.adsbygoogle || []).push({}); - } catch (error) { - console.error('AdSense initialization error:', error); - } + insElements.forEach((insElement) => { + if (insElement.dataset.adsbygoogleStatus === 'done') return; + + // Check if this ad is visible (not hidden by responsive classes) + const computedStyle = window.getComputedStyle(insElement); + if (computedStyle.display === 'none') return; + + try { + // @ts-ignore + (window.adsbygoogle = window.adsbygoogle || []).push({}); + } catch (error) { + console.error('AdSense initialization error:', error); + } + }); }; if (lazy) { @@ -42,7 +50,8 @@ export default function AdSenseAd({ (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { - initializeAd(); + // Small delay to ensure responsive CSS has been applied + setTimeout(initializeAds, 100); observer.disconnect(); } }); @@ -56,8 +65,8 @@ export default function AdSenseAd({ return () => observer.disconnect(); } else { - // Immediate initialization - initializeAd(); + // Immediate initialization with delay for responsive CSS + setTimeout(initializeAds, 100); } }, [adSlot, lazy]); @@ -70,7 +79,7 @@ export default function AdSenseAd({
{/* Desktop ad */}