Skip to content

Commit 3f7e408

Browse files
committed
fix(adsense): use globally configured client in component
Fixes #345
1 parent a671824 commit 3f7e408

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/runtime/components/ScriptGoogleAdsense.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { computed, onMounted, ref, watch } from 'vue'
33
import { callOnce } from 'nuxt/app'
44
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
55
import { useScriptGoogleAdsense } from '../registry/google-adsense'
6+
import { scriptRuntimeConfig } from '../utils'
67
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
78
89
const props = withDefaults(defineProps<{
@@ -29,8 +30,13 @@ const emits = defineEmits<{
2930
const rootEl = ref(null)
3031
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
3132
33+
const scriptConfig = scriptRuntimeConfig('googleAdsense')
34+
const addClient = computed(() => {
35+
return props.dataAdClient || scriptConfig?.client
36+
})
37+
3238
const instance = useScriptGoogleAdsense({
33-
client: props.dataAdClient,
39+
client: addClient.value,
3440
scriptOptions: {
3541
trigger,
3642
},
@@ -72,7 +78,7 @@ const rootAttrs = computed(() => {
7278
ref="rootEl"
7379
class="adsbygoogle"
7480
style="display: block;"
75-
:data-ad-client="dataAdClient"
81+
:data-ad-client="addClient"
7682
:data-ad-slot="dataAdSlot"
7783
:data-ad-format="dataAdFormat"
7884
:data-ad-layout="dataAdLayout"

0 commit comments

Comments
 (0)