From 810ad67ab61742277d86148fbfc92c8ec57e788b Mon Sep 17 00:00:00 2001 From: elpatron Date: Fri, 19 Jun 2026 16:58:58 +0200 Subject: [PATCH] Add Plausible analytics with JSON Upload custom event. Load tagged-events from plausible.elpatron.me on all pages, allow it in CSP, and track successful save uploads with import status. Co-authored-by: Cursor --- security.py | 4 ++-- static/app.js | 7 +++++++ templates/_analytics.html | 1 + templates/index.html | 1 + templates/landing.html | 1 + 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 templates/_analytics.html diff --git a/security.py b/security.py index 5ab9d46..2bcf769 100644 --- a/security.py +++ b/security.py @@ -48,10 +48,10 @@ def configure_app(flask_app: Flask) -> None: response.headers["Referrer-Policy"] = "strict-origin-when-cross-origin" response.headers["Content-Security-Policy"] = ( "default-src 'self'; " - "script-src 'self'; " + "script-src 'self' https://plausible.elpatron.me; " "style-src 'self' 'unsafe-inline'; " "img-src 'self' data:; " - "connect-src 'self'; " + "connect-src 'self' https://plausible.elpatron.me; " "frame-ancestors 'self'" ) return response diff --git a/static/app.js b/static/app.js index 7f1950a..d3f93ab 100644 --- a/static/app.js +++ b/static/app.js @@ -42,6 +42,12 @@ function getViewerId() { return document.body?.dataset?.viewerId || ""; } +function trackEvent(name, props) { + if (typeof window.plausible === "function") { + window.plausible(name, props ? { props } : undefined); + } +} + function apiBase() { const vid = getViewerId(); return vid ? `/v/${vid}/api` : "/api"; @@ -143,6 +149,7 @@ function setupUpload() { e.target.value = ""; return; } + trackEvent("JSON Upload", { status: result.imported ? "imported" : result.reason || "ok" }); if (result.imported) { await loadData(); notifyImportSuccess(result); diff --git a/templates/_analytics.html b/templates/_analytics.html new file mode 100644 index 0000000..dbebc9f --- /dev/null +++ b/templates/_analytics.html @@ -0,0 +1 @@ + diff --git a/templates/index.html b/templates/index.html index 18d93a6..78c8c11 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,6 +5,7 @@ Idle Fantasy Viewer + {% include '_analytics.html' %} diff --git a/templates/landing.html b/templates/landing.html index a40c784..c7ff830 100644 --- a/templates/landing.html +++ b/templates/landing.html @@ -5,6 +5,7 @@ Idle Fantasy Viewer + {% include '_analytics.html' %}