Script simplification: Less nesting
This commit is contained in:
@@ -86,9 +86,6 @@
|
||||
};
|
||||
|
||||
const handleClicks = () => {
|
||||
document.addEventListener(
|
||||
'click',
|
||||
async e => {
|
||||
const trackElement = async el => {
|
||||
const attr = el.getAttribute.bind(el);
|
||||
const eventName = attr(eventNameAttribute);
|
||||
@@ -103,7 +100,7 @@
|
||||
return track(eventName, eventData);
|
||||
}
|
||||
};
|
||||
|
||||
const onClick = async e => {
|
||||
const el = e.target;
|
||||
const parentElement = el.closest('a,button');
|
||||
if (!parentElement) return trackElement(el);
|
||||
@@ -129,9 +126,8 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
true,
|
||||
);
|
||||
};
|
||||
document.addEventListener('click', onClick, true);
|
||||
};
|
||||
|
||||
/* Tracking functions */
|
||||
|
||||
Reference in New Issue
Block a user