WORST ANALYTICS EVER BIGGEST UPDATE

This commit is contained in:
Soph :3 2025-11-02 12:55:32 +02:00
parent 6b77dd40e9
commit 2911d4f0e7

View file

@ -66,7 +66,7 @@ client.collectDefaultMetrics({ register });
const eventCounter = new client.Counter({
name: "web_event_total",
help: "Aggregated event counts",
labelNames: ["site", "type", "country", "device", "browser", "os"],
labelNames: ["site", "type", "path", "country", "device", "browser", "os"],
});
const durationHist = new client.Histogram({
@ -147,7 +147,19 @@ app.post("/some-cool-endpoint", (req, res) => {
return res.sendStatus(403);
}
eventCounter.labels(site, e.type, country, device, browser, os).inc();
let path = "/";
if (typeof e.path === "string" && e.path) {
path = e.path.startsWith("/") ? e.path : `/${e.path}`;
} else {
try {
if (e.url) {
path = new URL(e.url).pathname || "/";
}
} catch (err) {
}
}
eventCounter.labels(site, e.type, path, country, device, browser, os).inc();
if (e.type === "click" && e.label) {
try {