From 82ae1ef877c7175baf73e36aa946d3c91ce2c8e2 Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Thu, 3 Jul 2025 01:34:00 -0400 Subject: [PATCH] watch outbound links --- assets/scripts/main.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assets/scripts/main.ts b/assets/scripts/main.ts index ca24264..8bb795c 100644 --- a/assets/scripts/main.ts +++ b/assets/scripts/main.ts @@ -58,8 +58,20 @@ function addEffect({ target }: UIEvent) { }) } +function attend({ target}: UIEvent) { + if (!isElement(target) || !target.matches("a[href][target=_blank]")) { + return + } + umami?.track(`Link: ${target['innerText'] ?? target.getAttribute('href')}`, { + from: document.location.href, + destination: target.getAttribute('href'), + }) +} + document.addEventListener("mouseenter", addEffect, true) document.addEventListener("focus", addEffect, true) document.addEventListener("mouseleave", removeEffect, true) document.addEventListener("blur", removeEffect, true) + +document.addEventListener("click", attend, true)