Skip to content

Commit 884c51c

Browse files
authored
Merge pull request #27 from soranoo/beta
feat: add isAutoAd prop to GoogleAdSense for better script loading
2 parents 3e29f0a + 067d278 commit 884c51c

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ There are two ways to verify your site (of course you can implement both):
9191
const App = ({ Component, pageProps }) => {
9292
return (
9393
<>
94-
<GoogleAdSense publisherId="pub-XXXXXXXXXXXXXXXX" /> {/* 👈 16 digits */}
94+
<GoogleAdSense
95+
publisherId="pub-XXXXXXXXXXXXXXXX" // 👈 16 digits
96+
isAutoAd={false} // 👈 true if you want to use Auto Ads
97+
/>
9598
{/* or */}
9699
<GoogleAdSense /> {/* if NEXT_PUBLIC_ADSENSE_PUBLISHER_ID is set */}
97100
<Component {...pageProps} />
@@ -220,6 +223,8 @@ export default Page;
220223
| Parameter | Optional | Type | Default | Description |
221224
| ----------- | -------- | ------ | ------- | --------------------------------------------------------------------------------------------------- |
222225
| publisherId | Yes | string | n/a | You can skip this parameter if you set the environment variable `NEXT_PUBLIC_ADSENSE_PUBLISHER_ID`. |
226+
| isAutoAd | Yes | boolean| false | Whether to enable Auto Ads. |
227+
| debug | Yes | boolean| false | Enable Google AdSense debug mode. |
223228

224229
#### Manual AD
225230

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-google-adsense",
3-
"version": "1.1.0",
3+
"version": "1.2.0-beta.1",
44
"description": "Next.js Google AdSense",
55
"main": "dist/index.js",
66
"type": "commonjs",

src/GoogleAdSense.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ import { isPublisherId } from "./utils";
99

1010
interface GoogleAdSenseProps extends Omit<ScriptProps, "src" | "id"> {
1111
publisherId?: string;
12+
isAutoAd?: boolean;
1213
debug?: boolean;
1314
}
1415

1516
/**
1617
* @param publisherId - Google AdSense publisher ID, if not provided, it will use NEXT_PUBLIC_ADSENSE_PUBLISHER_ID from .env
18+
* @param isAutoAd - Whether to enable Auto Ads
1719
* @param debug - Google AdSense debug mode
1820
*/
1921
export const GoogleAdSense = ({
2022
publisherId,
23+
isAutoAd = false,
2124
debug = false,
2225
...props
2326
}: GoogleAdSenseProps): JSX.Element | null => {
@@ -37,7 +40,7 @@ export const GoogleAdSense = ({
3740
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-${_publisherId}${
3841
debug ? "google_console=1" : ""
3942
}`}
40-
strategy="afterInteractive"
43+
strategy={isAutoAd ? "lazyOnload" : "afterInteractive"}
4144
crossOrigin="anonymous"
4245
{...props}
4346
/>

0 commit comments

Comments
 (0)