Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

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

Leon Schmidta84d2181e709
diff --git a/tracker/index.js b/tracker/index.js
index 4d680c7e3..74a169d0a 100644
--- a/tracker/index.js
+++ b/tracker/index.js
@@ -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;