You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1 lines
3.5 KiB

const e={A:!0,BUTTON:!0,INPUT:!0,TEXTAREA:!0};let t={};const n=["MARK","STRONG","B","EM","I","U","ABBR","INS","DEL","S","SUP"];let r=["data-qidian-click"],o=[],a=!0;const c=window.TOLERANCE_TAGS||["BUTTON"],i=window.TOLERANCE_LEVEL||5;let s=!0,l=!1;function f(n){if(!n)return!1;const r=function(n){const r=(n.tagName||"").toUpperCase();return Object.assign({},e,t)[r]}(n);if(!0===r)return!0;if("object"==typeof r){let e=parseInt(r.max_level,10);isNaN(e)&&(e=1);return g(n)<=e}return!1}function u(e){if(!s||!e)return;if(!e.target)return;const{target:t}=e;let o=!1;t.tagName&&n.includes(t.tagName.toUpperCase())&&function(e){if(!e||!e.tagName||"DIV"!==e.tagName.toUpperCase())return!1;const{children:t}=e;if(!t.length)return!1;for(let e=0;e<t.length;e++){if(!t[e]||!t[e].tagName)return!1;if(!n.includes(t[e].tagName.toUpperCase()))return!1}return!0}(t.parentElement)&&(console.log("[QDTRACKER] div只包含样式标签"),!o&&m(QDTracker,d,t),o=!0),function(e){for(let t=0;t<r.length;t++)if(e.hasAttribute(r[t]))return!0;return!1}(t)&&(console.log("[QDTRACKER] track_attr 中自定义属性"),!o&&m(QDTracker,d,t),o=!0),f(t)&&(console.log("[QDTRACKER] interceptTags 中配置标签"),!o&&m(QDTracker,d,t),o=!0)}const m=function(e,n,r){if(!e.tracker||!e.tracker.track)return;const s=e.tracker.track;if("function"!=typeof s)return;const l=function(e){const n=e,r=n.id,s=n.innerText,l=n.getAttribute("name"),f=n.className,u=n.tagName?n.tagName.toLowerCase():"",m=function(e){const t=[];let n=e;function r(e){let t=1;for(;e.previousSibling;)1===(e=e.previousSibling).nodeType&&(t+=1);return t}for(;n&&n!==e.ownerDocument;){let e=n.tagName?n.tagName.toLowerCase():"";if(n.id)e+=`[@id='${n.id}']`;else if(n.className){let t="";t=n instanceof SVGElement?n.className.baseVal:n.className,e+=`[contains(@class, '${t.replace(/\s+/g," ")}')]`}else"html"!==e&&"body"!==e&&(e+=`[${r(n)}]`);t.unshift(e),n=n.parentNode}return`/${t.join("/")}`}(n),d=n.getBoundingClientRect().left+n.offsetWidth/2,g=n.getBoundingClientRect().top+n.offsetHeight/2,p={};o.forEach((e=>{const r=n.getAttribute(e);if(r)p[e]=r;else if(a){let r=n.parentNode,o=0;for(;r&&o<i;){const n=r.tagName.toUpperCase();if(c.includes(n)||t[n]){const t=r.getAttribute(e);if(t){p[e]=t;break}}r=r.parentNode,o+=1}}}));const N={element_id:r,element_content:s,element_name:l,element_class_name:f,element_type:u,element_path:m,touch_x:parseInt(d,10),touch_y:parseInt(g,10)};return Object.keys(p).forEach((e=>{p[e]&&(N[e]=p[e])})),N}(r);s("$WebClick",l)};let d="";function g(e,t=1){if(!e.children||0===e.children.length)return t;let n=t;for(const r of e.children){const e=g(r,t+1);n=Math.max(n,e)}return n}var p={apply:function(e,n){d=n;const c=((e.getCommonParams()||[])[0]||{}).heatmap||{},i="default"===c.clickmap;function s(e){try{e.contentWindow.document.removeEventListener("click",u,!0),e.contentWindow.document.addEventListener("click",u,!0)}catch(e){console.error("无法为 iframe 添加点击事件监听器:",e)}}if(a=!c.disabledToleracnce,t=c.collect_tags,c.track_attr&&(r=c.track_attr.concat(r)),c.tag_attr&&(o=c.tag_attr.concat(o)),l=c.iframeEnable,i&&(document.removeEventListener("click",u,!0),document.addEventListener("click",u,!0),l)){const e=document.getElementsByTagName("iframe");for(const t of e)s(t);new MutationObserver((e=>{for(const t of e)for(const e of t.addedNodes)e&&e.tagName&&"IFRAME"===e.tagName.toUpperCase()&&s(e)})).observe(document.body,{childList:!0,subtree:!0})}},startIntercepting:function(){s=!0},stopIntercepting:function(){s=!1},startInterceptingIframe:function(){l=!0},stopInterceptingIframe:function(){l=!1}};export{p as default};