Single-binary self-hosted website analytics on Rust axum: collector API, dashboards, world map, and PDF reports.
analyticsaxumdockerrustself-hostedsqliteviteweb-analytics
1// Persists which custom-event cards are enabled. The form's `action` attribute
2// holds the correct endpoint (`/properties/{id}/cards`); we use that directly
3// rather than reconstruct the URL from window.location.
4document.addEventListener("DOMContentLoaded", function () {
5 const form = document.getElementById("custom-card-form");
6 if (!form) return;
7
8 form.addEventListener("change", function () {
9 const data = [];
10 for (const [key, value] of new FormData(form).entries()) {
11 data.push({ event: key, value: value === "on" });
12 }
13 fetch(form.action, {
14 method: "POST",
15 headers: { "Content-Type": "application/json" },
16 body: JSON.stringify(data),
17 })
18 .then((r) => {
19 if (!r.ok) throw new Error(`${form.action} returned HTTP ${r.status}`);
20 window.location.reload();
21 })
22 .catch((err) => {
23 console.error("custom cards save failed:", err);
24 });
25 });
26});