diff --git a/web/src/modules/shared/components/client/ads/AdSlots.tsx b/web/src/modules/shared/components/client/ads/AdSlots.tsx index a8c1f377..a1c1a3a4 100644 --- a/web/src/modules/shared/components/client/ads/AdSlots.tsx +++ b/web/src/modules/shared/components/client/ads/AdSlots.tsx @@ -51,7 +51,6 @@ const AdTemplate = ({ showCloseButton?: boolean; }) => { const pubId = useAdSenseClient(); - const [isHidden, setIsHidden] = useState(false); useEffect(() => { @@ -85,6 +84,21 @@ const AdTemplate = ({ {!isHidden && ( <> { + // detect the ad has data-ad-status="unfilled" data + if (el) { + const observer = new MutationObserver(() => { + if (el.getAttribute('data-ad-status') === 'unfilled') { + setIsHidden(true); + } + }); + + observer.observe(el, { + attributes: true, + attributeFilter: ['data-ad-status'], + }); + } + }} className={cn('adsbygoogle', isHidden ? 'hidden' : '')} style={{ display: 'block',