Dynamically Add umami Events to Pages, with Support for halo and wordpress
- Published
- Views
- 100
- Comments
- 0
- Words
- 18
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