From ec385e6f5e7d4da8948612510a635a857260481c Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Tue, 3 Jan 2023 14:48:18 -0600 Subject: [PATCH] Deployed on 2023-01-03T14:48:18-06:00 --- .version | 2 +- app.js | 35 +++++++++++++++++++++++++++++++++++ index.html | 28 +++++++++++++++------------- 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 app.js diff --git a/.version b/.version index 3349a72..b83ea60 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -4a965e2 +d73ec6b diff --git a/app.js b/app.js new file mode 100644 index 0000000..4a22048 --- /dev/null +++ b/app.js @@ -0,0 +1,35 @@ +/* global umami */ + +document.addEventListener('click', getFollows); + +function getFollows(evt) { + const el = evt.target; + if (el.tagName.toLowerCase() !== 'a') { + return; + } + + const name = el.dataset.name; + + if (!name) { + return; + } + + const url = el.href; + if (!url) { + return; + } + + if (!window.umami) { + return; + } + + const umProm = umami.trackEvent('visit', { type: 'click', site: name }); + + if (!el.target || el.target.match(/^_(self|parent|top)$/i)) { + // If we're not opening in a new tab, then try to send event before navigating away + // Don't wait too long though (half a second, at most) + evt.preventDefault(); + umProm.then(() => location.href = url).catch(() => location.href = url); + setTimeout(() => location.href = url, 500); + } +} diff --git a/index.html b/index.html index a9e0242..a50539f 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,9 @@ Dan Jones's Links - + + +
@@ -22,73 +24,73 @@