Skip to content

Commit

Permalink
fix(googleAdsense): broken validation input path
Browse files Browse the repository at this point in the history
Fixes #223
  • Loading branch information
harlan-zw committed Sep 3, 2024
1 parent 50126bf commit f198a80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
16 changes: 16 additions & 0 deletions docs/content/scripts/ads/google-adsense.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ export function useScriptGoogleAdsense<T extends GoogleAdsenseApi>(_options?: Go

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

### Site Ownership Verification

When a `client` is provided, a meta tag will be inserted on the page so that Google can verify your site ownership.

```ts
const adsense = useScriptGoogleAdsense({
client: 'ca-pub-<your-id>',
})
```

The generated meta tag will look like this:

```html
<meta name="google-adsense-account" content="ca-pub-<your-id>">
```

### GoogleAdsenseApi

```ts
Expand Down
27 changes: 11 additions & 16 deletions src/runtime/registry/google-adsense.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { optional } from 'valibot'
import { useRegistryScript } from '../utils'
import { object, string } from '#nuxt-scripts-validator'
import { object, string, optional } from '#nuxt-scripts-validator'
import type { RegistryScriptInput } from '#nuxt-scripts'
import { useHead } from '#imports'

Expand Down Expand Up @@ -40,21 +39,17 @@ export function useScriptGoogleAdsense<T extends GoogleAdsenseApi>(_options?: Go
use() {
return { adsbygoogle: window.adsbygoogle }
},
// allow dataLayer to be accessed on the server
stub: import.meta.client
? undefined
: ({ fn }) => {
return fn === 'adsbygoogle' ? [] : undefined
},
beforeInit() {
useHead({
meta: [
{
name: 'google-adsense-account',
content: options?.client,
},
],
})
if (options?.client) {
useHead({
meta: [
{
name: 'google-adsense-account',
content: options?.client,
},
],
})
}
},
},
}), _options)
Expand Down

0 comments on commit f198a80

Please sign in to comment.