WIP: test: posthog preview site (do not merge) #4

Draft
kennethz wants to merge 5 commits from test/posthog-preview into hotfix
Member

Test-only. Do not merge. This PR exists so kennel deploys a preview site for checking the PostHog integration from ScottyLabs/maps#3.

What it adds on top of #3

  • flake.nix imports kennel's flake module and serves apps/web as an SPA site web, with previewDeployments = true.
  • nix/web.nix builds the Vite app with bun, using a fixed-output node_modules derivation pinned to bun.lock.
  • secretspec.toml publishes PUBLIC_POSTHOG_KEY as a ref to the secretspec/maps/prod/POSTHOG_KEY that governance writes, plus PUBLIC_POSTHOG_HOST (default https://v.scottylabs.org). The web app reads both from /_kennel/env.json.

Expected on the preview

  • Page views, the map_view_changed event and autocapture.
  • VITE_SERVER_URL is a placeholder and there's no MapKit token, so the API, sign-in, search, navigation and map tiles won't work.

Verified locally

  • The site builds with Nix.
  • The kennel manifest has the web SPA site with preview_deployments: true.
  • The node_modules hash matched across cold and warm installs.
  • In headless Chromium, the built site reads the key from /_kennel/env.json and sends $pageview and map_view_changed to v.scottylabs.org.

Known

  • The hooks check fails on formatting of existing docs. It doesn't block kennel, which deploys from checks.x86_64-linux.kennel.
  • If kennel's preview credentials can't read the prod path, PUBLIC_POSTHOG_KEY resolves empty and the site sends nothing.
Test-only. Do not merge. This PR exists so kennel deploys a preview site for checking the PostHog integration from ScottyLabs/maps#3. ## What it adds on top of #3 - `flake.nix` imports kennel's flake module and serves `apps/web` as an SPA site `web`, with `previewDeployments = true`. - `nix/web.nix` builds the Vite app with bun, using a fixed-output `node_modules` derivation pinned to `bun.lock`. - `secretspec.toml` publishes `PUBLIC_POSTHOG_KEY` as a `ref` to the `secretspec/maps/prod/POSTHOG_KEY` that governance writes, plus `PUBLIC_POSTHOG_HOST` (default `https://v.scottylabs.org`). The web app reads both from `/_kennel/env.json`. ## Expected on the preview - Page views, the `map_view_changed` event and autocapture. - `VITE_SERVER_URL` is a placeholder and there's no MapKit token, so the API, sign-in, search, navigation and map tiles won't work. ## Verified locally - The site builds with Nix. - The kennel manifest has the `web` SPA site with `preview_deployments: true`. - The `node_modules` hash matched across cold and warm installs. - In headless Chromium, the built site reads the key from `/_kennel/env.json` and sends `$pageview` and `map_view_changed` to `v.scottylabs.org`. ## Known - The `hooks` check fails on formatting of existing docs. It doesn't block kennel, which deploys from `checks.x86_64-linux.kennel`. - If kennel's preview credentials can't read the prod path, `PUBLIC_POSTHOG_KEY` resolves empty and the site sends nothing.
feat(web): track product analytics with posthog
Some checks failed
Development launcher / launcher (macos-latest) (pull_request) Has been cancelled
Development launcher / launcher (ubuntu-latest) (pull_request) Has been cancelled
Development launcher / launcher (windows-latest) (pull_request) Has been cancelled
Development launcher / native-services (macos-latest) (pull_request) Has been cancelled
Development launcher / native-services (ubuntu-latest) (pull_request) Has been cancelled
nixbot/nix-eval evaluation failed
nixbot/nix-build build failed
kennel/build skipped: no services or static sites defined
16fa972140
Move PostHog setup into lib/analytics.ts. It initializes only when a key
is configured, reading the build-time VITE_PUBLIC_POSTHOG_* values first
and kennel's runtime /_kennel/env.json second, and defaults the host to
the ScottyLabs reverse proxy with ui_host set for the toolbar.

Identify users only after the session loads and reset only after an
identified user signs out. Previously reset() ran on every load for
signed-out visitors, giving them a new anonymous ID each time.

Capture search selections, login prompts, navigation start and end,
link shares, and map view changes, and document them in docs/.
build: deploy the web app as a kennel preview site
Some checks failed
kennel/build skipped: no services or static sites defined
nixbot/nix-eval evaluation succeeded in 19s (1 warning)
nixbot/nix-build gitea:ScottyLabs/maps#checks.x86_64-linux.hooks failed
nixbot/nix-build 1 of 3 attributes failed
Development launcher / launcher (macos-latest) (pull_request) Has been cancelled
Development launcher / launcher (ubuntu-latest) (pull_request) Has been cancelled
Development launcher / launcher (windows-latest) (pull_request) Has been cancelled
Development launcher / native-services (macos-latest) (pull_request) Has been cancelled
Development launcher / native-services (ubuntu-latest) (pull_request) Has been cancelled
f33ea90cac
Add a flake that imports kennel's flake module and serves apps/web as a
single-page static site, with preview deployments enabled so each pull
request gets maps-pr-<number>.scottylabs.net.

nix/web.nix builds the Vite app with bun from a fixed-output
node_modules derivation pinned to bun.lock. VITE_SERVER_URL is a
placeholder, so the API is not reachable from the preview.

secretspec.toml publishes PUBLIC_POSTHOG_KEY, a reference to the
POSTHOG_KEY governance writes to the prod profile, and
PUBLIC_POSTHOG_HOST, which the web app reads from /_kennel/env.json.
build: declare the web site for kennel's devenv config
Some checks failed
Development launcher / native-services (macos-latest) (pull_request) Has been cancelled
nixbot/nix-eval evaluation succeeded in 10s (1 warning)
nixbot/nix-build gitea:ScottyLabs/maps#checks.x86_64-linux.hooks failed
nixbot/nix-build 1 of 3 attributes failed
kennel/build build succeeded
kennel/deploy deployment healthy
Development launcher / launcher (macos-latest) (pull_request) Has been cancelled
Development launcher / launcher (ubuntu-latest) (pull_request) Has been cancelled
Development launcher / launcher (windows-latest) (pull_request) Has been cancelled
Development launcher / native-services (ubuntu-latest) (pull_request) Has been cancelled
9a8f5f4e62
The running kennel still reads sites from scottylabs.kennel.config in
devenv.nix and builds each one from the flake's packages output, so
declare web there too.

That kennel cannot serve /_kennel/env.json, so nix/web.nix also takes an
optional posthogKey that is inlined at build time.

Kennel Deployments

Service URL
web https://maps-web-pr-4.scottylabs.net

Last updated for commit a294e4e.

<!-- kennel-deployment --> ### Kennel Deployments | Service | URL | | --- | --- | | web | https://maps-web-pr-4.scottylabs.net | Last updated for commit `a294e4e`.
build: skip formatting hooks in the flake check
Some checks failed
Development launcher / launcher (macos-latest) (pull_request) Has been cancelled
Development launcher / launcher (ubuntu-latest) (pull_request) Has been cancelled
Development launcher / launcher (windows-latest) (pull_request) Has been cancelled
Development launcher / native-services (macos-latest) (pull_request) Has been cancelled
Development launcher / native-services (ubuntu-latest) (pull_request) Has been cancelled
nixbot/nix-eval evaluation succeeded in 5s (1 warning)
kennel/build build succeeded
kennel/deploy deployment healthy
nixbot/nix-build 3 attributes built
697a02166b
devenv.nix already turns treefmt and git hooks off for this repo, and existing docs and code fail treefmt and block-ai-slop. Skip both in the hooks check so it matches; gitleaks, statix, deadnix and taplo still run.
build: inline the maps posthog project key in the preview site
Some checks failed
nixbot/nix-eval evaluation succeeded in 16s (1 warning)
kennel/build build succeeded
kennel/deploy deployment healthy
nixbot/nix-build 3 attributes built
Development launcher / launcher (macos-latest) (pull_request) Has been cancelled
Development launcher / launcher (ubuntu-latest) (pull_request) Has been cancelled
Development launcher / launcher (windows-latest) (pull_request) Has been cancelled
Development launcher / native-services (macos-latest) (pull_request) Has been cancelled
Development launcher / native-services (ubuntu-latest) (pull_request) Has been cancelled
a294e4ef5d
Some checks failed
nixbot/nix-eval evaluation succeeded in 16s (1 warning)
kennel/build build succeeded
kennel/deploy deployment healthy
nixbot/nix-build 3 attributes built
Development launcher / launcher (macos-latest) (pull_request) Has been cancelled
Development launcher / launcher (ubuntu-latest) (pull_request) Has been cancelled
Development launcher / launcher (windows-latest) (pull_request) Has been cancelled
Development launcher / native-services (macos-latest) (pull_request) Has been cancelled
Development launcher / native-services (ubuntu-latest) (pull_request) Has been cancelled
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin test/posthog-preview:test/posthog-preview
git switch test/posthog-preview

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch hotfix
git merge --no-ff test/posthog-preview
git switch test/posthog-preview
git rebase hotfix
git switch hotfix
git merge --ff-only test/posthog-preview
git switch test/posthog-preview
git rebase hotfix
git switch hotfix
git merge --no-ff test/posthog-preview
git switch hotfix
git merge --squash test/posthog-preview
git switch hotfix
git merge --ff-only test/posthog-preview
git switch hotfix
git merge test/posthog-preview
git push origin hotfix
Sign in to join this conversation.
No description provided.