Merge pull request #1940 from MexHigh/master
Adjusted tracking script to find parent a-tag for click trackingpull/1955/head
commit
288f77d6ff
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue