summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2024-12-18 12:48:35 +0800
committerEltrac <hi@guhub.cn>2024-12-18 12:48:35 +0800
commit8cfd3e06f1d838780d1089ece33aa12b7dd2b872 (patch)
tree963b9a2cb385d7c8f7a6333b21e5919a1d88fca3
parent777edbd10add96b2cba1304630c65ea23fa7159c (diff)
refactor: track comment event after waline is loaded
-rw-r--r--themes/yinyang/layouts/partials/head/headscript.html28
-rw-r--r--themes/yinyang/layouts/partials/snippets/waline-init.html3
2 files changed, 11 insertions, 20 deletions
diff --git a/themes/yinyang/layouts/partials/head/headscript.html b/themes/yinyang/layouts/partials/head/headscript.html
index 72008c9a..5f7b31b4 100644
--- a/themes/yinyang/layouts/partials/head/headscript.html
+++ b/themes/yinyang/layouts/partials/head/headscript.html
@@ -30,24 +30,12 @@
<!-- Umami -->
<script>
-if (window.location.hostname !== 'localhost') {
- // track traffic
- const script = document.createElement('script');
- script.defer = true;
- script.src = 'https://cloud.umami.is/script.js';
- script.dataset.websiteId = 'ae8c2619-56eb-4577-ac31-9dc6ea44bda7';
- document.head.appendChild(script);
-
- // track waline comment events
- const observer = new MutationObserver(() => {
- const walineButton = document.querySelector("#waline > div > div.wl-comment > div > div.wl-footer > div.wl-info > button.primary.wl-btn");
- if (walineButton) {
- walineButton.addEventListener('click', () => umami.track('Comment'));
- observer.disconnect(); // Stop observing once the button is found
- }
- });
-
- // Observe changes in the document body
- observer.observe(document.body, { childList: true, subtree: true });
-}
+ if (window.location.hostname !== 'localhost') {
+ // track traffic
+ const script = document.createElement('script');
+ script.defer = true;
+ script.src = 'https://cloud.umami.is/script.js';
+ script.dataset.websiteId = 'ae8c2619-56eb-4577-ac31-9dc6ea44bda7';
+ document.head.appendChild(script);
+ }
</script>
diff --git a/themes/yinyang/layouts/partials/snippets/waline-init.html b/themes/yinyang/layouts/partials/snippets/waline-init.html
index 65590344..4d89fc93 100644
--- a/themes/yinyang/layouts/partials/snippets/waline-init.html
+++ b/themes/yinyang/layouts/partials/snippets/waline-init.html
@@ -15,3 +15,6 @@ if (!window.location.pathname.endsWith('/')) {
}
init(options);
+
+const walineButton = document.querySelector("#waline > div > div.wl-comment > div > div.wl-footer > div.wl-info > button.primary.wl-btn");
+walineButton.addEventListener("click", () => umami.track("Comment"))