From 420a8058b4607db2778351f5b7dd6b12d00c5231 Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Sat, 3 Oct 2026 03:03:07 -0500 Subject: [PATCH] Plausible analytics from the API; version v1.12.0-accessibility The API adds Plausible's script to every page it serves, counting under the hostname of site.json's url, so each deployment reports as itself (nginx proxies /pa/ to the self-hosted Plausible). One script, no npm tracker: it follows the app's page changes on its own. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 1 + server/src/pageMeta.js | 17 +++++++++++++++++ src/lib/version.ts | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index 3e95d37..d462ebd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -32,6 +32,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu - Debugging: check `journalctl -u ngu-api -n 40 --no-pager` first. Make sure rsync ran from the repo (not the deployed copy) before restarting the service. - Never run commands against the production server or database unless explicitly asked. - Uploaded media: `UPLOADS_DIR=/var/lib/ngu/uploads`, served by nginx at `/uploads/`. Setup and the nginx block are in `docs/media-uploads.md`. +- Analytics: self-hosted Plausible, proxied by nginx at `/pa/`. The API adds its script to every page (`analyticsTag` in `server/src/pageMeta.js`), counting under the hostname of `site.json`'s `url`, so each deployment reports as itself. Nothing in `index.html` or the app. - Page HTML goes through the API, which fills in each page's title, description, preview image and structured data (`server/src/pageMeta.js`), and serves `/sitemap.xml`. It reads `SITE_CONFIG` (site.json) and `SITE_INDEX` (the built index.html), with Panel → Site settings (the `site_settings` table) laid over site.json, and serves `/robots.txt` from the same merge. nginx setup: `docs/seo.md`. - Video clips (Tools, admins and up): yt-dlp downloads our YouTube/Facebook videos into `CLIPS_DIR`, ffmpeg cuts them; one job at a time, files swept after a day (`server/src/clips.js`). Needs yt-dlp and ffmpeg on the VPS: `docs/video-clips.md`. - Newsletter countdown pictures: `/api/countdown/:id.png` (`server/src/routes/countdown.js`), drawn with sharp when an email is opened; it uses the VPS's fonts, so install Poppins there (eg. into `/usr/local/share/fonts`, then `fc-cache`) or it falls back to a plain sans. The social bar's icons are static files in `public/email/`. diff --git a/server/src/pageMeta.js b/server/src/pageMeta.js index 792f98b..65ff79d 100644 --- a/server/src/pageMeta.js +++ b/server/src/pageMeta.js @@ -445,6 +445,22 @@ const REPLACED = [ can end the element early. */ const scriptJson = (value) => JSON.stringify(value).replace(/`; +} + export function renderPage(html, meta) { const site = meta.site; let out = html; @@ -477,6 +493,7 @@ export function renderPage(html, meta) { // script in the head runs during parsing; modules wait). ``, site.themeCss && ``, + analyticsTag(site), ].filter(Boolean); // A blocked site (Site settings indexing off, or site.json's diff --git a/src/lib/version.ts b/src/lib/version.ts index e951ea8..5d62106 100644 --- a/src/lib/version.ts +++ b/src/lib/version.ts @@ -7,4 +7,4 @@ box or a build banner can read the same value later. ═══════════════════════════════════════════════════════════════ */ -export const SITE_VERSION = "NGU-Web.v1.11.2-newsletter"; +export const SITE_VERSION = "NGU-Web.v1.12.0-accessibility";