@nuxt/scripts 1.0.0-rc.9 → 1.0.0

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 (97) hide show
  1. package/dist/devtools-client/200.html +1 -1
  2. package/dist/devtools-client/404.html +1 -1
  3. package/dist/devtools-client/_nuxt/{BBS9G2Kb.js → Br5kvbNb.js} +1 -1
  4. package/dist/devtools-client/_nuxt/C25MBdR1.js +1 -0
  5. package/dist/devtools-client/_nuxt/{DCBsJT4N.js → Cg_OIb5q.js} +1 -1
  6. package/dist/devtools-client/_nuxt/{B4uHpJPz.js → D2o5loaz.js} +1 -1
  7. package/dist/devtools-client/_nuxt/De7Wf2b9.js +188 -0
  8. package/dist/devtools-client/_nuxt/{Cxq4HLPL.js → DnVCfhVR.js} +1 -1
  9. package/dist/devtools-client/_nuxt/builds/latest.json +1 -1
  10. package/dist/devtools-client/_nuxt/builds/meta/9d868e70-bc5a-425c-8c84-8defe5186920.json +1 -0
  11. package/dist/devtools-client/_nuxt/{entry.BwpOBArY.css → entry.BSxy0W1q.css} +1 -1
  12. package/dist/devtools-client/_nuxt/index.DZD1lwyI.css +1 -0
  13. package/dist/devtools-client/_nuxt/{DvZScWzI.js → pN4-T8ZD.js} +1 -1
  14. package/dist/devtools-client/docs/index.html +1 -1
  15. package/dist/devtools-client/first-party/index.html +1 -1
  16. package/dist/devtools-client/index.html +1 -1
  17. package/dist/devtools-client/registry/index.html +1 -1
  18. package/dist/module.d.mts +15 -0
  19. package/dist/module.d.ts +15 -0
  20. package/dist/module.json +1 -1
  21. package/dist/module.mjs +35 -8
  22. package/dist/registry.mjs +3 -3
  23. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsStaticMap.vue +6 -2
  24. package/dist/runtime/components/ScriptBlueskyEmbed.d.vue.ts +0 -1
  25. package/dist/runtime/components/ScriptBlueskyEmbed.vue +12 -10
  26. package/dist/runtime/components/ScriptBlueskyEmbed.vue.d.ts +0 -1
  27. package/dist/runtime/components/ScriptInstagramEmbed.vue +3 -1
  28. package/dist/runtime/components/ScriptXEmbed.d.vue.ts +0 -1
  29. package/dist/runtime/components/ScriptXEmbed.vue +11 -9
  30. package/dist/runtime/components/ScriptXEmbed.vue.d.ts +0 -1
  31. package/dist/runtime/composables/useScript.js +17 -6
  32. package/dist/runtime/composables/useScriptProxyToken.d.ts +12 -0
  33. package/dist/runtime/composables/useScriptProxyToken.js +4 -0
  34. package/dist/runtime/composables/useScriptProxyUrl.d.ts +12 -0
  35. package/dist/runtime/composables/useScriptProxyUrl.js +27 -0
  36. package/dist/runtime/plugins/proxy-token.server.d.ts +10 -0
  37. package/dist/runtime/plugins/proxy-token.server.js +17 -0
  38. package/dist/runtime/registry/bing-uet.d.ts +6 -2
  39. package/dist/runtime/registry/bing-uet.js +13 -1
  40. package/dist/runtime/registry/bluesky-embed.d.ts +0 -4
  41. package/dist/runtime/registry/bluesky-embed.js +0 -4
  42. package/dist/runtime/registry/clarity.d.ts +6 -2
  43. package/dist/runtime/registry/clarity.js +12 -1
  44. package/dist/runtime/registry/google-analytics.d.ts +6 -2
  45. package/dist/runtime/registry/google-analytics.js +12 -1
  46. package/dist/runtime/registry/google-tag-manager.d.ts +6 -2
  47. package/dist/runtime/registry/google-tag-manager.js +10 -1
  48. package/dist/runtime/registry/gravatar.js +10 -13
  49. package/dist/runtime/registry/matomo-analytics.d.ts +9 -3
  50. package/dist/runtime/registry/matomo-analytics.js +28 -1
  51. package/dist/runtime/registry/meta-pixel.d.ts +8 -2
  52. package/dist/runtime/registry/meta-pixel.js +10 -1
  53. package/dist/runtime/registry/mixpanel-analytics.d.ts +12 -2
  54. package/dist/runtime/registry/mixpanel-analytics.js +16 -4
  55. package/dist/runtime/registry/posthog.d.ts +8 -2
  56. package/dist/runtime/registry/posthog.js +15 -4
  57. package/dist/runtime/registry/schemas.d.ts +65 -0
  58. package/dist/runtime/registry/schemas.js +75 -8
  59. package/dist/runtime/registry/tiktok-pixel.d.ts +16 -2
  60. package/dist/runtime/registry/tiktok-pixel.js +22 -1
  61. package/dist/runtime/registry/x-embed.d.ts +0 -4
  62. package/dist/runtime/registry/x-embed.js +0 -4
  63. package/dist/runtime/server/bluesky-embed-image.d.ts +1 -1
  64. package/dist/runtime/server/bluesky-embed.d.ts +1 -15
  65. package/dist/runtime/server/bluesky-embed.js +22 -4
  66. package/dist/runtime/server/google-maps-geocode-proxy.js +8 -5
  67. package/dist/runtime/server/google-static-maps-proxy.d.ts +1 -1
  68. package/dist/runtime/server/google-static-maps-proxy.js +13 -8
  69. package/dist/runtime/server/gravatar-proxy.d.ts +1 -1
  70. package/dist/runtime/server/gravatar-proxy.js +6 -7
  71. package/dist/runtime/server/instagram-embed-asset.d.ts +1 -1
  72. package/dist/runtime/server/instagram-embed-image.d.ts +1 -1
  73. package/dist/runtime/server/instagram-embed.js +22 -10
  74. package/dist/runtime/server/utils/cached-upstream.d.ts +55 -0
  75. package/dist/runtime/server/utils/cached-upstream.js +65 -0
  76. package/dist/runtime/server/utils/embed-rewriters.d.ts +19 -0
  77. package/dist/runtime/server/utils/embed-rewriters.js +41 -0
  78. package/dist/runtime/server/utils/image-proxy.d.ts +3 -1
  79. package/dist/runtime/server/utils/image-proxy.js +8 -6
  80. package/dist/runtime/server/utils/instagram-embed.d.ts +4 -4
  81. package/dist/runtime/server/utils/instagram-embed.js +10 -9
  82. package/dist/runtime/server/utils/proxy-url.d.ts +9 -0
  83. package/dist/runtime/server/utils/proxy-url.js +21 -0
  84. package/dist/runtime/server/utils/sign-constants.d.ts +16 -0
  85. package/dist/runtime/server/utils/sign-constants.js +5 -0
  86. package/dist/runtime/server/utils/sign.d.ts +2 -10
  87. package/dist/runtime/server/utils/sign.js +8 -5
  88. package/dist/runtime/server/utils/withSigning.js +3 -2
  89. package/dist/runtime/server/x-embed-image.d.ts +1 -1
  90. package/dist/runtime/server/x-embed.js +20 -2
  91. package/dist/runtime/types.d.ts +24 -1
  92. package/dist/types-source.mjs +104 -11
  93. package/package.json +2 -2
  94. package/dist/devtools-client/_nuxt/CQR4zIAm.js +0 -1
  95. package/dist/devtools-client/_nuxt/DTxy5P8N.js +0 -188
  96. package/dist/devtools-client/_nuxt/builds/meta/bd58b869-1eb5-4c50-871c-707f9b71e8f9.json +0 -1
  97. package/dist/devtools-client/_nuxt/index.CA-OpSj0.css +0 -1
@@ -0,0 +1,17 @@
1
+ import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
2
+ import { useScriptProxyToken } from "../composables/useScriptProxyToken.js";
3
+ import { generateProxyToken } from "../server/utils/sign.js";
4
+ export default defineNuxtPlugin({
5
+ name: "nuxt-scripts:proxy-token",
6
+ enforce: "pre",
7
+ setup() {
8
+ const secret = useRuntimeConfig()["nuxt-scripts"]?.proxySecret;
9
+ if (!secret)
10
+ return;
11
+ const ts = Math.floor(Date.now() / 1e3);
12
+ useScriptProxyToken().value = {
13
+ token: generateProxyToken(secret, ts),
14
+ ts
15
+ };
16
+ }
17
+ });
@@ -1,4 +1,4 @@
1
- import type { RegistryScriptInput } from '#nuxt-scripts/types';
1
+ import type { RegistryScriptInput, UseScriptContext } from '#nuxt-scripts/types';
2
2
  import { BingUetOptions } from './schemas.js';
3
3
  export { BingUetOptions };
4
4
  export type BingUetInput = RegistryScriptInput<typeof BingUetOptions, true, false>;
@@ -189,6 +189,10 @@ declare global {
189
189
  uetq: any[] | BingUetQueue;
190
190
  }
191
191
  }
192
+ export interface BingUetConsent {
193
+ /** Push `['consent','update', state]` with the `ad_storage` signal. */
194
+ update: (state: BingUetConsentOptions) => void;
195
+ }
192
196
  export declare function useScriptBingUet<T extends BingUetApi>(_options?: BingUetInput & {
193
197
  onBeforeUetStart?: (uetq: BingUetQueue) => void;
194
- }): import("#nuxt-scripts/types").UseScriptContext<T>;
198
+ }): UseScriptContext<T, BingUetConsent>;
@@ -2,7 +2,7 @@ import { useRegistryScript } from "../utils.js";
2
2
  import { BingUetOptions } from "./schemas.js";
3
3
  export { BingUetOptions };
4
4
  export function useScriptBingUet(_options) {
5
- return useRegistryScript("bingUet", (options) => ({
5
+ const instance = useRegistryScript("bingUet", (options) => ({
6
6
  scriptInput: {
7
7
  src: "https://bat.bing.com/bat.js",
8
8
  crossorigin: false
@@ -25,7 +25,19 @@ export function useScriptBingUet(_options) {
25
25
  clientInit: import.meta.server ? void 0 : () => {
26
26
  const uetq = window.uetq || [];
27
27
  window.uetq = uetq;
28
+ if (options?.defaultConsent) {
29
+ uetq.push("consent", "default", options.defaultConsent);
30
+ }
28
31
  _options?.onBeforeUetStart?.(uetq);
29
32
  }
30
33
  }), _options);
34
+ if (import.meta.client && !instance.consent) {
35
+ instance.consent = {
36
+ update: (state) => {
37
+ ;
38
+ instance.proxy.uetq.push("consent", "update", state);
39
+ }
40
+ };
41
+ }
42
+ return instance;
31
43
  }
@@ -98,10 +98,6 @@ export declare function extractBlueskyPostId(url: string): {
98
98
  actor: string;
99
99
  rkey: string;
100
100
  } | undefined;
101
- /**
102
- * Proxy a Bluesky image URL through the server
103
- */
104
- export declare function proxyBlueskyImageUrl(url: string, proxyEndpoint?: string): string;
105
101
  /**
106
102
  * Format a Bluesky post date for display
107
103
  */
@@ -7,10 +7,6 @@ export function extractBlueskyPostId(url) {
7
7
  return void 0;
8
8
  return { actor: match[1], rkey: match[2] };
9
9
  }
10
- export function proxyBlueskyImageUrl(url, proxyEndpoint = "/_scripts/embed/bluesky-image") {
11
- const separator = proxyEndpoint.includes("?") ? "&" : "?";
12
- return `${proxyEndpoint}${separator}url=${encodeURIComponent(url)}`;
13
- }
14
10
  export function formatBlueskyDate(dateString) {
15
11
  const date = new Date(dateString);
16
12
  const time = date.toLocaleString("en-US", {
@@ -1,4 +1,4 @@
1
- import type { RegistryScriptInput } from '#nuxt-scripts/types';
1
+ import type { RegistryScriptInput, UseScriptContext } from '#nuxt-scripts/types';
2
2
  import { ClarityOptions } from './schemas.js';
3
3
  export { ClarityOptions };
4
4
  type ClarityFunctions = ((fn: 'start', options?: {
@@ -25,4 +25,8 @@ declare global {
25
25
  }
26
26
  }
27
27
  export type ClarityInput = RegistryScriptInput<typeof ClarityOptions>;
28
- export declare function useScriptClarity<T extends ClarityApi>(_options?: ClarityInput): import("#nuxt-scripts/types").UseScriptContext<T>;
28
+ export interface ClarityConsent {
29
+ /** Call `clarity('consent', value)` with either a boolean (default) or Clarity's advanced vector. */
30
+ set: (value: boolean | Record<string, string>) => void;
31
+ }
32
+ export declare function useScriptClarity<T extends ClarityApi>(_options?: ClarityInput): UseScriptContext<T, ClarityConsent>;
@@ -2,7 +2,7 @@ import { useRegistryScript } from "../utils.js";
2
2
  import { ClarityOptions } from "./schemas.js";
3
3
  export { ClarityOptions };
4
4
  export function useScriptClarity(_options) {
5
- return useRegistryScript("clarity", (options) => ({
5
+ const instance = useRegistryScript("clarity", (options) => ({
6
6
  scriptInput: {
7
7
  src: `https://www.clarity.ms/tag/${options.id}`
8
8
  },
@@ -22,6 +22,17 @@ export function useScriptClarity(_options) {
22
22
  window.clarity = window.clarity || function(...params) {
23
23
  (window.clarity.q = window.clarity.q || []).push(params);
24
24
  };
25
+ if (options?.defaultConsent !== void 0)
26
+ window.clarity("consent", options.defaultConsent);
25
27
  }
26
28
  }), _options);
29
+ if (import.meta.client && !instance.consent) {
30
+ instance.consent = {
31
+ set: (value) => {
32
+ ;
33
+ instance.proxy.clarity("consent", value);
34
+ }
35
+ };
36
+ }
37
+ return instance;
27
38
  }
@@ -1,4 +1,4 @@
1
- import type { RegistryScriptInput } from '#nuxt-scripts/types';
1
+ import type { ConsentState, RegistryScriptInput, UseScriptContext } from '#nuxt-scripts/types';
2
2
  import { GoogleAnalyticsOptions } from './schemas.js';
3
3
  export type GtagCustomParams = Record<string, any>;
4
4
  export type ConsentStatus = 'granted' | 'denied';
@@ -58,6 +58,10 @@ export interface GoogleAnalyticsApi {
58
58
  }
59
59
  export { GoogleAnalyticsOptions };
60
60
  export type GoogleAnalyticsInput = RegistryScriptInput<typeof GoogleAnalyticsOptions>;
61
+ export interface GoogleAnalyticsConsent {
62
+ /** Send `gtag('consent','update', state)` with GCMv2 partial state. */
63
+ update: (state: ConsentState) => void;
64
+ }
61
65
  export declare function useScriptGoogleAnalytics<T extends GoogleAnalyticsApi>(_options?: GoogleAnalyticsInput & {
62
66
  onBeforeGtagStart?: (gtag: GTag) => void;
63
- }): import("#nuxt-scripts/types").UseScriptContext<T>;
67
+ }): UseScriptContext<T, GoogleAnalyticsConsent>;
@@ -3,7 +3,7 @@ import { withQuery } from "ufo";
3
3
  import { GoogleAnalyticsOptions } from "./schemas.js";
4
4
  export { GoogleAnalyticsOptions };
5
5
  export function useScriptGoogleAnalytics(_options) {
6
- return useRegistryScript(_options?.key || "googleAnalytics", (options) => {
6
+ const instance = useRegistryScript(_options?.key || "googleAnalytics", (options) => {
7
7
  const dataLayerName = options?.l ?? "dataLayer";
8
8
  const w = import.meta.client ? window : {};
9
9
  return {
@@ -24,6 +24,8 @@ export function useScriptGoogleAnalytics(_options) {
24
24
  w.gtag = function() {
25
25
  w[dataLayerName].push(arguments);
26
26
  };
27
+ if (options?.defaultConsent)
28
+ w.gtag("consent", "default", options.defaultConsent);
27
29
  _options?.onBeforeGtagStart?.(w.gtag);
28
30
  w.gtag("js", /* @__PURE__ */ new Date());
29
31
  if (options?.id) {
@@ -32,4 +34,13 @@ export function useScriptGoogleAnalytics(_options) {
32
34
  }
33
35
  };
34
36
  }, _options);
37
+ if (import.meta.client && !instance.consent) {
38
+ instance.consent = {
39
+ update: (state) => {
40
+ ;
41
+ instance.proxy.gtag("consent", "update", state);
42
+ }
43
+ };
44
+ }
45
+ return instance;
35
46
  }
@@ -1,4 +1,4 @@
1
- import type { NuxtUseScriptOptions, RegistryScriptInput, UseFunctionType, UseScriptContext } from '#nuxt-scripts/types';
1
+ import type { ConsentState, NuxtUseScriptOptions, RegistryScriptInput, UseFunctionType, UseScriptContext } from '#nuxt-scripts/types';
2
2
  import type { GTag } from './google-analytics.js';
3
3
  import { GoogleTagManagerOptions } from './schemas.js';
4
4
  /**
@@ -68,6 +68,10 @@ declare global {
68
68
  }
69
69
  export { GoogleTagManagerOptions };
70
70
  export type GoogleTagManagerInput = RegistryScriptInput<typeof GoogleTagManagerOptions>;
71
+ export interface GoogleTagManagerConsent {
72
+ /** Push `['consent','update', state]` onto dataLayer with GCMv2 partial state. */
73
+ update: (state: ConsentState) => void;
74
+ }
71
75
  /**
72
76
  * Hook to use Google Tag Manager in Nuxt applications
73
77
  */
@@ -77,4 +81,4 @@ export declare function useScriptGoogleTagManager<T extends GoogleTagManagerApi>
77
81
  * Allows for custom initialization or configuration
78
82
  */
79
83
  onBeforeGtmStart?: (gtag: DataLayerPush) => void;
80
- }): UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T>, T>>;
84
+ }): UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T>, T>, GoogleTagManagerConsent>;
@@ -54,5 +54,14 @@ export function useScriptGoogleTagManager(options) {
54
54
  if (gtag)
55
55
  options.onBeforeGtmStart(gtag);
56
56
  }
57
- return instance;
57
+ const typed = instance;
58
+ if (import.meta.client && !typed.consent) {
59
+ typed.consent = {
60
+ update: (state) => {
61
+ ;
62
+ typed.proxy.dataLayer.push(["consent", "update", state]);
63
+ }
64
+ };
65
+ }
66
+ return typed;
58
67
  }
@@ -1,4 +1,5 @@
1
1
  import { scriptsPrefix, useRegistryScript } from "#nuxt-scripts/utils";
2
+ import { useScriptProxyUrl } from "../composables/useScriptProxyUrl.js";
2
3
  import { GravatarOptions } from "./schemas.js";
3
4
  export { GravatarOptions } from "./schemas.js";
4
5
  export function useScriptGravatar(_options) {
@@ -6,13 +7,11 @@ export function useScriptGravatar(_options) {
6
7
  const size = options?.size ?? 80;
7
8
  const defaultImg = options?.default ?? "mp";
8
9
  const rating = options?.rating ?? "g";
9
- const buildQuery = (overrides) => {
10
- const params = new URLSearchParams();
11
- params.set("s", String(overrides?.size ?? size));
12
- params.set("d", overrides?.default ?? defaultImg);
13
- params.set("r", overrides?.rating ?? rating);
14
- return params.toString();
15
- };
10
+ const buildQuery = (overrides) => ({
11
+ s: overrides?.size ?? size,
12
+ d: overrides?.default ?? defaultImg,
13
+ r: overrides?.rating ?? rating
14
+ });
16
15
  return {
17
16
  scriptInput: {
18
17
  src: "https://secure.gravatar.com/js/gprofiles.js"
@@ -21,13 +20,11 @@ export function useScriptGravatar(_options) {
21
20
  scriptOptions: {
22
21
  use: () => {
23
22
  const prefix = scriptsPrefix();
23
+ const proxyUrl = useScriptProxyUrl();
24
+ const path = `${prefix}/proxy/gravatar`;
24
25
  return {
25
- getAvatarUrl: (hash, overrides) => {
26
- return `${prefix}/proxy/gravatar?hash=${encodeURIComponent(hash)}&${buildQuery(overrides)}`;
27
- },
28
- getAvatarUrlFromEmail: (email, overrides) => {
29
- return `${prefix}/proxy/gravatar?email=${encodeURIComponent(email)}&${buildQuery(overrides)}`;
30
- }
26
+ getAvatarUrl: (hash, overrides) => proxyUrl(path, { hash, ...buildQuery(overrides) }),
27
+ getAvatarUrlFromEmail: (email, overrides) => proxyUrl(path, { email, ...buildQuery(overrides) })
31
28
  };
32
29
  }
33
30
  }
@@ -1,12 +1,18 @@
1
- import type { RegistryScriptInput } from '#nuxt-scripts/types';
1
+ import type { RegistryScriptInput, UseScriptContext } from '#nuxt-scripts/types';
2
2
  import { MatomoAnalyticsOptions } from './schemas.js';
3
3
  export { MatomoAnalyticsOptions };
4
4
  export type MatomoAnalyticsInput = RegistryScriptInput<typeof MatomoAnalyticsOptions, false, false>;
5
- interface MatomoAnalyticsApi {
5
+ export interface MatomoAnalyticsApi {
6
6
  _paq: unknown[];
7
7
  }
8
8
  declare global {
9
9
  interface Window extends MatomoAnalyticsApi {
10
10
  }
11
11
  }
12
- export declare function useScriptMatomoAnalytics<T extends MatomoAnalyticsApi>(_options?: MatomoAnalyticsInput): import("#nuxt-scripts/types").UseScriptContext<T>;
12
+ export interface MatomoConsent {
13
+ /** Push `setConsentGiven`. Requires `defaultConsent: 'required' | 'given'` at registration to have an effect. */
14
+ give: () => void;
15
+ /** Push `forgetConsentGiven`. Requires `defaultConsent: 'required' | 'given'` at registration to have an effect. */
16
+ forget: () => void;
17
+ }
18
+ export declare function useScriptMatomoAnalytics<T extends MatomoAnalyticsApi>(_options?: MatomoAnalyticsInput): UseScriptContext<T, MatomoConsent>;
@@ -5,7 +5,7 @@ import { useRegistryScript } from "../utils.js";
5
5
  import { MatomoAnalyticsOptions } from "./schemas.js";
6
6
  export { MatomoAnalyticsOptions };
7
7
  export function useScriptMatomoAnalytics(_options) {
8
- return useRegistryScript("matomoAnalytics", (options) => {
8
+ const instance = useRegistryScript("matomoAnalytics", (options) => {
9
9
  const normalizedCloudId = options?.cloudId ? withoutTrailingSlash(withoutProtocol(options.cloudId)) : void 0;
10
10
  const origin = options?.matomoUrl ? options.matomoUrl : `https://cdn.matomo.cloud/${normalizedCloudId}/`;
11
11
  const _paq = import.meta.client ? window._paq = window._paq || [] : [];
@@ -30,6 +30,12 @@ export function useScriptMatomoAnalytics(_options) {
30
30
  }
31
31
  },
32
32
  clientInit: import.meta.server ? void 0 : () => {
33
+ if (options?.defaultConsent === "required") {
34
+ _paq.push(["requireConsent"]);
35
+ } else if (options?.defaultConsent === "given") {
36
+ _paq.push(["requireConsent"]);
37
+ _paq.push(["setConsentGiven"]);
38
+ }
33
39
  if (options?.enableLinkTracking) {
34
40
  _paq.push(["enableLinkTracking"]);
35
41
  }
@@ -59,4 +65,25 @@ export function useScriptMatomoAnalytics(_options) {
59
65
  }
60
66
  };
61
67
  }, _options);
68
+ if (import.meta.client && !instance.consent) {
69
+ const requiresConsent = _options?.defaultConsent === "required" || _options?.defaultConsent === "given";
70
+ const warnIfUnsafe = import.meta.dev ? (method) => {
71
+ if (!requiresConsent) {
72
+ logger.warn(`matomo consent.${method}() is a no-op unless \`defaultConsent: 'required'\` or \`'given'\` is set at registration.`);
73
+ }
74
+ } : () => {
75
+ };
76
+ const paq = instance.proxy._paq;
77
+ instance.consent = {
78
+ give: () => {
79
+ warnIfUnsafe("give");
80
+ paq.push(["setConsentGiven"]);
81
+ },
82
+ forget: () => {
83
+ warnIfUnsafe("forget");
84
+ paq.push(["forgetConsentGiven"]);
85
+ }
86
+ };
87
+ }
88
+ return instance;
62
89
  }
@@ -1,4 +1,4 @@
1
- import type { RegistryScriptInput } from '#nuxt-scripts/types';
1
+ import type { RegistryScriptInput, UseScriptContext } from '#nuxt-scripts/types';
2
2
  import { MetaPixelOptions } from './schemas.js';
3
3
  type StandardEvents = 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent';
4
4
  interface EventObjectProperties {
@@ -38,4 +38,10 @@ declare global {
38
38
  }
39
39
  export { MetaPixelOptions };
40
40
  export type MetaPixelInput = RegistryScriptInput<typeof MetaPixelOptions, true, false>;
41
- export declare function useScriptMetaPixel<T extends MetaPixelApi>(_options?: MetaPixelInput): import("#nuxt-scripts/types").UseScriptContext<T>;
41
+ export interface MetaPixelConsent {
42
+ /** Call `fbq('consent','grant')`. */
43
+ grant: () => void;
44
+ /** Call `fbq('consent','revoke')`. */
45
+ revoke: () => void;
46
+ }
47
+ export declare function useScriptMetaPixel<T extends MetaPixelApi>(_options?: MetaPixelInput): UseScriptContext<T, MetaPixelConsent>;
@@ -2,7 +2,7 @@ import { useRegistryScript } from "../utils.js";
2
2
  import { MetaPixelOptions } from "./schemas.js";
3
3
  export { MetaPixelOptions };
4
4
  export function useScriptMetaPixel(_options) {
5
- return useRegistryScript("metaPixel", (options) => ({
5
+ const instance = useRegistryScript("metaPixel", (options) => ({
6
6
  scriptInput: {
7
7
  src: "https://connect.facebook.net/en_US/fbevents.js",
8
8
  crossorigin: false
@@ -27,8 +27,17 @@ export function useScriptMetaPixel(_options) {
27
27
  fbq.loaded = true;
28
28
  fbq.version = "2.0";
29
29
  fbq.queue = [];
30
+ if (options?.defaultConsent)
31
+ fbq("consent", options.defaultConsent === "granted" ? "grant" : "revoke");
30
32
  fbq("init", options?.id);
31
33
  fbq("track", "PageView");
32
34
  }
33
35
  }), _options);
36
+ if (import.meta.client && !instance.consent) {
37
+ instance.consent = {
38
+ grant: () => instance.proxy.fbq("consent", "grant"),
39
+ revoke: () => instance.proxy.fbq("consent", "revoke")
40
+ };
41
+ }
42
+ return instance;
34
43
  }
@@ -1,4 +1,4 @@
1
- import type { RegistryScriptInput } from '#nuxt-scripts/types';
1
+ import type { RegistryScriptInput, UseScriptContext } from '#nuxt-scripts/types';
2
2
  import { MixpanelAnalyticsOptions } from './schemas.js';
3
3
  export { MixpanelAnalyticsOptions };
4
4
  export type MixpanelAnalyticsInput = RegistryScriptInput<typeof MixpanelAnalyticsOptions>;
@@ -12,6 +12,10 @@ export interface MixpanelAnalyticsApi {
12
12
  };
13
13
  register: (properties: Record<string, any>) => void;
14
14
  init: (token: string, config?: Record<string, any>) => void;
15
+ /** Opt the user in to tracking. Available after the real SDK loads. */
16
+ opt_in_tracking?: () => void;
17
+ /** Opt the user out of tracking. Available after the real SDK loads. */
18
+ opt_out_tracking?: () => void;
15
19
  };
16
20
  }
17
21
  declare global {
@@ -19,4 +23,10 @@ declare global {
19
23
  mixpanel: MixpanelAnalyticsApi['mixpanel'];
20
24
  }
21
25
  }
22
- export declare function useScriptMixpanelAnalytics<T extends MixpanelAnalyticsApi>(_options?: MixpanelAnalyticsInput): import("#nuxt-scripts/types").UseScriptContext<T>;
26
+ export interface MixpanelConsent {
27
+ /** Call `mixpanel.opt_in_tracking()`. */
28
+ optIn: () => void;
29
+ /** Call `mixpanel.opt_out_tracking()`. For boot-time opt-out, use `defaultConsent: 'opt-out'` instead. */
30
+ optOut: () => void;
31
+ }
32
+ export declare function useScriptMixpanelAnalytics<T extends MixpanelAnalyticsApi>(_options?: MixpanelAnalyticsInput): UseScriptContext<T, MixpanelConsent>;
@@ -1,10 +1,10 @@
1
1
  import { useRegistryScript } from "../utils.js";
2
2
  import { MixpanelAnalyticsOptions } from "./schemas.js";
3
3
  export { MixpanelAnalyticsOptions };
4
- const methods = ["track", "identify", "reset", "register"];
4
+ const methods = ["track", "identify", "reset", "register", "opt_in_tracking", "opt_out_tracking"];
5
5
  const peopleMethods = ["set"];
6
6
  export function useScriptMixpanelAnalytics(_options) {
7
- return useRegistryScript("mixpanelAnalytics", (options) => {
7
+ const instance = useRegistryScript("mixpanelAnalytics", (options) => {
8
8
  return {
9
9
  scriptInput: {
10
10
  src: "https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js"
@@ -38,9 +38,21 @@ export function useScriptMixpanelAnalytics(_options) {
38
38
  mp._i.push([token, config, name]);
39
39
  };
40
40
  }
41
- if (options?.token)
42
- mp.init(options.token);
41
+ if (options?.token) {
42
+ const optOutByDefault = options?.defaultConsent === "opt-out";
43
+ mp.init(options.token, optOutByDefault ? { opt_out_tracking_by_default: true } : void 0);
44
+ if (options?.defaultConsent === "opt-in") {
45
+ mp.opt_in_tracking?.();
46
+ }
47
+ }
43
48
  }
44
49
  };
45
50
  }, _options);
51
+ if (import.meta.client && !instance.consent) {
52
+ instance.consent = {
53
+ optIn: () => instance.proxy.mixpanel.opt_in_tracking?.(),
54
+ optOut: () => instance.proxy.mixpanel.opt_out_tracking?.()
55
+ };
56
+ }
57
+ return instance;
46
58
  }
@@ -1,4 +1,4 @@
1
- import type { RegistryScriptInput } from '#nuxt-scripts/types';
1
+ import type { RegistryScriptInput, UseScriptContext } from '#nuxt-scripts/types';
2
2
  import type { PostHog, PostHogConfig } from 'posthog-js';
3
3
  import { PostHogOptions } from './schemas.js';
4
4
  export { PostHogOptions };
@@ -22,4 +22,10 @@ declare global {
22
22
  }[];
23
23
  }
24
24
  }
25
- export declare function useScriptPostHog<T extends PostHogApi>(_options?: PostHogInput): import("#nuxt-scripts/types").UseScriptContext<T>;
25
+ export interface PostHogConsent {
26
+ /** Call `posthog.opt_in_capturing()`. */
27
+ optIn: () => void;
28
+ /** Call `posthog.opt_out_capturing()`. For boot-time opt-out, use `defaultConsent: 'opt-out'` instead. */
29
+ optOut: () => void;
30
+ }
31
+ export declare function useScriptPostHog<T extends PostHogApi>(_options?: PostHogInput): UseScriptContext<T, PostHogConsent>;
@@ -3,7 +3,7 @@ import { useRegistryScript } from "../utils.js";
3
3
  import { PostHogOptions } from "./schemas.js";
4
4
  export { PostHogOptions };
5
5
  export function useScriptPostHog(_options) {
6
- return useRegistryScript("posthog", (options) => {
6
+ const instance = useRegistryScript("posthog", (options) => {
7
7
  return {
8
8
  scriptMode: "npm",
9
9
  // Use NPM mode - no external script tag
@@ -55,13 +55,17 @@ export function useScriptPostHog(_options) {
55
55
  config.capture_pageleave = options.capturePageleave;
56
56
  if (typeof options?.disableSessionRecording === "boolean")
57
57
  config.disable_session_recording = options.disableSessionRecording;
58
- const instance = posthog.init(options.apiKey, config);
59
- if (!instance) {
58
+ if (options?.defaultConsent === "opt-out")
59
+ config.opt_out_capturing_by_default = true;
60
+ const instance2 = posthog.init(options.apiKey, config);
61
+ if (!instance2) {
60
62
  logger.error("PostHog init returned undefined - initialization failed");
61
63
  delete window._posthogQueue;
62
64
  return void 0;
63
65
  }
64
- window.posthog = instance;
66
+ window.posthog = instance2;
67
+ if (options?.defaultConsent === "opt-in")
68
+ instance2.opt_in_capturing?.();
65
69
  if (window._posthogQueue && window._posthogQueue.length > 0) {
66
70
  window._posthogQueue.forEach((q) => window.posthog[q.prop]?.(...q.args));
67
71
  delete window._posthogQueue;
@@ -76,4 +80,11 @@ export function useScriptPostHog(_options) {
76
80
  }
77
81
  };
78
82
  }, _options);
83
+ if (import.meta.client && !instance.consent) {
84
+ instance.consent = {
85
+ optIn: () => instance.proxy.posthog?.opt_in_capturing?.(),
86
+ optOut: () => instance.proxy.posthog?.opt_out_capturing?.()
87
+ };
88
+ }
89
+ return instance;
79
90
  }
@@ -21,6 +21,13 @@ export declare const ClarityOptions: import("valibot").ObjectSchema<{
21
21
  * @see https://learn.microsoft.com/en-us/clarity/setup-clarity
22
22
  */
23
23
  readonly id: import("valibot").SchemaWithPipe<readonly [import("valibot").StringSchema<undefined>, import("valibot").MinLengthAction<string, 10, undefined>]>;
24
+ /**
25
+ * Default consent state applied before Clarity starts.
26
+ * - `boolean` - enable / disable cookies.
27
+ * - `Record<string, string>` - advanced consent vector (see Clarity docs).
28
+ * @see https://learn.microsoft.com/en-us/clarity/setup-and-installation/cookie-consent
29
+ */
30
+ readonly defaultConsent: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").BooleanSchema<undefined>, import("valibot").RecordSchema<import("valibot").StringSchema<undefined>, import("valibot").StringSchema<undefined>, undefined>], undefined>, undefined>;
24
31
  }, undefined>;
25
32
  export declare const CloudflareWebAnalyticsOptions: import("valibot").ObjectSchema<{
26
33
  /**
@@ -267,6 +274,21 @@ export declare const GoogleAnalyticsOptions: import("valibot").ObjectSchema<{
267
274
  * @see https://developers.google.com/analytics/devguides/collection/gtagjs/setting-up-gtag#rename_the_data_layer
268
275
  */
269
276
  readonly l: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
277
+ /**
278
+ * Default GCMv2 consent state fired as `gtag('consent', 'default', ...)` before `gtag('js', ...)`.
279
+ * @see https://developers.google.com/tag-platform/security/guides/consent
280
+ */
281
+ readonly defaultConsent: import("valibot").OptionalSchema<import("valibot").ObjectSchema<{
282
+ readonly ad_storage: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>], undefined>, undefined>;
283
+ readonly ad_user_data: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>], undefined>, undefined>;
284
+ readonly ad_personalization: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>], undefined>, undefined>;
285
+ readonly analytics_storage: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>], undefined>, undefined>;
286
+ readonly functionality_storage: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>], undefined>, undefined>;
287
+ readonly personalization_storage: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>], undefined>, undefined>;
288
+ readonly security_storage: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>], undefined>, undefined>;
289
+ readonly wait_for_update: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, undefined>;
290
+ readonly region: import("valibot").OptionalSchema<import("valibot").ArraySchema<import("valibot").StringSchema<undefined>, undefined>, undefined>;
291
+ }, undefined>, undefined>;
270
292
  }, undefined>;
271
293
  export declare const GoogleMapsOptions: import("valibot").ObjectSchema<{
272
294
  /**
@@ -533,6 +555,14 @@ export declare const MatomoAnalyticsOptions: import("valibot").ObjectSchema<{
533
555
  * @default true
534
556
  */
535
557
  readonly watch: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
558
+ /**
559
+ * Default tracking-consent state applied BEFORE the tracker is initialised.
560
+ * - `'required'` — call `requireConsent` without granting (user must opt in later).
561
+ * - `'given'` — call `requireConsent` then `setConsentGiven`.
562
+ * - `'not-required'` — no consent gating (default Matomo behaviour).
563
+ * @see https://developer.matomo.org/guides/tracking-consent
564
+ */
565
+ readonly defaultConsent: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"required", undefined>, import("valibot").LiteralSchema<"given", undefined>, import("valibot").LiteralSchema<"not-required", undefined>], undefined>, undefined>;
536
566
  }, undefined>;
537
567
  export declare const MetaPixelOptions: import("valibot").ObjectSchema<{
538
568
  /**
@@ -540,6 +570,12 @@ export declare const MetaPixelOptions: import("valibot").ObjectSchema<{
540
570
  * @see https://developers.facebook.com/docs/meta-pixel/get-started
541
571
  */
542
572
  readonly id: import("valibot").UnionSchema<[import("valibot").StringSchema<undefined>, import("valibot").NumberSchema<undefined>], undefined>;
573
+ /**
574
+ * Default consent state. `'granted'` fires `fbq('consent', 'grant')`,
575
+ * `'denied'` fires `fbq('consent', 'revoke')`, both called before `fbq('init', id)`.
576
+ * @see https://www.facebook.com/business/help/1151321516677370
577
+ */
578
+ readonly defaultConsent: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>], undefined>, undefined>;
543
579
  }, undefined>;
544
580
  export declare const NpmOptions: import("valibot").ObjectSchema<{
545
581
  /**
@@ -630,6 +666,13 @@ export declare const PostHogOptions: import("valibot").ObjectSchema<{
630
666
  * @see https://posthog.com/docs/libraries/js#config
631
667
  */
632
668
  readonly config: import("valibot").OptionalSchema<import("valibot").RecordSchema<import("valibot").StringSchema<undefined>, import("valibot").AnySchema, undefined>, undefined>;
669
+ /**
670
+ * Default capture-consent state for PostHog.
671
+ * - `'opt-out'`: passed as `opt_out_capturing_by_default: true` to `posthog.init`, so capturing is suppressed from the first event.
672
+ * - `'opt-in'`: applied after `posthog.init` via `posthog.opt_in_capturing()` on the returned instance.
673
+ * @see https://posthog.com/docs/privacy/opting-out
674
+ */
675
+ readonly defaultConsent: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"opt-in", undefined>, import("valibot").LiteralSchema<"opt-out", undefined>], undefined>, undefined>;
633
676
  }, undefined>;
634
677
  export declare const RedditPixelOptions: import("valibot").ObjectSchema<{
635
678
  /**
@@ -703,6 +746,13 @@ export declare const MixpanelAnalyticsOptions: import("valibot").ObjectSchema<{
703
746
  * @see https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#1-initialize-the-library
704
747
  */
705
748
  readonly token: import("valibot").StringSchema<undefined>;
749
+ /**
750
+ * Default tracking-consent state for Mixpanel.
751
+ * - `'opt-out'`: passed as `opt_out_tracking_by_default: true` to `mixpanel.init`, so tracking is suppressed from the first call.
752
+ * - `'opt-in'`: queued via `mixpanel.push(['opt_in_tracking'])` so the real SDK runs it immediately after load.
753
+ * @see https://docs.mixpanel.com/docs/privacy/opt-out-of-tracking
754
+ */
755
+ readonly defaultConsent: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"opt-in", undefined>, import("valibot").LiteralSchema<"opt-out", undefined>], undefined>, undefined>;
706
756
  }, undefined>;
707
757
  export declare const BingUetOptions: import("valibot").ObjectSchema<{
708
758
  /**
@@ -715,6 +765,13 @@ export declare const BingUetOptions: import("valibot").ObjectSchema<{
715
765
  * @default true
716
766
  */
717
767
  readonly enableAutoSpaTracking: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
768
+ /**
769
+ * Default consent state fired as `uetq.push('consent', 'default', ...)` before UET init.
770
+ * @see https://help.ads.microsoft.com/#apex/ads/en/60119/1-500
771
+ */
772
+ readonly defaultConsent: import("valibot").OptionalSchema<import("valibot").ObjectSchema<{
773
+ readonly ad_storage: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>], undefined>, undefined>;
774
+ }, undefined>, undefined>;
718
775
  }, undefined>;
719
776
  export declare const SegmentOptions: import("valibot").ObjectSchema<{
720
777
  /**
@@ -857,6 +914,14 @@ export declare const TikTokPixelOptions: import("valibot").ObjectSchema<{
857
914
  * @default true
858
915
  */
859
916
  readonly trackPageView: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
917
+ /**
918
+ * Default consent state, applied before `ttq('init', id)`.
919
+ * - `'granted'` fires `ttq.grantConsent()`
920
+ * - `'denied'` fires `ttq.revokeConsent()`
921
+ * - `'hold'` fires `ttq.holdConsent()` to defer until an explicit update
922
+ * @see https://business-api.tiktok.com/portal/docs?id=1739585600931842
923
+ */
924
+ readonly defaultConsent: import("valibot").OptionalSchema<import("valibot").UnionSchema<[import("valibot").LiteralSchema<"granted", undefined>, import("valibot").LiteralSchema<"denied", undefined>, import("valibot").LiteralSchema<"hold", undefined>], undefined>, undefined>;
860
925
  }, undefined>;
861
926
  export declare const UmamiAnalyticsOptions: import("valibot").ObjectSchema<{
862
927
  /**