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 <cursoragent@cursor.com>
This commit is contained in:
+2
-2
@@ -48,10 +48,10 @@ def configure_app(flask_app: Flask) -> None:
|
|||||||
response.headers["Referrer-Policy"] = "strict-origin-when-cross-origin"
|
response.headers["Referrer-Policy"] = "strict-origin-when-cross-origin"
|
||||||
response.headers["Content-Security-Policy"] = (
|
response.headers["Content-Security-Policy"] = (
|
||||||
"default-src 'self'; "
|
"default-src 'self'; "
|
||||||
"script-src 'self'; "
|
"script-src 'self' https://plausible.elpatron.me; "
|
||||||
"style-src 'self' 'unsafe-inline'; "
|
"style-src 'self' 'unsafe-inline'; "
|
||||||
"img-src 'self' data:; "
|
"img-src 'self' data:; "
|
||||||
"connect-src 'self'; "
|
"connect-src 'self' https://plausible.elpatron.me; "
|
||||||
"frame-ancestors 'self'"
|
"frame-ancestors 'self'"
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ function getViewerId() {
|
|||||||
return document.body?.dataset?.viewerId || "";
|
return document.body?.dataset?.viewerId || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trackEvent(name, props) {
|
||||||
|
if (typeof window.plausible === "function") {
|
||||||
|
window.plausible(name, props ? { props } : undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function apiBase() {
|
function apiBase() {
|
||||||
const vid = getViewerId();
|
const vid = getViewerId();
|
||||||
return vid ? `/v/${vid}/api` : "/api";
|
return vid ? `/v/${vid}/api` : "/api";
|
||||||
@@ -143,6 +149,7 @@ function setupUpload() {
|
|||||||
e.target.value = "";
|
e.target.value = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
trackEvent("JSON Upload", { status: result.imported ? "imported" : result.reason || "ok" });
|
||||||
if (result.imported) {
|
if (result.imported) {
|
||||||
await loadData();
|
await loadData();
|
||||||
notifyImportSuccess(result);
|
notifyImportSuccess(result);
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<script defer data-domain="if-viewer.elpatron.me" src="https://plausible.elpatron.me/js/script.tagged-events.js"></script>
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Idle Fantasy Viewer</title>
|
<title>Idle Fantasy Viewer</title>
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
|
{% include '_analytics.html' %}
|
||||||
<script src="/static/vendor/chart.umd.min.js" defer></script>
|
<script src="/static/vendor/chart.umd.min.js" defer></script>
|
||||||
<script src="/static/i18n.js" defer></script>
|
<script src="/static/i18n.js" defer></script>
|
||||||
<script src="/static/app.js" defer></script>
|
<script src="/static/app.js" defer></script>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Idle Fantasy Viewer</title>
|
<title>Idle Fantasy Viewer</title>
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
|
{% include '_analytics.html' %}
|
||||||
<script src="/static/i18n.js" defer></script>
|
<script src="/static/i18n.js" defer></script>
|
||||||
<script src="/static/landing.js" defer></script>
|
<script src="/static/landing.js" defer></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user