Skip to content

Commit 038d891

Browse files
committed
fix!: rename useElementScriptTrigger, useConsentScriptTrigger, useAnalyticsPageEvent
1 parent 899d228 commit 038d891

22 files changed

+58
-58
lines changed

docs/content/docs/1.getting-started/3.confetti-tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ addConfetti({ emojis: ['🌈', '⚡️', '💥', '✨', '💫', '🌸'] })
168168

169169
You can delay the loading of the script by using the `trigger` option. This can be useful if you want to load the script after a certain event or time.
170170

171-
In this example we'll combine the [useElementScriptTrigger](/docs/api/use-element-script-trigger) composable with the `useScriptNpm` composable to load the script after a certain element is in view.
171+
In this example we'll combine the [useScriptTriggerElement](/docs/api/use-script-trigger-element) composable with the `useScriptNpm` composable to load the script after a certain element is in view.
172172

173173
```vue [app.vue]
174174
<script setup lang="ts">
@@ -178,7 +178,7 @@ const { addConfetti } = useScriptNpm<{ addConfetti: (options?: { emojis: string[
178178
file: 'dist/js-confetti.browser.js',
179179
version: '0.12.0',
180180
scriptOptions: {
181-
trigger: useElementScriptTrigger({ trigger: 'mouseover', el: mouseOverEl })
181+
trigger: useScriptTriggerElement({ trigger: 'mouseover', el: mouseOverEl })
182182
}
183183
})
184184
addConfetti({ emojis: ['🌈', '⚡️', '💥', '✨', '💫', '🌸'] })

docs/content/docs/1.guides/1.script-triggers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ By default, scripts are loaded when Nuxt is fully hydrated. You can change this
4646

4747
## Element Event Triggers
4848

49-
The [useElementScriptTrigger](/docs/api/use-element-script-trigger) composable allows you to hook into element events as a way to load script. This is useful for loading scripts when a user interacts with a specific element.
49+
The [useScriptTriggerElement](/docs/api/use-script-trigger-element) composable allows you to hook into element events as a way to load script. This is useful for loading scripts when a user interacts with a specific element.
5050

5151
```ts
5252
const somethingEl = ref<HTMLElement>()
5353
const { trigger } = useScript({
5454
src: 'https://example.com/script.js',
5555
}, {
56-
trigger: useElementScriptTrigger({
56+
trigger: useScriptTriggerElement({
5757
trigger: 'hover',
5858
somethingEl,
5959
})

docs/content/docs/1.guides/3.consent.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ description: Learn how to get user consent before loading scripts.
55

66
## Background
77

8-
Many third-party scripts include tracking cookies that require user consent under privacy laws. Nuxt Scripts simplifies this process with the [useConsentScriptTrigger](/docs/api/use-consent-script-trigger) composable, allowing scripts to be loaded only after receiving user consent.
8+
Many third-party scripts include tracking cookies that require user consent under privacy laws. Nuxt Scripts simplifies this process with the [useScriptTriggerConsent](/docs/api/use-script-trigger-consent) composable, allowing scripts to be loaded only after receiving user consent.
99

1010
## Usage
1111

12-
The [useConsentScriptTrigger](/docs/api/use-consent-script-trigger) composable offers flexible interaction options suitable for various scenarios.
12+
The [useScriptTriggerConsent](/docs/api/use-script-trigger-consent) composable offers flexible interaction options suitable for various scenarios.
1313

14-
See the [API](/docs/api/use-consent-script-trigger) docs for full details on the available options.
14+
See the [API](/docs/api/use-script-trigger-consent) docs for full details on the available options.
1515

1616
### Accepting as a Function
1717

18-
The easiest way to make use of `useConsentScriptTrigger` is by invoking the `accept` method when user consent is granted.
18+
The easiest way to make use of `useScriptTriggerConsent` is by invoking the `accept` method when user consent is granted.
1919

2020
For an example of how you might lay out your code to handle this, see the following:
2121

2222
::code-group
2323

2424
```ts [utils/cookie.ts]
25-
export const agreedToCookiesScriptConsent = useConsentScriptTrigger()
25+
export const agreedToCookiesScriptConsent = useScriptTriggerConsent()
2626
```
2727

2828
```vue [app.vue]
@@ -51,12 +51,12 @@ import { agreedToCookiesScriptConsent } from '#imports'
5151

5252
### Accepting as a resolvable boolean
5353

54-
Alternatively, you can pass a reactive reference to the consent state to the `useConsentScriptTrigger` composable. This will automatically load the script when the consent state is `true`.
54+
Alternatively, you can pass a reactive reference to the consent state to the `useScriptTriggerConsent` composable. This will automatically load the script when the consent state is `true`.
5555

5656
```ts
5757
const agreedToCookies = ref(false)
5858
useScript('https://www.google-analytics.com/analytics.js', {
59-
trigger: useConsentScriptTrigger({
59+
trigger: useScriptTriggerConsent({
6060
consent: agreedToCookies
6161
})
6262
})
@@ -71,7 +71,7 @@ For this you can use the `postConsentTrigger`, which shares the same API as `tri
7171
```ts
7272
const agreedToCookies = ref(false)
7373
useScript('https://www.google-analytics.com/analytics.js', {
74-
trigger: useConsentScriptTrigger({
74+
trigger: useScriptTriggerConsent({
7575
consent: agreedToCookies,
7676
// load 3 seconds after consent is granted
7777
postConsentTrigger: new Promise<void>(resolve => setTimeout(resolve, 3000))

docs/content/docs/1.guides/3.page-events.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ description: Learn how to send page events to your analytics provider.
88
When using tracking scripts, it's common to send an event when the page changes. Due to Nuxt's head implementation being
99
async, the page title is not always available on route change immediately.
1010

11-
Nuxt Scripts provides the [useAnalyticsPageEvent](/docs/api/use-analytics-page-event) composable to solve this problem.
11+
Nuxt Scripts provides the [useScriptEventPage](/docs/api/use-script-event-page) composable to solve this problem.
1212

13-
See the [API](/docs/api/use-analytics-page-event) docs for full details on the available options.
13+
See the [API](/docs/api/use-script-event-page) docs for full details on the available options.
1414

1515
### Usage
1616

@@ -22,7 +22,7 @@ You can use this with any analytics provider where you're seeing the page title
2222
```ts
2323
const { gtag } = useScriptGoogleAnalytics()
2424

25-
useAnalyticsPageEvent(({ title, path }) => {
25+
useScriptEventPage(({ title, path }) => {
2626
// triggered on route change
2727
gtag('event', 'page_view', {
2828
page_title: title,

docs/content/docs/3.api/3.use-consent-script-trigger.md renamed to docs/content/docs/3.api/3.use-script-trigger-consent.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: useConsentScriptTrigger
3-
description: API documentation for the useConsentScriptTrigger function.
2+
title: useScriptTriggerConsent
3+
description: API documentation for the useScriptTriggerConsent function.
44
links:
55
- label: Source
66
icon: i-simple-icons-github
7-
to: https://github.com/nuxt/scripts/blob/main/src/runtime/composables/useConsentScriptTrigger.ts
7+
to: https://github.com/nuxt/scripts/blob/main/src/runtime/composables/useScriptTriggerConsent.ts
88
size: xs
99
---
1010

@@ -13,7 +13,7 @@ Load a script once consent has been provided either through a resolvable `consen
1313
## Signature
1414

1515
```ts
16-
function useConsentScriptTrigger(options?: ConsentScriptTriggerOptions): UseConsentScriptTriggerApi {}
16+
function useScriptTriggerConsent(options?: ConsentScriptTriggerOptions): UseConsentScriptTriggerApi {}
1717
```
1818

1919
## Arguments
@@ -50,7 +50,7 @@ interface UseConsentScriptTriggerApi extends Promise<void> {
5050

5151
```vue [app.vue]
5252
<script setup lang="ts">
53-
const trigger = useConsentScriptTrigger()
53+
const trigger = useScriptTriggerConsent()
5454
useScript('https://example.com/script.js', { trigger })
5555
</script>
5656

docs/content/docs/3.api/3.use-element-script-trigger.md renamed to docs/content/docs/3.api/3.use-script-trigger-element.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: useElementScriptTrigger
3-
description: API documentation for the useElementScriptTrigger function.
2+
title: useScriptTriggerElement
3+
description: API documentation for the useScriptTriggerElement function.
44
links:
55
- label: Source
66
icon: i-simple-icons-github
7-
to: https://github.com/nuxt/scripts/blob/main/src/runtime/composables/useElementScriptTrigger.ts
7+
to: https://github.com/nuxt/scripts/blob/main/src/runtime/composables/useScriptTriggerElement.ts
88
size: xs
99
---
1010

@@ -13,7 +13,7 @@ Create a trigger for an element to load a script based on specific element event
1313
## Signature
1414

1515
```ts
16-
function useElementScriptTrigger(options: ElementScriptTriggerOptions): Promise<void> {}
16+
function useScriptTriggerElement(options: ElementScriptTriggerOptions): Promise<void> {}
1717
```
1818

1919
## Arguments
@@ -44,7 +44,7 @@ A promise that resolves when the script is loaded.
4444
<script setup lang="ts">
4545
const el = ref<HTMLElement>()
4646
useScript('/script.js', {
47-
trigger: useElementScriptTrigger({
47+
trigger: useScriptTriggerElement({
4848
trigger: 'visible',
4949
el,
5050
})
@@ -67,7 +67,7 @@ useScript('/script.js', {
6767
<script setup lang="ts">
6868
const el = ref<HTMLElement>()
6969
useScript('/script.js', {
70-
trigger: useElementScriptTrigger({
70+
trigger: useScriptTriggerElement({
7171
trigger: 'hover',
7272
el,
7373
})

docs/content/docs/3.api/4.use-analytics-page-event.md renamed to docs/content/docs/3.api/4.use-script-event-page.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: useAnalyticsPageEvent
3-
description: API documentation for the useAnalyticsPageEvent function.
2+
title: useScriptEventPage
3+
description: API documentation for the useScriptEventPage function.
44
links:
55
- label: Source
66
icon: i-simple-icons-github
7-
to: https://github.com/nuxt/scripts/blob/main/src/runtime/composables/useAnalyticsPageEvent.ts
7+
to: https://github.com/nuxt/scripts/blob/main/src/runtime/composables/useScriptEventPage.ts
88
size: xs
99
---
1010

@@ -13,7 +13,7 @@ Access the current page title and path and trigger an event when they change.
1313
## Signature
1414

1515
```ts
16-
function useAnalyticsPageEvent(callback?: (title: string, path: string) => void): Ref<{ title: string, path: string }> {}
16+
function useScriptEventPage(callback?: (title: string, path: string) => void): Ref<{ title: string, path: string }> {}
1717
```
1818

1919
#### Arguments
@@ -30,7 +30,7 @@ A ref containing the current page title and path.
3030

3131
```vue
3232
<script setup lang="ts">
33-
useAnalyticsPageEvent((ctx) => {
33+
useScriptEventPage((ctx) => {
3434
console.log(ctx.title, ctx.path)
3535
})
3636
</script>

playground/pages/npm/js-confetti.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script lang="ts" setup>
2-
import { ref, useElementScriptTrigger, useScriptNpm } from '#imports'
2+
import { ref, useScriptTriggerElement, useScriptNpm } from '#imports'
33
44
const mouseOverEl = ref()
55
const { addConfetti } = useScriptNpm<JSConfettiApi>({
66
packageName: 'js-confetti',
77
file: 'dist/js-confetti.browser.js',
88
version: '0.12.0',
99
scriptOptions: {
10-
trigger: useElementScriptTrigger({ trigger: 'mouseover', el: mouseOverEl }),
10+
trigger: useScriptTriggerElement({ trigger: 'mouseover', el: mouseOverEl }),
1111
bundle: true,
1212
use() {
1313
return typeof window.JSConfetti !== 'undefined' && new window.JSConfetti()

src/runtime/components/ScriptCarbonAds.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { withQuery } from 'ufo'
3-
import { onBeforeUnmount, onMounted, ref, useElementScriptTrigger } from '#imports'
3+
import { onBeforeUnmount, onMounted, ref, useScriptTriggerElement } from '#imports'
44
import type { ElementScriptTrigger } from '#nuxt-scripts'
55
66
const props = defineProps<{
@@ -50,7 +50,7 @@ onMounted(() => {
5050
loadCarbon()
5151
}
5252
else {
53-
useElementScriptTrigger({ trigger: props.trigger, el: carbonadsEl })
53+
useScriptTriggerElement({ trigger: props.trigger, el: carbonadsEl })
5454
}
5555
})
5656

src/runtime/components/ScriptCrisp.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { useElementScriptTrigger } from '../composables/useElementScriptTrigger'
2+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
33
import { useScriptCrisp } from '../registry/crisp'
44
import { ref, onMounted, onBeforeUnmount, watch } from '#imports'
55
import type { ElementScriptTrigger } from '#nuxt-scripts'
@@ -27,7 +27,7 @@ const emits = defineEmits<{
2727
}>()
2828
2929
const rootEl = ref(null)
30-
const trigger = useElementScriptTrigger({ trigger: props.trigger, el: rootEl })
30+
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
3131
3232
const isReady = ref(false)
3333
const crisp = useScriptCrisp({

0 commit comments

Comments
 (0)