You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Google Adsense](https://www.google.com/adsense/start/) allows you to monetize your website by displaying relevant ads from Google.
15
+
[Google AdSense](https://www.google.com/adsense/start/) allows you to monetize your website by displaying relevant ads from Google.
16
16
17
-
Nuxt Scripts provides a `useScriptGoogleAdsense` composable and a headless `ScriptGoogleAdsense` component to interact with Google Adsense.
17
+
Nuxt Scripts provides:
18
+
19
+
-`useScriptGoogleAdsense`: A composable to manage Google AdSense dynamically.
20
+
-`<ScriptGoogleAdsense>`: A headless component to embed ads directly in your Nuxt app.
18
21
19
22
## Global Setup
20
23
21
-
You can configure Google Adsense globally in your `nuxt.config.ts`file so the script is automatically loaded on all pages.
24
+
You can configure Google AdSense **globally** in your `nuxt.config.ts`so that the script is automatically loaded on all pages.
22
25
23
26
```ts [nuxt.config.ts]
24
27
exportdefaultdefineNuxtConfig({
25
28
scripts: {
26
29
registry: {
27
30
googleAdsense: {
28
-
client: 'ca-pub-<your-id>', // Your Google AdSense Publisher ID
31
+
client: "ca-pub-<your-id>", // Your Google AdSense Publisher ID
29
32
autoAds: true, // Enable Auto Ads
30
-
}
31
-
}
32
-
}
33
-
})
33
+
},
34
+
},
35
+
},
36
+
});
34
37
```
35
38
36
-
## Where to Find `<your-id>`
37
-
Your **Google AdSense Publisher ID** (also known as `ca-pub-XXXXXXX`) can be found in your **Google AdSense Account**:
39
+
## Where to Find `<your-id>` (Publisher ID)
38
40
39
-
1. Log in to your **Google AdSense** account.
40
-
2. Navigate to **Account > Settings** (click on your profile icon > "Account information").
41
-
3. Locate the **Publisher ID** under **Account Information**.
42
-
4. Replace `<your-id>` in the config above with your actual ID.
41
+
Your **Google AdSense Publisher ID** (also known as `ca-pub-XXXXXXX`) can be found in your **Google AdSense Account**:
43
42
44
-
> **Note**: You can also manage Auto Ads settings directly from [Google Adsense](https://adsense.google.com/start/), where you can control ad types, placements, and optimization for higher revenue.
43
+
1. Log in to your **Google AdSense** account.
44
+
2. Navigate to **Account > Settings** (click on your profile icon > "Account information").
45
+
3. Locate the **Publisher ID** under **Account Information**.
46
+
4. Replace `<your-id>` in the config above with your actual ID.
3. Replace `<your-id>` with your **AdSense Publisher ID**.
74
99
75
-
> **Why is `ads.txt` important?**
76
-
> Adding this file helps prevent **ad fraud** and ensures that only your site can display your ads.
77
-
78
-
## `ScriptGoogleAdsense` Component
79
-
80
-
The `ScriptGoogleAdsense` component is a wrapper around the `useScriptGoogleAdsense` composable. It provides a simple way to embed ads in your Nuxt app.
100
+
::callout{icon="i-heroicons-light-bulb"}
101
+
**Why use `ads.txt`?** It helps **prevent ad fraud** and ensures that **only your site** can display your ads.
102
+
::
103
+
104
+
## Enabling Auto Ads
105
+
106
+
Auto Ads allow Google to **automatically** place ads for **better optimization**.
107
+
108
+
::tabs
109
+
::div
110
+
---
111
+
label: Example
112
+
icon: i-heroicons-code-bracket-square
113
+
---
114
+
```ts [nuxt.config.ts]
115
+
exportdefaultdefineNuxtConfig({
116
+
scripts: {
117
+
registry: {
118
+
googleAdsense: {
119
+
client: "ca-pub-<your-id>", // AdSense Publisher ID
120
+
autoAds: true, // Enable Auto Ads
121
+
},
122
+
},
123
+
},
124
+
});
125
+
```
126
+
::
127
+
::div
128
+
---
129
+
label: Output
130
+
icon: i-heroicons-magnifying-glass-circle
131
+
---
132
+
```html
133
+
<script>
134
+
(adsbygoogle =window.adsbygoogle|| []).push({
135
+
google_ad_client:"ca-pub-<your-id>",
136
+
enable_page_level_ads:true,
137
+
});
138
+
</script>
139
+
```
140
+
::
141
+
::
142
+
143
+
## Using `ScriptGoogleAdsense` Component
144
+
145
+
It provides a simple way to **embed ads** in your Nuxt app.
81
146
82
147
```vue
83
148
<template>
84
149
<ScriptGoogleAdsense
85
-
data-ad-client="ca-pub-..."
86
-
data-ad-slot="..."
150
+
data-ad-client="ca-pub-<your-id>"
151
+
data-ad-slot="1234567890"
152
+
data-ad-format="auto"
87
153
/>
88
154
</template>
89
155
```
90
156
91
157
### Component Props
92
158
93
-
-`data-ad-client`: **(Required)** Your **Google Adsense Publisher ID** (`ca-pub-XXXXXXXXXX`).
94
-
-`data-ad-slot`: **(Required)** Your **Ad Slot ID** (available in AdSense dashboard).
95
-
-`data-ad-format`: Ad format type (`auto`, `rectangle`, `horizontal`, `vertical`, `fluid`, `autorelaxed`).
0 commit comments