Integrate plausible

This commit is contained in:
Andras Schmelczer 2026-06-06 20:34:34 +01:00
parent eb807a63a6
commit 6b586f6e07
5 changed files with 17 additions and 6 deletions

View file

@ -8,6 +8,7 @@
"name": "fizika-admin-backend",
"version": "1.0.0",
"dependencies": {
"@plausible-analytics/tracker": "^0.4.5",
"cors": "^2.8.6",
"express": "^5.2.1",
"helmet": "^8.2.0",
@ -20,6 +21,12 @@
"node": ">=18.0.0"
}
},
"node_modules/@plausible-analytics/tracker": {
"version": "0.4.5",
"resolved": "https://registry.npmjs.org/@plausible-analytics/tracker/-/tracker-0.4.5.tgz",
"integrity": "sha512-6BfAGejXY+YA3Cw6LYT2Zpn4hTxDtPQAawFsYUsQCOg78wIS5C4deAGXTfJffa5VleMWITv5lpJ/EYuQBl1tPA==",
"license": "MIT"
},
"node_modules/accepts": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",

View file

@ -9,6 +9,7 @@
"test": "node --test"
},
"dependencies": {
"@plausible-analytics/tracker": "^0.4.5",
"express": "^5.2.1",
"multer": "^2.1.1",
"cors": "^2.8.6",

View file

@ -1,11 +1,5 @@
const API_BASE = window.location.origin;
window.plausible =
window.plausible ||
function () {
(window.plausible.q = window.plausible.q || []).push(arguments);
};
// Escape user-supplied text before interpolating it into HTML, to prevent XSS.
function escapeHtml(value) {
return String(value).replace(

View file

@ -37,6 +37,14 @@ app.use(
app.use(express.json({ limit: "100mb" }));
app.use(express.static("public"));
// Serve the official Plausible tracker (npm: @plausible-analytics/tracker) from node_modules.
const plausibleTrackerPath =
require.resolve("@plausible-analytics/tracker/plausible.js");
app.get("/vendor/plausible.js", (req, res) => {
res.sendFile(plausibleTrackerPath);
});
// File paths
const DATA_PATH =
process.env.DATA_PATH || path.join(__dirname, "../frontend/fizika.json");