Simplify tracking script integration

This commit is contained in:
thePR0M3TH3AN committed 2025-09-25 11:14:10 -04:00
1 parent 73e5a6bc83
commit f9f9c8149c
6 files changed
+51 -9

No files matched your search

+1
View File
@@ -34,6 +34,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title>
<script src="./js/tracking.js" defer></script>
<script type="module" crossorigin>
var pv = Object.defineProperty;
var gv = (e, t, n) =>
+1
View File
@@ -39,6 +39,7 @@
<meta name="theme-color" content="#0f172a" />
<!-- Styles -->
<script src="js/tracking.js" defer></script>
<link href="css/tailwind.min.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
<link href="css/markdown.css" rel="stylesheet" />
+6 -9
View File
@@ -298,9 +298,6 @@ function handleQueryParams() {
}
}
/**
* Handle #view=... in the hash and load the correct partial view.
*/
function handleHashChange() {
console.log("handleHashChange called, current hash =", window.location.hash);
@@ -327,11 +324,11 @@ function handleHashChange() {
// Now dynamically load that partial, then call its init function
import("./viewManager.js").then(({ loadView, viewInitRegistry }) => {
loadView(viewUrl).then(() => {
const initFn = viewInitRegistry[viewName];
if (typeof initFn === "function") {
initFn();
}
});
loadView(viewUrl).then(() => {
const initFn = viewInitRegistry[viewName];
if (typeof initFn === "function") {
initFn();
}
});
});
}
+41
View File
@@ -0,0 +1,41 @@
// js/tracking.js
// Centralized configuration and loader for the site's analytics script.
// Update `bitvidTrackingConfig` to change the tracking provider or settings.
window.bitvidTrackingConfig = window.bitvidTrackingConfig || {
src: "https://umami.malin.onl/script.js",
websiteId: "1f8eead2-79f0-4dba-8c3b-ed9b08b6e877",
};
(function loadTrackingScript(config) {
if (!config || !config.src) {
return;
}
if (document.querySelector(`script[src="${config.src}"]`)) {
return;
}
const script = document.createElement("script");
script.src = config.src;
script.defer = true;
if (config.websiteId) {
script.setAttribute("data-website-id", config.websiteId);
}
const additionalAttributes = config.attributes || {};
Object.entries(additionalAttributes).forEach(([key, value]) => {
if (key === "defer") {
script.defer = Boolean(value);
return;
}
if (value === false || value === null || typeof value === "undefined") {
return;
}
script.setAttribute(key, value);
});
document.head.appendChild(script);
})(window.bitvidTrackingConfig);
+1
View File
@@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<title>Nostr Ephemeral DM Tester (Using finalizeEvent)</title>
<script src="../js/tracking.js" defer></script>
<style>
/* Basic styling for the demo page */
body {
+1
View File
@@ -17,6 +17,7 @@
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<!-- Scripts: webtorrent, angular, etc. -->
<script src="../js/tracking.js" defer></script>
<script src="bundle.min.js"></script>
<!--<script src="https://cdn.jsdelivr.net/combine/npm/webtorrent/webtorrent.min.js,npm/moment@2,npm/[email protected]/angular.min.js,npm/angular-[email protected]/angular-route.min.js,npm/angular-[email protected]/angular-sanitize.min.js,npm/angular-ui-grid@3/ui-grid.min.js,gh/matowens/ng-notify/dist/ng-notify.min.js,npm/ng-file-[email protected]/dist/ng-file-upload.min.js"></script>-->