forked from sensorsdata/sa-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvapph5define.min.js
1 lines (1 loc) · 4.59 KB
/
vapph5define.min.js
1
!function(){var e=window.history.pushState,t=window.history.replaceState,n={sdStore:null,getDefineTags:function(e){function t(e,t){var n={level:t,id:"h"+s};s++,e.sensorsDefineStore=n,r.push(e)}function o(e,r){for(var s=0;s<e.length;s++){var a=e[s],d=["input","a","button","textarea"],l=a.tagName.toLowerCase();if(d.indexOf(l)>-1)t(a,r);else if("div"===l&&n.sdStore.heatmap.isCollectableDiv(a,!0)){if(i(a))continue;t(a,r)}a.children&&o(a.children,r+1)}}function i(e){try{if(!(e&&e.parentNode&&e.parentNode.tagName&&e.parentNode.tagName.toLowerCase))return!1;var t=e.parentNode.tagName.toLowerCase();return"body"!==t&&1==e.nodeType&&("a"===t||i(e.parentNode))}catch(o){n.sdStore.log(o)}return!1}var r=[],s=0;return o(e,1),r},getVisibility:function(e){function t(e){var i=e.parentNode;if(9===i.nodeType)return!0;if("0"===n(e,"opacity")||"none"===n(e,"display")||"hidden"===n(e,"visibility"))return!1;if(i){var r=i.getBoundingClientRect();if("hidden"===n(i,"overflow")||"scroll"===n(i,"overflow")){if(o.bottom<=r.top||o.top>=r.bottom||o.right<=r.left||o.left>=r.right)return!1}else if("hidden"===n(i,"overflow-y")||"scroll"===n(i,"overflow-y")){if(o.bottom<=r.top||o.top>=r.bottom)return!1}else if(("hidden"===n(i,"overflow-x")||"scroll"===n(i,"overflow-x"))&&(o.right<=r.left||o.left>=r.right))return!1;return t(i)}return!0}function n(e,t){return window.getComputedStyle?document.defaultView.getComputedStyle(e,null)[t]:e.currentStyle?e.currentStyle[t]:void 0}var o=e.getBoundingClientRect();return t(e)},getZIndex:function(e){var t=window.getComputedStyle(e,null).getPropertyValue("z-index"),n=0;return t&&!isNaN(+t)&&(n=+t),this.sdStore._.isObject(e.sensorsDefineStore)&&(n+=e.sensorsDefineStore.level),n},getSubElements:function(e){function t(e){if(e.children)for(var o=0;o<e.children.length;o++)"object"==typeof e.children[o].sensorsDefineStore&&e.children[o].sensorsDefineStore.id&&n.push(e.children[o].sensorsDefineStore.id),t(e.children[o])}var n=[];return t(e),n},getElementInfo:function(e){var t=e.getBoundingClientRect(),n=e.tagName,o={id:e.sensorsDefineStore.id,$element_content:this.sdStore._.getElementContent(e,n),$element_selector:this.sdStore.heatmap.getDomSelector(e),tagName:n,top:t.top,left:t.left,scrollX:window.pageXOffset,scrollY:window.pageYOffset,width:t.width,height:t.height,scale:window.devicePixelRatio,visibility:this.getVisibility(e),$url:_.isDecodeURI(sd.para.url_is_decode,location.href),$title:document.title,zIndex:this.getZIndex(e),subelements:this.getSubElements(e)};return o},getAllTagsInfo:function(e){for(var t=[],n=0;n<e.length;n++)t.push(this.getElementInfo(e[n]));return this.sortIndex(t)},sortIndex:function(e){e.sort(function(e,t){return e.zIndex-t.zIndex});for(var t=0;t<e.length;t++)delete e[t].zIndex;return e},getDefineInfo:function(){var e=n.getDefineTags(document.children),t=n.getAllTagsInfo(e),o={callType:"visualized_track",data:t};console.log(t),n.postData(o)},postData:function(e){"object"==typeof window.SensorsData_App_Visual_Bridge&&window.SensorsData_App_Visual_Bridge.sensorsdata_visualized_mode&&window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.sensorsdataNativeTracker?window.webkit.messageHandlers.sensorsdataNativeTracker.postMessage(JSON.stringify(e)):"object"==typeof window.SensorsData_App_Visual_Bridge&&window.SensorsData_App_Visual_Bridge.sensorsdata_visualized_mode()&&window.SensorsData_App_Visual_Bridge.sensorsdata_hover_web_nodes&&window.SensorsData_App_Visual_Bridge.sensorsdata_hover_web_nodes(JSON.stringify(e))},addDefineListener:function(e){function t(e,t,n){var o=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver,i=new o(n);i.observe(e,t)}var o=this,i={childList:!0,subtree:!0,attributes:!0},r=function(){return n.sdStore._.throttle(e,1e3)}();t(document.body,i,r),o.sdStore._.addEvent(window,"scroll",r),o.sdStore._.addEvent(window,"resize",r),o.sdStore._.addEvent(window,"load",r)},postPageInfo:function(){function n(){var e={callType:"page_info",data:{$title:document.title,$url:_.isDecodeURI(sd.para.url_is_decode,location.href)}};o.postData(e)}var o=this;n();var i="pushState"in window.history?"popstate":"hashchange";history.pushState=function(){e.apply(window.history,arguments),n()},history.replaceState=function(){t.apply(window.history,arguments),n()},window.addEventListener(i,n)},init:function(){var e=this,t=null;window.sa_jssdk_app_define_mode=function(n,o){o?(e.postPageInfo(),e.getDefineInfo()):(e.sdStore=n,e.postPageInfo(),window.addEventListener("load",function(){this.clearTimeout(t),e.getDefineInfo(),e.addDefineListener(e.getDefineInfo)}),t=setTimeout(function(){e.getDefineInfo(),e.addDefineListener(e.getDefineInfo)},1e3))}}};n.init()}();