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 <noreply@anthropic.com>
This commit is contained in:
parent
e324422f32
commit
420a8058b4
3 changed files with 19 additions and 1 deletions
|
|
@ -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/`.
|
||||
|
|
|
|||
|
|
@ -445,6 +445,22 @@ const REPLACED = [
|
|||
can end the element early. */
|
||||
const scriptJson = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
||||
|
||||
/* Plausible, self-hosted and reached through nginx at /pa/ (the
|
||||
Privacy page describes it). Each deployment counts under its own
|
||||
address, site.json's url, so dev and live stay apart. Its script
|
||||
follows the app's page changes itself. */
|
||||
const PLAUSIBLE = { script: "/pa/js/script.js", api: "/pa/api/event" };
|
||||
|
||||
function analyticsTag(site) {
|
||||
let domain;
|
||||
try {
|
||||
domain = new URL(site.url).hostname;
|
||||
} catch {
|
||||
return null; // no url, nothing to count under
|
||||
}
|
||||
return `<script defer data-domain="${escapeHtml(domain)}" data-api="${PLAUSIBLE.api}" src="${PLAUSIBLE.script}"></script>`;
|
||||
}
|
||||
|
||||
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).
|
||||
`<script>window.__SITE__ = ${scriptJson(forBrowser(site))}</script>`,
|
||||
site.themeCss && `<style id="site-colors">${site.themeCss}</style>`,
|
||||
analyticsTag(site),
|
||||
].filter(Boolean);
|
||||
|
||||
// A blocked site (Site settings indexing off, or site.json's
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue