diff --git a/components/StatsModal.tsx b/components/StatsModal.tsx index a56b520..e077370 100644 --- a/components/StatsModal.tsx +++ b/components/StatsModal.tsx @@ -227,9 +227,12 @@ export default function StatsModal(props: Props) { const maxDistribution = Math.max(...Object.values(distribution)); const [isAdUnitRendered, setIsAdUnitRendered] = useState(false); + const adsByGooglePushedRef = useRef(false); const adUnitRef = useRef(null); + const adContentRef = useRef(null); + useEffect(() => { - if (!isOpen || !isAdUnitRendered) return; + if (!isOpen || !isAdUnitRendered || adsByGooglePushedRef.current) return; const adUnit = adUnitRef.current; adUnit.innerHTML = ` @@ -239,9 +242,11 @@ export default function StatsModal(props: Props) { data-ad-slot="2576511153" data-ad-format="auto" data-full-width-responsive="true">`; + try { // @ts-ignore window.adsbygoogle = (window.adsbygoogle || []).push({}); + adsByGooglePushedRef.current = true; } catch (err) { // ignore }