diff options
| author | Eltrac <hi@guhub.cn> | 2024-12-18 12:41:20 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2024-12-18 12:41:20 +0800 |
| commit | 777edbd10add96b2cba1304630c65ea23fa7159c (patch) | |
| tree | deb517b34f6322e9d6927c25eff4a4df4b88d4f7 | |
| parent | dd09bb78f2fa121e31d816288d1ed33148fa423a (diff) | |
feat(umami): add event tracking
| -rw-r--r-- | themes/yinyang/layouts/_default/list.html | 4 | ||||
| -rw-r--r-- | themes/yinyang/layouts/index.html | 6 | ||||
| -rw-r--r-- | themes/yinyang/layouts/partials/head/headscript.html | 27 |
3 files changed, 27 insertions, 10 deletions
diff --git a/themes/yinyang/layouts/_default/list.html b/themes/yinyang/layouts/_default/list.html index 5ccc0e3f..8cc70a0d 100644 --- a/themes/yinyang/layouts/_default/list.html +++ b/themes/yinyang/layouts/_default/list.html @@ -11,7 +11,7 @@ <div class="posts-title col-xs-10"> <div class="row"> <div class="col-xs-12"> - <a href="{{ .RelPermalink }}"> + <a href="{{ .RelPermalink }}" data-umami-event="Click Post Link from Category Page"> {{ .Title }}{{ with .Params.subtitle }}:<span class="posts-subtitle">{{. }}</span> {{ end }} </a> @@ -22,4 +22,4 @@ {{ end }} </div> </article> -{{ partial "snippets/document-end.html" . }}
\ No newline at end of file +{{ partial "snippets/document-end.html" . }} diff --git a/themes/yinyang/layouts/index.html b/themes/yinyang/layouts/index.html index 9080f1c4..8ded46d5 100644 --- a/themes/yinyang/layouts/index.html +++ b/themes/yinyang/layouts/index.html @@ -23,7 +23,11 @@ <div class="posts-title col-xs-9 col-sm-10"> <div class="row"> <div class="col-xs-11 col-sm-10"> - <a class="posts-title-link" href="{{ .RelPermalink }}">{{ .Title }}</a> + <a + class="posts-title-link" + href="{{ .RelPermalink }}" + data-umami-event="Click Post Link from Index" + >{{ .Title }}</a> <div class="posts-excerpt markdown-body"> {{ if $isFirstPost }} {{ if .Params.description }} diff --git a/themes/yinyang/layouts/partials/head/headscript.html b/themes/yinyang/layouts/partials/head/headscript.html index 5f0c3cbe..72008c9a 100644 --- a/themes/yinyang/layouts/partials/head/headscript.html +++ b/themes/yinyang/layouts/partials/head/headscript.html @@ -30,11 +30,24 @@ <!-- Umami --> <script> - if (window.location.hostname !== 'localhost') { - 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); - } +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 }); +} </script> |
