@wervt/nuxt 0.2.11 → 0.2.12

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/README.md CHANGED
@@ -19,6 +19,7 @@ export default defineNuxtConfig({
19
19
  - `proxyShape()` (server) and `useShape()` (app): live rows from Postgres via Electric.
20
20
  - `useWervtUser()`: the signed-in wervt user, on the server and in the app.
21
21
  - `useValidatedBody()` / `useValidatedQuery()` / `useValidatedParams()`: valibot validation.
22
+ - `useWervtTrack()`: custom events for wervt's cookieless analytics (page views are counted automatically).
22
23
  - `defineTool()` (server): tools in `server/tools/` that browser agents call through WebMCP.
23
24
  - `nuxt dev` starts against the local wervt stack (Postgres, Electric) and a dev user.
24
25
 
package/dist/module.d.ts CHANGED
@@ -18,6 +18,12 @@ export interface ModuleOptions {
18
18
  * Defaults to true; `false` leaves them out of the build.
19
19
  */
20
20
  webmcp?: boolean;
21
+ /**
22
+ * Reports client-side navigations and `useWervtTrack()` events to wervt's usage analytics, so
23
+ * page views count more than the first load. Defaults to true. Cookieless; page loads are
24
+ * counted by the runtime either way.
25
+ */
26
+ analytics?: boolean;
21
27
  }
22
28
  /** `server/wervt-tasks.json` in the build: the app's tasks and schedules, for the control plane. */
23
29
  export interface TasksManifest {
package/dist/module.js CHANGED
@@ -221,6 +221,17 @@ var module_default = defineNuxtModule({
221
221
  mode: "client"
222
222
  });
223
223
  }
224
+ if (options.analytics !== false && !nuxt.options.dev) {
225
+ const config = nuxt.options.runtimeConfig.public;
226
+ config.wervt = {
227
+ ...config.wervt,
228
+ analytics: true
229
+ };
230
+ addPlugin({
231
+ src: resolver.resolve("./runtime/app/plugins/analytics.client"),
232
+ mode: "client"
233
+ });
234
+ }
224
235
  nuxt.options.build.transpile.push(resolver.resolve("./runtime"));
225
236
  addImports([
226
237
  {
@@ -231,6 +242,10 @@ var module_default = defineNuxtModule({
231
242
  name: "useWervtUser",
232
243
  from: resolver.resolve("./runtime/app/useWervtUser")
233
244
  },
245
+ {
246
+ name: "useWervtTrack",
247
+ from: resolver.resolve("./runtime/app/useWervtTrack")
248
+ },
234
249
  {
235
250
  name: "wervtLoginUrl",
236
251
  from: resolver.resolve("./runtime/app/useWervtUser")
@@ -0,0 +1,4 @@
1
+ //#region src/runtime/app/plugins/analytics.client.d.ts
2
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
3
+ //#endregion
4
+ export { _default as default };
@@ -0,0 +1,16 @@
1
+ import { defineNuxtPlugin, useRouter, useRuntimeConfig } from "#app";
2
+ //#region src/runtime/app/plugins/analytics.client.ts
3
+ var analytics_client_default = defineNuxtPlugin({
4
+ name: "wervt:analytics",
5
+ setup() {
6
+ const router = useRouter();
7
+ const base = useRuntimeConfig().app.baseURL.replace(/\/$/, "");
8
+ router.afterEach((to, from, failure) => {
9
+ if (failure || !from.matched.length || to.path === from.path) return;
10
+ const body = new Blob([JSON.stringify({ path: `${base}${to.path}` })], { type: "application/json" });
11
+ navigator.sendBeacon?.(`${base}/_wervt/view`, body);
12
+ });
13
+ }
14
+ });
15
+ //#endregion
16
+ export { analytics_client_default as default };
@@ -0,0 +1,9 @@
1
+ //#region src/runtime/app/useWervtTrack.d.ts
2
+ /**
3
+ * Custom events for wervt's analytics, e.g. `track('signup')` or `track('click', url)`. They
4
+ * show up with their counts and visitors in the dashboard and `wervt stats`. Like page views
5
+ * they are cookieless: only the event, its label and the current path are sent. Does nothing
6
+ * in `nuxt dev`, during SSR and with `wervt.analytics: false`.
7
+ */
8
+ export declare function useWervtTrack(): (name: string, label?: string) => void;
9
+ //#endregion
@@ -0,0 +1,24 @@
1
+ import { useRuntimeConfig } from "#app";
2
+ //#region src/runtime/app/useWervtTrack.ts
3
+ /**
4
+ * Custom events for wervt's analytics, e.g. `track('signup')` or `track('click', url)`. They
5
+ * show up with their counts and visitors in the dashboard and `wervt stats`. Like page views
6
+ * they are cookieless: only the event, its label and the current path are sent. Does nothing
7
+ * in `nuxt dev`, during SSR and with `wervt.analytics: false`.
8
+ */
9
+ function useWervtTrack() {
10
+ const config = useRuntimeConfig();
11
+ const enabled = config.public.wervt?.analytics;
12
+ const base = config.app.baseURL.replace(/\/$/, "");
13
+ return (name, label) => {
14
+ if (!enabled || import.meta.server || typeof navigator === "undefined") return;
15
+ const body = JSON.stringify({
16
+ path: location.pathname,
17
+ name,
18
+ label
19
+ });
20
+ navigator.sendBeacon?.(`${base}/_wervt/view`, new Blob([body], { type: "application/json" }));
21
+ };
22
+ }
23
+ //#endregion
24
+ export { useWervtTrack };
@@ -3,8 +3,8 @@ declare const _default: import("nuxt/server").EventHandler<{
3
3
  error: string;
4
4
  ok?: undefined;
5
5
  } | {
6
- error?: undefined;
7
6
  ok: boolean;
7
+ error?: undefined;
8
8
  }>;
9
9
  //#endregion
10
10
  export { _default as default };
@@ -3,8 +3,8 @@ declare const _default: import("nuxt/server").EventHandler<Promise<{
3
3
  error: string;
4
4
  result?: undefined;
5
5
  } | {
6
- error?: undefined;
7
6
  result: {} | null;
7
+ error?: undefined;
8
8
  }>>;
9
9
  //#endregion
10
10
  export { _default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wervt/nuxt",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Nuxt module for apps hosted on wervt: database, live data and runtime setup.",
5
5
  "keywords": [
6
6
  "drizzle",