🐛 If umami is broken, don't prevent following links

This commit is contained in:
Dan Jones 2024-05-08 16:22:01 -05:00
commit cde01f25f2

View file

@ -5,26 +5,30 @@ document.addEventListener('click', getFollows);
function getFollows(evt) { function getFollows(evt) {
const el = evt.target; const el = evt.target;
if (el.tagName.toLowerCase() !== 'a') { if (el.tagName.toLowerCase() !== 'a') {
return; return true;
} }
const name = el.dataset.name; const name = el.dataset.name;
if (!name) { if (!name) {
return; return true;
} }
const url = el.href; const url = el.href;
if (!url) { if (!url) {
return; return true;
} }
if (!window.umami) { if (!window.umami) {
return; return true;
} }
const umProm = umami.trackEvent('visit', { type: 'click', site: name }); const umProm = umami.trackEvent('visit', { type: 'click', site: name });
if (!umProm) {
return true;
}
if (!el.target || el.target.match(/^_(self|parent|top)$/i)) { 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 // 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) // Don't wait too long though (half a second, at most)