Merge pull request #1940 from MexHigh/master

Adjusted tracking script to find parent a-tag for click tracking
This commit is contained in:
Mike Cao 2023-04-20 11:34:18 -07:00 committed by GitHub
commit 288f77d6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;