Skip to content

Commit 1fd40d9

Browse files
committed
Add adsense
1 parent 342e68d commit 1fd40d9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pages/_document.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Html, Head, Main, NextScript } from "next/document";
2+
import Script from "next/script";
23

34
const modeScript = `
45
let darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
@@ -55,6 +56,10 @@ const faviconScript = `
5556
onUpdate();
5657
`;
5758

59+
const adSenseScript = `
60+
(adsbygoogle = (window.adsbygoogle || [])).push({});
61+
`;
62+
5863
export default function Document() {
5964
return (
6065
<Html lang="en">
@@ -75,6 +80,18 @@ export default function Document() {
7580
/>
7681
<script dangerouslySetInnerHTML={{ __html: modeScript }} />
7782
<script dangerouslySetInnerHTML={{ __html: faviconScript }} />
83+
<script
84+
async
85+
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-${process.env.NEXT_PUBLIC_ADSENSE_ID}`}
86+
></script>
87+
<script dangerouslySetInnerHTML={{ __html: adSenseScript }} />
88+
<ins
89+
className="adsbygoogle"
90+
style={{ display: "block" }}
91+
data-ad-client={`ca-pub-${process.env.NEXT_PUBLIC_ADSENSE_ID}`}
92+
data-ad-slot={`${process.env.NEXT_PUBLIC_ADSENSE_ID}`}
93+
data-full-width-responsive="true"
94+
></ins>
7895
</Head>
7996
<body className="!min-h-screen bg-zinc-50 dark:bg-black">
8097
<Main />

0 commit comments

Comments
 (0)