forked from sensorsdata/sa-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vapph5define.min.js
1 lines (1 loc) · 4.2 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"+o};o++,e.sensorsDefineStore=n,i.push(e)}function n(e,i){for(var o=0;o<e.length;o++){var r=e[o],s=["input","a","button","textarea"],a=r.tagName.toLowerCase();s.indexOf(a)>-1&&t(r,i),r.children&&n(r.children,i+1)}}var i=[],o=0;return n(e,1),i},getVisibility:function(e){function t(e){var o=e.parentNode;if(9===o.nodeType)return!0;if("0"===n(e,"opacity")||"none"===n(e,"display")||"hidden"===n(e,"visibility"))return!1;if(o){var r=o.getBoundingClientRect();if("hidden"===n(o,"overflow")||"scroll"===n(o,"overflow")){if(i.bottom<=r.top||i.top>=r.bottom||i.right<=r.left||i.left>=r.right)return!1}else if("hidden"===n(o,"overflow-y")||"scroll"===n(o,"overflow-y")){if(i.bottom<=r.top||i.top>=r.bottom)return!1}else if(("hidden"===n(o,"overflow-x")||"scroll"===n(o,"overflow-x"))&&(i.right<=r.left||i.left>=r.right))return!1;return t(o)}return!0}function n(e,t){return window.getComputedStyle?document.defaultView.getComputedStyle(e,null)[t]:e.currentStyle?e.currentStyle[t]:void 0}var i=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 i=0;i<e.children.length;i++)"object"==typeof e.children[i].sensorsDefineStore&&e.children[i].sensorsDefineStore.id&&n.push(e.children[i].sensorsDefineStore.id),t(e.children[i])}var n=[];return t(e),n},getElementInfo:function(e){var t=e.getBoundingClientRect(),n=e.tagName,i={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:location.href,$title:document.title,zIndex:this.getZIndex(e),subelements:this.getSubElements(e)};return i},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),i={callType:"visualized_track",data:t};console.log(t),n.postData(i)},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 i=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver,o=new i(n);o.observe(e,t)}var i=this,o={childList:!0,subtree:!0,attributes:!0},r=function(){return n.sdStore._.throttle(e,1e3)}();t(document.body,o,r),i.sdStore._.addEvent(window,"scroll",r),i.sdStore._.addEvent(window,"resize",r),i.sdStore._.addEvent(window,"load",r)},postPageInfo:function(){function n(){var e={callType:"page_info",data:{$title:document.title,$url:location.href}};i.postData(e)}var i=this;n();var o="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(o,n)},init:function(){var e=this,t=null;window.sa_jssdk_app_define_mode=function(n,i){i?(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()}();