@nuxt/scripts 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -71
- package/dist/client/200.html +9 -9
- package/dist/client/404.html +9 -9
- package/dist/client/_nuxt/{CtQNcfGE.js → Bo1SWr6k.js} +1 -1
- package/dist/client/_nuxt/BojlM8av.js +21 -0
- package/dist/client/_nuxt/{BFM-Ncmx.js → BwFnCI0m.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/4c86029b-49d8-417d-817c-09c5117d4d78.json +1 -0
- package/dist/client/_nuxt/{entry.ipQkUTQD.css → entry.CJckMUzn.css} +1 -1
- package/dist/client/_nuxt/error-404.BiTeRF3j.css +1 -0
- package/dist/client/_nuxt/error-500.Be1AE5oK.css +1 -0
- package/dist/client/_nuxt/{BSA2bgdb.js → yRslIvSb.js} +1 -1
- package/dist/client/index.html +9 -9
- package/dist/module.json +1 -1
- package/dist/module.mjs +21 -19
- package/dist/registry.d.mts +3 -2
- package/dist/registry.d.ts +3 -2
- package/dist/registry.mjs +37 -26
- package/dist/runtime/components/ScriptAriaLoadingIndicator.vue +5 -5
- package/dist/runtime/components/ScriptCarbonAds.vue +83 -83
- package/dist/runtime/components/ScriptCrisp.vue +94 -94
- package/dist/runtime/components/ScriptGoogleAdsense.vue +93 -93
- package/dist/runtime/components/ScriptGoogleMaps.vue +495 -469
- package/dist/runtime/components/ScriptIntercom.vue +103 -103
- package/dist/runtime/components/ScriptLemonSqueezy.vue +52 -52
- package/dist/runtime/components/ScriptLoadingIndicator.vue +22 -22
- package/dist/runtime/components/ScriptStripePricingTable.vue +74 -74
- package/dist/runtime/components/ScriptVimeoPlayer.vue +288 -289
- package/dist/runtime/components/ScriptYouTubePlayer.vue +215 -215
- package/dist/runtime/composables/useScript.js +6 -3
- package/dist/runtime/composables/useScriptEventPage.js +1 -2
- package/dist/runtime/registry/clarity.d.ts +1 -1
- package/dist/runtime/registry/cloudflare-web-analytics.d.ts +1 -1
- package/dist/runtime/registry/google-adsense.js +1 -1
- package/dist/runtime/registry/google-analytics.d.ts +57 -13
- package/dist/runtime/registry/google-analytics.js +30 -28
- package/dist/runtime/registry/google-maps.d.ts +1 -1
- package/dist/runtime/registry/google-maps.js +4 -2
- package/dist/runtime/registry/google-tag-manager.d.ts +83 -21
- package/dist/runtime/registry/google-tag-manager.js +65 -24
- package/dist/runtime/types.d.ts +3 -10
- package/dist/runtime/utils.d.ts +1 -1
- package/package.json +20 -20
- package/dist/client/_nuxt/DuCkB5R-.js +0 -21
- package/dist/client/_nuxt/builds/meta/6161796c-413c-4c03-ac47-cad81a701b23.json +0 -1
- package/dist/client/_nuxt/error-404.BdjopNsg.css +0 -1
- package/dist/client/_nuxt/error-500.Bd7Z7Q7I.css +0 -1
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { withQuery } from 'ufo'
|
|
3
|
-
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
4
|
-
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
-
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
|
|
6
|
-
|
|
7
|
-
const props = defineProps<{
|
|
8
|
-
serve: string
|
|
9
|
-
placement: string
|
|
10
|
-
format: string
|
|
11
|
-
/**
|
|
12
|
-
* Defines the trigger event to load the script.
|
|
13
|
-
*/
|
|
14
|
-
trigger?: ElementScriptTrigger
|
|
15
|
-
}>()
|
|
16
|
-
|
|
17
|
-
const emit = defineEmits<{
|
|
18
|
-
error: [error: string | Event]
|
|
19
|
-
ready: [HTMLScriptElement]
|
|
20
|
-
}>()
|
|
21
|
-
|
|
22
|
-
const attrId = `_carbonads_js`
|
|
23
|
-
const carbonadsEl = ref<HTMLElement | null>(import.meta.client ? document.getElementById(attrId) : null)
|
|
24
|
-
// syncs to useScript status
|
|
25
|
-
const status = ref('awaitingLoad')
|
|
26
|
-
|
|
27
|
-
function loadCarbon() {
|
|
28
|
-
if (!carbonadsEl.value) {
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
status.value = 'loading'
|
|
32
|
-
const script = document.createElement('script')
|
|
33
|
-
script.setAttribute('src', withQuery('https://cdn.carbonads.com/carbon.js', {
|
|
34
|
-
serve: props.serve,
|
|
35
|
-
placement: props.placement,
|
|
36
|
-
format: props.format,
|
|
37
|
-
}))
|
|
38
|
-
script.setAttribute('id', attrId)
|
|
39
|
-
script.onerror = (err) => {
|
|
40
|
-
if (status.value !== 'error') {
|
|
41
|
-
status.value = 'error'
|
|
42
|
-
emit('error', err)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
script.onload = () => {
|
|
46
|
-
if (status.value !== 'loaded') {
|
|
47
|
-
status.value = 'loaded'
|
|
48
|
-
emit('ready', script)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
carbonadsEl.value.appendChild(script)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: carbonadsEl })
|
|
55
|
-
onMounted(() => {
|
|
56
|
-
if (trigger === 'onNuxtReady') {
|
|
57
|
-
loadCarbon()
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
trigger.then(loadCarbon)
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const rootAttrs = computed(() => {
|
|
65
|
-
return {
|
|
66
|
-
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
onBeforeUnmount(() => {
|
|
71
|
-
if (carbonadsEl.value) {
|
|
72
|
-
carbonadsEl.value.remove()
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
</script>
|
|
76
|
-
|
|
77
|
-
<template>
|
|
78
|
-
<div ref="carbonadsEl" v-bind="rootAttrs">
|
|
79
|
-
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
80
|
-
<slot v-else-if="status === 'loading'" name="loading" />
|
|
81
|
-
<slot v-else-if="status === 'error'" name="error" />
|
|
82
|
-
</div>
|
|
83
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { withQuery } from 'ufo'
|
|
3
|
+
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
4
|
+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
+
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
|
|
6
|
+
|
|
7
|
+
const props = defineProps<{
|
|
8
|
+
serve: string
|
|
9
|
+
placement: string
|
|
10
|
+
format: string
|
|
11
|
+
/**
|
|
12
|
+
* Defines the trigger event to load the script.
|
|
13
|
+
*/
|
|
14
|
+
trigger?: ElementScriptTrigger
|
|
15
|
+
}>()
|
|
16
|
+
|
|
17
|
+
const emit = defineEmits<{
|
|
18
|
+
error: [error: string | Event]
|
|
19
|
+
ready: [HTMLScriptElement]
|
|
20
|
+
}>()
|
|
21
|
+
|
|
22
|
+
const attrId = `_carbonads_js`
|
|
23
|
+
const carbonadsEl = ref<HTMLElement | null>(import.meta.client ? document.getElementById(attrId) : null)
|
|
24
|
+
// syncs to useScript status
|
|
25
|
+
const status = ref('awaitingLoad')
|
|
26
|
+
|
|
27
|
+
function loadCarbon() {
|
|
28
|
+
if (!carbonadsEl.value) {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
status.value = 'loading'
|
|
32
|
+
const script = document.createElement('script')
|
|
33
|
+
script.setAttribute('src', withQuery('https://cdn.carbonads.com/carbon.js', {
|
|
34
|
+
serve: props.serve,
|
|
35
|
+
placement: props.placement,
|
|
36
|
+
format: props.format,
|
|
37
|
+
}))
|
|
38
|
+
script.setAttribute('id', attrId)
|
|
39
|
+
script.onerror = (err) => {
|
|
40
|
+
if (status.value !== 'error') {
|
|
41
|
+
status.value = 'error'
|
|
42
|
+
emit('error', err)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
script.onload = () => {
|
|
46
|
+
if (status.value !== 'loaded') {
|
|
47
|
+
status.value = 'loaded'
|
|
48
|
+
emit('ready', script)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
carbonadsEl.value.appendChild(script)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: carbonadsEl })
|
|
55
|
+
onMounted(() => {
|
|
56
|
+
if (trigger === 'onNuxtReady') {
|
|
57
|
+
loadCarbon()
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
trigger.then(loadCarbon)
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const rootAttrs = computed(() => {
|
|
65
|
+
return {
|
|
66
|
+
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
onBeforeUnmount(() => {
|
|
71
|
+
if (carbonadsEl.value) {
|
|
72
|
+
carbonadsEl.value.remove()
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<template>
|
|
78
|
+
<div ref="carbonadsEl" v-bind="rootAttrs">
|
|
79
|
+
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
80
|
+
<slot v-else-if="status === 'loading'" name="loading" />
|
|
81
|
+
<slot v-else-if="status === 'error'" name="error" />
|
|
82
|
+
</div>
|
|
83
|
+
</template>
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { ref, onMounted, onBeforeUnmount, watch, computed } from 'vue'
|
|
3
|
-
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
4
|
-
import { useScriptCrisp } from '../registry/crisp'
|
|
5
|
-
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
|
|
6
|
-
|
|
7
|
-
const props = withDefaults(defineProps<{
|
|
8
|
-
/**
|
|
9
|
-
* Defines the trigger event to load the script.
|
|
10
|
-
*/
|
|
11
|
-
trigger?: ElementScriptTrigger
|
|
12
|
-
id: string
|
|
13
|
-
runtimeConfig?: {
|
|
14
|
-
locale: string
|
|
15
|
-
}
|
|
16
|
-
tokenId?: string
|
|
17
|
-
cookieDomain?: string
|
|
18
|
-
cookieExpiry?: number
|
|
19
|
-
}>(), {
|
|
20
|
-
trigger: 'click',
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const emits = defineEmits<{
|
|
24
|
-
// our emit
|
|
25
|
-
ready: [e: ReturnType<typeof useScriptCrisp>]
|
|
26
|
-
error: []
|
|
27
|
-
}>()
|
|
28
|
-
|
|
29
|
-
const rootEl = ref(null)
|
|
30
|
-
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
31
|
-
|
|
32
|
-
const isReady = ref(false)
|
|
33
|
-
const crisp = useScriptCrisp({
|
|
34
|
-
id: props.id,
|
|
35
|
-
runtimeConfig: props.runtimeConfig,
|
|
36
|
-
tokenId: props.tokenId,
|
|
37
|
-
cookieDomain: props.cookieDomain,
|
|
38
|
-
cookieExpiry: props.cookieExpiry,
|
|
39
|
-
scriptOptions: {
|
|
40
|
-
trigger,
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
const { onLoaded, status } = crisp
|
|
44
|
-
if (props.trigger === 'click') {
|
|
45
|
-
onLoaded((instance) => {
|
|
46
|
-
instance.do('chat:open')
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
defineExpose({
|
|
51
|
-
crisp,
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
let observer: MutationObserver
|
|
55
|
-
onMounted(() => {
|
|
56
|
-
watch(status, (status) => {
|
|
57
|
-
if (status === 'loaded') {
|
|
58
|
-
observer = new MutationObserver(() => {
|
|
59
|
-
if (document.getElementById('crisp-chatbox')) {
|
|
60
|
-
isReady.value = true
|
|
61
|
-
emits('ready', crisp)
|
|
62
|
-
observer.disconnect()
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
observer.observe(document.body, { childList: true, subtree: true })
|
|
66
|
-
}
|
|
67
|
-
else if (status === 'error') {
|
|
68
|
-
emits('error')
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
onBeforeUnmount(() => {
|
|
73
|
-
observer?.disconnect()
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
const rootAttrs = computed(() => {
|
|
77
|
-
return {
|
|
78
|
-
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
</script>
|
|
82
|
-
|
|
83
|
-
<template>
|
|
84
|
-
<div
|
|
85
|
-
ref="rootEl"
|
|
86
|
-
:style="{ display: isReady ? 'none' : 'block' }"
|
|
87
|
-
v-bind="rootAttrs"
|
|
88
|
-
>
|
|
89
|
-
<slot :ready="isReady" />
|
|
90
|
-
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
91
|
-
<slot v-else-if="status === 'loading' || !isReady" name="loading" />
|
|
92
|
-
<slot v-else-if="status === 'error'" name="error" />
|
|
93
|
-
</div>
|
|
94
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, onMounted, onBeforeUnmount, watch, computed } from 'vue'
|
|
3
|
+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
4
|
+
import { useScriptCrisp } from '../registry/crisp'
|
|
5
|
+
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{
|
|
8
|
+
/**
|
|
9
|
+
* Defines the trigger event to load the script.
|
|
10
|
+
*/
|
|
11
|
+
trigger?: ElementScriptTrigger
|
|
12
|
+
id: string
|
|
13
|
+
runtimeConfig?: {
|
|
14
|
+
locale: string
|
|
15
|
+
}
|
|
16
|
+
tokenId?: string
|
|
17
|
+
cookieDomain?: string
|
|
18
|
+
cookieExpiry?: number
|
|
19
|
+
}>(), {
|
|
20
|
+
trigger: 'click',
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const emits = defineEmits<{
|
|
24
|
+
// our emit
|
|
25
|
+
ready: [e: ReturnType<typeof useScriptCrisp>]
|
|
26
|
+
error: []
|
|
27
|
+
}>()
|
|
28
|
+
|
|
29
|
+
const rootEl = ref(null)
|
|
30
|
+
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
31
|
+
|
|
32
|
+
const isReady = ref(false)
|
|
33
|
+
const crisp = useScriptCrisp({
|
|
34
|
+
id: props.id,
|
|
35
|
+
runtimeConfig: props.runtimeConfig,
|
|
36
|
+
tokenId: props.tokenId,
|
|
37
|
+
cookieDomain: props.cookieDomain,
|
|
38
|
+
cookieExpiry: props.cookieExpiry,
|
|
39
|
+
scriptOptions: {
|
|
40
|
+
trigger,
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
const { onLoaded, status } = crisp
|
|
44
|
+
if (props.trigger === 'click') {
|
|
45
|
+
onLoaded((instance) => {
|
|
46
|
+
instance.do('chat:open')
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
defineExpose({
|
|
51
|
+
crisp,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
let observer: MutationObserver
|
|
55
|
+
onMounted(() => {
|
|
56
|
+
watch(status, (status) => {
|
|
57
|
+
if (status === 'loaded') {
|
|
58
|
+
observer = new MutationObserver(() => {
|
|
59
|
+
if (document.getElementById('crisp-chatbox')) {
|
|
60
|
+
isReady.value = true
|
|
61
|
+
emits('ready', crisp)
|
|
62
|
+
observer.disconnect()
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
66
|
+
}
|
|
67
|
+
else if (status === 'error') {
|
|
68
|
+
emits('error')
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
onBeforeUnmount(() => {
|
|
73
|
+
observer?.disconnect()
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const rootAttrs = computed(() => {
|
|
77
|
+
return {
|
|
78
|
+
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<template>
|
|
84
|
+
<div
|
|
85
|
+
ref="rootEl"
|
|
86
|
+
:style="{ display: isReady ? 'none' : 'block' }"
|
|
87
|
+
v-bind="rootAttrs"
|
|
88
|
+
>
|
|
89
|
+
<slot :ready="isReady" />
|
|
90
|
+
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
91
|
+
<slot v-else-if="status === 'loading' || !isReady" name="loading" />
|
|
92
|
+
<slot v-else-if="status === 'error'" name="error" />
|
|
93
|
+
</div>
|
|
94
|
+
</template>
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed, onMounted, ref, watch } from 'vue'
|
|
3
|
-
import { callOnce } from 'nuxt/app'
|
|
4
|
-
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
-
import { useScriptGoogleAdsense } from '../registry/google-adsense'
|
|
6
|
-
import { scriptRuntimeConfig } from '../utils'
|
|
7
|
-
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
|
|
8
|
-
|
|
9
|
-
const props = withDefaults(defineProps<{
|
|
10
|
-
dataAdClient: string
|
|
11
|
-
dataAdSlot: string
|
|
12
|
-
dataAdFormat?: 'auto' | 'rectangle' | 'vertical' | 'horizontal' | 'fluid' | 'autorelaxed'
|
|
13
|
-
dataAdLayout?: 'in-article' | 'in-feed' | 'fixed'
|
|
14
|
-
dataFullWidthResponsive?: boolean
|
|
15
|
-
/**
|
|
16
|
-
* Defines the trigger event to load the script.
|
|
17
|
-
*/
|
|
18
|
-
trigger?: ElementScriptTrigger
|
|
19
|
-
}>(), {
|
|
20
|
-
dataFullWidthResponsive: true,
|
|
21
|
-
dataAdFormat: undefined, // Preserve previous behavior
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const emits = defineEmits<{
|
|
25
|
-
// our emit
|
|
26
|
-
ready: [e: ReturnType<typeof useScriptGoogleAdsense>]
|
|
27
|
-
error: []
|
|
28
|
-
}>()
|
|
29
|
-
|
|
30
|
-
const rootEl = ref(null)
|
|
31
|
-
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
32
|
-
|
|
33
|
-
const scriptConfig = scriptRuntimeConfig('googleAdsense')
|
|
34
|
-
const addClient = computed(() => {
|
|
35
|
-
return props.dataAdClient || scriptConfig?.client
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const instance = useScriptGoogleAdsense({
|
|
39
|
-
client: addClient.value,
|
|
40
|
-
scriptOptions: {
|
|
41
|
-
trigger,
|
|
42
|
-
},
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const { status } = instance
|
|
46
|
-
|
|
47
|
-
function pushAdSlot() {
|
|
48
|
-
(window.adsbygoogle = window.adsbygoogle || []).push({})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
onMounted(() => {
|
|
52
|
-
if (import.meta.dev) {
|
|
53
|
-
callOnce(() => pushAdSlot())
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
pushAdSlot()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
watch(status, (val) => {
|
|
60
|
-
if (val === 'loaded') {
|
|
61
|
-
emits('ready', instance)
|
|
62
|
-
}
|
|
63
|
-
else if (val === 'error') {
|
|
64
|
-
emits('error')
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
const rootAttrs = computed(() => {
|
|
70
|
-
return {
|
|
71
|
-
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
</script>
|
|
75
|
-
|
|
76
|
-
<template>
|
|
77
|
-
<div>
|
|
78
|
-
<ins
|
|
79
|
-
ref="rootEl"
|
|
80
|
-
class="adsbygoogle"
|
|
81
|
-
style="display: block;"
|
|
82
|
-
:data-ad-client="addClient"
|
|
83
|
-
:data-ad-slot="dataAdSlot"
|
|
84
|
-
:data-ad-format="dataAdFormat"
|
|
85
|
-
:data-ad-layout="dataAdLayout"
|
|
86
|
-
:data-full-width-responsive="dataFullWidthResponsive"
|
|
87
|
-
v-bind="rootAttrs"
|
|
88
|
-
/>
|
|
89
|
-
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
90
|
-
<slot v-else-if="status === 'loading'" name="loading" />
|
|
91
|
-
<slot v-else-if="status === 'error'" name="error" />
|
|
92
|
-
</div>
|
|
93
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onMounted, ref, watch } from 'vue'
|
|
3
|
+
import { callOnce } from 'nuxt/app'
|
|
4
|
+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
+
import { useScriptGoogleAdsense } from '../registry/google-adsense'
|
|
6
|
+
import { scriptRuntimeConfig } from '../utils'
|
|
7
|
+
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{
|
|
10
|
+
dataAdClient: string
|
|
11
|
+
dataAdSlot: string
|
|
12
|
+
dataAdFormat?: 'auto' | 'rectangle' | 'vertical' | 'horizontal' | 'fluid' | 'autorelaxed'
|
|
13
|
+
dataAdLayout?: 'in-article' | 'in-feed' | 'fixed'
|
|
14
|
+
dataFullWidthResponsive?: boolean
|
|
15
|
+
/**
|
|
16
|
+
* Defines the trigger event to load the script.
|
|
17
|
+
*/
|
|
18
|
+
trigger?: ElementScriptTrigger
|
|
19
|
+
}>(), {
|
|
20
|
+
dataFullWidthResponsive: true,
|
|
21
|
+
dataAdFormat: undefined, // Preserve previous behavior
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const emits = defineEmits<{
|
|
25
|
+
// our emit
|
|
26
|
+
ready: [e: ReturnType<typeof useScriptGoogleAdsense>]
|
|
27
|
+
error: []
|
|
28
|
+
}>()
|
|
29
|
+
|
|
30
|
+
const rootEl = ref(null)
|
|
31
|
+
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
32
|
+
|
|
33
|
+
const scriptConfig = scriptRuntimeConfig('googleAdsense')
|
|
34
|
+
const addClient = computed(() => {
|
|
35
|
+
return props.dataAdClient || scriptConfig?.client
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const instance = useScriptGoogleAdsense({
|
|
39
|
+
client: addClient.value,
|
|
40
|
+
scriptOptions: {
|
|
41
|
+
trigger,
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const { status } = instance
|
|
46
|
+
|
|
47
|
+
function pushAdSlot() {
|
|
48
|
+
(window.adsbygoogle = window.adsbygoogle || []).push({})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
onMounted(() => {
|
|
52
|
+
if (import.meta.dev) {
|
|
53
|
+
callOnce(() => pushAdSlot())
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
pushAdSlot()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
watch(status, (val) => {
|
|
60
|
+
if (val === 'loaded') {
|
|
61
|
+
emits('ready', instance)
|
|
62
|
+
}
|
|
63
|
+
else if (val === 'error') {
|
|
64
|
+
emits('error')
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const rootAttrs = computed(() => {
|
|
70
|
+
return {
|
|
71
|
+
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<template>
|
|
77
|
+
<div>
|
|
78
|
+
<ins
|
|
79
|
+
ref="rootEl"
|
|
80
|
+
class="adsbygoogle"
|
|
81
|
+
style="display: block;"
|
|
82
|
+
:data-ad-client="addClient"
|
|
83
|
+
:data-ad-slot="dataAdSlot"
|
|
84
|
+
:data-ad-format="dataAdFormat"
|
|
85
|
+
:data-ad-layout="dataAdLayout"
|
|
86
|
+
:data-full-width-responsive="dataFullWidthResponsive"
|
|
87
|
+
v-bind="rootAttrs"
|
|
88
|
+
/>
|
|
89
|
+
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
90
|
+
<slot v-else-if="status === 'loading'" name="loading" />
|
|
91
|
+
<slot v-else-if="status === 'error'" name="error" />
|
|
92
|
+
</div>
|
|
93
|
+
</template>
|