@faststats/nuxt 0.7.0 → 0.8.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.
package/dist/module.d.mts CHANGED
@@ -1,7 +1,17 @@
1
1
  import { WebAnalyticsOptions } from "@faststats/web";
2
-
2
+ import { ErrorTrackingExtensionOptions } from "@faststats/web/error";
3
+ import { SessionReplayExtensionOptions } from "@faststats/web/replay";
4
+ import { WebVitalsExtensionOptions } from "@faststats/web/web-vitals";
5
+ import { NuxtModule } from "@nuxt/schema";
3
6
  //#region src/module.d.ts
4
- type ModuleOptions = Partial<WebAnalyticsOptions>;
5
- declare const _default: import("nuxt/schema").NuxtModule<Partial<WebAnalyticsOptions>, Partial<WebAnalyticsOptions>, false>;
7
+ type ModuleOptions = Omit<Partial<WebAnalyticsOptions>, "extensions"> & {
8
+ extensions?: {
9
+ outboundLinks?: boolean;
10
+ errorTracking?: boolean | ErrorTrackingExtensionOptions;
11
+ webVitals?: boolean | WebVitalsExtensionOptions;
12
+ sessionReplay?: boolean | SessionReplayExtensionOptions;
13
+ };
14
+ };
15
+ declare const faststatsModule: NuxtModule<ModuleOptions, ModuleOptions, false>;
6
16
  //#endregion
7
- export { ModuleOptions, _default as default };
17
+ export { ModuleOptions, faststatsModule as default };
package/dist/module.mjs CHANGED
@@ -3,32 +3,38 @@ import { addPlugin, addTypeTemplate, createResolver, defineNuxtModule, useLogger
3
3
  import { defu } from "defu";
4
4
  //#region src/module.ts
5
5
  const SDK_NAME = "@faststats/nuxt";
6
- const SDK_VERSION = "0.7.0";
7
- var module_default = defineNuxtModule({
6
+ const SDK_VERSION = "0.8.0";
7
+ const faststatsModule = defineNuxtModule({
8
8
  meta: {
9
9
  name: "@faststats/nuxt",
10
10
  configKey: "faststats"
11
11
  },
12
12
  defaults: {
13
13
  baseUrl: "https://metrics.faststats.dev",
14
- debug: false,
15
- autoTrack: true
14
+ debug: false
16
15
  },
17
16
  setup(options, nuxt) {
18
17
  const logger = useLogger("faststats");
19
- const resolver = createResolver(fileURLToPath(new URL("..", import.meta.url)));
18
+ const rootDir = fileURLToPath(new URL("..", import.meta.url));
19
+ const resolver = createResolver(rootDir);
20
20
  addTypeTemplate({
21
21
  filename: "types/faststats.d.ts",
22
- getContents: () => `import type { WebAnalyticsOptions } from '@faststats/web'
22
+ getContents: () => `import type { WebAnalytics } from '@faststats/web'
23
+ import type { ModuleOptions } from '@faststats/nuxt'
23
24
  declare module 'nuxt/schema' {
24
25
  interface PublicRuntimeConfig {
25
- faststats: WebAnalyticsOptions
26
+ faststats: ModuleOptions
26
27
  }
27
28
  interface NuxtConfig {
28
- faststats?: Partial<WebAnalyticsOptions>
29
+ faststats?: ModuleOptions
29
30
  }
30
31
  interface NuxtConfigInput {
31
- faststats?: Partial<WebAnalyticsOptions>
32
+ faststats?: ModuleOptions
33
+ }
34
+ }
35
+ declare module '#app' {
36
+ interface NuxtApp {
37
+ $faststats: WebAnalytics
32
38
  }
33
39
  }
34
40
  export {}
@@ -47,4 +53,4 @@ export {}
47
53
  }
48
54
  });
49
55
  //#endregion
50
- export { module_default as default };
56
+ export { faststatsModule as default };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/faststats-dev/faststats-javascript.git"
6
6
  },
7
- "version": "0.7.0",
7
+ "version": "0.8.0",
8
8
  "type": "module",
9
9
  "main": "./dist/module.mjs",
10
10
  "types": "./dist/module.d.mts",
@@ -31,13 +31,14 @@
31
31
  "nuxt": "^3.12.0 || ^4.0.0"
32
32
  },
33
33
  "dependencies": {
34
- "@faststats/web": "^0.7.0",
35
- "@nuxt/kit": "^4.4.0",
36
- "defu": "^6.1.4"
34
+ "@faststats/web": "^0.8.0",
35
+ "@nuxt/kit": "^4.5.2",
36
+ "@nuxt/schema": "^4.5.2",
37
+ "defu": "^6.1.7"
37
38
  },
38
39
  "devDependencies": {
39
- "nuxt": "^4.4.2",
40
- "tsdown": "^0.22.3",
40
+ "nuxt": "^4.5.2",
41
+ "tsdown": "^0.22.14",
41
42
  "typescript": "^6.0.3"
42
43
  }
43
44
  }
@@ -1,25 +1,71 @@
1
1
  import {
2
- reportError,
2
+ type AnalyticsExtension,
3
3
  WebAnalytics,
4
4
  type WebAnalyticsOptions,
5
5
  } from "@faststats/web";
6
+ import type { ErrorTrackingExtensionOptions } from "@faststats/web/error";
7
+ import type { SessionReplayExtensionOptions } from "@faststats/web/replay";
8
+ import type { WebVitalsExtensionOptions } from "@faststats/web/web-vitals";
6
9
  import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
7
10
 
11
+ type RuntimeOptions = Omit<WebAnalyticsOptions, "siteKey" | "extensions"> & {
12
+ siteKey?: string;
13
+ extensions?: {
14
+ outboundLinks?: boolean;
15
+ errorTracking?: boolean | ErrorTrackingExtensionOptions;
16
+ webVitals?: boolean | WebVitalsExtensionOptions;
17
+ sessionReplay?: boolean | SessionReplayExtensionOptions;
18
+ };
19
+ };
20
+
21
+ function extensionOptions<T>(value: boolean | T): T {
22
+ return (value === true ? {} : value) as T;
23
+ }
24
+
8
25
  function normalizeVueError(error: unknown, info?: string): Error {
9
26
  if (error instanceof Error) return error;
10
27
  const message = typeof error === "string" ? error : String(error);
11
28
  return new Error(info ? `${info}: ${message}` : message);
12
29
  }
13
30
 
14
- export default defineNuxtPlugin((nuxtApp) => {
15
- const runtime = useRuntimeConfig().public.faststats;
31
+ export default defineNuxtPlugin(async (nuxtApp) => {
32
+ const runtime = useRuntimeConfig().public.faststats as RuntimeOptions;
16
33
  if (!runtime?.siteKey) return;
34
+ const { extensions: configured = {}, siteKey, ...options } = runtime;
35
+ const extensions = (
36
+ await Promise.all([
37
+ configured.outboundLinks
38
+ ? import("@faststats/web/outbound-links").then(({ outboundLinks }) =>
39
+ outboundLinks(),
40
+ )
41
+ : undefined,
42
+ configured.errorTracking
43
+ ? import("@faststats/web/error").then(({ errorTracking }) =>
44
+ errorTracking(extensionOptions(configured.errorTracking)),
45
+ )
46
+ : undefined,
47
+ configured.webVitals
48
+ ? import("@faststats/web/web-vitals").then(({ webVitals }) =>
49
+ webVitals(extensionOptions(configured.webVitals)),
50
+ )
51
+ : undefined,
52
+ configured.sessionReplay
53
+ ? import("@faststats/web/replay").then(({ sessionReplay }) =>
54
+ sessionReplay(extensionOptions(configured.sessionReplay)),
55
+ )
56
+ : undefined,
57
+ ])
58
+ ).filter((extension): extension is AnalyticsExtension => !!extension);
17
59
 
18
- new WebAnalytics(runtime as WebAnalyticsOptions);
60
+ const analytics = new WebAnalytics({ ...options, siteKey, extensions });
61
+ analytics.start();
62
+ nuxtApp.provide("faststats", analytics);
19
63
 
20
- const previousErrorHandler = nuxtApp.vueApp.config.errorHandler;
21
- nuxtApp.vueApp.config.errorHandler = (error, instance, info) => {
22
- reportError(normalizeVueError(error, info));
23
- previousErrorHandler?.(error, instance, info);
24
- };
64
+ if (configured.errorTracking) {
65
+ const previousErrorHandler = nuxtApp.vueApp.config.errorHandler;
66
+ nuxtApp.vueApp.config.errorHandler = (error, instance, info) => {
67
+ analytics.reportError(normalizeVueError(error, info));
68
+ previousErrorHandler?.(error, instance, info);
69
+ };
70
+ }
25
71
  });