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 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 el = e.target;
const anchor = const anchor =
el.tagName === 'A' el.tagName === 'A'
? el ? el
: el.parentElement && el.parentElement.tagName === 'A' : findATagParent(el, 5);
? el.parentElement
: null;
if (anchor) { if (anchor) {
const { href, target } = anchor; const { href, target } = anchor;