@nuxt/scripts 0.1.3 → 0.1.4

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.
Files changed (38) hide show
  1. package/README.md +24 -23
  2. package/dist/client/200.html +5 -5
  3. package/dist/client/404.html +5 -5
  4. package/dist/client/_nuxt/{B7gLnlpM.js → B3yRAOXz.js} +1 -1
  5. package/dist/client/_nuxt/{CXVVb7oJ.js → BqAhYH0E.js} +10 -10
  6. package/dist/client/_nuxt/{Bw1vr1xi.js → C2uur0MR.js} +1 -1
  7. package/dist/client/_nuxt/{DnntiO6I.js → CO8u40Ut.js} +1 -1
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/4e9eefe2-f4a5-46ff-889b-aa701f38d2cd.json +1 -0
  10. package/dist/client/index.html +5 -5
  11. package/dist/module.d.mts +4 -0
  12. package/dist/module.d.ts +4 -0
  13. package/dist/module.json +1 -1
  14. package/dist/module.mjs +4 -1
  15. package/dist/runtime/composables/useScript.mjs +5 -1
  16. package/dist/runtime/registry/cloudflare-turnstile.d.ts +1 -0
  17. package/dist/runtime/registry/cloudflare-turnstile.mjs +3 -0
  18. package/dist/runtime/registry/cloudflare-web-analytics.d.ts +34 -0
  19. package/dist/runtime/registry/cloudflare-web-analytics.mjs +37 -0
  20. package/dist/runtime/registry/confetti.d.ts +14 -0
  21. package/dist/runtime/registry/confetti.mjs +12 -0
  22. package/dist/runtime/registry/facebook-pixel.d.ts +42 -0
  23. package/dist/runtime/registry/facebook-pixel.mjs +37 -0
  24. package/dist/runtime/registry/fathom-analytics.d.ts +33 -0
  25. package/dist/runtime/registry/fathom-analytics.mjs +28 -0
  26. package/dist/runtime/registry/google-analytics.d.ts +1 -0
  27. package/dist/runtime/registry/google-analytics.mjs +3 -0
  28. package/dist/runtime/registry/google-tag-manager.d.ts +1 -0
  29. package/dist/runtime/registry/google-tag-manager.mjs +3 -0
  30. package/dist/runtime/registry/hotjar.d.ts +24 -0
  31. package/dist/runtime/registry/hotjar.mjs +32 -0
  32. package/dist/runtime/registry/intercom.d.ts +31 -0
  33. package/dist/runtime/registry/intercom.mjs +34 -0
  34. package/dist/runtime/registry/segment.d.ts +25 -0
  35. package/dist/runtime/registry/segment.mjs +44 -0
  36. package/dist/runtime/types.d.ts +4 -0
  37. package/package.json +10 -8
  38. package/dist/client/_nuxt/builds/meta/dfbad358-c258-488d-9323-84d07e1f8acf.json +0 -1
@@ -1 +1 @@
1
- import{_ as i,u as a}from"./B7gLnlpM.js";import{o as r,c as n,a as e,t as s,p as l,e as d}from"./CXVVb7oJ.js";const c=t=>(l("data-v-c967d9a9"),t=t(),d(),t),p={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},h=c(()=>e("div",{class:"fixed -bottom-1/2 left-0 right-0 h-1/2 spotlight"},null,-1)),f={class:"max-w-520px text-center"},m=["textContent"],g=["textContent"],x={__name:"error-500",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:500},statusMessage:{type:String,default:"Server error"},description:{type:String,default:"This page is temporarily unavailable."}},setup(t){const o=t;return a({title:`${o.statusCode} - ${o.statusMessage} | ${o.appName}`,script:[],style:[{children:'*,:before,:after{-webkit-box-sizing:border-box;box-sizing:border-box;border-width:0;border-style:solid;border-color:#e0e0e0}*{--tw-ring-inset:var(--tw-empty, );--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(14, 165, 233, .5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000}:root{-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{margin:0;font-family:inherit;line-height:inherit}html{-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";line-height:1.5}h1,p{margin:0}h1{font-size:inherit;font-weight:inherit}'}]}),(b,u)=>(r(),n("div",p,[h,e("div",f,[e("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:s(t.statusCode)},null,8,m),e("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:s(t.description)},null,8,g)])]))}},y=i(x,[["__scopeId","data-v-c967d9a9"]]);export{y as default};
1
+ import{_ as i,u as a}from"./B3yRAOXz.js";import{o as r,c as n,a as e,t as s,p as l,e as d}from"./BqAhYH0E.js";const c=t=>(l("data-v-c967d9a9"),t=t(),d(),t),p={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},h=c(()=>e("div",{class:"fixed -bottom-1/2 left-0 right-0 h-1/2 spotlight"},null,-1)),f={class:"max-w-520px text-center"},m=["textContent"],g=["textContent"],x={__name:"error-500",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:500},statusMessage:{type:String,default:"Server error"},description:{type:String,default:"This page is temporarily unavailable."}},setup(t){const o=t;return a({title:`${o.statusCode} - ${o.statusMessage} | ${o.appName}`,script:[],style:[{children:'*,:before,:after{-webkit-box-sizing:border-box;box-sizing:border-box;border-width:0;border-style:solid;border-color:#e0e0e0}*{--tw-ring-inset:var(--tw-empty, );--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(14, 165, 233, .5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000}:root{-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{margin:0;font-family:inherit;line-height:inherit}html{-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";line-height:1.5}h1,p{margin:0}h1{font-size:inherit;font-weight:inherit}'}]}),(b,u)=>(r(),n("div",p,[h,e("div",f,[e("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:s(t.statusCode)},null,8,m),e("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:s(t.description)},null,8,g)])]))}},y=i(x,[["__scopeId","data-v-c967d9a9"]]);export{y as default};
@@ -1 +1 @@
1
- import{o as a,c as n,a as e,t as s,b as r,w as l,d,_ as c,p,e as m}from"./CXVVb7oJ.js";import{_ as f,u as h}from"./B7gLnlpM.js";const x=t=>(p("data-v-05a2b8a3"),t=t(),m(),t),u={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},g=x(()=>e("div",{class:"fixed left-0 right-0 spotlight z-10"},null,-1)),b={class:"max-w-520px text-center z-20"},_=["textContent"],w=["textContent"],y={class:"w-full flex items-center justify-center"},S={__name:"error-404",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:404},statusMessage:{type:String,default:"Not Found"},description:{type:String,default:"Sorry, the page you are looking for could not be found."},backHome:{type:String,default:"Go back home"}},setup(t){const o=t;return h({title:`${o.statusCode} - ${o.statusMessage} | ${o.appName}`,script:[],style:[{children:'*,:before,:after{-webkit-box-sizing:border-box;box-sizing:border-box;border-width:0;border-style:solid;border-color:#e0e0e0}*{--tw-ring-inset:var(--tw-empty, );--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(14, 165, 233, .5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000}:root{-moz-tab-size:4;-o-tab-size:4;tab-size:4}a{color:inherit;text-decoration:inherit}body{margin:0;font-family:inherit;line-height:inherit}html{-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";line-height:1.5}h1,p{margin:0}h1{font-size:inherit;font-weight:inherit}'}]}),(k,N)=>{const i=c;return a(),n("div",u,[g,e("div",b,[e("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:s(t.statusCode)},null,8,_),e("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:s(t.description)},null,8,w),e("div",y,[r(i,{to:"/",class:"gradient-border text-md sm:text-xl py-2 px-4 sm:py-3 sm:px-6 cursor-pointer"},{default:l(()=>[d(s(t.backHome),1)]),_:1})])])])}}},C=f(S,[["__scopeId","data-v-05a2b8a3"]]);export{C as default};
1
+ import{o as a,c as n,a as e,t as s,b as r,w as l,d,_ as c,p,e as m}from"./BqAhYH0E.js";import{_ as f,u as h}from"./B3yRAOXz.js";const x=t=>(p("data-v-05a2b8a3"),t=t(),m(),t),u={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},g=x(()=>e("div",{class:"fixed left-0 right-0 spotlight z-10"},null,-1)),b={class:"max-w-520px text-center z-20"},_=["textContent"],w=["textContent"],y={class:"w-full flex items-center justify-center"},S={__name:"error-404",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:404},statusMessage:{type:String,default:"Not Found"},description:{type:String,default:"Sorry, the page you are looking for could not be found."},backHome:{type:String,default:"Go back home"}},setup(t){const o=t;return h({title:`${o.statusCode} - ${o.statusMessage} | ${o.appName}`,script:[],style:[{children:'*,:before,:after{-webkit-box-sizing:border-box;box-sizing:border-box;border-width:0;border-style:solid;border-color:#e0e0e0}*{--tw-ring-inset:var(--tw-empty, );--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(14, 165, 233, .5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000}:root{-moz-tab-size:4;-o-tab-size:4;tab-size:4}a{color:inherit;text-decoration:inherit}body{margin:0;font-family:inherit;line-height:inherit}html{-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";line-height:1.5}h1,p{margin:0}h1{font-size:inherit;font-weight:inherit}'}]}),(k,N)=>{const i=c;return a(),n("div",u,[g,e("div",b,[e("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:s(t.statusCode)},null,8,_),e("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:s(t.description)},null,8,w),e("div",y,[r(i,{to:"/",class:"gradient-border text-md sm:text-xl py-2 px-4 sm:py-3 sm:px-6 cursor-pointer"},{default:l(()=>[d(s(t.backHome),1)]),_:1})])])])}}},C=f(S,[["__scopeId","data-v-05a2b8a3"]]);export{C as default};
@@ -1 +1 @@
1
- {"id":"dfbad358-c258-488d-9323-84d07e1f8acf","timestamp":1711553364503}
1
+ {"id":"4e9eefe2-f4a5-46ff-889b-aa701f38d2cd","timestamp":1711697722263}
@@ -0,0 +1 @@
1
+ {"id":"4e9eefe2-f4a5-46ff-889b-aa701f38d2cd","timestamp":1711697722263,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html><html><head><meta charset="utf-8">
2
2
  <meta name="viewport" content="width=device-width, initial-scale=1">
3
3
  <link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.D91GVkD7.css">
4
- <link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/CXVVb7oJ.js">
4
+ <link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/BqAhYH0E.js">
5
5
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DXFkqnOI.js">
6
6
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/D6NljDpC.js">
7
7
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/CowR2XfX.js">
@@ -229,10 +229,10 @@
229
229
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DggdVF2v.js">
230
230
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/A1WiD9SJ.js">
231
231
  <link rel="prefetch" as="style" href="/__nuxt-scripts/_nuxt/error-404.ORekjfyJ.css">
232
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DnntiO6I.js">
233
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/B7gLnlpM.js">
232
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/CO8u40Ut.js">
233
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/B3yRAOXz.js">
234
234
  <link rel="prefetch" as="style" href="/__nuxt-scripts/_nuxt/error-500.BIuFL0tW.css">
235
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/Bw1vr1xi.js">
236
- <script type="module" src="/__nuxt-scripts/_nuxt/CXVVb7oJ.js" crossorigin></script><script>"use strict";(()=>{const a=window,e=document.documentElement,c=window.localStorage,d=["dark","light"],n=c&&c.getItem&&c.getItem("nuxt-color-mode")||"system";let l=n==="system"?f():n;const i=e.getAttribute("data-color-mode-forced");i&&(l=i),r(l),a["__NUXT_COLOR_MODE__"]={preference:n,value:l,getColorScheme:f,addColorScheme:r,removeColorScheme:u};function r(o){const t=""+o+"",s="";e.classList?e.classList.add(t):e.className+=" "+t,s&&e.setAttribute("data-"+s,o)}function u(o){const t=""+o+"",s="";e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp(t,"g"),""),s&&e.removeAttribute("data-"+s)}function m(o){return a.matchMedia("(prefers-color-scheme"+o+")")}function f(){if(a.matchMedia&&m("").media!=="not all"){for(const o of d)if(m(":"+o).matches)return o}return"light"}})();
235
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/C2uur0MR.js">
236
+ <script type="module" src="/__nuxt-scripts/_nuxt/BqAhYH0E.js" crossorigin></script><script>"use strict";(()=>{const a=window,e=document.documentElement,c=window.localStorage,d=["dark","light"],n=c&&c.getItem&&c.getItem("nuxt-color-mode")||"system";let l=n==="system"?f():n;const i=e.getAttribute("data-color-mode-forced");i&&(l=i),r(l),a["__NUXT_COLOR_MODE__"]={preference:n,value:l,getColorScheme:f,addColorScheme:r,removeColorScheme:u};function r(o){const t=""+o+"",s="";e.classList?e.classList.add(t):e.className+=" "+t,s&&e.setAttribute("data-"+s,o)}function u(o){const t=""+o+"",s="";e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp(t,"g"),""),s&&e.removeAttribute("data-"+s)}function m(o){return a.matchMedia("(prefers-color-scheme"+o+")")}function f(){if(a.matchMedia&&m("").media!=="not all"){for(const o of d)if(m(":"+o).matches)return o}return"light"}})();
237
237
  </script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"_errors":1,"serverRendered":2,"data":3,"state":4,"once":5},{},false,{},{},["Set"]]</script>
238
238
  <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-scripts",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.d.mts CHANGED
@@ -16,6 +16,10 @@ type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
16
16
  * improves privacy by not sharing the user's IP address with third-party servers.
17
17
  */
18
18
  assetStrategy?: 'bundle';
19
+ /**
20
+ * A hook to run when a script does not exist and will be initialized for the first time.
21
+ */
22
+ beforeInit?: () => void;
19
23
  };
20
24
  type NuxtUseScriptInput = UseScriptInput;
21
25
 
package/dist/module.d.ts CHANGED
@@ -16,6 +16,10 @@ type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
16
16
  * improves privacy by not sharing the user's IP address with third-party servers.
17
17
  */
18
18
  assetStrategy?: 'bundle';
19
+ /**
20
+ * A hook to run when a script does not exist and will be initialized for the first time.
21
+ */
22
+ beforeInit?: () => void;
19
23
  };
20
24
  type NuxtUseScriptInput = UseScriptInput;
21
25
 
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.11.1",
6
6
  "bridge": false
7
7
  },
8
- "version": "0.1.3"
8
+ "version": "0.1.4"
9
9
  }
package/dist/module.mjs CHANGED
@@ -252,7 +252,10 @@ const module = defineNuxtModule({
252
252
  }
253
253
  nuxt.options.alias["#nuxt-scripts"] = resolve("./runtime/types");
254
254
  nuxt.options.runtimeConfig["nuxt-scripts"] = { version };
255
- addImportsDir(resolve("./runtime/composables"));
255
+ addImportsDir([
256
+ resolve("./runtime/composables"),
257
+ resolve("./runtime/registry")
258
+ ]);
256
259
  if (config.globals?.length) {
257
260
  const template = addTemplate({
258
261
  filename: "modules/nuxt-scripts/plugin.client.mjs",
@@ -1,11 +1,15 @@
1
1
  import { useScript as _useScript, injectHead } from "@unhead/vue";
2
+ import { hashCode } from "@unhead/shared";
2
3
  import { onNuxtReady, useNuxtApp } from "#imports";
3
4
  export function useScript(input, options) {
4
5
  input = typeof input === "string" ? { src: input } : input;
5
6
  options = options || {};
6
7
  if (options.trigger === "onNuxtReady")
7
- options.trigger = onNuxtReady;
8
+ options.trigger = new Promise((resolve) => onNuxtReady(resolve));
8
9
  const nuxtApp = useNuxtApp();
10
+ const id = input.key || hashCode(input.src || (typeof input.innerHTML === "string" ? input.innerHTML : ""));
11
+ if (import.meta.dev && !nuxtApp.scripts?.[id])
12
+ options.beforeInit?.();
9
13
  const instance = _useScript(input, options);
10
14
  if (import.meta.dev && import.meta.client) {
11
15
  let syncScripts = function() {
@@ -0,0 +1 @@
1
+ export declare function useScriptCloudflareTurnstile(): void;
@@ -0,0 +1,3 @@
1
+ export function useScriptCloudflareTurnstile() {
2
+ throw new Error("Failed to load Cloudflare Turnstile script. Make sure you have @nuxtjs/turnstile installed and configured.");
3
+ }
@@ -0,0 +1,34 @@
1
+ import { type Input } from 'valibot';
2
+ import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
+ export interface CloudflareWebAnalyticsApi {
4
+ __cfBeacon: {
5
+ load: 'single';
6
+ spa: boolean;
7
+ token: string;
8
+ };
9
+ __cfRl?: unknown;
10
+ }
11
+ declare global {
12
+ interface Window extends CloudflareWebAnalyticsApi {
13
+ }
14
+ }
15
+ declare const CloudflareWebAnalyticsOptions: import("valibot").ObjectSchema<{
16
+ /**
17
+ * The Cloudflare Web Analytics token.
18
+ *
19
+ * Required when used for the first time.
20
+ */
21
+ token: import("valibot").StringSchema<string>;
22
+ /**
23
+ * Cloudflare Web Analytics enables measuring SPAs automatically by overriding the History API’s pushState function
24
+ * and listening to the onpopstate. Hash-based router is not supported.
25
+ *
26
+ * @default true
27
+ */
28
+ spa: import("valibot").OptionalSchema<import("valibot").BooleanSchema<boolean>, undefined, boolean | undefined>;
29
+ }, undefined, {
30
+ token: string;
31
+ spa?: boolean | undefined;
32
+ }>;
33
+ export declare function useScriptCloudflareWebAnalytics<T extends CloudflareWebAnalyticsApi>(options?: Input<typeof CloudflareWebAnalyticsOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
34
+ export {};
@@ -0,0 +1,37 @@
1
+ import { boolean, minLength, object, optional, parse, string } from "valibot";
2
+ import { defu } from "defu";
3
+ import { useScript } from "#imports";
4
+ const CloudflareWebAnalyticsOptions = object({
5
+ /**
6
+ * The Cloudflare Web Analytics token.
7
+ *
8
+ * Required when used for the first time.
9
+ */
10
+ token: string([minLength(33)]),
11
+ /**
12
+ * Cloudflare Web Analytics enables measuring SPAs automatically by overriding the History API’s pushState function
13
+ * and listening to the onpopstate. Hash-based router is not supported.
14
+ *
15
+ * @default true
16
+ */
17
+ spa: optional(boolean())
18
+ });
19
+ export function useScriptCloudflareWebAnalytics(options, _scriptOptions) {
20
+ const scriptOptions = _scriptOptions || {};
21
+ if (import.meta.dev) {
22
+ scriptOptions.beforeInit = () => {
23
+ parse(CloudflareWebAnalyticsOptions, options);
24
+ };
25
+ }
26
+ return useScript({
27
+ "src": "https://static.cloudflareinsights.com/beacon.min.js",
28
+ "data-cf-beacon": JSON.stringify(defu(options, { spa: true }))
29
+ }, {
30
+ trigger: "onNuxtReady",
31
+ ...scriptOptions,
32
+ assetStrategy: "bundle",
33
+ use() {
34
+ return { __cfBeacon: window.__cfBeacon, __cfRl: window.__cfRl };
35
+ }
36
+ });
37
+ }
@@ -0,0 +1,14 @@
1
+ import type { NuxtUseScriptOptions } from '#nuxt-scripts';
2
+ export interface JSConfettiApi {
3
+ addConfetti: (options?: {
4
+ emojis: string[];
5
+ }) => void;
6
+ }
7
+ declare global {
8
+ interface Window {
9
+ JSConfetti: {
10
+ new (): JSConfettiApi;
11
+ };
12
+ }
13
+ }
14
+ export declare function useScriptConfetti<T extends JSConfettiApi>(options?: NuxtUseScriptOptions<T>): any;
@@ -0,0 +1,12 @@
1
+ import { useScript } from "#imports";
2
+ export function useScriptConfetti(options = {}) {
3
+ return useScript({
4
+ src: "https://cdn.jsdelivr.net/npm/js-confetti@latest/dist/js-confetti.browser.js"
5
+ }, {
6
+ ...options,
7
+ assetStrategy: "bundle",
8
+ use() {
9
+ return new window.JSConfetti();
10
+ }
11
+ });
12
+ }
@@ -0,0 +1,42 @@
1
+ import { type Input } from 'valibot';
2
+ import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
+ type StandardEvents = 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent';
4
+ interface EventObjectProperties {
5
+ content_category?: string;
6
+ content_ids?: string[];
7
+ content_name?: string;
8
+ content_type?: string;
9
+ contents: {
10
+ id: string;
11
+ quantity: number;
12
+ }[];
13
+ currency?: string;
14
+ delivery_category?: 'in_store' | 'curbside' | 'home_delivery';
15
+ num_items?: number;
16
+ predicted_ltv?: number;
17
+ search_string?: string;
18
+ status?: 'completed' | 'updated' | 'viewed' | 'added_to_cart' | 'removed_from_cart' | string;
19
+ value?: number;
20
+ [key: string]: any;
21
+ }
22
+ type FbqFns = ((event: 'track', eventName: StandardEvents, data?: EventObjectProperties) => void) & ((event: 'trackCustom', eventName: string, data?: EventObjectProperties) => void) & ((event: 'init', id: number, data?: Record<string, any>) => void) & ((event: 'init', id: string) => void) & ((event: string, ...params: any[]) => void);
23
+ export interface FacebookPixelApi {
24
+ fbq: FbqFns & {
25
+ push: FbqFns;
26
+ loaded: boolean;
27
+ version: string;
28
+ queue: any[];
29
+ };
30
+ _fbq: FacebookPixelApi['fbq'];
31
+ }
32
+ declare global {
33
+ interface Window extends FacebookPixelApi {
34
+ }
35
+ }
36
+ declare const FacebookPixelOptions: import("valibot").ObjectSchema<{
37
+ id: import("valibot").UnionSchema<(import("valibot").StringSchema<string> | import("valibot").NumberSchema<number>)[], string | number>;
38
+ }, undefined, {
39
+ id: string | number;
40
+ }>;
41
+ export declare function useScriptFacebookPixel<T extends FacebookPixelApi>(options?: Input<typeof FacebookPixelOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
42
+ export {};
@@ -0,0 +1,37 @@
1
+ import { number, object, parse, string, union } from "valibot";
2
+ import { useScript } from "#imports";
3
+ const FacebookPixelOptions = object({
4
+ id: union([string(), number()])
5
+ });
6
+ export function useScriptFacebookPixel(options, _scriptOptions) {
7
+ const scriptOptions = _scriptOptions || {};
8
+ scriptOptions.beforeInit = () => {
9
+ if (import.meta.dev)
10
+ parse(FacebookPixelOptions, options);
11
+ if (import.meta.client) {
12
+ const fbq = window.fbq = function(...params) {
13
+ fbq.callMethod ? fbq.callMethod.apply(fbq, params) : fbq.queue.push(params);
14
+ };
15
+ if (!window._fbq)
16
+ window._fbq = fbq;
17
+ fbq.push = fbq;
18
+ fbq.loaded = true;
19
+ fbq.version = "2.0";
20
+ fbq.queue = [];
21
+ fbq("init", options?.id);
22
+ fbq("track", "PageView");
23
+ }
24
+ };
25
+ return useScript({
26
+ key: "facebook-pixel",
27
+ src: "https://connect.facebook.net/en_US/fbevents.js",
28
+ defer: true
29
+ }, {
30
+ trigger: "onNuxtReady",
31
+ ...scriptOptions,
32
+ assetStrategy: "bundle",
33
+ use() {
34
+ return { fbq: window.fbq };
35
+ }
36
+ });
37
+ }
@@ -0,0 +1,33 @@
1
+ import { type Input } from 'valibot';
2
+ import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
+ declare const FathomAnalyticsOptions: import("valibot").ObjectSchema<{
4
+ site: import("valibot").StringSchema<string>;
5
+ src: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
6
+ 'data-spa': import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"auto", "auto"> | import("valibot").LiteralSchema<"history", "history"> | import("valibot").LiteralSchema<"hash", "hash">)[], "auto" | "history" | "hash">, undefined, "auto" | "history" | "hash" | undefined>;
7
+ 'data-auto': import("valibot").OptionalSchema<import("valibot").BooleanSchema<boolean>, undefined, boolean | undefined>;
8
+ 'data-canonical': import("valibot").OptionalSchema<import("valibot").BooleanSchema<boolean>, undefined, boolean | undefined>;
9
+ 'data-honor-dnt': import("valibot").OptionalSchema<import("valibot").BooleanSchema<boolean>, undefined, boolean | undefined>;
10
+ }, undefined, {
11
+ site: string;
12
+ src?: string | undefined;
13
+ 'data-spa'?: "auto" | "history" | "hash" | undefined;
14
+ 'data-auto'?: boolean | undefined;
15
+ 'data-canonical'?: boolean | undefined;
16
+ 'data-honor-dnt'?: boolean | undefined;
17
+ }>;
18
+ export interface FathomAnalyticsApi {
19
+ trackPageview: (ctx?: {
20
+ url: string;
21
+ referrer?: string;
22
+ }) => void;
23
+ trackEvent: (eventName: string, value: {
24
+ _value: number;
25
+ }) => void;
26
+ }
27
+ declare global {
28
+ interface Window {
29
+ fathom: FathomAnalyticsApi;
30
+ }
31
+ }
32
+ export declare function useScriptFathomAnalytics<T extends FathomAnalyticsApi>(options?: Input<typeof FathomAnalyticsOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
33
+ export {};
@@ -0,0 +1,28 @@
1
+ import { boolean, literal, object, optional, parse, string, union } from "valibot";
2
+ import { useScript } from "#imports";
3
+ const FathomAnalyticsOptions = object({
4
+ "site": string(),
5
+ // site is required
6
+ "src": optional(string()),
7
+ "data-spa": optional(union([literal("auto"), literal("history"), literal("hash")])),
8
+ "data-auto": optional(boolean()),
9
+ "data-canonical": optional(boolean()),
10
+ "data-honor-dnt": optional(boolean())
11
+ });
12
+ export function useScriptFathomAnalytics(options, _scriptOptions) {
13
+ const scriptOptions = _scriptOptions || {};
14
+ if (import.meta.dev) {
15
+ scriptOptions.beforeInit = () => {
16
+ parse(FathomAnalyticsOptions, options);
17
+ };
18
+ }
19
+ return useScript({
20
+ src: "https://cdn.usefathom.com/script.js",
21
+ defer: true,
22
+ ...options
23
+ }, {
24
+ ...scriptOptions,
25
+ assetStrategy: "bundle",
26
+ use: () => window.fathom
27
+ });
28
+ }
@@ -0,0 +1 @@
1
+ export declare function useScriptGoogleAnalytics(): void;
@@ -0,0 +1,3 @@
1
+ export function useScriptGoogleAnalytics() {
2
+ throw new Error("Failed to load Google Analytics script. Make sure you have @nuxtjs/third-party-capital installed and configured.");
3
+ }
@@ -0,0 +1 @@
1
+ export declare function useScriptGoogleTagManager(): void;
@@ -0,0 +1,3 @@
1
+ export function useScriptGoogleTagManager() {
2
+ throw new Error("Failed to load Google Tag Manager script. Make sure you have @nuxtjs/third-party-capital installed and configured.");
3
+ }
@@ -0,0 +1,24 @@
1
+ import { type Input } from 'valibot';
2
+ import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
+ export interface HotjarApi {
4
+ hj: ((event: 'identify', userId: string, attributes?: Record<string, any>) => void) & ((event: 'stateChange', path: string) => void) & ((event: 'event', eventName: string) => void) & ((event: string, arg?: string) => void) & ((...params: any[]) => void) & {
5
+ q: any[];
6
+ };
7
+ }
8
+ declare global {
9
+ interface Window extends HotjarApi {
10
+ _hjSettings: {
11
+ hjid: number;
12
+ hjsv?: number;
13
+ };
14
+ }
15
+ }
16
+ declare const HotjarOptions: import("valibot").ObjectSchema<{
17
+ id: import("valibot").NumberSchema<number>;
18
+ sv: import("valibot").OptionalSchema<import("valibot").NumberSchema<number>, undefined, number | undefined>;
19
+ }, undefined, {
20
+ id: number;
21
+ sv?: number | undefined;
22
+ }>;
23
+ export declare function useScriptHotjar<T extends HotjarApi>(options?: Input<typeof HotjarOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
24
+ export {};
@@ -0,0 +1,32 @@
1
+ import { number, object, optional, parse } from "valibot";
2
+ import { useScript } from "#imports";
3
+ const HotjarOptions = object({
4
+ id: number(),
5
+ sv: optional(number())
6
+ });
7
+ export function useScriptHotjar(options, _scriptOptions) {
8
+ const scriptOptions = _scriptOptions || {};
9
+ scriptOptions.beforeInit = () => {
10
+ if (import.meta.dev) {
11
+ parse(HotjarOptions, options);
12
+ }
13
+ if (import.meta.client) {
14
+ window._hjSettings = window._hjSettings || { hjid: options?.id, hjsv: options?.sv };
15
+ window.hj = window.hj || function(...params) {
16
+ (window.hj.q = window.hj.q || []).push(params);
17
+ };
18
+ }
19
+ };
20
+ return useScript({
21
+ key: "hotjar",
22
+ src: `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv}`,
23
+ defer: true
24
+ }, {
25
+ trigger: "onNuxtReady",
26
+ ...scriptOptions,
27
+ assetStrategy: "bundle",
28
+ use() {
29
+ return { hj: window.hj };
30
+ }
31
+ });
32
+ }
@@ -0,0 +1,31 @@
1
+ import { type Input } from 'valibot';
2
+ import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
+ declare const IntercomOptions: import("valibot").ObjectSchema<{
4
+ app_id: import("valibot").StringSchema<string>;
5
+ api_base: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"https://api-iam.intercom.io", "https://api-iam.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.eu.intercom.io", "https://api-iam.eu.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.au.intercom.io", "https://api-iam.au.intercom.io">)[], "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io">, undefined, "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io" | undefined>;
6
+ name: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
7
+ email: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
8
+ user_id: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
9
+ alignment: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"left", "left"> | import("valibot").LiteralSchema<"right", "right">)[], "left" | "right">, undefined, "left" | "right" | undefined>;
10
+ horizontal_padding: import("valibot").OptionalSchema<import("valibot").NumberSchema<number>, undefined, number | undefined>;
11
+ vertical_padding: import("valibot").OptionalSchema<import("valibot").NumberSchema<number>, undefined, number | undefined>;
12
+ }, undefined, {
13
+ app_id: string;
14
+ api_base?: "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io" | undefined;
15
+ name?: string | undefined;
16
+ email?: string | undefined;
17
+ user_id?: string | undefined;
18
+ alignment?: "left" | "right" | undefined;
19
+ horizontal_padding?: number | undefined;
20
+ vertical_padding?: number | undefined;
21
+ }>;
22
+ export interface IntercomApi {
23
+ Intercom: ((event: 'boot', data?: Input<typeof IntercomOptions>) => void) & ((event: 'shutdown') => void) & ((event: 'update', options?: Input<typeof IntercomOptions>) => void) & ((event: 'hide') => void) & ((event: 'show') => void) & ((event: 'showSpace', spaceName: 'home' | 'messages' | 'help' | 'news' | 'tasks' | 'tickets' | string) => void) & ((event: 'showMessages') => void) & ((event: 'showNewMessage', content?: string) => void) & ((event: 'onHide', fn: () => void) => void) & ((event: 'onShow', fn: () => void) => void) & ((event: 'onUnreadCountChange', fn: () => void) => void) & ((event: 'trackEvent', eventName: string, metadata?: Record<string, any>) => void) & ((event: 'getVisitorId') => Promise<string>) & ((event: 'startTour', tourId: string | number) => void) & ((event: 'showArticle', articleId: string | number) => void) & ((event: 'showNews', newsItemId: string | number) => void) & ((event: 'startSurvey', surveyId: string | number) => void) & ((event: 'startChecklist', checklistId: string | number) => void) & ((event: 'showTicket', ticketId: string | number) => void) & ((event: 'showConversation', conversationId: string | number) => void) & ((event: 'onUserEmailSupplied', fn: () => void) => void) & ((event: string, ...params: any[]) => void);
24
+ }
25
+ declare global {
26
+ interface Window extends IntercomApi {
27
+ intercomSettings?: Input<typeof IntercomOptions>;
28
+ }
29
+ }
30
+ export declare function useScriptIntercom<T extends IntercomApi>(options?: Input<typeof IntercomOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
31
+ export {};
@@ -0,0 +1,34 @@
1
+ import { literal, number, object, optional, parse, string, union } from "valibot";
2
+ import { useScript } from "#imports";
3
+ const IntercomOptions = object({
4
+ app_id: string(),
5
+ api_base: optional(union([literal("https://api-iam.intercom.io"), literal("https://api-iam.eu.intercom.io"), literal("https://api-iam.au.intercom.io")])),
6
+ name: optional(string()),
7
+ email: optional(string()),
8
+ user_id: optional(string()),
9
+ // customizing the messenger
10
+ alignment: optional(union([literal("left"), literal("right")])),
11
+ horizontal_padding: optional(number()),
12
+ vertical_padding: optional(number())
13
+ });
14
+ export function useScriptIntercom(options, _scriptOptions) {
15
+ const scriptOptions = _scriptOptions || {};
16
+ scriptOptions.beforeInit = () => {
17
+ if (import.meta.dev)
18
+ parse(IntercomOptions, options);
19
+ if (import.meta.client)
20
+ window.intercomSettings = options;
21
+ };
22
+ return useScript({
23
+ key: "intercom",
24
+ src: `https://widget.intercom.io/widget/${options?.app_id}`,
25
+ defer: true
26
+ }, {
27
+ trigger: "onNuxtReady",
28
+ ...scriptOptions,
29
+ assetStrategy: "bundle",
30
+ use() {
31
+ return { Intercom: window.Intercom };
32
+ }
33
+ });
34
+ }
@@ -0,0 +1,25 @@
1
+ import { type Input } from 'valibot';
2
+ import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
+ declare const SegmentOptions: import("valibot").ObjectSchema<{
4
+ writeKey: import("valibot").StringSchema<string>;
5
+ analyticsKey: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
6
+ }, undefined, {
7
+ writeKey: string;
8
+ analyticsKey?: string | undefined;
9
+ }>;
10
+ export interface SegmentApi {
11
+ analytics: {
12
+ track: (event: string, properties?: Record<string, any>) => void;
13
+ page: (name?: string, properties?: Record<string, any>) => void;
14
+ identify: (userId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
15
+ group: (groupId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
16
+ alias: (userId: string, previousId: string, options?: Record<string, any>) => void;
17
+ reset: () => void;
18
+ };
19
+ }
20
+ declare global {
21
+ interface Window extends SegmentApi {
22
+ }
23
+ }
24
+ export declare function useScriptSegment<T extends SegmentApi>(options?: Input<typeof SegmentOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
25
+ export {};
@@ -0,0 +1,44 @@
1
+ import { object, optional, parse, string } from "valibot";
2
+ import { useScript } from "#imports";
3
+ const SegmentOptions = object({
4
+ writeKey: string(),
5
+ analyticsKey: optional(string())
6
+ });
7
+ export function useScriptSegment(options, _scriptOptions) {
8
+ const scriptOptions = _scriptOptions || {};
9
+ scriptOptions.beforeInit = () => {
10
+ if (import.meta.dev)
11
+ parse(SegmentOptions, options);
12
+ if (import.meta.client) {
13
+ window.analytics = window.analytics || [];
14
+ window.analytics.methods = ["track", "page", "identify", "group", "alias", "reset"];
15
+ window.analytics.factory = function(method) {
16
+ return function() {
17
+ const args = Array.prototype.slice.call(arguments);
18
+ args.unshift(method);
19
+ window.analytics.push(args);
20
+ return window.analytics;
21
+ };
22
+ };
23
+ for (let i = 0; i < window.analytics.methods.length; i++) {
24
+ const key = window.analytics.methods[i];
25
+ window.analytics[key] = window.analytics.factory(key);
26
+ }
27
+ window.analytics.page();
28
+ }
29
+ };
30
+ const analyticsKey = options?.analyticsKey || "analytics";
31
+ return useScript({
32
+ "key": "segment",
33
+ "data-global-segment-analytics-key": analyticsKey,
34
+ "src": `https://cdn.segment.com/analytics.js/v1/${options?.writeKey}/analytics.min.js`,
35
+ "defer": true
36
+ }, {
37
+ trigger: "onNuxtReady",
38
+ ...scriptOptions,
39
+ assetStrategy: "bundle",
40
+ use() {
41
+ return { analytics: window[analyticsKey] };
42
+ }
43
+ });
44
+ }
@@ -15,6 +15,10 @@ export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'>
15
15
  * improves privacy by not sharing the user's IP address with third-party servers.
16
16
  */
17
17
  assetStrategy?: 'bundle';
18
+ /**
19
+ * A hook to run when a script does not exist and will be initialized for the first time.
20
+ */
21
+ beforeInit?: () => void;
18
22
  };
19
23
  export type NuxtUseScriptInput = UseScriptInput;
20
24
  export interface TrackedPage {