@datarangers/sdk-javascript 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/es/index.min.js +1 -0
- package/core/lib/index.min.js +1 -0
- package/es/index-base.min.js +6430 -1
- package/es/index.min.js +9936 -1
- package/es/plugin/ab.js +928 -1
- package/es/plugin/autotrack.js +1897 -1
- package/es/plugin/duration.js +117 -1
- package/es/plugin/route.js +363 -1
- package/es/plugin/stay.js +547 -1
- package/es/plugin/store.js +151 -1
- package/lib/index-base.min.js +6435 -1
- package/lib/index.min.js +9941 -1
- package/lib/plugin/ab.js +930 -1
- package/lib/plugin/autotrack.js +1899 -1
- package/lib/plugin/duration.js +119 -1
- package/lib/plugin/route.js +365 -1
- package/lib/plugin/stay.js +549 -1
- package/lib/plugin/store.js +153 -1
- package/package.json +2 -2
package/lib/plugin/autotrack.js
CHANGED
|
@@ -1 +1,1899 @@
|
|
|
1
|
-
"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)},t=function(e){return Array.isArray(e)};Date.now(),Number((""+Math.random()).slice(2,8));function n(e,t){if(void 0===t&&(t="list"),!e)return!1;if(t&&"list"===t){if(["LI","TR","DL"].includes(e.nodeName))return!0;if(e.dataset&&e.dataset.hasOwnProperty("teaIdx"))return!0;if(e.hasAttribute&&e.hasAttribute("data-tea-idx"))return!0}else{if(["A","BUTTON"].includes(e.nodeName))return!0;if(e.dataset&&e.dataset.hasOwnProperty("teaContainer"))return!0;if(e.hasAttribute&&e.hasAttribute("data-tea-container"))return!0;if(e.hasAttribute&&s(e,"ss"))return!0}return!1}var i=function(e,t){return!!s(e,t)};function o(e){for(var t=e;t&&!n(t,"container");){if("HTML"===t.nodeName||"BODY"===t.nodeName)return e;t=t.parentElement}return t||e}function r(e){var t="";return 3===e.nodeType?t=e.textContent.trim():e.dataset&&e.dataset.hasOwnProperty("teaTitle")||e.hasAttribute("ata-tea-title")?t=e.getAttribute("data-tea-title"):e.hasAttribute("title")?t=e.getAttribute("title"):"INPUT"===e.nodeName&&["button","submit"].includes(e.getAttribute("type"))?t=e.getAttribute("value"):"IMG"===e.nodeName&&e.getAttribute("alt")&&(t=e.getAttribute("alt")),t.slice(0,200)}var a=function(e,t){return e.hasAttribute?e.hasAttribute(t):e.attributes?!(!e.attributes[t]||!e.attributes[t].specified):void 0},s=function(e,n){if("string"==typeof n)return a(e,n);if(t(n)){for(var i=!1,o=0;o<n.length;o++){if(a(e,n[o])){i=!0;break}}return i}};var c=function(){function t(t,o,r){var a=this;this.clickEvent=function(e){(function(e,t){if(1!==e.nodeType)return!1;if(!t.svg&&function(e){if("svg"===e.tagName.toLowerCase())return!0;for(var t=e.parentElement,n=!1;t;)"svg"===t.tagName.toLowerCase()?(t=null,n=!0):t=t.parentElement;return n}(e))return!1;if(["HTML","BODY"].includes(e.tagName.toUpperCase()))return!1;var o=e;return!!("none"!==o.style.display&&(n(o,"container")||t.track_attr&&i(o,t.track_attr)||function(e){if(e.children.length){var t=e.children;return![].slice.call(t).some((function(e){return e.children.length>0}))}return!0}(o)))})(e.target,a.options)&&a.eventHandel({eventType:"dom",eventName:"click"},e)},this.changeEvent=function(e){a.eventHandel({eventType:"dom",eventName:"change"},e)},this.submitEvent=function(e){a.eventHandel({eventType:"dom",eventName:"submit"},e)},this.getPageViewEvent=function(t,n){n&&"pushState"===n&&a.eventHandel({eventType:"dom",eventName:"beat"},e({beat_type:0},t)),a.eventHandel({eventType:"dom",eventName:"page_view"},t)},this.getPageLoadEvent=function(e){a.eventHandel({eventType:"dom",eventName:"page_statistics"},{lcp:e})},this.config=r.getConfig().eventConfig,this.collect=o,this.options=t,this.beatTime=t.beat,this.statistics=!1}return t.prototype.init=function(e){this.eventHandel=e;var t=this.config.mode;this.addListener(t)},t.prototype.addListener=function(e){var t=this;if("proxy-capturing"===e&&(this.config.click&&window.document.addEventListener("click",this.clickEvent,!0),this.config.change&&window.document.addEventListener("change",this.changeEvent,!0),this.config.submit&&window.document.addEventListener("submit",this.submitEvent,!0),this.config.pv&&this.collect.on("route-change",(function(e){var n=e.config,i=e.name;t.getPageViewEvent(n,i)})),this.config.beat)){try{"complete"===document.readyState?this.beatEvent(this.beatTime):window.addEventListener("load",(function(){t.beatEvent(t.beatTime)}));var n=0,i=null;window.addEventListener("scroll",(function(){clearTimeout(i),i=setTimeout(o,500),n=document.documentElement.scrollTop||document.body.scrollTop}));var o=function(){(document.documentElement.scrollTop||document.body.scrollTop)==n&&t.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:1})}}catch(e){}try{var r=window.performance&&window.performance.getEntriesByType("paint");if(r&&r.length){var a=new PerformanceObserver((function(e){var n=e.getEntries(),i=n[n.length-1],o=i.renderTime||i.loadTime;t.statistics||(t.getPageLoadEvent(o),t.statistics=!0)}));a.observe({entryTypes:["largest-contentful-paint"]}),setTimeout((function(){t.statistics||(t.getPageLoadEvent(r[0].startTime||0),t.statistics=!0)}),2e3)}else this.getPageLoadEvent(0)}catch(e){this.getPageLoadEvent(0)}}},t.prototype.removeListener=function(){window.document.removeEventListener("click",this.clickEvent,!0),window.document.removeEventListener("change",this.changeEvent,!0),window.document.removeEventListener("submit",this.submitEvent,!0)},t.prototype.beatEvent=function(e){var t,n=this;try{var i;this.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:3}),this.beatTime&&(i=setInterval((function(){n.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:2})}),e)),t=function(){n.eventHandel({eventType:"dom",eventName:"beat",eventSend:"becon"},{beat_type:0}),n.beatTime&&clearInterval(i)},navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?window.addEventListener("pagehide",t,!1):window.addEventListener("beforeunload",t,!1)}catch(e){}},t}(),u={eventConfig:{mode:"proxy-capturing",submit:!1,click:!0,change:!1,pv:!0,beat:!0,hashTag:!1,impr:!1},scoutConfig:{mode:"xpath"}},d=function(){function e(e,t){this.config=e,this.config.eventConfig=Object.assign(this.config.eventConfig,t)}return e.prototype.getConfig=function(){return this.config},e.prototype.setConfig=function(e){return this.config=e},e}();function l(e){for(var t=[];null!==e.parentElement;)t.push(e),e=e.parentElement;var i=[],o=[];return t.forEach((function(e){var t=function(e){if(null===e)return{str:"",index:0};var t=0,i=e.parentElement;if(i)for(var o=i.children,r=0;r<o.length&&o[r]!==e;r++)o[r].nodeName===e.nodeName&&t++;return{str:[e.nodeName.toLowerCase(),n(e,"list")?"[]":""].join(""),index:t}}(e),r=t.str,a=t.index;i.unshift(r),o.unshift(a)})),{element_path:"/"+i.join("/"),positions:o}}function p(e,n,s,c){var u={},d=function(e){if(e){var t=e.getBoundingClientRect(),n=t.width,i=t.height;return{left:t.left,top:t.top,element_width:n,element_height:i}}}(n),p=function(e,t){void 0===e&&(e={}),void 0===t&&(t={});var n=e.clientX,i=e.clientY,o=t.left,r=t.top,a=n-o>=0?n-o:0,s=i-r>=0?i-r:0;return{touch_x:Math.floor(a),touch_y:Math.floor(s)}}(e,d),h=d.element_width,v=d.element_height,f=p.touch_x,g=p.touch_y,m=l(n),_=m.element_path,b=m.positions,y=function(e){var t=o(e),n=[];return function e(t){var i=r(t);if(i&&-1===n.indexOf(i)&&n.push(i),t.childNodes.length>0)for(var o=t.childNodes,a=0;a<o.length;a++)8!==o[a].nodeType&&e(o[a])}(t),n}(n),w=window.performance.timing.navigationStart,E=Date.now()-w,T=b.map((function(e){return""+e})),x=null;if(window.TEAVisualEditor.getOriginXpath&&(x=window.TEAVisualEditor.getOriginXpath({xpath:_,positions:T})),u.element_path=x&&x.xpath||_,u.positions=x&&x.positions||T,c&&!c.text&&(u.texts=y,u.element_title=function(e){var t=o(e),n="";return function e(t){var i=r(t);if(i&&(n+=i),t.childNodes.length>0)for(var o=t.childNodes,a=0;a<o.length;a++)3===o[a].nodeType&&e(o[a])}(t),n}(n)),u.element_id=n.getAttribute("id")||"",u.element_class_name=n.getAttribute("class")||"",u.element_type=n.nodeType,u.element_width=Math.floor(h),u.element_height=Math.floor(v),u.touch_x=f,u.touch_y=g,u.page_manual_key="",u.elememt_manual_key="",u.since_page_start_ms=E,u.page_start_ms=w,u.page_path=location.pathname,u.page_host=location.host,s.track_attr&&i(n,s.track_attr)){var A=function(e,n){var i={};if("string"==typeof n)a(e,n)&&(i.attrs=e.getAttribute(n));else if(t(n))for(var o=0;o<n.length;o++)a(e,n[o])&&(i[n[o]]=e.getAttribute(n[o]));return i}(n,s.track_attr);for(var k in A)u[k]=A[k]}var N=o(n);return"A"===N.tagName&&(u.href=N.getAttribute("href")),"IMG"===n.tagName&&(u.src=n.getAttribute("src")),u}var h=function(t,n,i,o,r){return e({event:t},p(n,i,o,r),{is_html:1,page_key:window.location.href,page_title:document.title})},v=function(){function t(e,t){this.ignore={text:!1},this.initConfig=e,this.options=t,this.eventName=t&&"tea"===t.custom?{click:"__bav_click",page:"__bav_page",beat:"__bav_beat",static:"__bav_page_statistics",exposure:"__bav_page_exposure"}:{click:"bav2b_click",page:"bav2b_page",beat:"bav2b_beat",static:"bav2b_page_statistics",exposure:"bav2b_exposure"},t&&!1===t.text&&(this.ignore.text=!0),t&&t.exposure&&t.exposure.eventName&&(this.eventName.exposure=t.exposure.eventName)}return t.prototype.handleEvent=function(t,n){try{if(function(e){for(var t=e;t&&t.parentNode;){if(t.hasAttribute("data-tea-ignore"))return!0;if("HTML"===t.nodeName||"body"===t.nodeName)return!1;t=t.parentNode}return!1}(t.target))return null;var i="bav2b_click";switch(n){case"click":return i=this.eventName.click,h(i,t,t.target,this.options,this.ignore);case"exposure":return i=this.eventName.exposure,h(i,t,t.target,this.options,this.ignore);case"change":return e({},h(i="bav2b_change",t,t.target,this.options),function(e,t){try{if("bav2b_change"===e)return t.hasAttribute("data-tea-track")?{value:t.value}:{}}catch(e){return{}}}(i,t.target));case"submit":return h(i="bav2b_submit",t,t.target,this.options)}}catch(e){return console.error(e),null}},t.prototype.handleViewEvent=function(e){e.event=this.eventName.page,e.page_title=document.title,e.page_total_width=window.innerWidth,e.page_total_height=window.innerHeight;try{var t=window.sessionStorage.getItem("_tea_cache_duration");if(t){var n=JSON.parse(t);e.refer_page_duration_ms=n?n.duration:""}e.scroll_width=document.documentElement.scrollLeft?document.documentElement.scrollLeft+window.innerWidth:window.innerWidth,e.scroll_height=document.documentElement.scrollTop?document.documentElement.scrollTop+window.innerHeight:window.innerHeight,e.page_start_ms=window.performance.timing.navigationStart}catch(e){console.log("page event error "+JSON.stringify(e))}return e},t.prototype.handleStatisticsEvent=function(e){var t={};t.event=this.eventName.static,t.is_html=1,t.page_key=location.href,t.refer_page_key=document.referrer||"",t.page_title=document.title,t.page_manual_key=this.initConfig.autotrack.page_manual_key||"",t.refer_page_manual_key="";try{var n=e.lcp,i=window.performance.timing,o=i.loadEventEnd-i.navigationStart;t.page_init_cost_ms=parseInt(n||(o>0?o:0)),t.page_start_ms=i.navigationStart}catch(e){console.log("page_statistics event error "+JSON.stringify(e))}return t},t.prototype.handleBeadtEvent=function(e){e.event=this.eventName.beat,e.page_key=window.location.href,e.is_html=1,e.page_title=document.title,e.page_manual_key=this.initConfig.autotrack.page_manual_key||"";try{e.page_viewport_width=window.innerWidth,e.page_viewport_height=window.innerHeight,e.page_total_width=document.documentElement.scrollWidth,e.page_total_height=document.documentElement.scrollHeight,e.scroll_width=document.documentElement.scrollLeft+window.innerWidth,e.scroll_height=document.documentElement.scrollTop+window.innerHeight,e.since_page_start_ms=Date.now()-window.performance.timing.navigationStart,e.page_start_ms=window.performance.timing.navigationStart}catch(e){console.log("beat event error "+JSON.stringify(e))}return e},t}(),f=function(){function e(e){this.collect=e,this.eventNameList=["report_click_event","report_change_event","report_submit_event","report_exposure_event","report_page_view_event","report_page_statistics_event","report_beat_event"]}return e.prototype.send=function(e,t){var n=e.eventSend,i=t.event;delete t.event,n&&"becon"===n?this.collect.beconEvent(i,t):this.collect.event(i,t)},e.prototype.get=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"GET"},t);fetch(e,n)},e.prototype.post=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"POST"},t);fetch(e,n)},e}(),g={},m=[];function _(e,t,n,i){var o=e&&e.source||window.opener||window.parent,r=e&&e.origin||i||"*",a={type:t,payload:n};o.postMessage(JSON.stringify(a),r)}function b(e,t){g[e]=g[e]||[],g[e].push(t)}function y(e){if(m.some((function(e){return"*"===e}))||m.some((function(t){return e.origin===t}))){var t=e.data;if("string"==typeof e.data)try{t=JSON.parse(e.data)}catch(e){t=void 0}if(!t)return;var n=t.type,i=t.payload;g[n]&&g[n].forEach((function(t){"function"==typeof t&&t(e,i)}))}}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var w=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){e.exports=function(){function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)e[i]=n[i]}return e}function t(n,i){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=e({},i,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var s in r)r[s]&&(a+="; "+s,!0!==r[s]&&(a+="="+r[s].split(";")[0]));return document.cookie=t+"="+n.write(o,t)+a}}function r(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],i={},o=0;o<t.length;o++){var r=t[o].split("="),a=r.slice(1).join("=");try{var s=decodeURIComponent(r[0]);if(i[s]=n.read(a,s),e===s)break}catch(e){}}return e?i[e]:i}}return Object.create({set:o,get:r,remove:function(t,n){o(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(i)},converter:{value:Object.freeze(n)}})}return t({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}()})),E=w;function T(){try{var e=window.TEAVisualEditor.lang=window.TEAVisualEditor.lang||E.get("lang"),t=window.TEAVisualEditor.__editor_ajax_domain=window.TEAVisualEditor.__editor_ajax_domain||E.get("_TEA_VE_APIHOST"),n=window.TEAVisualEditor.__editor_verison=window.TEAVisualEditor.__editor_verison||E.get("_VISUAL_EDITOR_V"),i=window.TEAVisualEditor.__editor_url=window.TEAVisualEditor.__editor_url||E.get("_VISUAL_EDITOR_U"),o=+new Date,r=new Date(o+18e5);E.set("_TEA_VE_OPEN","1",{expires:r}),E.set("_TEA_VE_APIHOST",t,{expires:r}),E.set("_VISUAL_EDITOR_U",i,{expires:r}),E.set("lang",e,{expires:r}),E.set("_VISUAL_EDITOR_V",n||"",{expires:r})}catch(e){console.log("set cookie err")}}var x=!1;function A(e){var t,n,i,o,r=e.event,a=e.editorUrl,s=e.autoTrackInstance;x||(x=!0,t=a,n=function(){_(r,"editorScriptloadSuccess"),s.destroy()},i=function(){r&&_(r,"editorScriptloadError"),x=!1},(o=document.createElement("script")).src=t,o.onerror=function(){i(t)},o.onload=function(){n()},document.getElementsByTagName("head")[0].appendChild(o))}function k(t,n){window.TEAVisualEditor=window.TEAVisualEditor||{};var i="",o="https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/visual-editor-rangers.js?query="+Date.now();window.TEAVisualEditor.appId=n.app_id;var r,a,s,c=n.channel_domain,u="";if((r=["*"]).length&&r.forEach((function(e){m.push(e)})),c){var d,l="";try{var p=window.performance.getEntriesByType("resource");if(p&&p.length&&(p.forEach((function(e){"script"===e.initiatorType&&e.name&&-1!==e.name.indexOf("collect")&&(l=e.name)})),l||document.currentScript&&(l=document.currentScript.src),l&&(d=l.split("/"))&&d.length)){u="https:/";for(var h=2;h<d.length&&h!==d.length-1;h++)u=u+"/"+d[h];if(u&&u.indexOf("/5.0")){var v=u.split("/5.0");u=v[0]||u}}}catch(e){}}if(a="0.0.6",(s=e({},n)).filter&&delete s.filter,"object"==typeof s.autotrack&&s.autotrack.collect_url&&delete s.autotrack.collect_url,(window.opener||window.parent).postMessage({type:"tea:sdk:info",config:s,version:a},"*"),window.addEventListener("message",y,!1),"1"===E.get("_TEA_VE_OPEN")){var f=function(){var e=E.get("_TEA_VE_APIHOST");try{e=JSON.parse(e)}catch(e){}return e}(),g="";f&&(window.TEAVisualEditor.__editor_ajax_domain=f,g=E.get("_VISUAL_EDITOR_U")),A({event:null,editorUrl:g||o,autoTrackInstance:t}),T()}else try{b("tea:openVisualEditor",(function(e){var n=e.data;if("string"==typeof e.data)try{n=JSON.parse(e.data)}catch(e){n=void 0}if(n){var r=n.referrer,a=n.lang;if(r&&(window.TEAVisualEditor.__editor_ajax_domain=r),i=o,c){var s=n.version;i=u?""+u+(s?"/visual-editor-rangers-v"+s:"/visual-editor-rangers-v1.0.0")+".js":o,window.TEAVisualEditor.__editor_verison=s}window.TEAVisualEditor.__editor_url=i,window.TEAVisualEditor.lang=a,A({event:e,editorUrl:i,autoTrackInstance:t}),T()}})),window.TEAVisualEditor.openAutotrackEditor=function(){A({event:null,editorUrl:window.TEAVisualEditor.__editor_url,autoTrackInstance:t})}}catch(e){console.log("receive message error")}try{b("tea:openHeatMapCore",(function(e){A({event:e,editorUrl:"https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/heatmap-core.js?query="+Date.now(),autoTrackInstance:t})}))}catch(e){console.log("openHeatMapCore error")}}var N=function(){function e(e){this._instance=null,this._intersection=e,this._intersection&&this.init()}return e.prototype.init=function(){var e=this;MutationObserver?(this._instance=new MutationObserver((function(t){t.forEach((function(t){"attributes"===t.type&&e.attributeChangeObserve(t),"childList"===t.type&&e.modifyNodeObserve(t)}))})),this._instance.observe(document.body,{childList:!0,attributes:!0,subtree:!0,attributeOldValue:!1})):console.log("your browser cannot support MutationObserver")},e.prototype.attributeChangeObserve=function(e){e.target.hasAttribute("data-exposure")?this.exposureAdd(e,"mutation"):this.exposureRemove(e)},e.prototype.modifyNodeObserve=function(e){var t=this;Array.prototype.forEach.call(e.addedNodes,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t.exposureAdd(e,"intersect"),t.mapChild(e,t.exposureAdd)})),Array.prototype.forEach.call(e.removedNodes,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t.exposureRemove(e),t.mapChild(e,t.exposureRemove)}))},e.prototype.mapChild=function(e,t){var n=this;1===e.nodeType&&e.children.length&&Array.prototype.forEach.call(e.children,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t(e),n.mapChild(e,t)}))},e.prototype.exposureAdd=function(e,t){try{this._intersection&&this._intersection.exposureAdd(e,t)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},e.prototype.exposureRemove=function(e){try{this._intersection&&this._intersection.exposureRemove(e)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},e._exposure_observer=null,e}(),O=function(){function e(t,n){this.count=1,this.instance=this.buildObserver(),this.observeMap=e._observer_map,t.autotrack.exposure.ratio?this.Ratio=t.autotrack.exposure.ratio:0===t.autotrack.exposure.ratio?this.Ratio=0:this.Ratio=.5,this.EventHandle=n}return e.prototype.buildObserver=function(){var t=this;return e._observer_instance?(console.log("your browser cannot support IntersectionObserver"),null):(IntersectionObserver&&(e._observer_instance=new IntersectionObserver((function(e){e.forEach((function(e){t.observeMap.get(e.target._observeId)&&t.exposureEvent(e)}))}),{threshold:[.01,.25,.5,.75,1]})),e._observer_instance)},e.prototype.exposureAdd=function(e,t){var n=e;"mutation"===t&&(n=e.target);var i=n._observeId;if(i||this.observeMap.has(i)){if(!1===n.visible){var o=n.getBoundingClientRect(),r=o.top,a=o.left,s=o.right,c=o.bottom;r>=0&&c<=window.innerHeight&&a>=0&&s<=window.innerWidth&&(n.visible=!0,this.EventHandle({eventType:"dom",eventName:"exposure"},e))}}else n._observeId=this.count,n.visible=!1,this.observeMap.set(this.count,n),this.observe(n),this.count++},e.prototype.exposureRemove=function(e){this.observeMap.has(e._observeId)&&(this.observeMap.delete(e._observeId),this.unobserve(e))},e.prototype.exposureEvent=function(e){if(e.intersectionRatio>=this.Ratio&&e.isIntersecting){if("0"===e.target.style.opacity||"hidden"===e.target.style.visibility)return;if(!0===e.target.visible)return;e.target.visible=!0,this.EventHandle({eventType:"dom",eventName:"exposure"},e)}else e.target.visible=!1},e.prototype.observe=function(e){this.instance&&this.instance.observe(e)},e.prototype.unobserve=function(e){this.instance&&this.instance.unobserve(e)},e._observer_instance=null,e._observer_map=new Map,e}(),S=function(){function e(e,t){e.autotrack&&e.autotrack.exposure&&(this._intersection=new O(e,t),this._observer=new N(this._intersection),this._intersection&&this._observer?this.initObserver():console.log("your browser version cannot support exposure, please update~"))}return e.prototype.initObserver=function(){var e=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),(function(t){e._intersection.exposureAdd(t,"intersect")}))},e}(),I={hashTag:!1,impr:!1},C=function(){function e(){}return e.prototype.apply=function(e,t){if(this.autoTrackStart=!1,this.collect=e,this.config=t,t.autotrack){var n=e.Types;t.autotrack&&t.autotrack.collect_url&&!t.autotrack.collect_url()||(this.ready(n.Autotrack),this.collect.emit(n.AutotrackReady))}},e.prototype.ready=function(e){this.collect.set(e);var t=this.config.autotrack;t="object"==typeof t?t:{},t=Object.assign(I,t),this.destroyed=!1,this.options=t,this.Config=new d(u,this.options),this.Exposure=new S(this.config,this.handle.bind(this)),this.Listener=new c(t,this.collect,this.Config),this.EventHandle=new v(this.config,t),this.Request=new f(this.collect),this.autoTrackStart=!0,this.init(),k(this,this.config)},e.prototype.init=function(){this.Listener.init(this.handle.bind(this))},e.prototype.handle=function(e,t){"dom"===e.eventType&&this.handleDom(e,t)},e.prototype.handleDom=function(e,t){try{var n=e.eventName;if("click"===n||"exposure"===n||"change"===n||"submit"===n){var i=this.EventHandle.handleEvent(t,n);null!==i&&this.Request.send({eventType:"custom",eventName:"report_"+n+"_event",extra:{methods:"GET"}},i)}else if("page_view"===n||"page_statistics"===n){var o=void 0;o="page_view"===n?this.EventHandle.handleViewEvent(t):this.EventHandle.handleStatisticsEvent(t),this.Request.send({eventType:"custom",eventName:"report_${eventName}_event",extra:{methods:"GET"}},o)}else if("beat"===n){var r=this.EventHandle.handleBeadtEvent(t),a=e.eventSend;this.Request.send({eventType:"custom",eventName:"report_${eventName}_event",extra:{methods:"GET"},eventSend:a},r)}}catch(e){console.log("handel dom event error "+JSON.stringify(e))}},e.prototype.destroy=function(){if(!this.autoTrackStart)return console.warn("engine is undefined, make sure you have called autoTrack.start()");this.autoTrackStart=!1,this.Listener.removeListener()},e}();module.exports=C;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
|
|
18
|
+
var __assign = function() {
|
|
19
|
+
__assign = Object.assign || function __assign(t) {
|
|
20
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
+
s = arguments[i];
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function __read(o, n) {
|
|
30
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
31
|
+
if (!m) return o;
|
|
32
|
+
var i = m.call(o), r, ar = [], e;
|
|
33
|
+
try {
|
|
34
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
35
|
+
}
|
|
36
|
+
catch (error) { e = { error: error }; }
|
|
37
|
+
finally {
|
|
38
|
+
try {
|
|
39
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
40
|
+
}
|
|
41
|
+
finally { if (e) throw e.error; }
|
|
42
|
+
}
|
|
43
|
+
return ar;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @deprecated */
|
|
47
|
+
function __spread() {
|
|
48
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
49
|
+
ar = ar.concat(__read(arguments[i]));
|
|
50
|
+
return ar;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
54
|
+
var isArray = function isArray(obj) {
|
|
55
|
+
return Array.isArray(obj);
|
|
56
|
+
};
|
|
57
|
+
(function () {
|
|
58
|
+
var lastEventId = +Date.now() + Number(("" + Math.random()).slice(2, 8));
|
|
59
|
+
return function () {
|
|
60
|
+
lastEventId += 1;
|
|
61
|
+
return lastEventId;
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
var beforePageUnload = function beforePageUnload(fn) {
|
|
65
|
+
var isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
|
|
66
|
+
|
|
67
|
+
if (isiOS) {
|
|
68
|
+
window.addEventListener("pagehide", fn, false);
|
|
69
|
+
} else {
|
|
70
|
+
window.addEventListener("beforeunload", fn, false);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var addListener = function addListener(target, type, handler, pop) {
|
|
74
|
+
if (target.addEventListener) {
|
|
75
|
+
target.addEventListener(type, handler, pop);
|
|
76
|
+
} else if (target.attachEven) {
|
|
77
|
+
target.attachEven("on" + type, handler);
|
|
78
|
+
} else {
|
|
79
|
+
target["on" + type] = handler;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var removeListener = function removeListener(target, type, handler, pop) {
|
|
83
|
+
if (target.addEventListener) {
|
|
84
|
+
target.removeEventListener(type, handler, pop);
|
|
85
|
+
} else if (target.attachEven) {
|
|
86
|
+
target.detachEven("on" + type, handler);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
91
|
+
function isNeedElement(element, type) {
|
|
92
|
+
if (type === void 0) {
|
|
93
|
+
type = 'list';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!element) return false;
|
|
97
|
+
|
|
98
|
+
if (type && type === 'list') {
|
|
99
|
+
if (['LI', 'TR', 'DL'].includes(element.nodeName)) return true;
|
|
100
|
+
if (element.dataset && element.dataset.hasOwnProperty('teaIdx')) return true;
|
|
101
|
+
if (element.hasAttribute && element.hasAttribute('data-tea-idx')) return true;
|
|
102
|
+
} else {
|
|
103
|
+
if (['A', 'BUTTON'].includes(element.nodeName)) return true;
|
|
104
|
+
if (element.dataset && element.dataset.hasOwnProperty('teaContainer')) return true;
|
|
105
|
+
if (element.hasAttribute && element.hasAttribute('data-tea-container')) return true;
|
|
106
|
+
if (element.hasAttribute && hasAttributes(element, 'ss')) return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
var isAttrFilter = function isAttrFilter(element, attrs) {
|
|
112
|
+
if (hasAttributes(element, attrs)) return true;
|
|
113
|
+
return false;
|
|
114
|
+
};
|
|
115
|
+
function getContainer(element) {
|
|
116
|
+
var current = element;
|
|
117
|
+
|
|
118
|
+
while (current && !isNeedElement(current, 'container')) {
|
|
119
|
+
if (current.nodeName === 'HTML' || current.nodeName === 'BODY') {
|
|
120
|
+
return element;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
current = current.parentElement;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return current || element;
|
|
127
|
+
}
|
|
128
|
+
function getNodeText(node) {
|
|
129
|
+
var text = '';
|
|
130
|
+
|
|
131
|
+
if (node.nodeType === 3) {
|
|
132
|
+
text = node.textContent.trim();
|
|
133
|
+
} else if (node['dataset'] && node['dataset'].hasOwnProperty('teaTitle')) {
|
|
134
|
+
text = node['getAttribute']('data-tea-title');
|
|
135
|
+
} else if (node['hasAttribute']('ata-tea-title')) {
|
|
136
|
+
text = node['getAttribute']('data-tea-title');
|
|
137
|
+
} else if (node['hasAttribute']('title')) {
|
|
138
|
+
text = node['getAttribute']('title');
|
|
139
|
+
} else if (node.nodeName === 'INPUT' && ['button', 'submit'].includes(node['getAttribute']('type'))) {
|
|
140
|
+
text = node['getAttribute']('value');
|
|
141
|
+
} else if (node.nodeName === 'IMG' && node['getAttribute']('alt')) {
|
|
142
|
+
text = node['getAttribute']('alt');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return text.slice(0, 200);
|
|
146
|
+
}
|
|
147
|
+
function getText(element) {
|
|
148
|
+
var ele = getContainer(element);
|
|
149
|
+
var textArr = [];
|
|
150
|
+
|
|
151
|
+
(function _get(node) {
|
|
152
|
+
var text = getNodeText(node);
|
|
153
|
+
|
|
154
|
+
if (text && textArr.indexOf(text) === -1) {
|
|
155
|
+
textArr.push(text);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (node.childNodes.length > 0) {
|
|
159
|
+
var childNodes = node.childNodes;
|
|
160
|
+
|
|
161
|
+
for (var i = 0; i < childNodes.length; i++) {
|
|
162
|
+
if (childNodes[i].nodeType !== 8) {
|
|
163
|
+
_get(childNodes[i]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
})(ele);
|
|
168
|
+
|
|
169
|
+
return textArr;
|
|
170
|
+
}
|
|
171
|
+
var getElementText = function getElementText(element) {
|
|
172
|
+
if (!element) return '';
|
|
173
|
+
var elementText = '';
|
|
174
|
+
|
|
175
|
+
if (element.textContent) {
|
|
176
|
+
elementText = element.textContent.trim();
|
|
177
|
+
} else if (element.innerText) {
|
|
178
|
+
elementText = element.innerText.trim();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (element.tagName === 'input' || element.tagName === 'INPUT') {
|
|
182
|
+
elementText = element.value || '';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return elementText;
|
|
186
|
+
};
|
|
187
|
+
function ignore(element) {
|
|
188
|
+
var _element = element;
|
|
189
|
+
|
|
190
|
+
while (_element && _element.parentNode) {
|
|
191
|
+
if (_element.hasAttribute('data-tea-ignore')) return true;
|
|
192
|
+
if (_element.nodeName === 'HTML' || _element.nodeName === 'body') return false;
|
|
193
|
+
_element = _element.parentNode;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
var hasAttribute = function hasAttribute(ele, attr) {
|
|
199
|
+
if (ele.hasAttribute) {
|
|
200
|
+
return ele.hasAttribute(attr);
|
|
201
|
+
} else if (ele.attributes) {
|
|
202
|
+
return !!(ele.attributes[attr] && ele.attributes[attr].specified);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var hasAttributes = function hasAttributes(ele, attrs) {
|
|
206
|
+
if (typeof attrs === 'string') {
|
|
207
|
+
return hasAttribute(ele, attrs);
|
|
208
|
+
} else if (isArray(attrs)) {
|
|
209
|
+
var result = false;
|
|
210
|
+
|
|
211
|
+
for (var i = 0; i < attrs.length; i++) {
|
|
212
|
+
var testResult = hasAttribute(ele, attrs[i]);
|
|
213
|
+
|
|
214
|
+
if (testResult) {
|
|
215
|
+
result = true;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var getAttributes = function getAttributes(ele, attrs) {
|
|
224
|
+
var result = {};
|
|
225
|
+
|
|
226
|
+
if (typeof attrs === 'string') {
|
|
227
|
+
if (hasAttribute(ele, attrs)) {
|
|
228
|
+
result[attrs] = ele.getAttribute(attrs);
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
if (isArray(attrs)) {
|
|
232
|
+
for (var i = 0; i < attrs.length; i++) {
|
|
233
|
+
var testResult = hasAttribute(ele, attrs[i]);
|
|
234
|
+
|
|
235
|
+
if (testResult) {
|
|
236
|
+
result[attrs[i]] = ele.getAttribute(attrs[i]);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return result;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
246
|
+
|
|
247
|
+
var elementLevel = function elementLevel(element) {
|
|
248
|
+
if (element.children.length) {
|
|
249
|
+
var childElement = element.children;
|
|
250
|
+
|
|
251
|
+
if ([].slice.call(childElement).some(function (element) {
|
|
252
|
+
return element.children.length > 0;
|
|
253
|
+
})) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return true;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
var isSVG = function isSVG(element) {
|
|
264
|
+
if (element.tagName.toLowerCase() === 'svg') {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
var parent = element.parentElement;
|
|
269
|
+
var flag = false;
|
|
270
|
+
|
|
271
|
+
while (parent) {
|
|
272
|
+
if (parent.tagName.toLowerCase() === 'svg') {
|
|
273
|
+
parent = null;
|
|
274
|
+
flag = true;
|
|
275
|
+
} else {
|
|
276
|
+
parent = parent.parentElement;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return flag;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
function isTrack(node, options) {
|
|
284
|
+
if (node.nodeType !== 1) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (!options.svg && isSVG(node)) {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (['HTML', 'BODY'].includes(node.tagName.toUpperCase())) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
var element = node;
|
|
297
|
+
|
|
298
|
+
if (element.style.display === 'none') {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (isNeedElement(element, 'container')) {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (options.track_attr) {
|
|
307
|
+
if (isAttrFilter(element, options.track_attr)) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (!elementLevel(element)) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
320
|
+
|
|
321
|
+
var Listener =
|
|
322
|
+
/** @class */
|
|
323
|
+
function () {
|
|
324
|
+
function Listener(options, collect, Config) {
|
|
325
|
+
var _this = this;
|
|
326
|
+
|
|
327
|
+
this.clickEvent = function (e) {
|
|
328
|
+
if (isTrack(e['target'], _this.options)) {
|
|
329
|
+
_this.eventHandel({
|
|
330
|
+
eventType: 'dom',
|
|
331
|
+
eventName: 'click'
|
|
332
|
+
}, e);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
this.changeEvent = function (e) {
|
|
337
|
+
_this.eventHandel({
|
|
338
|
+
eventType: 'dom',
|
|
339
|
+
eventName: 'change'
|
|
340
|
+
}, e);
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
this.submitEvent = function (e) {
|
|
344
|
+
_this.eventHandel({
|
|
345
|
+
eventType: 'dom',
|
|
346
|
+
eventName: 'submit'
|
|
347
|
+
}, e);
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
this.getPageViewEvent = function (eventData, name) {
|
|
351
|
+
if (name && name === 'pushState') {
|
|
352
|
+
_this.eventHandel({
|
|
353
|
+
eventType: 'dom',
|
|
354
|
+
eventName: 'beat'
|
|
355
|
+
}, __assign({
|
|
356
|
+
beat_type: 0
|
|
357
|
+
}, eventData));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
_this.eventHandel({
|
|
361
|
+
eventType: 'dom',
|
|
362
|
+
eventName: 'page_view'
|
|
363
|
+
}, eventData);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
this.getPageLoadEvent = function (lcp) {
|
|
367
|
+
_this.eventHandel({
|
|
368
|
+
eventType: 'dom',
|
|
369
|
+
eventName: 'page_statistics'
|
|
370
|
+
}, {
|
|
371
|
+
lcp: lcp
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
this.config = Config.getConfig().eventConfig;
|
|
376
|
+
this.collect = collect;
|
|
377
|
+
this.options = options;
|
|
378
|
+
this.beatTime = options.beat;
|
|
379
|
+
this.statistics = false;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
Listener.prototype.init = function (eventHandel) {
|
|
383
|
+
this.eventHandel = eventHandel;
|
|
384
|
+
var mode = this.config.mode;
|
|
385
|
+
this.addListener(mode);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
Listener.prototype.addListener = function (mode) {
|
|
389
|
+
var _this = this; // 注册事件捕获
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
if (mode === 'proxy-capturing') {
|
|
393
|
+
if (this.config.click) {
|
|
394
|
+
window.document.addEventListener('click', this.clickEvent, true);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (this.config.change) {
|
|
398
|
+
window.document.addEventListener('change', this.changeEvent, true);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (this.config.submit) {
|
|
402
|
+
window.document.addEventListener('submit', this.submitEvent, true);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (this.config.pv) {
|
|
406
|
+
this.collect.on('route-change', function (info) {
|
|
407
|
+
var config = info.config,
|
|
408
|
+
name = info.name;
|
|
409
|
+
|
|
410
|
+
_this.getPageViewEvent(config, name);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (this.config.beat) {
|
|
415
|
+
try {
|
|
416
|
+
if (document.readyState === 'complete') {
|
|
417
|
+
this.beatEvent(this.beatTime);
|
|
418
|
+
} else {
|
|
419
|
+
window.addEventListener('load', function () {
|
|
420
|
+
_this.beatEvent(_this.beatTime);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
var t1_1 = 0;
|
|
425
|
+
var t2_1 = 0;
|
|
426
|
+
var timer_1 = null; // 定时器
|
|
427
|
+
|
|
428
|
+
window.addEventListener('scroll', function () {
|
|
429
|
+
clearTimeout(timer_1);
|
|
430
|
+
timer_1 = setTimeout(isScrollEnd_1, 500);
|
|
431
|
+
t1_1 = document.documentElement.scrollTop || document.body.scrollTop;
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
var isScrollEnd_1 = function isScrollEnd_1() {
|
|
435
|
+
t2_1 = document.documentElement.scrollTop || document.body.scrollTop;
|
|
436
|
+
|
|
437
|
+
if (t2_1 == t1_1) {
|
|
438
|
+
_this.eventHandel({
|
|
439
|
+
eventType: 'dom',
|
|
440
|
+
eventName: 'beat'
|
|
441
|
+
}, {
|
|
442
|
+
beat_type: 1
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
} catch (e) {}
|
|
447
|
+
|
|
448
|
+
try {
|
|
449
|
+
var entryList = window.performance && window.performance.getEntriesByType('paint');
|
|
450
|
+
|
|
451
|
+
if (entryList && entryList.length) {
|
|
452
|
+
var observer = new PerformanceObserver(function (entryList) {
|
|
453
|
+
var entries = entryList.getEntries();
|
|
454
|
+
var lastEntry = entries[entries.length - 1];
|
|
455
|
+
var lcp = lastEntry['renderTime'] || lastEntry['loadTime'];
|
|
456
|
+
|
|
457
|
+
if (!_this.statistics) {
|
|
458
|
+
_this.getPageLoadEvent(lcp);
|
|
459
|
+
|
|
460
|
+
_this.statistics = true;
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
observer.observe({
|
|
464
|
+
entryTypes: ['largest-contentful-paint']
|
|
465
|
+
}); // 没触发2S后强制触发
|
|
466
|
+
|
|
467
|
+
setTimeout(function () {
|
|
468
|
+
if (_this.statistics) return;
|
|
469
|
+
|
|
470
|
+
_this.getPageLoadEvent(entryList[0].startTime || 0);
|
|
471
|
+
|
|
472
|
+
_this.statistics = true;
|
|
473
|
+
}, 2000);
|
|
474
|
+
} else {
|
|
475
|
+
this.getPageLoadEvent(0);
|
|
476
|
+
}
|
|
477
|
+
} catch (e) {
|
|
478
|
+
this.getPageLoadEvent(0);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
Listener.prototype.removeListener = function () {
|
|
485
|
+
window.document.removeEventListener('click', this.clickEvent, true);
|
|
486
|
+
window.document.removeEventListener('change', this.changeEvent, true);
|
|
487
|
+
window.document.removeEventListener('submit', this.submitEvent, true);
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
Listener.prototype.beatEvent = function (beatTime) {
|
|
491
|
+
var _this = this;
|
|
492
|
+
|
|
493
|
+
try {
|
|
494
|
+
this.eventHandel({
|
|
495
|
+
eventType: 'dom',
|
|
496
|
+
eventName: 'beat'
|
|
497
|
+
}, {
|
|
498
|
+
beat_type: 3
|
|
499
|
+
});
|
|
500
|
+
var beaInterval_1;
|
|
501
|
+
|
|
502
|
+
if (this.beatTime) {
|
|
503
|
+
beaInterval_1 = setInterval(function () {
|
|
504
|
+
_this.eventHandel({
|
|
505
|
+
eventType: 'dom',
|
|
506
|
+
eventName: 'beat'
|
|
507
|
+
}, {
|
|
508
|
+
beat_type: 2
|
|
509
|
+
});
|
|
510
|
+
}, beatTime);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
beforePageUnload(function () {
|
|
514
|
+
_this.eventHandel({
|
|
515
|
+
eventType: 'dom',
|
|
516
|
+
eventName: 'beat',
|
|
517
|
+
eventSend: 'becon'
|
|
518
|
+
}, {
|
|
519
|
+
beat_type: 0
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
if (_this.beatTime) {
|
|
523
|
+
clearInterval(beaInterval_1);
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
} catch (e) {}
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
return Listener;
|
|
530
|
+
}();
|
|
531
|
+
|
|
532
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
533
|
+
var defaultConfig = {
|
|
534
|
+
eventConfig: {
|
|
535
|
+
mode: "proxy-capturing",
|
|
536
|
+
submit: false,
|
|
537
|
+
click: true,
|
|
538
|
+
change: false,
|
|
539
|
+
pv: true,
|
|
540
|
+
beat: true,
|
|
541
|
+
hashTag: false,
|
|
542
|
+
impr: false
|
|
543
|
+
},
|
|
544
|
+
scoutConfig: {
|
|
545
|
+
mode: "xpath"
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
var Config =
|
|
550
|
+
/** @class */
|
|
551
|
+
function () {
|
|
552
|
+
function Config(config, options) {
|
|
553
|
+
this.config = config;
|
|
554
|
+
this.config.eventConfig = Object.assign(this.config.eventConfig, options);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
Config.prototype.getConfig = function () {
|
|
558
|
+
return this.config;
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
Config.prototype.setConfig = function (config) {
|
|
562
|
+
return this.config = config;
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
return Config;
|
|
566
|
+
}();
|
|
567
|
+
|
|
568
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
569
|
+
function getPositionData(target) {
|
|
570
|
+
if (!target) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
var rect = target.getBoundingClientRect();
|
|
575
|
+
var width = rect.width,
|
|
576
|
+
height = rect.height,
|
|
577
|
+
left = rect.left,
|
|
578
|
+
top = rect.top;
|
|
579
|
+
return {
|
|
580
|
+
left: left,
|
|
581
|
+
top: top,
|
|
582
|
+
element_width: width,
|
|
583
|
+
element_height: height
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
function getEventData$1(event, extData) {
|
|
587
|
+
if (event === void 0) {
|
|
588
|
+
event = {};
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (extData === void 0) {
|
|
592
|
+
extData = {};
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
var clientX = event.clientX,
|
|
596
|
+
clientY = event.clientY;
|
|
597
|
+
var left = extData.left,
|
|
598
|
+
top = extData.top;
|
|
599
|
+
var touchX = clientX - left >= 0 ? clientX - left : 0;
|
|
600
|
+
var touchY = clientY - top >= 0 ? clientY - top : 0;
|
|
601
|
+
return {
|
|
602
|
+
touch_x: Math.floor(touchX),
|
|
603
|
+
touch_y: Math.floor(touchY)
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function getXpath(target) {
|
|
607
|
+
var targetList = [];
|
|
608
|
+
|
|
609
|
+
while (target.parentElement !== null) {
|
|
610
|
+
targetList.push(target);
|
|
611
|
+
target = target.parentElement;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
var xpathArr = [];
|
|
615
|
+
var positions = [];
|
|
616
|
+
targetList.forEach(function (cur) {
|
|
617
|
+
var _a = getXpathIndex(cur),
|
|
618
|
+
str = _a.str,
|
|
619
|
+
index = _a.index;
|
|
620
|
+
|
|
621
|
+
xpathArr.unshift(str);
|
|
622
|
+
positions.unshift(index);
|
|
623
|
+
});
|
|
624
|
+
return {
|
|
625
|
+
element_path: "/" + xpathArr.join('/'),
|
|
626
|
+
positions: positions
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function getXpathIndex(dom) {
|
|
631
|
+
if (dom === null) {
|
|
632
|
+
return {
|
|
633
|
+
str: '',
|
|
634
|
+
index: 0
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
var index = 0;
|
|
639
|
+
var parent = dom.parentElement;
|
|
640
|
+
|
|
641
|
+
if (parent) {
|
|
642
|
+
var childrens = parent.children;
|
|
643
|
+
|
|
644
|
+
for (var i = 0; i < childrens.length; i++) {
|
|
645
|
+
if (childrens[i] === dom) break;
|
|
646
|
+
|
|
647
|
+
if (childrens[i].nodeName === dom.nodeName) {
|
|
648
|
+
index++;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
var tag = [dom.nodeName.toLowerCase(), isNeedElement(dom, 'list') ? '[]' : ''].join('');
|
|
654
|
+
return {
|
|
655
|
+
str: tag,
|
|
656
|
+
index: index
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
661
|
+
function getElementData(event, element, options, ignore) {
|
|
662
|
+
var elementData = {};
|
|
663
|
+
var positionData = getPositionData(element);
|
|
664
|
+
var eventData = getEventData$1(event, positionData);
|
|
665
|
+
var element_width = positionData.element_width,
|
|
666
|
+
element_height = positionData.element_height;
|
|
667
|
+
var touch_x = eventData.touch_x,
|
|
668
|
+
touch_y = eventData.touch_y;
|
|
669
|
+
|
|
670
|
+
var _a = getXpath(element),
|
|
671
|
+
element_path = _a.element_path,
|
|
672
|
+
positions = _a.positions;
|
|
673
|
+
|
|
674
|
+
var texts = getText(element);
|
|
675
|
+
var page_start_ms = window.performance.timing.navigationStart;
|
|
676
|
+
var since_page_start_ms = Date.now() - page_start_ms;
|
|
677
|
+
|
|
678
|
+
var _position = positions.map(function (item) {
|
|
679
|
+
return "" + item;
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
var elementObj = null;
|
|
683
|
+
|
|
684
|
+
if (window.TEAVisualEditor && window.TEAVisualEditor.getOriginXpath) {
|
|
685
|
+
elementObj = window.TEAVisualEditor.getOriginXpath({
|
|
686
|
+
xpath: element_path,
|
|
687
|
+
positions: _position
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
elementData.element_path = elementObj && elementObj.xpath || element_path;
|
|
692
|
+
elementData.positions = elementObj && elementObj.positions || _position;
|
|
693
|
+
|
|
694
|
+
if (ignore && !ignore.text) {
|
|
695
|
+
elementData.texts = texts;
|
|
696
|
+
elementData.element_title = getElementText(element);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
elementData.element_id = element.getAttribute('id') || '';
|
|
700
|
+
elementData.element_class_name = element.getAttribute('class') || '';
|
|
701
|
+
elementData.element_type = element.nodeType;
|
|
702
|
+
elementData.element_width = Math.floor(element_width);
|
|
703
|
+
elementData.element_height = Math.floor(element_height);
|
|
704
|
+
elementData.touch_x = touch_x;
|
|
705
|
+
elementData.touch_y = touch_y;
|
|
706
|
+
elementData.page_manual_key = '';
|
|
707
|
+
elementData.elememt_manual_key = '';
|
|
708
|
+
elementData.since_page_start_ms = since_page_start_ms;
|
|
709
|
+
elementData.page_start_ms = page_start_ms;
|
|
710
|
+
elementData.page_path = location.pathname;
|
|
711
|
+
elementData.page_host = location.host;
|
|
712
|
+
|
|
713
|
+
if (options.track_attr) {
|
|
714
|
+
if (isAttrFilter(element, options.track_attr)) {
|
|
715
|
+
var attrData = getAttributes(element, options.track_attr);
|
|
716
|
+
|
|
717
|
+
for (var attr in attrData) {
|
|
718
|
+
elementData[attr] = attrData[attr];
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (options.custom_attr) {
|
|
724
|
+
try {
|
|
725
|
+
if (isAttrFilter(element, options.custom_attr)) {
|
|
726
|
+
var attrData = getAttributes(element, options.custom_attr);
|
|
727
|
+
var attr = decodeURIComponent(attrData[options.custom_attr]);
|
|
728
|
+
var attrObj = JSON.parse(attr);
|
|
729
|
+
|
|
730
|
+
if (Object.keys(attrObj)) {
|
|
731
|
+
for (var key in attrObj) {
|
|
732
|
+
elementData[key] = attrObj[key];
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
} catch (e) {
|
|
737
|
+
console.log('custom attr error');
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
var containerNoode = getContainer(element);
|
|
742
|
+
|
|
743
|
+
if (containerNoode.tagName === 'A') {
|
|
744
|
+
elementData.href = containerNoode.getAttribute('href');
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
if (options.src !== false) {
|
|
748
|
+
if (element.tagName === 'IMG' && !element.getAttribute('src').includes('base64')) {
|
|
749
|
+
elementData.src = element.getAttribute('src');
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
return elementData;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
757
|
+
|
|
758
|
+
var getEventData = function getEventData(event, e, element, options, ignore) {
|
|
759
|
+
return __assign({
|
|
760
|
+
event: event
|
|
761
|
+
}, getElementData(e, element, options, ignore), {
|
|
762
|
+
is_html: 1,
|
|
763
|
+
page_key: window.location.href,
|
|
764
|
+
page_title: document.title
|
|
765
|
+
});
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
var getExtraEventData = function getExtraEventData(event, element) {
|
|
769
|
+
try {
|
|
770
|
+
if (event === 'bav2b_change') {
|
|
771
|
+
if (element.hasAttribute('data-tea-track')) {
|
|
772
|
+
return {
|
|
773
|
+
value: element.value
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
return {};
|
|
778
|
+
}
|
|
779
|
+
} catch (err) {
|
|
780
|
+
return {};
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
var EventHandle =
|
|
785
|
+
/** @class */
|
|
786
|
+
function () {
|
|
787
|
+
function EventHandle(initConfig, options) {
|
|
788
|
+
this.ignore = {
|
|
789
|
+
text: false
|
|
790
|
+
};
|
|
791
|
+
this.initConfig = initConfig;
|
|
792
|
+
this.options = options;
|
|
793
|
+
this.eventName = options && options.custom === 'tea' ? {
|
|
794
|
+
click: '__bav_click',
|
|
795
|
+
page: '__bav_page',
|
|
796
|
+
beat: '__bav_beat',
|
|
797
|
+
"static": '__bav_page_statistics',
|
|
798
|
+
exposure: '__bav_page_exposure'
|
|
799
|
+
} : {
|
|
800
|
+
click: 'bav2b_click',
|
|
801
|
+
page: 'bav2b_page',
|
|
802
|
+
beat: 'bav2b_beat',
|
|
803
|
+
"static": 'bav2b_page_statistics',
|
|
804
|
+
exposure: 'bav2b_exposure',
|
|
805
|
+
scroll: '$bav2b_slide'
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
if (options && options.text === false) {
|
|
809
|
+
this.ignore.text = true;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
if (options && options.exposure && options.exposure.eventName) {
|
|
813
|
+
this.eventName['exposure'] = options.exposure.eventName;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
EventHandle.prototype.handleEvent = function (e, eventType) {
|
|
818
|
+
try {
|
|
819
|
+
if (ignore(e.target)) {
|
|
820
|
+
return null;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
var event_1 = 'bav2b_click';
|
|
824
|
+
|
|
825
|
+
switch (eventType) {
|
|
826
|
+
case 'click':
|
|
827
|
+
event_1 = this.eventName['click'];
|
|
828
|
+
return getEventData(event_1, e, e.target, this.options, this.ignore);
|
|
829
|
+
|
|
830
|
+
case 'exposure':
|
|
831
|
+
event_1 = this.eventName['exposure'];
|
|
832
|
+
return getEventData(event_1, e, e.target, this.options, this.ignore);
|
|
833
|
+
|
|
834
|
+
case 'change':
|
|
835
|
+
event_1 = 'bav2b_change';
|
|
836
|
+
return __assign({}, getEventData(event_1, e, e.target, this.options), getExtraEventData(event_1, e.target));
|
|
837
|
+
|
|
838
|
+
case 'submit':
|
|
839
|
+
event_1 = 'bav2b_submit';
|
|
840
|
+
return getEventData(event_1, e, e.target, this.options);
|
|
841
|
+
}
|
|
842
|
+
} catch (err) {
|
|
843
|
+
console.error(err);
|
|
844
|
+
return null;
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
EventHandle.prototype.handleViewEvent = function (data) {
|
|
849
|
+
data.event = this.eventName['page'];
|
|
850
|
+
data.page_title = document.title;
|
|
851
|
+
data.page_total_width = window.innerWidth;
|
|
852
|
+
data.page_total_height = window.innerHeight;
|
|
853
|
+
|
|
854
|
+
try {
|
|
855
|
+
var cache = window.sessionStorage.getItem('_tea_cache_duration');
|
|
856
|
+
|
|
857
|
+
if (cache) {
|
|
858
|
+
var duration = JSON.parse(cache);
|
|
859
|
+
data.refer_page_duration_ms = duration ? duration.duration : '';
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
data.scroll_width = document.documentElement.scrollLeft ? document.documentElement.scrollLeft + window.innerWidth : window.innerWidth;
|
|
863
|
+
data.scroll_height = document.documentElement.scrollTop ? document.documentElement.scrollTop + window.innerHeight : window.innerHeight;
|
|
864
|
+
data.page_start_ms = window.performance.timing.navigationStart;
|
|
865
|
+
} catch (e) {
|
|
866
|
+
console.log("page event error " + JSON.stringify(e));
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
return data;
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
EventHandle.prototype.handleStatisticsEvent = function (data) {
|
|
873
|
+
var _data = {};
|
|
874
|
+
_data['event'] = this.eventName['static'];
|
|
875
|
+
_data['is_html'] = 1;
|
|
876
|
+
_data['page_key'] = location.href;
|
|
877
|
+
_data['refer_page_key'] = document.referrer || '';
|
|
878
|
+
_data['page_title'] = document.title;
|
|
879
|
+
_data['page_manual_key'] = this.initConfig.autotrack.page_manual_key || '';
|
|
880
|
+
_data['refer_page_manual_key'] = '';
|
|
881
|
+
|
|
882
|
+
try {
|
|
883
|
+
var lcp = data.lcp;
|
|
884
|
+
var timing = window.performance.timing;
|
|
885
|
+
var init_cos = timing.loadEventEnd - timing.navigationStart;
|
|
886
|
+
_data['page_init_cost_ms'] = parseInt(lcp || (init_cos > 0 ? init_cos : 0));
|
|
887
|
+
_data['page_start_ms'] = timing.navigationStart;
|
|
888
|
+
} catch (e) {
|
|
889
|
+
console.log("page_statistics event error " + JSON.stringify(e));
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
return _data;
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
EventHandle.prototype.handleBeadtEvent = function (data) {
|
|
896
|
+
data.event = this.eventName['beat'];
|
|
897
|
+
data.page_key = window.location.href;
|
|
898
|
+
data.is_html = 1;
|
|
899
|
+
data.page_title = document.title;
|
|
900
|
+
data.page_manual_key = this.initConfig.autotrack.page_manual_key || '';
|
|
901
|
+
|
|
902
|
+
try {
|
|
903
|
+
data.page_viewport_width = window.innerWidth;
|
|
904
|
+
data.page_viewport_height = window.innerHeight;
|
|
905
|
+
data.page_total_width = document.documentElement.scrollWidth;
|
|
906
|
+
data.page_total_height = document.documentElement.scrollHeight;
|
|
907
|
+
data.scroll_width = document.documentElement.scrollLeft + window.innerWidth;
|
|
908
|
+
data.scroll_height = document.documentElement.scrollTop + window.innerHeight;
|
|
909
|
+
data.since_page_start_ms = Date.now() - window.performance.timing.navigationStart;
|
|
910
|
+
data.page_start_ms = window.performance.timing.navigationStart;
|
|
911
|
+
} catch (e) {
|
|
912
|
+
console.log("beat event error " + JSON.stringify(e));
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
return data;
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
EventHandle.prototype.handleExposureEvent = function (eventInfo, e) {
|
|
919
|
+
if (ignore(e.target)) {
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
var data = getEventData(eventInfo.event || this.eventName['exposure'], e, e.target || e, this.options, this.ignore);
|
|
924
|
+
data.$exposure_type = eventInfo.exposureType;
|
|
925
|
+
|
|
926
|
+
if (this.options.exposure.callback) {
|
|
927
|
+
var callData = this.options.exposure.callback(data);
|
|
928
|
+
|
|
929
|
+
if (!callData && !Object.keys(callData).length) {
|
|
930
|
+
console.warn('exposure callback must return data!');
|
|
931
|
+
return data;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
return callData;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
return data;
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
EventHandle.prototype.handleScrollEvent = function (eventInfo, e) {
|
|
941
|
+
var data = getEventData(eventInfo.event || this.eventName['scroll'], e, e.target || e, this.options, this.ignore);
|
|
942
|
+
data = Object.assign(data, eventInfo.params);
|
|
943
|
+
|
|
944
|
+
if (this.options.scroll.callback) {
|
|
945
|
+
data = this.options.scroll.callback(data);
|
|
946
|
+
|
|
947
|
+
if (!data && !Object.keys(data).length) {
|
|
948
|
+
console.warn('scroll callback must return data!');
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
return data;
|
|
954
|
+
};
|
|
955
|
+
|
|
956
|
+
return EventHandle;
|
|
957
|
+
}();
|
|
958
|
+
|
|
959
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
960
|
+
var Request =
|
|
961
|
+
/** @class */
|
|
962
|
+
function () {
|
|
963
|
+
function Request(collect) {
|
|
964
|
+
this.collect = collect;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
Request.prototype.send = function (eventInfo, data) {
|
|
968
|
+
var event = data['event'];
|
|
969
|
+
delete data['event'];
|
|
970
|
+
|
|
971
|
+
if (eventInfo && eventInfo.eventSend === 'becon') {
|
|
972
|
+
this.collect.beconEvent(event, data);
|
|
973
|
+
} else {
|
|
974
|
+
this.collect.event(event, data);
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
Request.prototype.get = function (url, options) {
|
|
979
|
+
var reqOptions = {
|
|
980
|
+
headers: {
|
|
981
|
+
'content-type': 'application/json'
|
|
982
|
+
},
|
|
983
|
+
method: 'GET'
|
|
984
|
+
};
|
|
985
|
+
var myOptions = Object.assign(reqOptions, options);
|
|
986
|
+
fetch(url, myOptions);
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
Request.prototype.post = function (url, options) {
|
|
990
|
+
var reqOptions = {
|
|
991
|
+
headers: {
|
|
992
|
+
'content-type': 'application/json'
|
|
993
|
+
},
|
|
994
|
+
method: 'POST'
|
|
995
|
+
};
|
|
996
|
+
var myOptions = Object.assign(reqOptions, options);
|
|
997
|
+
fetch(url, myOptions);
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
return Request;
|
|
1001
|
+
}();
|
|
1002
|
+
|
|
1003
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
1004
|
+
// 监视曝光的上层类 处理动态dom
|
|
1005
|
+
var Observer =
|
|
1006
|
+
/** @class */
|
|
1007
|
+
function () {
|
|
1008
|
+
function Observer(intersection, config) {
|
|
1009
|
+
this._instance = null;
|
|
1010
|
+
this._intersection = intersection;
|
|
1011
|
+
this.config = config;
|
|
1012
|
+
if (!this._intersection) return;
|
|
1013
|
+
this.init();
|
|
1014
|
+
} // 初始化mutation对象观察动态dom
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
Observer.prototype.init = function () {
|
|
1018
|
+
var _this = this;
|
|
1019
|
+
|
|
1020
|
+
if (window['MutationObserver']) {
|
|
1021
|
+
try {
|
|
1022
|
+
this._instance = new MutationObserver(function (mutations) {
|
|
1023
|
+
mutations.forEach(function (mutation) {
|
|
1024
|
+
// 更新dom节点可能是update,只是属性改变,需要监听
|
|
1025
|
+
if (mutation.type === 'attributes') {
|
|
1026
|
+
_this.attributeChangeObserve(mutation);
|
|
1027
|
+
} // dom节点变化
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
if (mutation.type === 'childList') {
|
|
1031
|
+
_this.modifyNodeObserve(mutation);
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
if (!document || !document.body) {
|
|
1037
|
+
console.warn('please use sdk api init after body element');
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
var attributes = this.config.autotrack.exposure.attributes === false ? false : true;
|
|
1042
|
+
|
|
1043
|
+
this._instance.observe(document.body, {
|
|
1044
|
+
childList: true,
|
|
1045
|
+
attributes: attributes,
|
|
1046
|
+
subtree: true,
|
|
1047
|
+
attributeOldValue: false
|
|
1048
|
+
});
|
|
1049
|
+
} catch (e) {
|
|
1050
|
+
console.log('your browser cannot support MutationObserver,so cannot report exposure event, please update');
|
|
1051
|
+
}
|
|
1052
|
+
} else {
|
|
1053
|
+
console.log('your browser cannot support MutationObserver,so cannot report exposure event, please update');
|
|
1054
|
+
}
|
|
1055
|
+
}; // 监听dom属性变化添加或删除节点曝光监听
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
Observer.prototype.attributeChangeObserve = function (mutation) {
|
|
1059
|
+
var dom = mutation.target;
|
|
1060
|
+
|
|
1061
|
+
if (dom.hasAttribute('data-exposure')) {
|
|
1062
|
+
this.exposureAdd(mutation, 'mutation');
|
|
1063
|
+
} else {
|
|
1064
|
+
this.exposureRemove(mutation);
|
|
1065
|
+
}
|
|
1066
|
+
}; // 监听dom变化添加或删除节点曝光监听
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
Observer.prototype.modifyNodeObserve = function (mutation) {
|
|
1070
|
+
var _this = this; // 不能为文本节点&&要有auto-exp属性
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
Array.prototype.forEach.call(mutation.addedNodes, function (node) {
|
|
1074
|
+
if (node.nodeType === 1 && node.hasAttribute('data-exposure')) {
|
|
1075
|
+
_this.exposureAdd(node, 'intersect');
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
_this.mapChild(node, _this.exposureAdd.bind(_this));
|
|
1079
|
+
}); // 遍历子节点的删除
|
|
1080
|
+
|
|
1081
|
+
Array.prototype.forEach.call(mutation.removedNodes, function (node) {
|
|
1082
|
+
if (node.nodeType === 1 && node.hasAttribute('data-exposure')) {
|
|
1083
|
+
_this.exposureRemove(node);
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
_this.mapChild(node, _this.exposureRemove.bind(_this));
|
|
1087
|
+
});
|
|
1088
|
+
}; // 递归后代节点
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
Observer.prototype.mapChild = function (node, action) {
|
|
1092
|
+
var _this = this;
|
|
1093
|
+
|
|
1094
|
+
if (node.nodeType !== 1) {
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
if (!node.children.length) {
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
Array.prototype.forEach.call(node.children, function (item) {
|
|
1103
|
+
if (item.nodeType === 1 && item.hasAttribute('data-exposure')) {
|
|
1104
|
+
action(item);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
_this.mapChild(item, action);
|
|
1108
|
+
});
|
|
1109
|
+
}; // 添加进入曝光队列
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
Observer.prototype.exposureAdd = function (dom, type) {
|
|
1113
|
+
try {
|
|
1114
|
+
this._intersection && this._intersection.exposureAdd(dom, type);
|
|
1115
|
+
} catch (e) {
|
|
1116
|
+
console.log('intersection error', JSON.stringify(e.message));
|
|
1117
|
+
}
|
|
1118
|
+
}; // 从曝光队列中移除
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
Observer.prototype.exposureRemove = function (dom) {
|
|
1122
|
+
try {
|
|
1123
|
+
this._intersection && this._intersection.exposureRemove(dom);
|
|
1124
|
+
} catch (e) {
|
|
1125
|
+
console.log('intersection error', JSON.stringify(e.message));
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1129
|
+
Observer._exposure_observer = null;
|
|
1130
|
+
return Observer;
|
|
1131
|
+
}();
|
|
1132
|
+
|
|
1133
|
+
var b = function b(a) {
|
|
1134
|
+
return a ? (a ^ Math.random() * 16 >> a / 4).toString(10) : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, b);
|
|
1135
|
+
};
|
|
1136
|
+
var localWebId = function localWebId() {
|
|
1137
|
+
return b().replace(/-/g, '').slice(0, 19);
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
1141
|
+
var ExposureTypeE;
|
|
1142
|
+
|
|
1143
|
+
(function (ExposureTypeE) {
|
|
1144
|
+
ExposureTypeE[ExposureTypeE["EXPOSURE_ONCE"] = 0] = "EXPOSURE_ONCE";
|
|
1145
|
+
ExposureTypeE[ExposureTypeE["LIFECYCLE_SHOW_NEW"] = 3] = "LIFECYCLE_SHOW_NEW";
|
|
1146
|
+
ExposureTypeE[ExposureTypeE["RESUME_FORM_PAGE"] = 6] = "RESUME_FORM_PAGE";
|
|
1147
|
+
ExposureTypeE[ExposureTypeE["RESUME_FORM_BACK"] = 7] = "RESUME_FORM_BACK";
|
|
1148
|
+
ExposureTypeE[ExposureTypeE["NOT_EXPOSURE"] = -1] = "NOT_EXPOSURE";
|
|
1149
|
+
})(ExposureTypeE || (ExposureTypeE = {}));
|
|
1150
|
+
|
|
1151
|
+
var Intersection =
|
|
1152
|
+
/** @class */
|
|
1153
|
+
function () {
|
|
1154
|
+
function Intersection(collect, config, eventHandle) {
|
|
1155
|
+
var _this = this;
|
|
1156
|
+
|
|
1157
|
+
this.backStatus = false;
|
|
1158
|
+
this.instance = this.buildObserver();
|
|
1159
|
+
this.collect = collect;
|
|
1160
|
+
this.observeMap = Intersection._observer_map;
|
|
1161
|
+
|
|
1162
|
+
if (config.autotrack.exposure.ratio) {
|
|
1163
|
+
this.ratio = config.autotrack.exposure.ratio;
|
|
1164
|
+
} else if (config.autotrack.exposure.ratio === 0) {
|
|
1165
|
+
this.ratio = 0;
|
|
1166
|
+
} else {
|
|
1167
|
+
this.ratio = 0.5;
|
|
1168
|
+
} // 元素出现的时长,有值则等待,无值则立刻曝光
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
this.timeLimit = config.autotrack.exposure.stay || 0;
|
|
1172
|
+
this.exposureType = ExposureTypeE.NOT_EXPOSURE;
|
|
1173
|
+
this.eventHandle = eventHandle;
|
|
1174
|
+
this.hashMap = new Map();
|
|
1175
|
+
this.backStatus = false;
|
|
1176
|
+
this.lastState = null;
|
|
1177
|
+
this.collect.on('re-start-sdk', function () {
|
|
1178
|
+
_this.visibilitychange();
|
|
1179
|
+
});
|
|
1180
|
+
this.addListen();
|
|
1181
|
+
} // dom元素出现在视窗,出现回调;
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
Intersection.prototype.buildObserver = function () {
|
|
1185
|
+
var _this = this;
|
|
1186
|
+
|
|
1187
|
+
if (!Intersection._observer_instance) {
|
|
1188
|
+
if (window['IntersectionObserver']) {
|
|
1189
|
+
var threshold = [];
|
|
1190
|
+
|
|
1191
|
+
for (var i = 0; i <= 1.0; i += 0.01) {
|
|
1192
|
+
threshold.push(i);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
threshold.push(1);
|
|
1196
|
+
|
|
1197
|
+
try {
|
|
1198
|
+
Intersection._observer_instance = new IntersectionObserver(function (entries) {
|
|
1199
|
+
entries.forEach(function (entry) {
|
|
1200
|
+
var elememtMapKey = entry.target['observeId'];
|
|
1201
|
+
|
|
1202
|
+
var exposureDom = _this.observeMap.get(elememtMapKey);
|
|
1203
|
+
|
|
1204
|
+
var target = entry.target,
|
|
1205
|
+
isIntersecting = entry.isIntersecting,
|
|
1206
|
+
intersectionRatio = entry.intersectionRatio;
|
|
1207
|
+
exposureDom.intersectionRatio = intersectionRatio;
|
|
1208
|
+
|
|
1209
|
+
if (intersectionRatio <= 0.1) {
|
|
1210
|
+
// 离开曝光区
|
|
1211
|
+
entry.target['backStatus'] = false;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
_this.observeMap.set(elememtMapKey, exposureDom);
|
|
1215
|
+
|
|
1216
|
+
if (intersectionRatio < _this.ratio) {
|
|
1217
|
+
exposureDom.isIntersecting = false;
|
|
1218
|
+
exposureDom.added = false;
|
|
1219
|
+
exposureDom.exposured = false;
|
|
1220
|
+
exposureDom.startTime = Date.now();
|
|
1221
|
+
|
|
1222
|
+
_this.observeMap.set(elememtMapKey, exposureDom);
|
|
1223
|
+
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
if (!exposureDom.added) {
|
|
1228
|
+
exposureDom.startTime = Date.now(); // 元素交互时处理一次,为false或者undefined的代表没有处理过
|
|
1229
|
+
|
|
1230
|
+
exposureDom.added = true;
|
|
1231
|
+
exposureDom.isIntersecting = true;
|
|
1232
|
+
|
|
1233
|
+
if (_this.timeLimit) {
|
|
1234
|
+
var exposureTimeout = setTimeout(function () {
|
|
1235
|
+
try {
|
|
1236
|
+
if (exposureDom.isIntersecting && !exposureDom.exposured && _this.observeMap.get(elememtMapKey)) {
|
|
1237
|
+
var intersectionRatio_1 = _this.observeMap.get(elememtMapKey).intersectionRatio;
|
|
1238
|
+
|
|
1239
|
+
_this.exposureEvent(entry, intersectionRatio_1, elememtMapKey, exposureDom); // this.eventHandle({ eventType: 'dom', eventName: 'exposure' }, entry)
|
|
1240
|
+
|
|
1241
|
+
}
|
|
1242
|
+
} catch (e) {
|
|
1243
|
+
console.log("IntersectionObserver setTimeout error\uFF0Cmsg: " + JSON.stringify(e));
|
|
1244
|
+
}
|
|
1245
|
+
}, _this.timeLimit);
|
|
1246
|
+
exposureDom.wait = exposureTimeout;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
_this.observeMap.set(elememtMapKey, exposureDom);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
if (Date.now() - exposureDom.startTime >= _this.timeLimit && !exposureDom.exposured) {
|
|
1253
|
+
_this.exposureEvent(entry, intersectionRatio, elememtMapKey, exposureDom);
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
}, {
|
|
1257
|
+
threshold: threshold
|
|
1258
|
+
});
|
|
1259
|
+
} catch (e) {
|
|
1260
|
+
console.log("IntersectionObserver error\uFF0Cmsg: " + JSON.stringify(e));
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
return Intersection._observer_instance;
|
|
1264
|
+
} else {
|
|
1265
|
+
console.log('your browser cannot support IntersectionObserver, so cannot report exposure event, please update');
|
|
1266
|
+
return null;
|
|
1267
|
+
}
|
|
1268
|
+
} else {
|
|
1269
|
+
console.log('your browser cannot support IntersectionObserver, so cannot report exposure event, please update');
|
|
1270
|
+
return null;
|
|
1271
|
+
}
|
|
1272
|
+
}; // 添加进入曝光队列
|
|
1273
|
+
|
|
1274
|
+
|
|
1275
|
+
Intersection.prototype.exposureAdd = function (dom, type) {
|
|
1276
|
+
var trueDom = type === 'mutation' ? dom.target : dom;
|
|
1277
|
+
var elememtMapKey = trueDom['observeId'];
|
|
1278
|
+
var domId = localWebId();
|
|
1279
|
+
|
|
1280
|
+
if (!elememtMapKey && !this.observeMap.has(elememtMapKey)) {
|
|
1281
|
+
trueDom['observeId'] = domId;
|
|
1282
|
+
trueDom['visible'] = false;
|
|
1283
|
+
this.observeMap.set(domId, {
|
|
1284
|
+
instance: trueDom.cloneNode(true),
|
|
1285
|
+
isIntersecting: false
|
|
1286
|
+
});
|
|
1287
|
+
this.observe(trueDom);
|
|
1288
|
+
} else {
|
|
1289
|
+
var exposureDom = this.observeMap.get(elememtMapKey);
|
|
1290
|
+
|
|
1291
|
+
if (exposureDom && trueDom !== exposureDom.instance) {
|
|
1292
|
+
// 有id,但实例变了
|
|
1293
|
+
this.unobserve(trueDom);
|
|
1294
|
+
this.observeMap["delete"](elememtMapKey);
|
|
1295
|
+
trueDom['observeId'] = domId;
|
|
1296
|
+
trueDom['visible'] = false;
|
|
1297
|
+
this.observeMap.set(domId, {
|
|
1298
|
+
instance: trueDom.cloneNode(true),
|
|
1299
|
+
isIntersecting: false
|
|
1300
|
+
});
|
|
1301
|
+
this.observe(trueDom);
|
|
1302
|
+
} else {
|
|
1303
|
+
if (trueDom['visible'] === true) return;
|
|
1304
|
+
this.handleBoundingExposure(trueDom);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
}; // 从曝光队列中移除
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
Intersection.prototype.exposureRemove = function (dom) {
|
|
1311
|
+
if (this.observeMap.has(dom['observeId'])) {
|
|
1312
|
+
this.observeMap["delete"](dom['observeId']);
|
|
1313
|
+
this.unobserve(dom);
|
|
1314
|
+
dom['observeId'] = '';
|
|
1315
|
+
dom['visible'] = false;
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
Intersection.prototype.exposureEvent = function (entry, intersectionRatio, elememtMapKey, exposureDom) {
|
|
1320
|
+
if (intersectionRatio >= this.ratio) {
|
|
1321
|
+
if (entry.target.style.opacity === '0' || entry.target.style.visibility === 'hidden') return; // if (entry.target.visible === true || exposureDom.exposured === true) return;
|
|
1322
|
+
|
|
1323
|
+
if (exposureDom.exposured === true) return;
|
|
1324
|
+
|
|
1325
|
+
if (exposureDom.startWait) {
|
|
1326
|
+
// 元素有定时器
|
|
1327
|
+
clearTimeout(exposureDom.startWait);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
var event_1 = entry.target.getAttribute('data-exposure-event');
|
|
1331
|
+
this.eventHandle({
|
|
1332
|
+
eventType: 'dom',
|
|
1333
|
+
eventName: 'exposure',
|
|
1334
|
+
event: event_1,
|
|
1335
|
+
exposureType: this.getExposureType(entry.target)
|
|
1336
|
+
}, entry);
|
|
1337
|
+
entry.target.visible = true;
|
|
1338
|
+
entry.target.hasExposure = true;
|
|
1339
|
+
exposureDom.startTime = Date.now();
|
|
1340
|
+
exposureDom.exposured = true;
|
|
1341
|
+
} else {
|
|
1342
|
+
exposureDom.startTime = Date.now();
|
|
1343
|
+
exposureDom.exposured = false; // entry.target.visible = false;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
this.observeMap.set(elememtMapKey, exposureDom);
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
Intersection.prototype.observe = function (dom) {
|
|
1350
|
+
this.instance && this.instance.observe(dom);
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1353
|
+
Intersection.prototype.unobserve = function (dom) {
|
|
1354
|
+
this.instance && this.instance.unobserve(dom);
|
|
1355
|
+
};
|
|
1356
|
+
|
|
1357
|
+
Intersection.prototype.getExposureDomToExposure = function () {
|
|
1358
|
+
var _this = this;
|
|
1359
|
+
|
|
1360
|
+
Array.prototype.forEach.call(document.querySelectorAll('[data-exposure]'), function (dom) {
|
|
1361
|
+
_this.handleBoundingExposure(dom);
|
|
1362
|
+
});
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1365
|
+
Intersection.prototype.visibilitychange = function () {
|
|
1366
|
+
var _this = this;
|
|
1367
|
+
|
|
1368
|
+
var visTime = null;
|
|
1369
|
+
|
|
1370
|
+
if (document.visibilityState === 'visible') {
|
|
1371
|
+
// 重置时间
|
|
1372
|
+
if (this.timeLimit) {
|
|
1373
|
+
visTime = setTimeout(function () {
|
|
1374
|
+
_this.getExposureDomToExposure();
|
|
1375
|
+
}, this.timeLimit);
|
|
1376
|
+
} else {
|
|
1377
|
+
this.getExposureDomToExposure();
|
|
1378
|
+
}
|
|
1379
|
+
} else {
|
|
1380
|
+
clearTimeout(visTime); // 页面隐藏了,可能是最小化,新开webview,等等
|
|
1381
|
+
|
|
1382
|
+
this.customType = undefined;
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
|
|
1386
|
+
Intersection.prototype.handleBoundingExposure = function (dom) {
|
|
1387
|
+
// 处理非IntersectionObserver触发条件下的曝光
|
|
1388
|
+
if (this.getBoundingRatio(dom) >= this.ratio) {
|
|
1389
|
+
dom['visible'] = true;
|
|
1390
|
+
var event_2 = dom.getAttribute && dom.getAttribute('data-exposure-event');
|
|
1391
|
+
this.eventHandle({
|
|
1392
|
+
eventType: 'dom',
|
|
1393
|
+
eventName: 'exposure',
|
|
1394
|
+
event: event_2,
|
|
1395
|
+
exposureType: this.customType || ExposureTypeE.RESUME_FORM_BACK
|
|
1396
|
+
}, dom);
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
|
|
1400
|
+
Intersection.prototype.getBoundingRatio = function (dom) {
|
|
1401
|
+
var _a = dom.getBoundingClientRect(),
|
|
1402
|
+
top = _a.top,
|
|
1403
|
+
left = _a.left,
|
|
1404
|
+
width = _a.width,
|
|
1405
|
+
height = _a.height;
|
|
1406
|
+
|
|
1407
|
+
var viewportWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
1408
|
+
var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
1409
|
+
var elementArea = width * height;
|
|
1410
|
+
|
|
1411
|
+
if (top >= 0 && left >= 0 && top <= viewportHeight && left <= viewportWidth) {
|
|
1412
|
+
// 首先判断元素是否能看见
|
|
1413
|
+
var viewWidth = width > viewportWidth ? viewportWidth : width;
|
|
1414
|
+
var viewHeight = viewportHeight - top;
|
|
1415
|
+
var viewArea = viewWidth * viewHeight;
|
|
1416
|
+
return viewArea / elementArea;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
return 0;
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
Intersection.prototype.getExposureType = function (target) {
|
|
1423
|
+
if (target.visible) {
|
|
1424
|
+
// 多页面的重复曝光
|
|
1425
|
+
if (target.backStatus !== false && (this.backStatus || this.customType || window.performance.navigation.type === 2)) {
|
|
1426
|
+
this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1427
|
+
} else {
|
|
1428
|
+
this.exposureType = ExposureTypeE.LIFECYCLE_SHOW_NEW;
|
|
1429
|
+
}
|
|
1430
|
+
} else {
|
|
1431
|
+
if (target.hasExposure) {
|
|
1432
|
+
// 单页面的重复
|
|
1433
|
+
if (target.backStatus !== false && (this.backStatus || this.customType || window.performance.navigation.type === 2)) {
|
|
1434
|
+
this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1435
|
+
} else {
|
|
1436
|
+
this.exposureType = ExposureTypeE.EXPOSURE_ONCE;
|
|
1437
|
+
}
|
|
1438
|
+
} else {
|
|
1439
|
+
if (target.backStatus !== false && (this.backStatus || this.customType || window.performance.navigation.type === 2)) {
|
|
1440
|
+
this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1441
|
+
} else {
|
|
1442
|
+
this.exposureType = ExposureTypeE.EXPOSURE_ONCE;
|
|
1443
|
+
}
|
|
1444
|
+
} // this.exposureType = ExposureTypeE.EXPOSURE_ONCE
|
|
1445
|
+
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
return this.exposureType;
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
Intersection.prototype.addListen = function () {
|
|
1452
|
+
var _this = this;
|
|
1453
|
+
|
|
1454
|
+
this.collect.on('set-exposure-type', function (type) {
|
|
1455
|
+
_this.customType = type;
|
|
1456
|
+
});
|
|
1457
|
+
var change = this.visibilitychange.bind(this);
|
|
1458
|
+
addListener(document, 'visibilitychange', change, false);
|
|
1459
|
+
window.addEventListener("hashchange", function (hash) {
|
|
1460
|
+
var current = _this.hashMap.get(hash.oldURL);
|
|
1461
|
+
|
|
1462
|
+
if (current && location.href === current.prev) {
|
|
1463
|
+
_this.backStatus = true;
|
|
1464
|
+
_this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1465
|
+
} else {
|
|
1466
|
+
_this.backStatus = false;
|
|
1467
|
+
|
|
1468
|
+
_this.hashMap.set(location.href, {
|
|
1469
|
+
current: hash.newURL,
|
|
1470
|
+
prev: hash.oldURL
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
});
|
|
1474
|
+
|
|
1475
|
+
if (this.collect.bridgeReport) {
|
|
1476
|
+
var oldPushState_1 = window.history.pushState;
|
|
1477
|
+
|
|
1478
|
+
history.pushState = function (state) {
|
|
1479
|
+
var args = [];
|
|
1480
|
+
|
|
1481
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1482
|
+
args[_i - 1] = arguments[_i];
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
if (typeof history['onpushstate'] === 'function') {
|
|
1486
|
+
history['onpushstate']({
|
|
1487
|
+
state: state
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
var ret = oldPushState_1.call.apply(oldPushState_1, __spread([history, state], args));
|
|
1492
|
+
_this.lastState = state;
|
|
1493
|
+
return ret;
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1496
|
+
var oldReplaceState_1 = history.replaceState;
|
|
1497
|
+
|
|
1498
|
+
history.replaceState = function (state) {
|
|
1499
|
+
var args = [];
|
|
1500
|
+
|
|
1501
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1502
|
+
args[_i - 1] = arguments[_i];
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
if (typeof history['onreplacestate'] === 'function') {
|
|
1506
|
+
history['onreplacestate']({
|
|
1507
|
+
state: state
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
var ret = oldReplaceState_1.call.apply(oldReplaceState_1, __spread([history, state], args));
|
|
1512
|
+
_this.lastState = state;
|
|
1513
|
+
return ret;
|
|
1514
|
+
};
|
|
1515
|
+
} else {
|
|
1516
|
+
this.collect.on('STATE_CHANGE', function (state) {
|
|
1517
|
+
_this.lastState = state;
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
window.addEventListener('popstate', function (state) {
|
|
1522
|
+
var currentState = state.state;
|
|
1523
|
+
|
|
1524
|
+
if (currentState && currentState.current && _this.lastState && _this.lastState.back && currentState.current === _this.lastState.back) {
|
|
1525
|
+
// 用户点击了“退回”按钮
|
|
1526
|
+
_this.backStatus = true;
|
|
1527
|
+
_this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1528
|
+
} else {
|
|
1529
|
+
_this.backStatus = false;
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
return function () {
|
|
1533
|
+
removeListener(document, 'visibilitychange', change, false);
|
|
1534
|
+
};
|
|
1535
|
+
};
|
|
1536
|
+
|
|
1537
|
+
Intersection._observer_instance = null;
|
|
1538
|
+
Intersection._observer_map = new Map();
|
|
1539
|
+
return Intersection;
|
|
1540
|
+
}();
|
|
1541
|
+
|
|
1542
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
1543
|
+
|
|
1544
|
+
var Exposure =
|
|
1545
|
+
/** @class */
|
|
1546
|
+
function () {
|
|
1547
|
+
function Exposure(collect, config, eventHandle) {
|
|
1548
|
+
if (!config.autotrack || !config.autotrack.exposure) return;
|
|
1549
|
+
this._intersection = new Intersection(collect, config, eventHandle);
|
|
1550
|
+
this._observer = new Observer(this._intersection, config);
|
|
1551
|
+
|
|
1552
|
+
if (this._intersection && this._observer) {
|
|
1553
|
+
this.initObserver();
|
|
1554
|
+
} else {
|
|
1555
|
+
console.log('your browser version cannot support exposure event, please update~');
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
Exposure.prototype.initObserver = function () {
|
|
1560
|
+
var self = this;
|
|
1561
|
+
Array.prototype.forEach.call(document.querySelectorAll('[data-exposure]'), function (dom) {
|
|
1562
|
+
self._intersection.exposureAdd(dom, 'intersect');
|
|
1563
|
+
});
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1566
|
+
return Exposure;
|
|
1567
|
+
}();
|
|
1568
|
+
|
|
1569
|
+
var ScrollTypeE;
|
|
1570
|
+
|
|
1571
|
+
(function (ScrollTypeE) {
|
|
1572
|
+
ScrollTypeE[ScrollTypeE["SCROLL_UP"] = 1] = "SCROLL_UP";
|
|
1573
|
+
ScrollTypeE[ScrollTypeE["SCROLL_DOWN"] = 2] = "SCROLL_DOWN";
|
|
1574
|
+
ScrollTypeE[ScrollTypeE["SCROLL_LEFT"] = 3] = "SCROLL_LEFT";
|
|
1575
|
+
ScrollTypeE[ScrollTypeE["SCROLL_RIGHT"] = 4] = "SCROLL_RIGHT";
|
|
1576
|
+
ScrollTypeE[ScrollTypeE["NOT_SCROLL"] = -1] = "NOT_SCROLL";
|
|
1577
|
+
})(ScrollTypeE || (ScrollTypeE = {}));
|
|
1578
|
+
|
|
1579
|
+
var ScrollSlide =
|
|
1580
|
+
/** @class */
|
|
1581
|
+
function () {
|
|
1582
|
+
function ScrollSlide(config, eventHandle) {
|
|
1583
|
+
this.distance = 30;
|
|
1584
|
+
if (!config.autotrack || !config.autotrack.scroll) return;
|
|
1585
|
+
|
|
1586
|
+
if (config.autotrack.scroll.distance) {
|
|
1587
|
+
this.distance = config.autotrack.scroll.distance;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
this.eventHandle = eventHandle;
|
|
1591
|
+
this.addLinstenr();
|
|
1592
|
+
this.mutation();
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
ScrollSlide.prototype.addLinstenr = function () {
|
|
1596
|
+
var _this = this;
|
|
1597
|
+
|
|
1598
|
+
Array.prototype.forEach.call(document.querySelectorAll('[data-scroll]'), function (dom) {
|
|
1599
|
+
_this.scrollHandle(dom);
|
|
1600
|
+
});
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
ScrollSlide.prototype.mutation = function () {
|
|
1604
|
+
var _this = this;
|
|
1605
|
+
|
|
1606
|
+
if (window['MutationObserver']) {
|
|
1607
|
+
try {
|
|
1608
|
+
var instance = new MutationObserver(function (mutations) {
|
|
1609
|
+
mutations.forEach(function (mutation) {
|
|
1610
|
+
// 更新dom节点可能是update,只是属性改变,需要监听
|
|
1611
|
+
// if (mutation.type === 'attributes') {
|
|
1612
|
+
// this.attributeChangeObserve(mutation);
|
|
1613
|
+
// }
|
|
1614
|
+
// dom节点变化
|
|
1615
|
+
if (mutation.type === 'childList') {
|
|
1616
|
+
_this.modifyNodeObserve(mutation);
|
|
1617
|
+
}
|
|
1618
|
+
});
|
|
1619
|
+
});
|
|
1620
|
+
|
|
1621
|
+
if (!document || !document.body) {
|
|
1622
|
+
console.warn('please use sdk api init after body element');
|
|
1623
|
+
return;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
instance.observe(document.body, {
|
|
1627
|
+
childList: true,
|
|
1628
|
+
attributes: true,
|
|
1629
|
+
subtree: true,
|
|
1630
|
+
attributeOldValue: false
|
|
1631
|
+
});
|
|
1632
|
+
} catch (e) {
|
|
1633
|
+
console.log('your browser cannot support MutationObserver');
|
|
1634
|
+
}
|
|
1635
|
+
} else {
|
|
1636
|
+
console.log('your browser cannot support MutationObserver');
|
|
1637
|
+
}
|
|
1638
|
+
}; // 监听dom属性变化添加或删除节点曝光监听
|
|
1639
|
+
// attributeChangeObserve(mutation) {
|
|
1640
|
+
// const dom = mutation.target;
|
|
1641
|
+
// if (dom.hasAttribute('data-scroll')) {
|
|
1642
|
+
// this.scrollHandle(mutation);
|
|
1643
|
+
// }
|
|
1644
|
+
// }
|
|
1645
|
+
// 监听dom变化添加或删除节点曝光监听
|
|
1646
|
+
|
|
1647
|
+
|
|
1648
|
+
ScrollSlide.prototype.modifyNodeObserve = function (mutation) {
|
|
1649
|
+
var _this = this; // 不能为文本节点&&要有auto-exp属性
|
|
1650
|
+
|
|
1651
|
+
|
|
1652
|
+
Array.prototype.forEach.call(mutation.addedNodes, function (node) {
|
|
1653
|
+
if (node.nodeType === 1 && node.hasAttribute('data-scroll')) {
|
|
1654
|
+
_this.scrollHandle(node);
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
_this.mapChild(node, _this.scrollHandle.bind(_this));
|
|
1658
|
+
}); // 遍历子节点的删除
|
|
1659
|
+
|
|
1660
|
+
Array.prototype.forEach.call(mutation.removedNodes, function (node) {
|
|
1661
|
+
if (node.nodeType === 1 && node.hasAttribute('data-scroll')) {
|
|
1662
|
+
_this.scrollHandle(node, 'remove');
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
_this.mapChild(node, _this.scrollHandle.bind(_this));
|
|
1666
|
+
});
|
|
1667
|
+
}; // 递归后代节点
|
|
1668
|
+
|
|
1669
|
+
|
|
1670
|
+
ScrollSlide.prototype.mapChild = function (node, action) {
|
|
1671
|
+
var _this = this;
|
|
1672
|
+
|
|
1673
|
+
if (node.nodeType !== 1) {
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
if (!node.children.length) {
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
Array.prototype.forEach.call(node.children, function (item) {
|
|
1682
|
+
if (item.nodeType === 1 && item.hasAttribute('data-scroll')) {
|
|
1683
|
+
action(item);
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
_this.mapChild(item, action);
|
|
1687
|
+
});
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1690
|
+
ScrollSlide.prototype.scrollHandle = function (dom, type) {
|
|
1691
|
+
var _this = this;
|
|
1692
|
+
|
|
1693
|
+
try {
|
|
1694
|
+
var preScrollTop_1 = dom.scrollTop;
|
|
1695
|
+
var preScrollLeft_1 = dom.scrollLeft;
|
|
1696
|
+
var timer_1 = null;
|
|
1697
|
+
var $offsetX_1 = 0;
|
|
1698
|
+
var $offsetY_1 = 0;
|
|
1699
|
+
|
|
1700
|
+
var scrollFn_1 = function scrollFn_1(e) {
|
|
1701
|
+
clearTimeout(timer_1);
|
|
1702
|
+
timer_1 = setTimeout(function () {
|
|
1703
|
+
var finalScrollTop = dom.scrollTop;
|
|
1704
|
+
var finalScrollLeft = dom.scrollLeft;
|
|
1705
|
+
var event = e.target && e.target['getAttribute']('data-scroll-event') || '';
|
|
1706
|
+
|
|
1707
|
+
if (scrollDirection === 1 || scrollDirection === 2) {
|
|
1708
|
+
if (finalScrollTop === currentScrollTop) {
|
|
1709
|
+
// 滚动停止了
|
|
1710
|
+
$offsetY_1 = currentScrollTop - preScrollTop_1;
|
|
1711
|
+
|
|
1712
|
+
if (Math.abs($offsetY_1) >= _this.distance && _this.distance) {
|
|
1713
|
+
_this.eventHandle({
|
|
1714
|
+
eventType: 'dom',
|
|
1715
|
+
eventName: 'scroll',
|
|
1716
|
+
event: event,
|
|
1717
|
+
params: {
|
|
1718
|
+
$direction: scrollDirection,
|
|
1719
|
+
$offsetY: $offsetY_1,
|
|
1720
|
+
$offsetX: $offsetX_1
|
|
1721
|
+
}
|
|
1722
|
+
}, e);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
} else if (scrollDirection === 3 || scrollDirection === 4) {
|
|
1726
|
+
if (finalScrollLeft === currentScrollLeft) {
|
|
1727
|
+
// 滚动停止了
|
|
1728
|
+
$offsetX_1 = currentScrollLeft - preScrollLeft_1;
|
|
1729
|
+
|
|
1730
|
+
if (Math.abs($offsetX_1) >= _this.distance && _this.distance) {
|
|
1731
|
+
_this.eventHandle({
|
|
1732
|
+
eventType: 'dom',
|
|
1733
|
+
eventName: 'scroll',
|
|
1734
|
+
event: event,
|
|
1735
|
+
params: {
|
|
1736
|
+
$direction: scrollDirection,
|
|
1737
|
+
$offsetY: $offsetY_1,
|
|
1738
|
+
$offsetX: $offsetX_1
|
|
1739
|
+
}
|
|
1740
|
+
}, e);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
preScrollTop_1 = currentScrollTop;
|
|
1746
|
+
preScrollLeft_1 = currentScrollLeft;
|
|
1747
|
+
}, 100);
|
|
1748
|
+
var currentScrollTop = dom.scrollTop;
|
|
1749
|
+
var currentScrollLeft = dom.scrollLeft;
|
|
1750
|
+
var scrollDirection = ScrollTypeE.NOT_SCROLL;
|
|
1751
|
+
|
|
1752
|
+
if (currentScrollTop > preScrollTop_1) {
|
|
1753
|
+
scrollDirection = ScrollTypeE.SCROLL_DOWN;
|
|
1754
|
+
} else if (currentScrollTop < preScrollTop_1) {
|
|
1755
|
+
scrollDirection = ScrollTypeE.SCROLL_UP;
|
|
1756
|
+
} else {
|
|
1757
|
+
if (currentScrollLeft > preScrollLeft_1) {
|
|
1758
|
+
scrollDirection = ScrollTypeE.SCROLL_LEFT;
|
|
1759
|
+
} else if (currentScrollLeft < preScrollLeft_1) {
|
|
1760
|
+
scrollDirection = ScrollTypeE.SCROLL_RIGHT;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1764
|
+
|
|
1765
|
+
if (type === 'remove') {
|
|
1766
|
+
dom.removeEventListener('scroll', scrollFn_1, false);
|
|
1767
|
+
} else {
|
|
1768
|
+
dom.addEventListener('scroll', scrollFn_1, false);
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
return function () {
|
|
1772
|
+
dom.removeEventListener('scroll', scrollFn_1, false);
|
|
1773
|
+
};
|
|
1774
|
+
} catch (e) {
|
|
1775
|
+
console.warn('scroll event error', JSON.stringify(e));
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
|
|
1779
|
+
return ScrollSlide;
|
|
1780
|
+
}();
|
|
1781
|
+
|
|
1782
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
1783
|
+
var defaultOpt = {
|
|
1784
|
+
hashTag: false,
|
|
1785
|
+
impr: false
|
|
1786
|
+
};
|
|
1787
|
+
|
|
1788
|
+
var AutoTrack =
|
|
1789
|
+
/** @class */
|
|
1790
|
+
function () {
|
|
1791
|
+
function AutoTrack() {}
|
|
1792
|
+
|
|
1793
|
+
AutoTrack.prototype.apply = function (collect, config) {
|
|
1794
|
+
this.autoTrackStart = false;
|
|
1795
|
+
this.collect = collect;
|
|
1796
|
+
this.config = config;
|
|
1797
|
+
if (!config.autotrack) return;
|
|
1798
|
+
|
|
1799
|
+
if (config.autotrack && config.autotrack.collect_url) {
|
|
1800
|
+
if (!config.autotrack.collect_url()) return;
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
var Types = collect.Types;
|
|
1804
|
+
this.ready(Types.Autotrack);
|
|
1805
|
+
this.collect.emit(Types.AutotrackReady);
|
|
1806
|
+
};
|
|
1807
|
+
|
|
1808
|
+
AutoTrack.prototype.ready = function (name) {
|
|
1809
|
+
this.collect.set(name);
|
|
1810
|
+
var options = this.config.autotrack;
|
|
1811
|
+
options = typeof options === 'object' ? options : {};
|
|
1812
|
+
options = Object.assign(defaultOpt, options);
|
|
1813
|
+
this.destroyed = false;
|
|
1814
|
+
this.options = options;
|
|
1815
|
+
this.Config = new Config(defaultConfig, this.options);
|
|
1816
|
+
this.Exposure = new Exposure(this.collect, this.config, this.handle.bind(this));
|
|
1817
|
+
this.Scroll = new ScrollSlide(this.config, this.handle.bind(this));
|
|
1818
|
+
this.Listener = new Listener(options, this.collect, this.Config);
|
|
1819
|
+
this.EventHandle = new EventHandle(this.config, options);
|
|
1820
|
+
this.Request = new Request(this.collect);
|
|
1821
|
+
this.autoTrackStart = true;
|
|
1822
|
+
this.init(); // readyToLoadEditor(this, this.config)
|
|
1823
|
+
};
|
|
1824
|
+
|
|
1825
|
+
AutoTrack.prototype.init = function () {
|
|
1826
|
+
this.Listener.init(this.handle.bind(this));
|
|
1827
|
+
};
|
|
1828
|
+
|
|
1829
|
+
AutoTrack.prototype.handle = function (eventInfo, data) {
|
|
1830
|
+
try {
|
|
1831
|
+
if (this.config.autotrack.collect_url) {
|
|
1832
|
+
if (!this.config.autotrack.collect_url()) return;
|
|
1833
|
+
}
|
|
1834
|
+
} catch (e) {}
|
|
1835
|
+
|
|
1836
|
+
if (this.collect.sdkStop) return;
|
|
1837
|
+
|
|
1838
|
+
if (eventInfo.eventType === 'dom') {
|
|
1839
|
+
this.handleDom(eventInfo, data);
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1842
|
+
|
|
1843
|
+
AutoTrack.prototype.handleDom = function (eventInfo, data) {
|
|
1844
|
+
try {
|
|
1845
|
+
var eventName = eventInfo.eventName;
|
|
1846
|
+
|
|
1847
|
+
if (eventName === 'click' || eventName === 'change' || eventName === 'submit') {
|
|
1848
|
+
var handleResult = this.EventHandle.handleEvent(data, eventName);
|
|
1849
|
+
handleResult && this.Request.send({
|
|
1850
|
+
eventType: 'custom'
|
|
1851
|
+
}, handleResult);
|
|
1852
|
+
} else if (eventName === 'page_view' || eventName === 'page_statistics') {
|
|
1853
|
+
var pageData = void 0;
|
|
1854
|
+
|
|
1855
|
+
if (eventName === 'page_view') {
|
|
1856
|
+
pageData = this.EventHandle.handleViewEvent(data);
|
|
1857
|
+
} else {
|
|
1858
|
+
pageData = this.EventHandle.handleStatisticsEvent(data);
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
pageData && this.Request.send({
|
|
1862
|
+
eventType: 'custom'
|
|
1863
|
+
}, pageData);
|
|
1864
|
+
} else if (eventName === 'beat') {
|
|
1865
|
+
var beatData = this.EventHandle.handleBeadtEvent(data);
|
|
1866
|
+
var eventSend = eventInfo.eventSend;
|
|
1867
|
+
beatData && this.Request.send({
|
|
1868
|
+
eventType: 'custom',
|
|
1869
|
+
eventSend: eventSend
|
|
1870
|
+
}, beatData);
|
|
1871
|
+
} else if (eventName === 'exposure') {
|
|
1872
|
+
var handleResult = this.EventHandle.handleExposureEvent(eventInfo, data);
|
|
1873
|
+
handleResult && this.Request.send({
|
|
1874
|
+
eventType: 'custom'
|
|
1875
|
+
}, handleResult);
|
|
1876
|
+
} else if (eventName === 'scroll') {
|
|
1877
|
+
var handleResult = this.EventHandle.handleScrollEvent(eventInfo, data);
|
|
1878
|
+
handleResult && this.Request.send({
|
|
1879
|
+
eventType: 'custom'
|
|
1880
|
+
}, handleResult);
|
|
1881
|
+
}
|
|
1882
|
+
} catch (e) {
|
|
1883
|
+
console.log("handel dom event error " + JSON.stringify(e));
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
|
|
1887
|
+
AutoTrack.prototype.destroy = function () {
|
|
1888
|
+
if (!this.autoTrackStart) {
|
|
1889
|
+
return console.warn('engine is undefined, make sure you have called autoTrack.start()');
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
this.autoTrackStart = false;
|
|
1893
|
+
this.Listener.removeListener();
|
|
1894
|
+
};
|
|
1895
|
+
|
|
1896
|
+
return AutoTrack;
|
|
1897
|
+
}();
|
|
1898
|
+
|
|
1899
|
+
module.exports = AutoTrack;
|