Adjusted tracking script to find parent a-tag for click tracking

This commit is contained in:
Leon Schmidt 2023-04-20 17:14:41 +02:00
parent b39ef68372
commit a84d2181e7
No known key found for this signature in database
GPG Key ID: C20651EF8C00463B

View File

@ -112,13 +112,21 @@
};
const callback = e => {
const findATagParent = (rootElem, maxSearchDepth) => {
let currentElement = rootElem;
for (let i = 0; i < maxSearchDepth; i++) {
if (currentElement.tagName === 'A')
return currentElement;
currentElement = currentElement.parentElement;
}
return null;
};
const el = e.target;
const anchor =
el.tagName === 'A'
? el
: el.parentElement && el.parentElement.tagName === 'A'
? el.parentElement
: null;
: findATagParent(el, 5);
if (anchor) {
const { href, target } = anchor;