Skip to content

Commit

Permalink
reuse ins content
Browse files Browse the repository at this point in the history
  • Loading branch information
pveyes committed Oct 31, 2023
1 parent 5fbb585 commit 43c7e70
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion components/StatsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDivElement>(null);
const adContentRef = useRef<string>(null);

useEffect(() => {
if (!isOpen || !isAdUnitRendered) return;

const adUnit = adUnitRef.current;
adUnit.innerHTML = `<!-- stats-ads -->
adUnit.innerHTML =
adContentRef.current ??
`<!-- stats-ads -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-3081263972680635"
data-ad-slot="2576511153"
data-ad-format="auto"
data-full-width-responsive="true"></ins>`;
if (adsByGooglePushedRef.current) return;

try {
// @ts-ignore
window.adsbygoogle = (window.adsbygoogle || []).push({});
adsByGooglePushedRef.current = true;
adContentRef.current = adUnit.innerHTML;
} catch (err) {
// ignore
}
Expand Down

1 comment on commit 43c7e70

@vercel
Copy link

@vercel vercel bot commented on 43c7e70 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

katla – ./

katla-git-main-katla.vercel.app
katla.vercel.app
katla-katla.vercel.app
katla.id

Please sign in to comment.