@faststats/nuxt 0.0.0-dev.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.
@@ -0,0 +1,8 @@
1
+ import * as nuxt_schema0 from "nuxt/schema";
2
+ import { WebAnalyticsOptions } from "@faststats/web";
3
+
4
+ //#region src/module.d.ts
5
+ type ModuleOptions = Partial<WebAnalyticsOptions>;
6
+ declare const _default: nuxt_schema0.NuxtModule<Partial<WebAnalyticsOptions>, Partial<WebAnalyticsOptions>, false>;
7
+ //#endregion
8
+ export { ModuleOptions, _default as default };
@@ -0,0 +1,48 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { addPlugin, addTypeTemplate, createResolver, defineNuxtModule, useLogger } from "@nuxt/kit";
3
+ import { defu } from "defu";
4
+ //#region src/module.ts
5
+ var module_default = defineNuxtModule({
6
+ meta: {
7
+ name: "@faststats/nuxt",
8
+ configKey: "faststats"
9
+ },
10
+ defaults: {
11
+ baseUrl: "https://metrics.faststats.dev",
12
+ debug: false,
13
+ autoTrack: true,
14
+ trackErrors: true,
15
+ trackWebVitals: true,
16
+ trackReplay: true
17
+ },
18
+ setup(options, nuxt) {
19
+ const logger = useLogger("faststats");
20
+ const resolver = createResolver(fileURLToPath(new URL("..", import.meta.url)));
21
+ addTypeTemplate({
22
+ filename: "types/faststats.d.ts",
23
+ getContents: () => `import type { WebAnalyticsOptions } from '@faststats/web'
24
+ declare module 'nuxt/schema' {
25
+ interface PublicRuntimeConfig {
26
+ faststats: WebAnalyticsOptions
27
+ }
28
+ interface NuxtConfig {
29
+ faststats?: Partial<WebAnalyticsOptions>
30
+ }
31
+ interface NuxtConfigInput {
32
+ faststats?: Partial<WebAnalyticsOptions>
33
+ }
34
+ }
35
+ export {}
36
+ `
37
+ });
38
+ const merged = defu(nuxt.options.runtimeConfig.public.faststats, options);
39
+ nuxt.options.runtimeConfig.public.faststats = merged;
40
+ if (!merged.siteKey) logger.warn("Missing `faststats.siteKey`. Set `faststats.siteKey` in nuxt.config or `NUXT_PUBLIC_FASTSTATS_SITE_KEY`.");
41
+ addPlugin({
42
+ src: resolver.resolve("./runtime/faststats.client.ts"),
43
+ mode: "client"
44
+ });
45
+ }
46
+ });
47
+ //#endregion
48
+ export { module_default as default };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@faststats/nuxt",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "https://github.com/faststats-dev/web-analytics.git"
6
+ },
7
+ "version": "0.0.0-dev.0",
8
+ "type": "module",
9
+ "main": "./dist/module.mjs",
10
+ "types": "./dist/module.d.mts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/module.d.mts",
14
+ "import": "./dist/module.mjs",
15
+ "default": "./dist/module.mjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "runtime"
21
+ ],
22
+ "sideEffects": false,
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "build": "tsdown",
28
+ "typecheck": "tsc --noEmit -p tsconfig.json"
29
+ },
30
+ "peerDependencies": {
31
+ "nuxt": "^3.12.0 || ^4.0.0"
32
+ },
33
+ "dependencies": {
34
+ "@faststats/web": "^0.1.4",
35
+ "@nuxt/kit": "^4.4.0",
36
+ "defu": "^6.1.4"
37
+ },
38
+ "devDependencies": {
39
+ "nuxt": "^4.4.2",
40
+ "tsdown": "^0.21.4",
41
+ "typescript": "^5.9.3"
42
+ }
43
+ }
@@ -0,0 +1,33 @@
1
+ import {
2
+ getInstance,
3
+ reportError,
4
+ WebAnalytics,
5
+ type WebAnalyticsOptions,
6
+ } from "@faststats/web";
7
+ import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
8
+
9
+ function normalizeVueError(error: unknown, info?: string): Error {
10
+ if (error instanceof Error) return error;
11
+ const message = typeof error === "string" ? error : String(error);
12
+ return new Error(info ? `${info}: ${message}` : message);
13
+ }
14
+
15
+ export default defineNuxtPlugin((nuxtApp) => {
16
+ const runtime = useRuntimeConfig().public.faststats;
17
+
18
+ new WebAnalytics(runtime as WebAnalyticsOptions);
19
+
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
+ };
25
+
26
+ if (typeof window !== "undefined") {
27
+ (
28
+ window as Window & { __faststats?: { getInstance: typeof getInstance } }
29
+ ).__faststats = {
30
+ getInstance,
31
+ };
32
+ }
33
+ });