Dynamically Add umami Events to Pages, with Support for halo and wordpress
This post was translated from Chinese by AI. If anything reads oddly, the Chinese original is authoritative. 中文原文
Add a script before </body:
<script>
function addUmamiEvent() {
document.querySelectorAll('a:not([data-umami-event])').forEach(function(a) {
var href = (a.getAttribute('href') || '').trim();
a.setAttribute('data-umami-event', '链接: ' + href);
});
}
addUmamiEvent();
// Support dynamic rendering (such as pjax, ajax, etc.)
var observer = new MutationObserver(addUmamiEvent);
observer.observe(document.body, {childList: true, subtree: true});
</script>
The event attributes will be added automatically

They will also appear in umami:

Comments 0