Deployed on 2023-01-03T14:48:18-06:00
This commit is contained in:
parent
30292d4a00
commit
ec385e6f5e
3 changed files with 51 additions and 14 deletions
35
app.js
Normal file
35
app.js
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue