@faststats/nuxt 0.6.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 +14 -4
- package/dist/module.mjs +16 -11
- package/package.json +7 -6
- package/runtime/faststats.client.ts +53 -15
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
|
-
|
|
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,
|
|
17
|
+
export { ModuleOptions, faststatsModule as default };
|
package/dist/module.mjs
CHANGED
|
@@ -3,33 +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
|
-
|
|
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,
|
|
16
|
-
errorTracking: { enabled: true }
|
|
14
|
+
debug: false
|
|
17
15
|
},
|
|
18
16
|
setup(options, nuxt) {
|
|
19
17
|
const logger = useLogger("faststats");
|
|
20
|
-
const
|
|
18
|
+
const rootDir = fileURLToPath(new URL("..", import.meta.url));
|
|
19
|
+
const resolver = createResolver(rootDir);
|
|
21
20
|
addTypeTemplate({
|
|
22
21
|
filename: "types/faststats.d.ts",
|
|
23
|
-
getContents: () => `import type {
|
|
22
|
+
getContents: () => `import type { WebAnalytics } from '@faststats/web'
|
|
23
|
+
import type { ModuleOptions } from '@faststats/nuxt'
|
|
24
24
|
declare module 'nuxt/schema' {
|
|
25
25
|
interface PublicRuntimeConfig {
|
|
26
|
-
|
|
26
|
+
faststats: ModuleOptions
|
|
27
27
|
}
|
|
28
28
|
interface NuxtConfig {
|
|
29
|
-
|
|
29
|
+
faststats?: ModuleOptions
|
|
30
30
|
}
|
|
31
31
|
interface NuxtConfigInput {
|
|
32
|
-
|
|
32
|
+
faststats?: ModuleOptions
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
declare module '#app' {
|
|
36
|
+
interface NuxtApp {
|
|
37
|
+
$faststats: WebAnalytics
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
export {}
|
|
@@ -48,4 +53,4 @@ export {}
|
|
|
48
53
|
}
|
|
49
54
|
});
|
|
50
55
|
//#endregion
|
|
51
|
-
export {
|
|
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
|
+
"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.
|
|
35
|
-
"@nuxt/kit": "^4.
|
|
36
|
-
"
|
|
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.
|
|
40
|
-
"tsdown": "^0.22.
|
|
40
|
+
"nuxt": "^4.5.2",
|
|
41
|
+
"tsdown": "^0.22.14",
|
|
41
42
|
"typescript": "^6.0.3"
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -1,33 +1,71 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
reportError,
|
|
2
|
+
type AnalyticsExtension,
|
|
4
3
|
WebAnalytics,
|
|
5
4
|
type WebAnalyticsOptions,
|
|
6
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";
|
|
7
9
|
import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
|
|
8
10
|
|
|
9
|
-
type
|
|
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
|
+
};
|
|
11
19
|
};
|
|
12
20
|
|
|
21
|
+
function extensionOptions<T>(value: boolean | T): T {
|
|
22
|
+
return (value === true ? {} : value) as T;
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
function normalizeVueError(error: unknown, info?: string): Error {
|
|
14
26
|
if (error instanceof Error) return error;
|
|
15
27
|
const message = typeof error === "string" ? error : String(error);
|
|
16
28
|
return new Error(info ? `${info}: ${message}` : message);
|
|
17
29
|
}
|
|
18
30
|
|
|
19
|
-
export default defineNuxtPlugin((nuxtApp) => {
|
|
20
|
-
const runtime = useRuntimeConfig().public.faststats;
|
|
31
|
+
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
32
|
+
const runtime = useRuntimeConfig().public.faststats as RuntimeOptions;
|
|
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);
|
|
21
59
|
|
|
22
|
-
new WebAnalytics(
|
|
60
|
+
const analytics = new WebAnalytics({ ...options, siteKey, extensions });
|
|
61
|
+
analytics.start();
|
|
62
|
+
nuxtApp.provide("faststats", analytics);
|
|
23
63
|
|
|
24
|
-
if (
|
|
25
|
-
|
|
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
|
+
};
|
|
26
70
|
}
|
|
27
|
-
|
|
28
|
-
const previousErrorHandler = nuxtApp.vueApp.config.errorHandler;
|
|
29
|
-
nuxtApp.vueApp.config.errorHandler = (error, instance, info) => {
|
|
30
|
-
reportError(normalizeVueError(error, info));
|
|
31
|
-
previousErrorHandler?.(error, instance, info);
|
|
32
|
-
};
|
|
33
71
|
});
|