Skip to content

Commit f198a80

Browse files
committed
fix(googleAdsense): broken validation input path
Fixes #223
1 parent 50126bf commit f198a80

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

docs/content/scripts/ads/google-adsense.md

+16
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ export function useScriptGoogleAdsense<T extends GoogleAdsenseApi>(_options?: Go
7272

7373
Please follow the [Registry Scripts](/docs/guides/registry-scripts) guide to learn more about advanced usage.
7474

75+
### Site Ownership Verification
76+
77+
When a `client` is provided, a meta tag will be inserted on the page so that Google can verify your site ownership.
78+
79+
```ts
80+
const adsense = useScriptGoogleAdsense({
81+
client: 'ca-pub-<your-id>',
82+
})
83+
```
84+
85+
The generated meta tag will look like this:
86+
87+
```html
88+
<meta name="google-adsense-account" content="ca-pub-<your-id>">
89+
```
90+
7591
### GoogleAdsenseApi
7692

7793
```ts

src/runtime/registry/google-adsense.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { optional } from 'valibot'
21
import { useRegistryScript } from '../utils'
3-
import { object, string } from '#nuxt-scripts-validator'
2+
import { object, string, optional } from '#nuxt-scripts-validator'
43
import type { RegistryScriptInput } from '#nuxt-scripts'
54
import { useHead } from '#imports'
65

@@ -40,21 +39,17 @@ export function useScriptGoogleAdsense<T extends GoogleAdsenseApi>(_options?: Go
4039
use() {
4140
return { adsbygoogle: window.adsbygoogle }
4241
},
43-
// allow dataLayer to be accessed on the server
44-
stub: import.meta.client
45-
? undefined
46-
: ({ fn }) => {
47-
return fn === 'adsbygoogle' ? [] : undefined
48-
},
4942
beforeInit() {
50-
useHead({
51-
meta: [
52-
{
53-
name: 'google-adsense-account',
54-
content: options?.client,
55-
},
56-
],
57-
})
43+
if (options?.client) {
44+
useHead({
45+
meta: [
46+
{
47+
name: 'google-adsense-account',
48+
content: options?.client,
49+
},
50+
],
51+
})
52+
}
5853
},
5954
},
6055
}), _options)

0 commit comments

Comments
 (0)