Skip to content

Commit

Permalink
dynamic ins experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
pveyes committed Oct 24, 2023
1 parent 886f451 commit 7252a4f
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions components/StatsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useSWR from "swr";
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { useTheme } from "next-themes";

import Modal from "./Modal";
Expand All @@ -25,6 +25,12 @@ interface Props {
remainingTime?: ReturnType<typeof useRemainingTime>;
}

declare global {
interface Window {
adsbygoogle: { loaded: boolean; push: (v: unknown) => void };
}
}

const GRAPH_WIDTH_MIN_RATIO = 10;

export default function StatsModal(props: Props) {
Expand Down Expand Up @@ -213,6 +219,19 @@ export default function StatsModal(props: Props) {
const { fail: _, ...distribution } = stats.distribution;
const maxDistribution = Math.max(...Object.values(distribution));

const hasPushedToAds = useRef(false);
useEffect(() => {
if (hasPushedToAds.current) return;

if (isOpen) {
hasPushedToAds.current = true;
// @ts-ignore
window.adsbygoogle = window.adsbygoogle || [];
if (window.adsbygoogle.loaded) return;
window.adsbygoogle.push({});
}
}, [isOpen]);

return (
<Modal isOpen={isOpen} onClose={onClose}>
<Modal.Title>Statistik</Modal.Title>
Expand Down Expand Up @@ -273,14 +292,16 @@ export default function StatsModal(props: Props) {
);
})}
</div>
<ins
className="adsbygoogle"
style={{ display: "block" }}
data-ad-client="ca-pub-3081263972680635"
data-ad-slot="2576511153"
data-ad-format="auto"
data-full-width-responsive="true"
/>
{isOpen && (
<ins
className="adsbygoogle"
style={{ display: "block" }}
data-ad-client="ca-pub-3081263972680635"
data-ad-slot="2576511153"
data-ad-format="auto"
data-full-width-responsive="true"
/>
)}
{showShare && (
<>
<WordDefinition answer={answer} />
Expand Down

1 comment on commit 7252a4f

@vercel
Copy link

@vercel vercel bot commented on 7252a4f Oct 24, 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.