diff --git a/components/StatsModal.tsx b/components/StatsModal.tsx index a56b520..d409d3d 100644 --- a/components/StatsModal.tsx +++ b/components/StatsModal.tsx @@ -227,21 +227,30 @@ 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; const adUnit = adUnitRef.current; - adUnit.innerHTML = ` + adUnit.innerHTML = + adContentRef.current ?? + ` `; + if (adsByGooglePushedRef.current) return; + try { // @ts-ignore window.adsbygoogle = (window.adsbygoogle || []).push({}); + adsByGooglePushedRef.current = true; + adContentRef.current = adUnit.innerHTML; } catch (err) { // ignore }