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
Copy file name to clipboardExpand all lines: docs/content/scripts/ads/google-adsense.md
+99-40Lines changed: 99 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,13 +12,70 @@ links:
12
12
size: xs
13
13
---
14
14
15
-
:UAlert{title="Experimental"description="The Google Adsense integration has not been fully tested, use with caution."color="yellow"variant="soft"class="not-prose"}
15
+
[Google Adsense](https://www.google.com/adsense/start/) allows you to monetize your website by displaying relevant ads from Google.
16
16
17
-
[Google Adsense](https://www.google.com/adsense/start/) allows you to monetize your website by displaying ads.
17
+
Nuxt Scripts provides a `useScriptGoogleAdsense` composable and a headless `ScriptGoogleAdsense` component to interact with Google Adsense.
18
18
19
-
Nuxt Scripts provides a `useScriptGoogleAdsense` composable and a headless `ScriptGoogleAdsense` component to interact with the Google Adsense.
19
+
## Global Setup
20
20
21
-
## ScriptGoogleAdsense
21
+
You can configure Google Adsense globally in your `nuxt.config.ts` file so the script is automatically loaded on all pages.
22
+
23
+
```ts [nuxt.config.ts]
24
+
exportdefaultdefineNuxtConfig({
25
+
scripts: {
26
+
registry: {
27
+
googleAdsense: {
28
+
client: 'ca-pub-<your-id>', // Your Google AdSense Publisher ID
29
+
autoAds: true, // Enable Auto Ads
30
+
}
31
+
}
32
+
}
33
+
})
34
+
```
35
+
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**:
38
+
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.
43
+
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.
45
+
46
+
## Site Ownership Verification
47
+
48
+
### Using *meta tag* for Verification
49
+
When a `client` is provided, a **meta tag** will be inserted on the page so that Google can verify your site ownership.
3. Replace `<your-id>` with your **AdSense Publisher ID**.
74
+
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
22
79
23
80
The `ScriptGoogleAdsense` component is a wrapper around the `useScriptGoogleAdsense` composable. It provides a simple way to embed ads in your Nuxt app.
24
81
@@ -31,7 +88,30 @@ The `ScriptGoogleAdsense` component is a wrapper around the `useScriptGoogleAdse
31
88
</template>
32
89
```
33
90
34
-
### Handling Ad-blockers
91
+
### Component Props
92
+
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`).
-`data-full-width-responsive`: **Set to `true`** to make the ad responsive.
98
+
99
+
### Example Usage with `data-ad-layout`
100
+
101
+
To specify a layout for your ads (such as "in-article"), you can use the `data-ad-layout` attribute:
102
+
103
+
```vue
104
+
<template>
105
+
<ScriptGoogleAdsense
106
+
data-ad-client="ca-pub-<your-id>"
107
+
data-ad-slot="1234567890"
108
+
data-ad-format="fluid"
109
+
data-ad-layout="in-article"
110
+
/>
111
+
</template>
112
+
```
113
+
114
+
### How to Handle Ad-Blockers?
35
115
36
116
You can use these hooks to add a fallback when the Google Adsense script is blocked.
37
117
@@ -42,67 +122,46 @@ You can use these hooks to add a fallback when the Google Adsense script is bloc
42
122
data-ad-slot="..."
43
123
>
44
124
<template #error>
45
-
<!-- Fallback ad -->
125
+
<!-- Fallback content -->
46
126
Please support us by disabling your ad blocker.
47
127
</template>
48
128
</ScriptGoogleAdsense>
49
129
</template>
50
130
```
51
131
132
+
## `useScriptGoogleAdsense` Composable
52
133
53
-
### Component API
54
-
55
-
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full props, events, and slots.
56
-
57
-
### Props
58
-
59
-
The `ScriptGoogleAdsense` component supports all props that Google Adsense supports on the `<ins>` tag. See the [Ad tags documentation](https://developers.google.com/adsense/platforms/transparent/ad-tags) for more information.
60
-
61
-
At a minimum you must provide the following tags:
62
-
-`data-ad-client`: The Google Adsense ID.
63
-
-`data-ad-slot`: The slot ID.
64
-
65
-
## useScriptGoogleAdsense
66
-
67
-
The `useScriptGoogleAdsense` composable lets you have fine-grain control over the Google Adsense script.
134
+
The `useScriptGoogleAdsense` composable gives fine-grain control over the Adsense script management.
0 commit comments