@valbuild/tanstack 0.148.2 → 0.148.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # @valbuild/tanstack
2
2
 
3
+ ## 0.148.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#881](https://github.com/valbuild/val/pull/881) [`0139436`](https://github.com/valbuild/val/commit/0139436426142d91cbb29ec6c696dfb86f34ab9d) Thanks [@freekh](https://github.com/freekh)! - The content analytics script. With analytics on (it is off by default, and turned on in a hosted project's settings), a TanStack site counts which content each visitor's page **rendered** and which they actually **viewed** (at least half on screen for a second), and sends it to `/api/val/analytics`.
8
+
9
+ - No cookies, no storage, no visitor IDs. Each page view also says where it came from (the referring site's host and any `utm_source` / `utm_medium` / `utm_campaign`) and whether it was a phone, tablet or desktop.
10
+ - A page is sent as its route's pattern (`/posts/$postId`), never its address, so a path that holds something about one visitor (an order number, a token) is never stored. `startValAnalytics` takes this as `routeFor`; `ValProvider` passes TanStack's matched route.
11
+ - Editors are never counted: nothing is sent in draft mode, in the Studio, with Val enabled, or at a proposal's address, and nothing from automated browsers. A page the browser prerenders counts nothing until it is shown.
12
+ - The script is the new `@valbuild/react/analytics` entry, loaded only for visitors of a site with analytics on, after the page has hydrated. It imports nothing else from Val.
13
+ - Storing the counts and showing them is part of Val's hosting, which takes these beacons before they reach the site. Anywhere else, `/api/val/analytics` checks each beacon and stores nothing; in local development, with `VAL_DEBUG=1`, it logs a line per beacon, so you can see it working.
14
+ - `ValProvider`'s Studio check now matches `/val` and what is below it only, not every route starting with those letters (`/values`). The same fix is in `@valbuild/next`.
15
+
16
+ - [#887](https://github.com/valbuild/val/pull/887) [`eaa77e0`](https://github.com/valbuild/val/commit/eaa77e0e5028b113037e76722e25e342a8301032) Thanks [@freekh](https://github.com/freekh)! - Content analytics records the content version each page was rendered from. `<ValProvider analytics>` takes a `ValAnalytics` -- `{ enabled, contentVersion? }` -- and the `val.server.ts` Val's hosting writes returns one from `fetchValAnalytics()`, with the id of the content version the platform is serving. Every beacon carries it as `cv`, so counts can be compared across a publish. The site layout passes `fetchValAnalytics()` to the provider exactly as before.
17
+
18
+ - [#878](https://github.com/valbuild/val/pull/878) [`4d862ce`](https://github.com/valbuild/val/commit/4d862cec40288ecbc415c3c3b8d792ddd6bc1ca3) Thanks [@freekh](https://github.com/freekh)! - TanStack Start: a new analytics mode, the first step towards content analytics. It is off by default. With `<ValProvider analytics>`, content read with the hooks (`useVal`, `useValRoute`, `useValKey`) is tagged for every visitor, not only in draft mode, so each element showing content carries a `data-val-path`. The tags are added in the browser after hydration, so the HTML the server sends is unchanged and a crawler that does not run the page never sees them.
19
+
20
+ On a site hosted by Val, analytics is a project setting: the owner turns it on in the project's settings, and the `val.server.ts` the platform writes now exports `fetchValAnalytics()` to read it. Pass it to the provider from the site layout's loader, beside `fetchValDraft()`; see the README.
21
+
22
+ - [#896](https://github.com/valbuild/val/pull/896) [`5eff8a0`](https://github.com/valbuild/val/commit/5eff8a055a4ef50d476797c28f9c3e50deb73c89) Thanks [@freekh](https://github.com/freekh)! - A demo's tour can now be written by the site: `<ValApp demo={{ tour }}>`, with each step as data (`ValDemoTourStep`), so what it says changes with the site rather than with a Val release.
23
+
24
+ It is drawn as a ring around what a step is about, with nothing dimmed and the Studio usable underneath, and a step can move on by itself once the visitor has done what it asks:
25
+
26
+ ```ts
27
+ const tour: ValDemoTourStep[] = [
28
+ {
29
+ id: "click",
30
+ title: "This is Val",
31
+ body: "Click the heading on the page.",
32
+ target: "canvas",
33
+ page: HEADING, // outlined on the page
34
+ moveOn: { open: HEADING },
35
+ },
36
+ {
37
+ id: "type",
38
+ title: "Change a word",
39
+ body: "The page changes as you type.",
40
+ field: HEADING, // ringed wherever the field is shown
41
+ moveOn: {
42
+ edit: true,
43
+ path: HEADING,
44
+ value: "Coffee, roasted this weekend",
45
+ },
46
+ },
47
+ ];
48
+ ```
49
+
50
+ A step that moves on has **Do it for me**, which does it the way the Studio would, and **Skip**. On a phone the card is a sheet along the bottom. The Studio's own tour is unchanged.
51
+
52
+ - Updated dependencies [[`0139436`](https://github.com/valbuild/val/commit/0139436426142d91cbb29ec6c696dfb86f34ab9d), [`5eff8a0`](https://github.com/valbuild/val/commit/5eff8a055a4ef50d476797c28f9c3e50deb73c89)]:
53
+ - @valbuild/react@0.148.3
54
+ - @valbuild/shared@0.148.3
55
+ - @valbuild/server@0.148.3
56
+ - @valbuild/ui@0.148.3
57
+ - @valbuild/language-server@0.148.3
58
+ - @valbuild/mcp@0.148.3
59
+
3
60
  ## 0.148.2
4
61
 
5
62
  ### Patch Changes
package/README.md CHANGED
@@ -381,6 +381,58 @@ nothing for it. It needs React 19 and a `<Suspense>` boundary (see above). With
381
381
  `draft` given, the server already has that page's content, so its first render
382
382
  does not 404 either.
383
383
 
384
+ ## Content analytics
385
+
386
+ Val can count which content your visitors see, on a site Val hosts. It is
387
+ **off by default**, and a setting of the hosted project rather than of the
388
+ code: the owner turns it on in the project's settings, and Val's hosting hands
389
+ it to the site as the `VAL_ANALYTICS` variable, along with the id of the
390
+ content version each page is rendered from. The `val.server.ts` the platform
391
+ writes for a hosted project exports `fetchValAnalytics()`, which reads both
392
+ into a `ValAnalytics`; pass that to the provider from the same loader as the
393
+ draft:
394
+
395
+ ```tsx
396
+ // src/routes/_site.tsx
397
+ const getValPage = createServerFn().handler(async () => {
398
+ const [draft, analytics] = await Promise.all([
399
+ fetchValDraft(),
400
+ fetchValAnalytics(),
401
+ ]);
402
+ return { draft, analytics };
403
+ });
404
+
405
+ function SiteLayout() {
406
+ const page = Route.useLoaderData();
407
+ return (
408
+ <ValProvider
409
+ config={config}
410
+ suspend
411
+ draft={page?.draft}
412
+ analytics={page?.analytics}
413
+ >
414
+ {/* ... */}
415
+ </ValProvider>
416
+ );
417
+ }
418
+ ```
419
+
420
+ With it on, content read with the hooks is tagged for every visitor after
421
+ hydration, so each element showing content carries a `data-val-path` to count.
422
+ The HTML the server sends is the same with it on or off. A small script,
423
+ loaded after hydration, then counts what each page rendered and what was on
424
+ screen, and sends it to `/api/val/analytics` with the content version, so a
425
+ page can be compared before and after a publish. No cookies, no storage and no
426
+ visitor IDs, and nothing is sent in draft mode, in the Studio or from an
427
+ automated browser.
428
+
429
+ `fetchValAnalytics` is not part of `initValContent`: it exists in the file the
430
+ platform writes, and nowhere else. A site Val does not host has nowhere to send
431
+ counts yet, so it leaves `analytics` out. To see the mode working in local
432
+ development, write your own -- `examples/tanstack/src/val/server.ts` reads
433
+ `VAL_ANALYTICS` from `process.env`, which TanStack Start fills from
434
+ `.env.development`.
435
+
384
436
  ## Images
385
437
 
386
438
  `ValImage` is a plain `<img>` that keeps the edit tags where the Studio can see
@@ -417,6 +469,7 @@ SDK of your choice. See [`@valbuild/mcp`](https://www.npmjs.com/package/@valbuil
417
469
  | `ValImage` wraps `next/image` | `ValImage` is an `<img>` |
418
470
  | `fetchVal` in a Server Component | hooks in components; `createServerFn` for loaders |
419
471
  | client hooks render published SSR | `ValProvider draft` renders the draft during SSR |
472
+ | no content analytics yet | `ValProvider analytics` (hosted projects only) |
420
473
 
421
474
  ## Schema reference
422
475
 
@@ -6,7 +6,7 @@ var _typeof = require('../../dist/typeof-dd0246a1.cjs.dev.js');
6
6
  var core = require('@valbuild/core');
7
7
  var stega = require('@valbuild/react/stega');
8
8
  var React = require('react');
9
- var ValOverlayContext = require('../../dist/ValOverlayContext-e5de843b.cjs.dev.js');
9
+ var ValOverlayContext = require('../../dist/ValOverlayContext-198b4bd1.cjs.dev.js');
10
10
  var routeFromVal = require('../../dist/routeFromVal-2f65a4fc.cjs.dev.js');
11
11
  require('@valbuild/core/patch');
12
12
  require('react/jsx-runtime');
@@ -46,6 +46,11 @@ function useHydrated() {
46
46
  * the draft text goes out without them, and the render React does right after
47
47
  * hydrating the component puts them in.
48
48
  *
49
+ * With analytics on and draft mode off, the same rule for every visitor: no
50
+ * tags on the server or while hydrating, tags from the render after. So the
51
+ * HTML a visitor is sent, prerendered or not, is the same with analytics on or
52
+ * off, and no edit tag ever reaches a crawler that does not run the page.
53
+ *
49
54
  * Because JSX auto-tagging turns a tagged string into a `data-val-path`
50
55
  * attribute as the element is created, and the switch for it is process-wide.
51
56
  * The server cannot be relied on to tag (whether the patched JSX runtime is
@@ -57,7 +62,10 @@ function useHydrated() {
57
62
  */
58
63
  function useEncodesEditTags(context) {
59
64
  var hydrated = useHydrated();
60
- return !!context.draftMode && (!context.serverDraft || hydrated);
65
+ if (context.draftMode) {
66
+ return !context.serverDraft || hydrated;
67
+ }
68
+ return !!context.analytics && hydrated;
61
69
  }
62
70
 
63
71
  /** What `useVal` gives back — see `ResolvedVal` in `@valbuild/react/stega`. */
@@ -6,7 +6,7 @@ var _typeof = require('../../dist/typeof-8998e126.cjs.prod.js');
6
6
  var core = require('@valbuild/core');
7
7
  var stega = require('@valbuild/react/stega');
8
8
  var React = require('react');
9
- var ValOverlayContext = require('../../dist/ValOverlayContext-98f8e877.cjs.prod.js');
9
+ var ValOverlayContext = require('../../dist/ValOverlayContext-d9b22d1a.cjs.prod.js');
10
10
  var routeFromVal = require('../../dist/routeFromVal-a13ac8a3.cjs.prod.js');
11
11
  require('@valbuild/core/patch');
12
12
  require('react/jsx-runtime');
@@ -46,6 +46,11 @@ function useHydrated() {
46
46
  * the draft text goes out without them, and the render React does right after
47
47
  * hydrating the component puts them in.
48
48
  *
49
+ * With analytics on and draft mode off, the same rule for every visitor: no
50
+ * tags on the server or while hydrating, tags from the render after. So the
51
+ * HTML a visitor is sent, prerendered or not, is the same with analytics on or
52
+ * off, and no edit tag ever reaches a crawler that does not run the page.
53
+ *
49
54
  * Because JSX auto-tagging turns a tagged string into a `data-val-path`
50
55
  * attribute as the element is created, and the switch for it is process-wide.
51
56
  * The server cannot be relied on to tag (whether the patched JSX runtime is
@@ -57,7 +62,10 @@ function useHydrated() {
57
62
  */
58
63
  function useEncodesEditTags(context) {
59
64
  var hydrated = useHydrated();
60
- return !!context.draftMode && (!context.serverDraft || hydrated);
65
+ if (context.draftMode) {
66
+ return !context.serverDraft || hydrated;
67
+ }
68
+ return !!context.analytics && hydrated;
61
69
  }
62
70
 
63
71
  /** What `useVal` gives back — see `ResolvedVal` in `@valbuild/react/stega`. */
@@ -2,7 +2,7 @@ import { c as _typeof } from '../../dist/typeof-66e2d869.esm.js';
2
2
  import { Internal } from '@valbuild/core';
3
3
  import { getModuleIds, stegaEncode } from '@valbuild/react/stega';
4
4
  import React from 'react';
5
- import { u as useValOverlayContext } from '../../dist/ValOverlayContext-2837c67f.esm.js';
5
+ import { u as useValOverlayContext } from '../../dist/ValOverlayContext-6411bbe3.esm.js';
6
6
  import { j as jsonValuesRecordToFill, f as fillJsonValuesRecord, g as getJsonEntryStegaRoot, b as bundledJsonEntryImport, i as isJsonValuesRecordSchema, a as getValRouteUrlFromVal, c as initValRouteFromVal } from '../../dist/routeFromVal-40cd8a5b.esm.js';
7
7
  import '@valbuild/core/patch';
8
8
  import 'react/jsx-runtime';
@@ -38,6 +38,11 @@ function useHydrated() {
38
38
  * the draft text goes out without them, and the render React does right after
39
39
  * hydrating the component puts them in.
40
40
  *
41
+ * With analytics on and draft mode off, the same rule for every visitor: no
42
+ * tags on the server or while hydrating, tags from the render after. So the
43
+ * HTML a visitor is sent, prerendered or not, is the same with analytics on or
44
+ * off, and no edit tag ever reaches a crawler that does not run the page.
45
+ *
41
46
  * Because JSX auto-tagging turns a tagged string into a `data-val-path`
42
47
  * attribute as the element is created, and the switch for it is process-wide.
43
48
  * The server cannot be relied on to tag (whether the patched JSX runtime is
@@ -49,7 +54,10 @@ function useHydrated() {
49
54
  */
50
55
  function useEncodesEditTags(context) {
51
56
  var hydrated = useHydrated();
52
- return !!context.draftMode && (!context.serverDraft || hydrated);
57
+ if (context.draftMode) {
58
+ return !context.serverDraft || hydrated;
59
+ }
60
+ return !!context.analytics && hydrated;
53
61
  }
54
62
 
55
63
  /** What `useVal` gives back — see `ResolvedVal` in `@valbuild/react/stega`. */
@@ -275,6 +275,7 @@ function ValOverlayProvider(_ref) {
275
275
  draftModeReady = _ref.draftModeReady,
276
276
  draftSourcesSynced = _ref.draftSourcesSynced,
277
277
  serverDraft = _ref.serverDraft,
278
+ analytics = _ref.analytics,
278
279
  snapshot = _ref.snapshot,
279
280
  children = _ref.children;
280
281
  return /*#__PURE__*/jsxRuntime.jsx(ValOverlayContext.Provider, {
@@ -285,6 +286,7 @@ function ValOverlayProvider(_ref) {
285
286
  draftModeReady: draftModeReady,
286
287
  draftSourcesSynced: draftSourcesSynced,
287
288
  serverDraft: serverDraft,
289
+ analytics: analytics,
288
290
  snapshot: snapshot
289
291
  },
290
292
  children: children
@@ -269,6 +269,7 @@ function ValOverlayProvider(_ref) {
269
269
  draftModeReady = _ref.draftModeReady,
270
270
  draftSourcesSynced = _ref.draftSourcesSynced,
271
271
  serverDraft = _ref.serverDraft,
272
+ analytics = _ref.analytics,
272
273
  snapshot = _ref.snapshot,
273
274
  children = _ref.children;
274
275
  return /*#__PURE__*/jsx(ValOverlayContext.Provider, {
@@ -279,6 +280,7 @@ function ValOverlayProvider(_ref) {
279
280
  draftModeReady: draftModeReady,
280
281
  draftSourcesSynced: draftSourcesSynced,
281
282
  serverDraft: serverDraft,
283
+ analytics: analytics,
282
284
  snapshot: snapshot
283
285
  },
284
286
  children: children
@@ -275,6 +275,7 @@ function ValOverlayProvider(_ref) {
275
275
  draftModeReady = _ref.draftModeReady,
276
276
  draftSourcesSynced = _ref.draftSourcesSynced,
277
277
  serverDraft = _ref.serverDraft,
278
+ analytics = _ref.analytics,
278
279
  snapshot = _ref.snapshot,
279
280
  children = _ref.children;
280
281
  return /*#__PURE__*/jsxRuntime.jsx(ValOverlayContext.Provider, {
@@ -285,6 +286,7 @@ function ValOverlayProvider(_ref) {
285
286
  draftModeReady: draftModeReady,
286
287
  draftSourcesSynced: draftSourcesSynced,
287
288
  serverDraft: serverDraft,
289
+ analytics: analytics,
288
290
  snapshot: snapshot
289
291
  },
290
292
  children: children
@@ -0,0 +1,23 @@
1
+ /**
2
+ * What `<ValProvider analytics>` is handed: whether content analytics is on
3
+ * for this site, and the content version the page is rendered from.
4
+ *
5
+ * Both come from the server, read in the site layout's loader. On a site Val
6
+ * hosts, `fetchValAnalytics()` in the `val.server.ts` the platform writes
7
+ * reads them from what the platform hands each render: the project's
8
+ * `VAL_ANALYTICS` setting, and `VAL_CONTENT_VERSION`, the id of the content
9
+ * version being served.
10
+ */
11
+ export type ValAnalytics = {
12
+ /** Off unless this says so. */
13
+ enabled: boolean;
14
+ /**
15
+ * The id of the content version this page is rendered from. Every count is
16
+ * stored with it, which is what lets a dashboard compare a page before and
17
+ * after a publish, and name what was at an array position on a given day.
18
+ *
19
+ * Left out where there is no such id -- outside Val's hosting -- and the
20
+ * counts then carry none.
21
+ */
22
+ contentVersion?: string;
23
+ };
@@ -1,5 +1,6 @@
1
1
  import { ValConfig } from "@valbuild/core";
2
2
  import { type ReactNode } from "react";
3
+ import type { ValDemoOptions } from "@valbuild/shared/internal";
3
4
  export declare const ValApp: ({ config, children, demo, }: {
4
5
  config: ValConfig;
5
6
  children?: ReactNode;
@@ -15,6 +16,10 @@ export declare const ValApp: ({ config, children, demo, }: {
15
16
  *
16
17
  * Set it from the build -- `demo={import.meta.env.VITE_VAL_DEMO === "true"}`
17
18
  * -- never from anything a visitor controls.
19
+ *
20
+ * Options instead of `true` give the demo a tour of the site's own:
21
+ * `demo={{ tour }}`, steps written as data (`ValDemoTourStep`), so what it
22
+ * says changes with the site rather than with a Val release.
18
23
  */
19
- demo?: boolean;
24
+ demo?: boolean | ValDemoOptions;
20
25
  }) => import("react").JSX.Element;
@@ -4,5 +4,6 @@ export declare const ValProvider: (props: {
4
4
  disableRefresh?: boolean;
5
5
  suspend?: boolean;
6
6
  draft?: import("./ValDraft.js").ValDraft | null;
7
+ analytics?: import("./ValAnalytics.js").ValAnalytics | null;
7
8
  demo?: boolean;
8
9
  }) => import("react").JSX.Element;
@@ -16,9 +16,12 @@ export { ValRichText } from "@valbuild/react/internal";
16
16
  export { type ValEncodedString, type File, type Image, type Video, type RichText, } from "@valbuild/react/stega";
17
17
  export { ValProvider } from "./ValProvider.js";
18
18
  export type { ValDraft } from "./ValDraft.js";
19
+ export type { ValAnalytics } from "./ValAnalytics.js";
19
20
  export { ValImage, type ValImageProps } from "./ValImage.js";
20
21
  export { ValVideo, type ValVideoProps } from "./ValVideo.js";
21
22
  export { ValApp } from "./ValApp.js";
23
+ /** What `<ValApp demo={{ tour }}>` takes. See `ValDemoTourStep`. */
24
+ export type { ValDemoOptions, ValDemoTourStep, ValDemoTourMoveOn, ValDemoTourTarget, ValDemoTourPanel, } from "@valbuild/shared/internal";
22
25
  export { ValModulesClient, useRegisterValModules } from "./ValModulesClient.js";
23
26
  import { Internal as InternalCore } from "@valbuild/core";
24
27
  import { VERSION } from "./version.js";
@@ -3,6 +3,7 @@ export { InMemoryPatchStore, type ValPatchStore } from "@valbuild/server";
3
3
  export type { ValHttpMode } from "./initValServer.js";
4
4
  export { initValContent } from "./initValContent.js";
5
5
  export type { ValDraft } from "../ValDraft.js";
6
+ export type { ValAnalytics } from "../ValAnalytics.js";
6
7
  export { valDraftMode, hasValEnableCookieOnServer, VAL_DRAFT_MODE_COOKIE, type ValDraftMode, } from "./valDraftMode.js";
7
8
  export { initValMcp } from "./initValMcp.js";
8
9
  export { createPrettierFormatter, type PrettierLike, type ValFormatter, } from "@valbuild/server";
@@ -6,12 +6,12 @@ var asyncToGenerator = require('./asyncToGenerator-c3823d62.cjs.dev.js');
6
6
  var _typeof = require('./typeof-dd0246a1.cjs.dev.js');
7
7
  var core = require('@valbuild/core');
8
8
  var stega = require('@valbuild/react/stega');
9
- var version = require('./version-2d885c7d.cjs.dev.js');
9
+ var version = require('./version-f0497731.cjs.dev.js');
10
10
  var internal = require('@valbuild/react/internal');
11
11
  var ui = require('@valbuild/ui');
12
12
  var reactRouter = require('@tanstack/react-router');
13
13
  var React = require('react');
14
- var ValOverlayContext = require('./ValOverlayContext-e5de843b.cjs.dev.js');
14
+ var ValOverlayContext = require('./ValOverlayContext-198b4bd1.cjs.dev.js');
15
15
  var client = require('@valbuild/shared/client');
16
16
  var jsxRuntime = require('react/jsx-runtime');
17
17
  var demoServiceWorker = require('./demoServiceWorker-382e1b63.cjs.dev.js');
@@ -951,7 +951,7 @@ var DRAFT_HANDSHAKE_POLL_MS = 100;
951
951
  */
952
952
  var DRAFT_HANDSHAKE_TIMEOUT_MS = 10000;
953
953
  var ValTanStackProvider = function ValTanStackProvider(props) {
954
- var _props$draft, _draftModeReady$curre2;
954
+ var _props$draft, _props$analytics, _draftModeReady$curre2;
955
955
  // TODO: use config:
956
956
  var route = "/api/val";
957
957
  /**
@@ -1006,6 +1006,14 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1006
1006
  * not a draft: it must not turn draft mode on or say the draft is synced.
1007
1007
  */
1008
1008
  var hasDraft = initialDraft !== null && initialDraft.draftMode !== false;
1009
+ /*
1010
+ * As the page was rendered. A ref, not the prop, for the reason
1011
+ * `initialDraft` is one: a later render's prop is a client navigation's
1012
+ * loader, which reads nothing.
1013
+ */
1014
+ var analyticsSetting = React__default["default"].useRef((_props$analytics = props.analytics) !== null && _props$analytics !== void 0 ? _props$analytics : null).current;
1015
+ var analytics = (analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.enabled) === true;
1016
+ var contentVersion = analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.contentVersion;
1009
1017
  var snapshot = initialDraft === null || initialDraft === void 0 ? void 0 : initialDraft.snapshot;
1010
1018
  /*
1011
1019
  * The base the Studio's overlay must start from, where it is not the
@@ -1177,6 +1185,54 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1177
1185
  setIsCanvas(client.isValCanvasFrame(location.search, readParentPathname()));
1178
1186
  setMountOverlay(hasValEnableCookie(document.cookie));
1179
1187
  }, []);
1188
+
1189
+ /**
1190
+ * The analytics script, for a visitor and nobody else.
1191
+ *
1192
+ * `mountOverlay === false` is "known not to be an editor": no Val enable
1193
+ * cookie, so no draft mode and no canvas. A page the server rendered from a
1194
+ * draft is an editor's too, whatever the enable cookie says -- the draft
1195
+ * mode cookie can outlive it. So is one at a proposal's address, which
1196
+ * comes with a snapshot: its content is not published, and counting it
1197
+ * would credit the live site with it. The Studio's own pages count nothing
1198
+ * either. Loaded with a dynamic import after hydration, so a site
1199
+ * with analytics off never downloads it, and one with it on downloads it
1200
+ * off the critical path. It imports nothing from core, shared or zod.
1201
+ */
1202
+ React__default["default"].useEffect(function () {
1203
+ if (!analytics || mountOverlay !== false || hasDraft || snapshot !== undefined || isCanvas || isValStudioPath(location.pathname)) {
1204
+ return;
1205
+ }
1206
+ // Where the page was hydrated, read now: the script loads later, and the
1207
+ // visitor may have moved on by then. See `landingPath`.
1208
+ var landingPath = location.pathname;
1209
+ var cancelled = false;
1210
+ var tracker = null;
1211
+ Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@valbuild/react/analytics')); }).then(function (_ref2) {
1212
+ var startValAnalytics = _ref2.startValAnalytics;
1213
+ if (!cancelled) {
1214
+ tracker = startValAnalytics({
1215
+ endpoint: "".concat(route, "/analytics"),
1216
+ landingPath: landingPath,
1217
+ contentVersion: contentVersion,
1218
+ // The route's pattern (`/posts/$postId`), never the pathname,
1219
+ // which can hold something about one visitor. A pathname no
1220
+ // route matches is not a page of the site.
1221
+ routeFor: function routeFor(pathname) {
1222
+ var _router$getMatchedRou, _router$getMatchedRou2;
1223
+ return (_router$getMatchedRou = (_router$getMatchedRou2 = router.getMatchedRoutes(pathname)[2]) === null || _router$getMatchedRou2 === void 0 ? void 0 : _router$getMatchedRou2.fullPath) !== null && _router$getMatchedRou !== void 0 ? _router$getMatchedRou : "(not found)";
1224
+ }
1225
+ });
1226
+ }
1227
+ })["catch"](function (error) {
1228
+ core.Internal.log.warn("could not load analytics", error);
1229
+ });
1230
+ return function () {
1231
+ var _tracker;
1232
+ cancelled = true;
1233
+ (_tracker = tracker) === null || _tracker === void 0 || _tracker.stop();
1234
+ };
1235
+ }, [analytics, contentVersion, mountOverlay, hasDraft, snapshot, isCanvas, route, router]);
1180
1236
  React__default["default"].useEffect(function () {
1181
1237
  // Activate the Suspense gate after hydration. Inside a transition so
1182
1238
  // already-visible (static) content stays on screen while useValStega
@@ -1456,8 +1512,14 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1456
1512
  }, [mountOverlay, draftMode, spaReady]);
1457
1513
  React__default["default"].useEffect(function () {
1458
1514
  if (!mountOverlay) {
1459
- stega.SET_AUTO_TAG_JSX_ENABLED(false);
1515
+ // A visitor: only analytics tags content, and only after hydration
1516
+ // (`useEncodesEditTags`), so this cannot reach a component still
1517
+ // hydrating either.
1518
+ stega.SET_AUTO_TAG_JSX_ENABLED(analytics);
1460
1519
  } else {
1520
+ if (analytics) {
1521
+ stega.SET_AUTO_TAG_JSX_ENABLED(true);
1522
+ }
1461
1523
  if (draftMode) {
1462
1524
  // Safe for a page rendered from a server draft too: what a component
1463
1525
  // renders while it hydrates has no edit tags to turn into attributes
@@ -1511,7 +1573,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1511
1573
  };
1512
1574
  }
1513
1575
  }
1514
- }, [mountOverlay, draftMode, props.disableRefresh]);
1576
+ }, [mountOverlay, draftMode, analytics, props.disableRefresh]);
1515
1577
  React__default["default"].useEffect(function () {
1516
1578
  if (!mountOverlay) {
1517
1579
  return;
@@ -1596,6 +1658,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1596
1658
  draftModeReady: (_draftModeReady$curre2 = draftModeReady.current) === null || _draftModeReady$curre2 === void 0 ? void 0 : _draftModeReady$curre2.promise,
1597
1659
  draftSourcesSynced: draftSourcesSynced,
1598
1660
  serverDraft: hasDraft,
1661
+ analytics: analytics,
1599
1662
  snapshot: snapshot,
1600
1663
  suspend: suspendActive,
1601
1664
  store: valStore,
@@ -1710,8 +1773,13 @@ function getPositionClassName(dropZone) {
1710
1773
  }
1711
1774
  return className;
1712
1775
  }
1776
+
1777
+ /**
1778
+ * The Studio is `/val` and what is below it -- not every route that starts
1779
+ * with the letters, which would leave `/values` without its overlay.
1780
+ */
1713
1781
  function isValStudioPath(pathname) {
1714
- return pathname.startsWith("/val");
1782
+ return pathname === "/val" || pathname.startsWith("/val/");
1715
1783
  }
1716
1784
 
1717
1785
  /**
@@ -2216,7 +2284,7 @@ var ValApp = function ValApp(_ref) {
2216
2284
  // in the commit that mounts it. Started on the first render, the demo read
2217
2285
  // them whenever the server's code had loaded -- before the child was there,
2218
2286
  // on a page that had that code already.
2219
- var demoStart = useDemoServer(demo === true && inMessageMode === false, config);
2287
+ var demoStart = useDemoServer(demo !== undefined && demo !== false && inMessageMode === false, config, demo === undefined || typeof demo === "boolean" ? undefined : demo);
2220
2288
  useConfigStorageSave(config);
2221
2289
  var container = React.useRef(null);
2222
2290
  React.useEffect(function () {
@@ -2397,19 +2465,28 @@ var ValApp = function ValApp(_ref) {
2397
2465
  * half of the server, and only a demo should download it.
2398
2466
  */
2399
2467
 
2400
- function useDemoServer(demo, config) {
2468
+ function useDemoServer(demo, config, options) {
2401
2469
  var _useState7 = React.useState({
2402
2470
  status: "starting"
2403
2471
  }),
2404
2472
  _useState8 = _typeof._slicedToArray(_useState7, 2),
2405
2473
  start = _useState8[0],
2406
2474
  setStart = _useState8[1];
2475
+ /*
2476
+ * Read when the demo starts, and not a dependency of the effect: options
2477
+ * written inline (`demo={{ tour }}`) are a new object on every render, and
2478
+ * starting Val's server again for each would throw away every edit. The
2479
+ * Studio reads them once anyway, when its script starts.
2480
+ */
2481
+ var optionsRef = React.useRef(options);
2482
+ optionsRef.current = options;
2407
2483
  React.useEffect(function () {
2408
2484
  if (!demo) return;
2409
2485
  var cancelled = false;
2410
2486
  var run = /*#__PURE__*/function () {
2411
2487
  var _ref2 = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee() {
2412
- var _yield$import, createInTabValFetch, modules, fetch, uploads, runtime;
2488
+ var _optionsRef$current;
2489
+ var _yield$import, createInTabValFetch, modules, fetch, uploads, tour, runtime;
2413
2490
  return asyncToGenerator._regenerator().w(function (_context) {
2414
2491
  while (1) switch (_context.n) {
2415
2492
  case 0:
@@ -2437,10 +2514,13 @@ function useDemoServer(demo, config) {
2437
2514
  return startDemoRelay(fetch);
2438
2515
  case 3:
2439
2516
  uploads = _context.v;
2440
- runtime = {
2517
+ tour = (_optionsRef$current = optionsRef.current) === null || _optionsRef$current === void 0 ? void 0 : _optionsRef$current.tour;
2518
+ runtime = _typeof._objectSpread2({
2441
2519
  fetch: fetch,
2442
2520
  uploads: uploads
2443
- };
2521
+ }, tour ? {
2522
+ tour: tour
2523
+ } : {});
2444
2524
  window.__VAL_DEMO__ = runtime;
2445
2525
  return _context.a(2, {
2446
2526
  status: "ready"
@@ -6,12 +6,12 @@ var asyncToGenerator = require('./asyncToGenerator-8e5c36c8.cjs.prod.js');
6
6
  var _typeof = require('./typeof-8998e126.cjs.prod.js');
7
7
  var core = require('@valbuild/core');
8
8
  var stega = require('@valbuild/react/stega');
9
- var version = require('./version-60499345.cjs.prod.js');
9
+ var version = require('./version-4353b65f.cjs.prod.js');
10
10
  var internal = require('@valbuild/react/internal');
11
11
  var ui = require('@valbuild/ui');
12
12
  var reactRouter = require('@tanstack/react-router');
13
13
  var React = require('react');
14
- var ValOverlayContext = require('./ValOverlayContext-98f8e877.cjs.prod.js');
14
+ var ValOverlayContext = require('./ValOverlayContext-d9b22d1a.cjs.prod.js');
15
15
  var client = require('@valbuild/shared/client');
16
16
  var jsxRuntime = require('react/jsx-runtime');
17
17
  var demoServiceWorker = require('./demoServiceWorker-994710f7.cjs.prod.js');
@@ -951,7 +951,7 @@ var DRAFT_HANDSHAKE_POLL_MS = 100;
951
951
  */
952
952
  var DRAFT_HANDSHAKE_TIMEOUT_MS = 10000;
953
953
  var ValTanStackProvider = function ValTanStackProvider(props) {
954
- var _props$draft, _draftModeReady$curre2;
954
+ var _props$draft, _props$analytics, _draftModeReady$curre2;
955
955
  // TODO: use config:
956
956
  var route = "/api/val";
957
957
  /**
@@ -1006,6 +1006,14 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1006
1006
  * not a draft: it must not turn draft mode on or say the draft is synced.
1007
1007
  */
1008
1008
  var hasDraft = initialDraft !== null && initialDraft.draftMode !== false;
1009
+ /*
1010
+ * As the page was rendered. A ref, not the prop, for the reason
1011
+ * `initialDraft` is one: a later render's prop is a client navigation's
1012
+ * loader, which reads nothing.
1013
+ */
1014
+ var analyticsSetting = React__default["default"].useRef((_props$analytics = props.analytics) !== null && _props$analytics !== void 0 ? _props$analytics : null).current;
1015
+ var analytics = (analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.enabled) === true;
1016
+ var contentVersion = analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.contentVersion;
1009
1017
  var snapshot = initialDraft === null || initialDraft === void 0 ? void 0 : initialDraft.snapshot;
1010
1018
  /*
1011
1019
  * The base the Studio's overlay must start from, where it is not the
@@ -1177,6 +1185,54 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1177
1185
  setIsCanvas(client.isValCanvasFrame(location.search, readParentPathname()));
1178
1186
  setMountOverlay(hasValEnableCookie(document.cookie));
1179
1187
  }, []);
1188
+
1189
+ /**
1190
+ * The analytics script, for a visitor and nobody else.
1191
+ *
1192
+ * `mountOverlay === false` is "known not to be an editor": no Val enable
1193
+ * cookie, so no draft mode and no canvas. A page the server rendered from a
1194
+ * draft is an editor's too, whatever the enable cookie says -- the draft
1195
+ * mode cookie can outlive it. So is one at a proposal's address, which
1196
+ * comes with a snapshot: its content is not published, and counting it
1197
+ * would credit the live site with it. The Studio's own pages count nothing
1198
+ * either. Loaded with a dynamic import after hydration, so a site
1199
+ * with analytics off never downloads it, and one with it on downloads it
1200
+ * off the critical path. It imports nothing from core, shared or zod.
1201
+ */
1202
+ React__default["default"].useEffect(function () {
1203
+ if (!analytics || mountOverlay !== false || hasDraft || snapshot !== undefined || isCanvas || isValStudioPath(location.pathname)) {
1204
+ return;
1205
+ }
1206
+ // Where the page was hydrated, read now: the script loads later, and the
1207
+ // visitor may have moved on by then. See `landingPath`.
1208
+ var landingPath = location.pathname;
1209
+ var cancelled = false;
1210
+ var tracker = null;
1211
+ Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@valbuild/react/analytics')); }).then(function (_ref2) {
1212
+ var startValAnalytics = _ref2.startValAnalytics;
1213
+ if (!cancelled) {
1214
+ tracker = startValAnalytics({
1215
+ endpoint: "".concat(route, "/analytics"),
1216
+ landingPath: landingPath,
1217
+ contentVersion: contentVersion,
1218
+ // The route's pattern (`/posts/$postId`), never the pathname,
1219
+ // which can hold something about one visitor. A pathname no
1220
+ // route matches is not a page of the site.
1221
+ routeFor: function routeFor(pathname) {
1222
+ var _router$getMatchedRou, _router$getMatchedRou2;
1223
+ return (_router$getMatchedRou = (_router$getMatchedRou2 = router.getMatchedRoutes(pathname)[2]) === null || _router$getMatchedRou2 === void 0 ? void 0 : _router$getMatchedRou2.fullPath) !== null && _router$getMatchedRou !== void 0 ? _router$getMatchedRou : "(not found)";
1224
+ }
1225
+ });
1226
+ }
1227
+ })["catch"](function (error) {
1228
+ core.Internal.log.warn("could not load analytics", error);
1229
+ });
1230
+ return function () {
1231
+ var _tracker;
1232
+ cancelled = true;
1233
+ (_tracker = tracker) === null || _tracker === void 0 || _tracker.stop();
1234
+ };
1235
+ }, [analytics, contentVersion, mountOverlay, hasDraft, snapshot, isCanvas, route, router]);
1180
1236
  React__default["default"].useEffect(function () {
1181
1237
  // Activate the Suspense gate after hydration. Inside a transition so
1182
1238
  // already-visible (static) content stays on screen while useValStega
@@ -1456,8 +1512,14 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1456
1512
  }, [mountOverlay, draftMode, spaReady]);
1457
1513
  React__default["default"].useEffect(function () {
1458
1514
  if (!mountOverlay) {
1459
- stega.SET_AUTO_TAG_JSX_ENABLED(false);
1515
+ // A visitor: only analytics tags content, and only after hydration
1516
+ // (`useEncodesEditTags`), so this cannot reach a component still
1517
+ // hydrating either.
1518
+ stega.SET_AUTO_TAG_JSX_ENABLED(analytics);
1460
1519
  } else {
1520
+ if (analytics) {
1521
+ stega.SET_AUTO_TAG_JSX_ENABLED(true);
1522
+ }
1461
1523
  if (draftMode) {
1462
1524
  // Safe for a page rendered from a server draft too: what a component
1463
1525
  // renders while it hydrates has no edit tags to turn into attributes
@@ -1511,7 +1573,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1511
1573
  };
1512
1574
  }
1513
1575
  }
1514
- }, [mountOverlay, draftMode, props.disableRefresh]);
1576
+ }, [mountOverlay, draftMode, analytics, props.disableRefresh]);
1515
1577
  React__default["default"].useEffect(function () {
1516
1578
  if (!mountOverlay) {
1517
1579
  return;
@@ -1596,6 +1658,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1596
1658
  draftModeReady: (_draftModeReady$curre2 = draftModeReady.current) === null || _draftModeReady$curre2 === void 0 ? void 0 : _draftModeReady$curre2.promise,
1597
1659
  draftSourcesSynced: draftSourcesSynced,
1598
1660
  serverDraft: hasDraft,
1661
+ analytics: analytics,
1599
1662
  snapshot: snapshot,
1600
1663
  suspend: suspendActive,
1601
1664
  store: valStore,
@@ -1710,8 +1773,13 @@ function getPositionClassName(dropZone) {
1710
1773
  }
1711
1774
  return className;
1712
1775
  }
1776
+
1777
+ /**
1778
+ * The Studio is `/val` and what is below it -- not every route that starts
1779
+ * with the letters, which would leave `/values` without its overlay.
1780
+ */
1713
1781
  function isValStudioPath(pathname) {
1714
- return pathname.startsWith("/val");
1782
+ return pathname === "/val" || pathname.startsWith("/val/");
1715
1783
  }
1716
1784
 
1717
1785
  /**
@@ -2216,7 +2284,7 @@ var ValApp = function ValApp(_ref) {
2216
2284
  // in the commit that mounts it. Started on the first render, the demo read
2217
2285
  // them whenever the server's code had loaded -- before the child was there,
2218
2286
  // on a page that had that code already.
2219
- var demoStart = useDemoServer(demo === true && inMessageMode === false, config);
2287
+ var demoStart = useDemoServer(demo !== undefined && demo !== false && inMessageMode === false, config, demo === undefined || typeof demo === "boolean" ? undefined : demo);
2220
2288
  useConfigStorageSave(config);
2221
2289
  var container = React.useRef(null);
2222
2290
  React.useEffect(function () {
@@ -2397,19 +2465,28 @@ var ValApp = function ValApp(_ref) {
2397
2465
  * half of the server, and only a demo should download it.
2398
2466
  */
2399
2467
 
2400
- function useDemoServer(demo, config) {
2468
+ function useDemoServer(demo, config, options) {
2401
2469
  var _useState7 = React.useState({
2402
2470
  status: "starting"
2403
2471
  }),
2404
2472
  _useState8 = _typeof._slicedToArray(_useState7, 2),
2405
2473
  start = _useState8[0],
2406
2474
  setStart = _useState8[1];
2475
+ /*
2476
+ * Read when the demo starts, and not a dependency of the effect: options
2477
+ * written inline (`demo={{ tour }}`) are a new object on every render, and
2478
+ * starting Val's server again for each would throw away every edit. The
2479
+ * Studio reads them once anyway, when its script starts.
2480
+ */
2481
+ var optionsRef = React.useRef(options);
2482
+ optionsRef.current = options;
2407
2483
  React.useEffect(function () {
2408
2484
  if (!demo) return;
2409
2485
  var cancelled = false;
2410
2486
  var run = /*#__PURE__*/function () {
2411
2487
  var _ref2 = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee() {
2412
- var _yield$import, createInTabValFetch, modules, fetch, uploads, runtime;
2488
+ var _optionsRef$current;
2489
+ var _yield$import, createInTabValFetch, modules, fetch, uploads, tour, runtime;
2413
2490
  return asyncToGenerator._regenerator().w(function (_context) {
2414
2491
  while (1) switch (_context.n) {
2415
2492
  case 0:
@@ -2437,10 +2514,13 @@ function useDemoServer(demo, config) {
2437
2514
  return startDemoRelay(fetch);
2438
2515
  case 3:
2439
2516
  uploads = _context.v;
2440
- runtime = {
2517
+ tour = (_optionsRef$current = optionsRef.current) === null || _optionsRef$current === void 0 ? void 0 : _optionsRef$current.tour;
2518
+ runtime = _typeof._objectSpread2({
2441
2519
  fetch: fetch,
2442
2520
  uploads: uploads
2443
- };
2521
+ }, tour ? {
2522
+ tour: tour
2523
+ } : {});
2444
2524
  window.__VAL_DEMO__ = runtime;
2445
2525
  return _context.a(2, {
2446
2526
  status: "ready"
@@ -5,12 +5,12 @@ import * as core from '@valbuild/core';
5
5
  export { core as expr };
6
6
  export { GenericSelector, Schema, VAL_EXTENSION, derefPatch, modules } from '@valbuild/core';
7
7
  import { stegaEncode, stegaDecodeStrings, attrs, raw, SET_AUTO_TAG_JSX_ENABLED, autoTagJSX } from '@valbuild/react/stega';
8
- import { r as readValEnableCookie, _ as _toConsumableArray, V as VERSION$1 } from './version-c7dc5935.esm.js';
8
+ import { r as readValEnableCookie, _ as _toConsumableArray, V as VERSION$1 } from './version-79ab0f75.esm.js';
9
9
  export { ValRichText } from '@valbuild/react/internal';
10
10
  import { VERSION, VAL_APP_PATH, VAL_OVERLAY_ID, VAL_APP_ID } from '@valbuild/ui';
11
11
  import { useRouter, useRouterState } from '@tanstack/react-router';
12
12
  import React, { useEffect, useRef, useState } from 'react';
13
- import { V as ValExternalStore, a as ValOverlayProvider } from './ValOverlayContext-2837c67f.esm.js';
13
+ import { V as ValExternalStore, a as ValOverlayProvider } from './ValOverlayContext-6411bbe3.esm.js';
14
14
  import { VAL_CONFIG_SESSION_STORAGE_KEY, VAL_THEME_SESSION_STORAGE_KEY, VAL_CANVAS_MESSAGE, DEFAULT_CANVAS_SELECTION, DEFAULT_CANVAS_SELECTION_SOFT, isValCanvasStudioMessage, isValCanvasFrame } from '@valbuild/shared/client';
15
15
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
16
16
  import { D as DEMO_CLAIM_MESSAGE, a as DEMO_SERVICE_WORKER_PATH, b as DEMO_RELAY_MESSAGE } from './demoServiceWorker-56fd96cf.esm.js';
@@ -927,7 +927,7 @@ var DRAFT_HANDSHAKE_POLL_MS = 100;
927
927
  */
928
928
  var DRAFT_HANDSHAKE_TIMEOUT_MS = 10000;
929
929
  var ValTanStackProvider = function ValTanStackProvider(props) {
930
- var _props$draft, _draftModeReady$curre2;
930
+ var _props$draft, _props$analytics, _draftModeReady$curre2;
931
931
  // TODO: use config:
932
932
  var route = "/api/val";
933
933
  /**
@@ -982,6 +982,14 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
982
982
  * not a draft: it must not turn draft mode on or say the draft is synced.
983
983
  */
984
984
  var hasDraft = initialDraft !== null && initialDraft.draftMode !== false;
985
+ /*
986
+ * As the page was rendered. A ref, not the prop, for the reason
987
+ * `initialDraft` is one: a later render's prop is a client navigation's
988
+ * loader, which reads nothing.
989
+ */
990
+ var analyticsSetting = React.useRef((_props$analytics = props.analytics) !== null && _props$analytics !== void 0 ? _props$analytics : null).current;
991
+ var analytics = (analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.enabled) === true;
992
+ var contentVersion = analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.contentVersion;
985
993
  var snapshot = initialDraft === null || initialDraft === void 0 ? void 0 : initialDraft.snapshot;
986
994
  /*
987
995
  * The base the Studio's overlay must start from, where it is not the
@@ -1153,6 +1161,54 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1153
1161
  setIsCanvas(isValCanvasFrame(location.search, readParentPathname()));
1154
1162
  setMountOverlay(hasValEnableCookie(document.cookie));
1155
1163
  }, []);
1164
+
1165
+ /**
1166
+ * The analytics script, for a visitor and nobody else.
1167
+ *
1168
+ * `mountOverlay === false` is "known not to be an editor": no Val enable
1169
+ * cookie, so no draft mode and no canvas. A page the server rendered from a
1170
+ * draft is an editor's too, whatever the enable cookie says -- the draft
1171
+ * mode cookie can outlive it. So is one at a proposal's address, which
1172
+ * comes with a snapshot: its content is not published, and counting it
1173
+ * would credit the live site with it. The Studio's own pages count nothing
1174
+ * either. Loaded with a dynamic import after hydration, so a site
1175
+ * with analytics off never downloads it, and one with it on downloads it
1176
+ * off the critical path. It imports nothing from core, shared or zod.
1177
+ */
1178
+ React.useEffect(function () {
1179
+ if (!analytics || mountOverlay !== false || hasDraft || snapshot !== undefined || isCanvas || isValStudioPath(location.pathname)) {
1180
+ return;
1181
+ }
1182
+ // Where the page was hydrated, read now: the script loads later, and the
1183
+ // visitor may have moved on by then. See `landingPath`.
1184
+ var landingPath = location.pathname;
1185
+ var cancelled = false;
1186
+ var tracker = null;
1187
+ import('@valbuild/react/analytics').then(function (_ref2) {
1188
+ var startValAnalytics = _ref2.startValAnalytics;
1189
+ if (!cancelled) {
1190
+ tracker = startValAnalytics({
1191
+ endpoint: "".concat(route, "/analytics"),
1192
+ landingPath: landingPath,
1193
+ contentVersion: contentVersion,
1194
+ // The route's pattern (`/posts/$postId`), never the pathname,
1195
+ // which can hold something about one visitor. A pathname no
1196
+ // route matches is not a page of the site.
1197
+ routeFor: function routeFor(pathname) {
1198
+ var _router$getMatchedRou, _router$getMatchedRou2;
1199
+ return (_router$getMatchedRou = (_router$getMatchedRou2 = router.getMatchedRoutes(pathname)[2]) === null || _router$getMatchedRou2 === void 0 ? void 0 : _router$getMatchedRou2.fullPath) !== null && _router$getMatchedRou !== void 0 ? _router$getMatchedRou : "(not found)";
1200
+ }
1201
+ });
1202
+ }
1203
+ })["catch"](function (error) {
1204
+ Internal$1.log.warn("could not load analytics", error);
1205
+ });
1206
+ return function () {
1207
+ var _tracker;
1208
+ cancelled = true;
1209
+ (_tracker = tracker) === null || _tracker === void 0 || _tracker.stop();
1210
+ };
1211
+ }, [analytics, contentVersion, mountOverlay, hasDraft, snapshot, isCanvas, route, router]);
1156
1212
  React.useEffect(function () {
1157
1213
  // Activate the Suspense gate after hydration. Inside a transition so
1158
1214
  // already-visible (static) content stays on screen while useValStega
@@ -1432,8 +1488,14 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1432
1488
  }, [mountOverlay, draftMode, spaReady]);
1433
1489
  React.useEffect(function () {
1434
1490
  if (!mountOverlay) {
1435
- SET_AUTO_TAG_JSX_ENABLED(false);
1491
+ // A visitor: only analytics tags content, and only after hydration
1492
+ // (`useEncodesEditTags`), so this cannot reach a component still
1493
+ // hydrating either.
1494
+ SET_AUTO_TAG_JSX_ENABLED(analytics);
1436
1495
  } else {
1496
+ if (analytics) {
1497
+ SET_AUTO_TAG_JSX_ENABLED(true);
1498
+ }
1437
1499
  if (draftMode) {
1438
1500
  // Safe for a page rendered from a server draft too: what a component
1439
1501
  // renders while it hydrates has no edit tags to turn into attributes
@@ -1487,7 +1549,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1487
1549
  };
1488
1550
  }
1489
1551
  }
1490
- }, [mountOverlay, draftMode, props.disableRefresh]);
1552
+ }, [mountOverlay, draftMode, analytics, props.disableRefresh]);
1491
1553
  React.useEffect(function () {
1492
1554
  if (!mountOverlay) {
1493
1555
  return;
@@ -1572,6 +1634,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1572
1634
  draftModeReady: (_draftModeReady$curre2 = draftModeReady.current) === null || _draftModeReady$curre2 === void 0 ? void 0 : _draftModeReady$curre2.promise,
1573
1635
  draftSourcesSynced: draftSourcesSynced,
1574
1636
  serverDraft: hasDraft,
1637
+ analytics: analytics,
1575
1638
  snapshot: snapshot,
1576
1639
  suspend: suspendActive,
1577
1640
  store: valStore,
@@ -1686,8 +1749,13 @@ function getPositionClassName(dropZone) {
1686
1749
  }
1687
1750
  return className;
1688
1751
  }
1752
+
1753
+ /**
1754
+ * The Studio is `/val` and what is below it -- not every route that starts
1755
+ * with the letters, which would leave `/values` without its overlay.
1756
+ */
1689
1757
  function isValStudioPath(pathname) {
1690
- return pathname.startsWith("/val");
1758
+ return pathname === "/val" || pathname.startsWith("/val/");
1691
1759
  }
1692
1760
 
1693
1761
  /**
@@ -2192,7 +2260,7 @@ var ValApp = function ValApp(_ref) {
2192
2260
  // in the commit that mounts it. Started on the first render, the demo read
2193
2261
  // them whenever the server's code had loaded -- before the child was there,
2194
2262
  // on a page that had that code already.
2195
- var demoStart = useDemoServer(demo === true && inMessageMode === false, config);
2263
+ var demoStart = useDemoServer(demo !== undefined && demo !== false && inMessageMode === false, config, demo === undefined || typeof demo === "boolean" ? undefined : demo);
2196
2264
  useConfigStorageSave(config);
2197
2265
  var container = useRef(null);
2198
2266
  useEffect(function () {
@@ -2373,19 +2441,28 @@ var ValApp = function ValApp(_ref) {
2373
2441
  * half of the server, and only a demo should download it.
2374
2442
  */
2375
2443
 
2376
- function useDemoServer(demo, config) {
2444
+ function useDemoServer(demo, config, options) {
2377
2445
  var _useState7 = useState({
2378
2446
  status: "starting"
2379
2447
  }),
2380
2448
  _useState8 = _slicedToArray(_useState7, 2),
2381
2449
  start = _useState8[0],
2382
2450
  setStart = _useState8[1];
2451
+ /*
2452
+ * Read when the demo starts, and not a dependency of the effect: options
2453
+ * written inline (`demo={{ tour }}`) are a new object on every render, and
2454
+ * starting Val's server again for each would throw away every edit. The
2455
+ * Studio reads them once anyway, when its script starts.
2456
+ */
2457
+ var optionsRef = useRef(options);
2458
+ optionsRef.current = options;
2383
2459
  useEffect(function () {
2384
2460
  if (!demo) return;
2385
2461
  var cancelled = false;
2386
2462
  var run = /*#__PURE__*/function () {
2387
2463
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
2388
- var _yield$import, createInTabValFetch, modules, fetch, uploads, runtime;
2464
+ var _optionsRef$current;
2465
+ var _yield$import, createInTabValFetch, modules, fetch, uploads, tour, runtime;
2389
2466
  return _regenerator().w(function (_context) {
2390
2467
  while (1) switch (_context.n) {
2391
2468
  case 0:
@@ -2413,10 +2490,13 @@ function useDemoServer(demo, config) {
2413
2490
  return startDemoRelay(fetch);
2414
2491
  case 3:
2415
2492
  uploads = _context.v;
2416
- runtime = {
2493
+ tour = (_optionsRef$current = optionsRef.current) === null || _optionsRef$current === void 0 ? void 0 : _optionsRef$current.tour;
2494
+ runtime = _objectSpread2({
2417
2495
  fetch: fetch,
2418
2496
  uploads: uploads
2419
- };
2497
+ }, tour ? {
2498
+ tour: tour
2499
+ } : {});
2420
2500
  window.__VAL_DEMO__ = runtime;
2421
2501
  return _context.a(2, {
2422
2502
  status: "ready"
@@ -95,7 +95,7 @@ var packageJson = {
95
95
  "tanstack-router",
96
96
  "react"
97
97
  ],
98
- version: "0.148.2",
98
+ version: "0.148.3",
99
99
  scripts: {
100
100
  typecheck: "tsc --noEmit",
101
101
  test: "jest"
@@ -93,7 +93,7 @@ var packageJson = {
93
93
  "tanstack-router",
94
94
  "react"
95
95
  ],
96
- version: "0.148.2",
96
+ version: "0.148.3",
97
97
  scripts: {
98
98
  typecheck: "tsc --noEmit",
99
99
  test: "jest"
@@ -95,7 +95,7 @@ var packageJson = {
95
95
  "tanstack-router",
96
96
  "react"
97
97
  ],
98
- version: "0.148.2",
98
+ version: "0.148.3",
99
99
  scripts: {
100
100
  typecheck: "tsc --noEmit",
101
101
  test: "jest"
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "tanstack-router",
15
15
  "react"
16
16
  ],
17
- "version": "0.148.2",
17
+ "version": "0.148.3",
18
18
  "main": "dist/valbuild-tanstack.cjs.js",
19
19
  "module": "dist/valbuild-tanstack.esm.js",
20
20
  "exports": {
@@ -47,13 +47,13 @@
47
47
  "exports": true
48
48
  },
49
49
  "dependencies": {
50
- "@valbuild/core": "0.148.2",
51
- "@valbuild/language-server": "0.148.2",
52
- "@valbuild/mcp": "0.148.2",
53
- "@valbuild/react": "0.148.2",
54
- "@valbuild/server": "0.148.2",
55
- "@valbuild/shared": "0.148.2",
56
- "@valbuild/ui": "0.148.2"
50
+ "@valbuild/mcp": "0.148.3",
51
+ "@valbuild/language-server": "0.148.3",
52
+ "@valbuild/react": "0.148.3",
53
+ "@valbuild/server": "0.148.3",
54
+ "@valbuild/shared": "0.148.3",
55
+ "@valbuild/ui": "0.148.3",
56
+ "@valbuild/core": "0.148.2"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@tanstack/react-router": "^1.170.41",
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = require('../../dist/version-2d885c7d.cjs.dev.js');
5
+ var version = require('../../dist/version-f0497731.cjs.dev.js');
6
6
  var asyncToGenerator = require('../../dist/asyncToGenerator-c3823d62.cjs.dev.js');
7
7
  var core = require('@valbuild/core');
8
8
  var _typeof = require('../../dist/typeof-dd0246a1.cjs.dev.js');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = require('../../dist/version-60499345.cjs.prod.js');
5
+ var version = require('../../dist/version-4353b65f.cjs.prod.js');
6
6
  var asyncToGenerator = require('../../dist/asyncToGenerator-8e5c36c8.cjs.prod.js');
7
7
  var core = require('@valbuild/core');
8
8
  var _typeof = require('../../dist/typeof-8998e126.cjs.prod.js');
@@ -1,4 +1,4 @@
1
- import { V as VERSION, _ as _toConsumableArray, s as setValEnableCookieReader } from '../../dist/version-c7dc5935.esm.js';
1
+ import { V as VERSION, _ as _toConsumableArray, s as setValEnableCookieReader } from '../../dist/version-79ab0f75.esm.js';
2
2
  import { _ as _asyncToGenerator, a as _regenerator } from '../../dist/asyncToGenerator-500f022f.esm.js';
3
3
  import { Internal } from '@valbuild/core';
4
4
  import { _ as _objectSpread2, a as _slicedToArray, b as _createForOfIteratorHelper, g as _defineProperty, c as _typeof } from '../../dist/typeof-66e2d869.esm.js';