@datarangers/sdk-javascript 0.1.5 → 0.1.7

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/lib/plugin/ab.js CHANGED
@@ -1 +1 @@
1
- "use strict";function e(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var t="__rangers_ab_style__";var i={cn:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"},n=function(e){return e.DEBUGGER_MESSAGE="debugger-message",e.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",e.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",e.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",e.DEBUGGER_MESSAGE_EVENT="debugger-message-event",e.DEVTOOL_WEB_READY="devtool-web-ready",e}({});Date.now(),Number((""+Math.random()).slice(2,8));var o=function(e){return function(e,t,i){if("string"==typeof e&&"number"==typeof t&&"number"==typeof i){var n,o=[];i=i<=25?i:i%25;var s=String.fromCharCode(i+97);n=e.split(s);for(var r=0;r<n.length;r++){var a=parseInt(n[r],i);a=1*a^t;var c=String.fromCharCode(a);o.push(c)}return o.join("")}}(e,64,25)},s=function(e){var t=document.createElement("a");return t.href=e,t};var r=function(e,t){return e(t={exports:{}},t.exports),t.exports}(function(e,t){var i;i=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var i=arguments[e];for(var n in i)t[n]=i[n]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function i(n){function o(){}function s(t,i,s){if("undefined"!=typeof document){"number"==typeof(s=e({path:"/"},o.defaults,s)).expires&&(s.expires=new Date(1*new Date+864e5*s.expires)),s.expires=s.expires?s.expires.toUTCString():"";try{var r=JSON.stringify(i);/^[\{\[]/.test(r)&&(i=r)}catch(e){}i=n.write?n.write(i,t):encodeURIComponent(String(i)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var c in s)s[c]&&(a+="; "+c,!0!==s[c]&&(a+="="+s[c].split(";")[0]));return document.cookie=t+"="+i+a}}function r(e,i){if("undefined"!=typeof document){for(var o={},s=document.cookie?document.cookie.split("; "):[],r=0;r<s.length;r++){var a=s[r].split("="),c=a.slice(1).join("=");i||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var l=t(a[0]);if(c=(n.read||n)(c,l)||t(c),i)try{c=JSON.parse(c)}catch(e){}if(o[l]=c,e===l)break}catch(e){}}return e?o[e]:o}}return o.set=s,o.get=function(e){return r(e,!1)},o.getJSON=function(e){return r(e,!0)},o.remove=function(t,i){s(t,"",e(i,{expires:-1}))},o.defaults={},o.withConverter=i,o}(function(){})},e.exports=i()}),a=function(){function t(){e(this,"cache",void 0),this.cache={}}var i=t.prototype;return i.setItem=function(e,t){this.cache[e]=t},i.getItem=function(e){return this.cache[e]},i.removeItem=function(e){this.cache[e]=void 0},t}(),c=function(){function t(){e(this,"support",void 0),this.support=this.isSupportLS()}var i=t.prototype;return i.isSupportLS=function(){try{return localStorage.setItem("_applogtest-test-key","hi"),localStorage.getItem("_applogtest-test-key"),localStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},i.getItem=function(e){try{var t=localStorage.getItem(e),i=t;try{t&&"string"==typeof t&&(i=JSON.parse(t))}catch(e){}return i||{}}catch(e){}return{}},i.setItem=function(e,t){try{var i="string"==typeof t?t:JSON.stringify(t);localStorage.setItem(e,i)}catch(e){}},i.removeItem=function(e){try{localStorage.removeItem(e)}catch(e){}},t}(),l=function(){function t(){e(this,"support",void 0),this.support=this.isSupportSession()}var i=t.prototype;return i.isSupportSession=function(){try{return sessionStorage.setItem("_applogtest-test-key","hi"),sessionStorage.getItem("_applogtest-test-key"),sessionStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},i.getItem=function(e){try{var t=sessionStorage.getItem(e),i=t;try{t&&"string"==typeof t&&(i=JSON.parse(t))}catch(e){}return i||{}}catch(e){}return{}},i.setItem=function(e,t){try{var i="string"==typeof t?t:JSON.stringify(t);sessionStorage.setItem(e,i)}catch(e){}},i.removeItem=function(e){try{sessionStorage.removeItem(e)}catch(e){}},t}(),h=function(){function t(){e(this,"local",void 0),e(this,"session",void 0),e(this,"cache",void 0),e(this,"defaultExpireTime",void 0),this.defaultExpireTime=6048e5,this.local=new c,this.session=new l,this.cache=new a}var i=t.prototype;return i.getLocalItem=function(e){return this.local.getItem(e)},i.setLocalItem=function(e,t){this.local.setItem(e,t)},i.removeLocalItem=function(e){this.local.removeItem(e)},i.getSessionItem=function(e){return this.session.getItem(e)},i.setSessionItem=function(e,t){this.session.setItem(e,t)},i.removeSessionItem=function(e){this.session.removeItem(e)},i.getCacheItem=function(e){return this.cache.getItem(e)},i.setCacheItem=function(e,t){this.cache.setItem(e,t)},i.removeCacheItem=function(e){this.cache.removeItem(e)},i.getCookie=function(e,t){try{return r.get(e)}catch(e){return""}},i.setCookie=function(e,t,i,n){void 0===i&&(i=this.defaultExpireTime);try{var o=n||document.domain,s=+new Date+i;r.set(e,t,{expires:new Date(s),path:"/",domain:o})}catch(e){}},i.removeCookie=function(e,t){try{r.remove(e,{path:"/",domain:t||""})}catch(e){}},t}(),u=function(e){return e[e.Var=0]="Var",e[e.All=1]="All",e}(u||{}),f=2592e6,m=function(){function r(){e(this,"collect",void 0),e(this,"config",void 0),e(this,"abOption",void 0),e(this,"fetchUrl",void 0),e(this,"reportUrl",void 0),e(this,"fetchStatus","no"),e(this,"refreshFetchStatus","complete"),e(this,"versions",[]),e(this,"extVersions",[]),e(this,"mulilinkVersions",[]),e(this,"enable_multilink",!1),e(this,"enable_ab_visual",!1),e(this,"editMode",!1),e(this,"callbacks",[]),e(this,"abKey",void 0),e(this,"cacheStorgae",void 0),e(this,"data",null),e(this,"changeListener",new Map),e(this,"fetch",void 0),e(this,"readyStatus",!1),e(this,"types",void 0),e(this,"ab_cross",void 0),e(this,"ab_cookie_domain",void 0),e(this,"exposureCache",[]),e(this,"exposureLimit",void 0),e(this,"ab_batch_time",void 0),e(this,"reportTimeout",void 0)}var a=r.prototype;return a.apply=function(e,t){var n=this;if(this.collect=e,this.config=t,this.config.enable_ab_test){var s=t.enable_multilink,r=t.ab_channel_domain,a=t.enable_ab_visual,c=t.ab_cross,l=t.ab_cookie_domain,u=t.disable_ab_reset,f=r||o(i[t.channel||"cn"]);this.cacheStorgae=new h,this.enable_multilink=s,this.enable_ab_visual=a,this.abKey="__tea_sdk_ab_version_"+t.app_id,this.ab_cross=c,this.ab_cookie_domain=l||"",this.fetchUrl=f+"/service/2/abtest_config/",this.reportUrl=""+e.configManager.getUrl("event"),this.exposureLimit=t.exposure_limit||20,this.ab_batch_time=t.ab_batch_time||500;var m=this.collect.Types;this.types=m,this.collect.on(m.TokenChange,function(e){u||"uuid"===e.type&&n.readyStatus&&(n.clearCache(),n.fetchAB())}),this.collect.on(m.TokenReset,function(){u||n.readyStatus&&(n.clearCache(),n.fetchAB())}),this.collect.on(m.AbVar,function(e){var t=e.name,i=e.defaultValue,o=e.callback;n.getVar(t,i,o)}),this.collect.on(m.AbAllVars,function(e){n.getAllVars(e)}),this.collect.on(m.AbConfig,function(e){var t=e.params,i=e.callback;n.getABconfig(t,i)}),this.collect.on(m.AbExternalVersion,function(e){n.setExternalAbVersion(e)}),this.collect.on(m.AbOpenLayer,function(){n.openOverlayer()}),this.collect.on(m.AbCloseLayer,function(){n.closeOverlayer()}),this.collect.on(m.AbVersionChangeOn,function(e){n.changeListener.set(e,e)}),this.collect.on(m.AbVersionChangeOff,function(e){n.changeListener.get(e)&&n.changeListener.delete(e)}),this.loadMode(),(this.enable_ab_visual||this.enable_multilink)&&this.openOverlayer(this.config.multilink_timeout_ms||500),this.checkLocal(),this.ready("ab"),this.readyStatus||(this.fetchAB(),this.readyStatus=!0),this.collect.emit(m.AbReady)}},a.ready=function(e){var t=this;if(this.collect.set(e),this.collect.hook._hooksCache.hasOwnProperty(e)){var i=this.collect.hook._hooksCache[e];if(!Object.keys(i).length)return;var n=function(e){i[e].length&&i[e].forEach(function(i){t.collect.hook.emit(e,i)})};for(var o in i)n(o)}},a.loadMode=function(){},a.checkLocal=function(){var e=this.getABCache(),t=e.ab_version,i=e.ab_ext_version,n=e.ab_version_multilink,o=e.data,s=this.checkFromUrl();s?this.mulilinkVersions.push(s):this.mulilinkVersions=n||[],this.extVersions=i||[],this.versions=t||[],this.data=o;var r=this.versions.concat(this.extVersions);this.enable_multilink&&(r=r.concat(this.mulilinkVersions)),this.configVersions(r.join(","))},a.checkFromUrl=function(){var e=function(e){var t={};try{var i=s(e).search;(i=i.slice(1)).split("&").forEach(function(e){var i,n,o=e.split("=");o.length&&(i=o[0],n=o[1]);try{t[i]=decodeURIComponent(void 0===n?"":n)}catch(e){t[i]=n}})}catch(e){}return t}(window.location.href);return e&&e.vid?e.vid:""},a.updateVersions=function(){var e=this.extVersions.length?this.versions.concat(this.extVersions):this.versions;this.enable_multilink&&(e=e.concat(this.mulilinkVersions)),this.configVersions(e.join(",")),this.updateABCache(),this.changeListener.size>0&&this.changeListener.forEach(function(t){"function"==typeof t&&t(e)})},a.configVersions=function(e){this.collect.configManager.setAbVersion(e)},a.getVar=function(e,t,i){if(!e)throw new Error("variable must not be empty");if(void 0===t)throw new Error("variable no default value");if("function"!=typeof i)throw new Error("callback must be a function");var n={name:e,defaultValue:t,callback:i,type:u.Var};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealVar(n,e):this.callbacks.push(n)},a.getRealVar=function(e,t){var i=e.name,o=e.defaultValue,s=e.callback,r=this.data;if(r){if(null!=(c=r[i])&&"[object Object]"==Object.prototype.toString.call(c)){var a=r[i].vid;return"$ab_url"===t?this.mulilinkVersions.includes(a)||this.mulilinkVersions.push(a):this.versions.includes(a)||this.versions.push(a),this.updateVersions(),this.fechEvent(a,t,o),s(r[i].val),void this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 曝光了实验"+i,level:"info",time:Date.now(),data:r[i]})}var c;this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getVar",level:"info",time:Date.now(),data:o}),s(o)}else s(o)},a.getAllVars=function(e){if("function"!=typeof e)throw new Error("callback must be a function");var t={callback:e,type:u.All};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealAllVars(t):this.callbacks.push(t)},a.getRealAllVars=function(e){(0,e.callback)(this.data?JSON.parse(JSON.stringify(this.data)):{}),this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getAllVars",level:"info",time:Date.now(),data:this.data})},a.fechEvent=function(e,t,i){try{if(this.config.disable_track_event)return;if(!e)return;var o=this.collect.configManager.get(),s=o.header,r=o.user,a=this.getABCache();if(a&&a.uuid&&a.uuid!==r.user_unique_id)return;var c={event:"abtest_exposure",ab_sdk_version:""+e,params:JSON.stringify({app_id:this.config.appId,ab_url:"$ab_url"===t?i:window.location.href}),local_time_ms:Date.now()};s.custom=JSON.stringify(s.custom);var l={events:[c],user:r,header:s};"$ab_url"===t&&window.navigator.sendBeacon?window.navigator.sendBeacon(this.reportUrl,JSON.stringify([l])):this.reportExposure(l)}catch(e){this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},a.reportExposure=function(e){var t=this;this.exposureCache.push(e),this.reportTimeout&&clearTimeout(this.reportTimeout),this.exposureCache.length>=this.exposureLimit?this.report():this.reportTimeout=setTimeout(function(){t.report(),clearTimeout(t.reportTimeout)},this.ab_batch_time)},a.report=function(){var e=this,t=this.collect.cryptoData(this.exposureCache);this.collect.requestManager.useRequest({url:this.reportUrl,data:t,timeout:1e5,useBeacon:!1,encryption:this.config.enable_encryption,encryption_header:this.config.encryption_header,zip:!0,type:"event"}),this.exposureCache.forEach(function(t){e.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:[t],code:200,status:"success"})}),this.exposureCache=[]},a.setExternalAbVersion=function(e){this.extVersions=[e],this.updateVersions()},a.getABconfig=function(e,t){var i=Object.keys(e);i&&i.length&&this.collect.configManager.set(e),this.fetchAB(t)},a.get=function(e){if(this.ab_cross){var t=this.cacheStorgae.getCookie(e,this.ab_cookie_domain);return t?JSON.parse(t):null}return this.cacheStorgae.getLocalItem(e)},a.set=function(e,t){this.ab_cross?this.cacheStorgae.setCookie(e,t,f,this.ab_cookie_domain):this.cacheStorgae.setLocalItem(e,t),this.collect.configManager.setAbCache(t)},a.getABCache=function(e){var t={ab_version:[],ab_ext_version:[],ab_version_multilink:[],data:null,timestamp:+new Date,uuid:""};return t=this.get(this.abKey)||t,Date.now()-t.timestamp>=f?(this.cacheStorgae.removeLocalItem(this.abKey),null):e?t[e]:t},a.updateABCache=function(){var e=this.getABCache();e.ab_version_multilink=this.mulilinkVersions,e.ab_ext_version=this.extVersions,e.ab_version=this.versions,e.timestamp=Date.now(),this.set(this.abKey,e)},a.setAbCache=function(e){var t=this.getABCache();t.data=this.data,t.uuid=e,t.timestamp=Date.now(),this.set(this.abKey,t)},a.clearCache=function(){this.refreshFetchStatus="ing",this.data={},this.extVersions=[],this.mulilinkVersions=[],this.versions=[],this.collect.configManager.clearAbCache()},a.openOverlayer=function(e){var i=this;if(function(){if(!document.getElementById(t)){var e="body { opacity: 0 !important; }",i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.id=t,n.type="text/css",n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e)),i.appendChild(n)}}(),e)var n=setTimeout(function(){i.closeOverlayer(),clearTimeout(n)},e)},a.closeOverlayer=function(){var e;(e=document.getElementById(t))&&e.parentElement.removeChild(e)},a.fetchComplete=function(e,t){var i=this;if(e&&"[object Object]"==Object.prototype.toString.call(e)){this.data=e,this.setAbCache(t);var n=[];Object.keys(e).forEach(function(t){var i=e[t].vid;i&&n.push(i)}),this.versions=this.versions.filter(function(e){return n.includes(e)});var o=e.$ab_url,r=e.$ab_modification;if(r&&r.val&&this.enable_ab_visual){if(this.collect.destroy)return;this.getVar("$ab_modification",window.location.href,function(){i.closeOverlayer()})}else if(o&&this.enable_multilink){this.mulilinkVersions=this.mulilinkVersions.filter(function(e){return n.includes(e)});var a=o.val,c=o.vid;a&&c&&this.getVar("$ab_url",a,function(){i.editMode||(a!==window.location.href?setTimeout(function(){if(!i.collect.destroy){var e=""+a;e=-1===e.indexOf("http")?"https://"+e:e;var t=s(e).host;try{var n=new URL(e);t!==location.host?n.searchParams.append("vid",c):window.history.replaceState("","",e),window.location.href=n.href}catch(t){window.location.href=e}}},100):i.closeOverlayer())})}this.updateVersions()}else this.closeOverlayer();this.callbacks.forEach(function(e){return i[e.type===u.Var?"getRealVar":"getRealAllVars"](e,"")}),this.callbacks=[]},a.fetchAB=function(e){var t=this,i=this.collect.configManager.get(),o=i.header,s=i.user;this.config.enable_anonymousid&&delete s.web_id;var r=s.user_unique_id,a={header:Object.assign({aid:this.config.app_id},s||{},o||{},{ab_sdk_version:this.collect.configManager.getAbVersion(),ab_url:window.location.href})},c=this.collect.cryptoData(a);this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"SDK 发起AB实验请求",level:"info",logType:"fetch",time:Date.now(),data:a,infoType:"sdk"}),this.collect.requestManager.useRequest({url:this.fetchUrl,data:c,success:function(i){t.fetchStatus="complete",t.refreshFetchStatus="complete";var o=i.data;"success"===i.message?(t.fetchComplete(o,r),e&&e(o)):(t.fetchComplete(null,r),e&&e(null)),t.collect.emit(t.types.AbComplete,o),t.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求成功",level:"info",logType:"fetch",time:Date.now(),data:o,infoType:"sdk"})},fail:function(){t.fetchStatus="complete",t.refreshFetchStatus="complete",t.fetchComplete(null,r),e&&e(null),t.collect.emit(t.types.AbTimeout),t.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求网络异常",level:"error",logType:"fetch",time:Date.now(),infoType:"sdk"})},timeout:this.config.ab_timeout||1e4,encryption:this.config.enable_encryption,encryption_header:this.config.encryption_header})},a.filterUrl=function(e){try{var t="";-1!==e.indexOf("&multilink=true")?t="&multilink=true[\0-ÿ]*":-1!==e.indexOf("?multilink=true")&&(t="\\?multilink=true[\0-ÿ]*");var i=new RegExp(t,"g");e=e.replace(i,"")}catch(e){}return e},r}();module.exports=m;
1
+ "use strict";function e(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i;if("undefined"!=typeof Symbol&&void 0!==(i=e[Symbol.toPrimitive])){var n=i.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var t="__rangers_ab_style__";var i={cn:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"},n=function(e){return e.DEBUGGER_MESSAGE="debugger-message",e.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",e.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",e.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",e.DEBUGGER_MESSAGE_EVENT="debugger-message-event",e.DEVTOOL_WEB_READY="devtool-web-ready",e}({});Date.now(),Number((""+Math.random()).slice(2,8));var o=function(e){return function(e,t,i){if("string"==typeof e&&"number"==typeof t&&"number"==typeof i){var n,o=[];i=i<=25?i:i%25;var s=String.fromCharCode(i+97);n=e.split(s);for(var r=0;r<n.length;r++){var a=parseInt(n[r],i);a=1*a^t;var c=String.fromCharCode(a);o.push(c)}return o.join("")}}(e,64,25)},s=function(e){var t=document.createElement("a");return t.href=e,t};var r=function(e,t){return e(t={exports:{}},t.exports),t.exports}(function(e,t){var i;i=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var i=arguments[e];for(var n in i)t[n]=i[n]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function i(n){function o(){}function s(t,i,s){if("undefined"!=typeof document){"number"==typeof(s=e({path:"/"},o.defaults,s)).expires&&(s.expires=new Date(1*new Date+864e5*s.expires)),s.expires=s.expires?s.expires.toUTCString():"";try{var r=JSON.stringify(i);/^[\{\[]/.test(r)&&(i=r)}catch(e){}i=n.write?n.write(i,t):encodeURIComponent(String(i)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var c in s)s[c]&&(a+="; "+c,!0!==s[c]&&(a+="="+s[c].split(";")[0]));return document.cookie=t+"="+i+a}}function r(e,i){if("undefined"!=typeof document){for(var o={},s=document.cookie?document.cookie.split("; "):[],r=0;r<s.length;r++){var a=s[r].split("="),c=a.slice(1).join("=");i||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var l=t(a[0]);if(c=(n.read||n)(c,l)||t(c),i)try{c=JSON.parse(c)}catch(e){}if(o[l]=c,e===l)break}catch(e){}}return e?o[e]:o}}return o.set=s,o.get=function(e){return r(e,!1)},o.getJSON=function(e){return r(e,!0)},o.remove=function(t,i){s(t,"",e(i,{expires:-1}))},o.defaults={},o.withConverter=i,o}(function(){})},e.exports=i()}),a=function(){function t(){e(this,"cache",void 0),this.cache={}}var i=t.prototype;return i.setItem=function(e,t){this.cache[e]=t},i.getItem=function(e){return this.cache[e]},i.removeItem=function(e){this.cache[e]=void 0},t}(),c=function(){function t(){e(this,"support",void 0),this.support=this.isSupportLS()}var i=t.prototype;return i.isSupportLS=function(){try{return localStorage.setItem("_applogtest-test-key","hi"),localStorage.getItem("_applogtest-test-key"),localStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},i.getItem=function(e){try{var t=localStorage.getItem(e),i=t;try{t&&"string"==typeof t&&(i=JSON.parse(t))}catch(e){}return i||{}}catch(e){}return{}},i.setItem=function(e,t){try{var i="string"==typeof t?t:JSON.stringify(t);localStorage.setItem(e,i)}catch(e){}},i.removeItem=function(e){try{localStorage.removeItem(e)}catch(e){}},t}(),l=function(){function t(){e(this,"support",void 0),this.support=this.isSupportSession()}var i=t.prototype;return i.isSupportSession=function(){try{return sessionStorage.setItem("_applogtest-test-key","hi"),sessionStorage.getItem("_applogtest-test-key"),sessionStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},i.getItem=function(e){try{var t=sessionStorage.getItem(e),i=t;try{t&&"string"==typeof t&&(i=JSON.parse(t))}catch(e){}return i||{}}catch(e){}return{}},i.setItem=function(e,t){try{var i="string"==typeof t?t:JSON.stringify(t);sessionStorage.setItem(e,i)}catch(e){}},i.removeItem=function(e){try{sessionStorage.removeItem(e)}catch(e){}},t}(),h=function(){function t(){e(this,"local",void 0),e(this,"session",void 0),e(this,"cache",void 0),e(this,"defaultExpireTime",void 0),this.defaultExpireTime=6048e5,this.local=new c,this.session=new l,this.cache=new a}var i=t.prototype;return i.getLocalItem=function(e){return this.local.getItem(e)},i.setLocalItem=function(e,t){this.local.setItem(e,t)},i.removeLocalItem=function(e){this.local.removeItem(e)},i.getSessionItem=function(e){return this.session.getItem(e)},i.setSessionItem=function(e,t){this.session.setItem(e,t)},i.removeSessionItem=function(e){this.session.removeItem(e)},i.getCacheItem=function(e){return this.cache.getItem(e)},i.setCacheItem=function(e,t){this.cache.setItem(e,t)},i.removeCacheItem=function(e){this.cache.removeItem(e)},i.getCookie=function(e,t){try{return r.get(e)}catch(e){return""}},i.setCookie=function(e,t,i,n){void 0===i&&(i=this.defaultExpireTime);try{var o=n||document.domain,s=+new Date+i;r.set(e,t,{expires:new Date(s),path:"/",domain:o})}catch(e){}},i.removeCookie=function(e,t){try{r.remove(e,{path:"/",domain:t||""})}catch(e){}},t}(),u=function(e){return e[e.Var=0]="Var",e[e.All=1]="All",e}(u||{}),f=2592e6,m=function(){function r(){e(this,"collect",void 0),e(this,"config",void 0),e(this,"abOption",void 0),e(this,"fetchUrl",void 0),e(this,"reportUrl",void 0),e(this,"fetchStatus","no"),e(this,"refreshFetchStatus","complete"),e(this,"versions",[]),e(this,"extVersions",[]),e(this,"mulilinkVersions",[]),e(this,"enable_multilink",!1),e(this,"enable_ab_visual",!1),e(this,"editMode",!1),e(this,"callbacks",[]),e(this,"abKey",void 0),e(this,"cacheStorgae",void 0),e(this,"data",null),e(this,"changeListener",new Map),e(this,"fetch",void 0),e(this,"readyStatus",!1),e(this,"types",void 0),e(this,"ab_cross",void 0),e(this,"ab_cookie_domain",void 0),e(this,"exposureCache",[]),e(this,"exposureLimit",void 0),e(this,"ab_batch_time",void 0),e(this,"reportTimeout",void 0)}var a=r.prototype;return a.apply=function(e,t){var n=this;if(this.collect=e,this.config=t,this.config.enable_ab_test){var s=t.enable_multilink,r=t.ab_channel_domain,a=t.enable_ab_visual,c=t.ab_cross,l=t.ab_cookie_domain,u=t.disable_ab_reset,f=r||o(i[t.channel||"cn"]);this.cacheStorgae=new h,this.enable_multilink=s,this.enable_ab_visual=a,this.abKey="__tea_sdk_ab_version_"+t.app_id,this.ab_cross=c,this.ab_cookie_domain=l||"",this.fetchUrl=f+"/service/2/abtest_config/",this.reportUrl=""+e.configManager.getUrl("event"),this.exposureLimit=t.exposure_limit||20,this.ab_batch_time=t.ab_batch_time||500;var m=this.collect.Types;this.types=m,this.collect.on(m.TokenChange,function(e){u||"uuid"===e.type&&n.readyStatus&&(n.clearCache(),n.fetchAB())}),this.collect.on(m.TokenReset,function(){u||n.readyStatus&&(n.clearCache(),n.fetchAB())}),this.collect.on(m.AbVar,function(e){var t=e.name,i=e.defaultValue,o=e.callback;n.getVar(t,i,o)}),this.collect.on(m.AbAllVars,function(e){n.getAllVars(e)}),this.collect.on(m.AbConfig,function(e){var t=e.params,i=e.callback;n.getABconfig(t,i)}),this.collect.on(m.AbExternalVersion,function(e){n.setExternalAbVersion(e)}),this.collect.on(m.AbOpenLayer,function(){n.openOverlayer()}),this.collect.on(m.AbCloseLayer,function(){n.closeOverlayer()}),this.collect.on(m.AbVersionChangeOn,function(e){n.changeListener.set(e,e)}),this.collect.on(m.AbVersionChangeOff,function(e){n.changeListener.get(e)&&n.changeListener.delete(e)}),this.loadMode(),(this.enable_ab_visual||this.enable_multilink)&&this.openOverlayer(this.config.multilink_timeout_ms||500),this.checkLocal(),this.ready("ab"),this.readyStatus||(this.fetchAB(),this.readyStatus=!0),this.collect.emit(m.AbReady)}},a.ready=function(e){var t=this;if(this.collect.set(e),this.collect.hook._hooksCache.hasOwnProperty(e)){var i=this.collect.hook._hooksCache[e];if(!Object.keys(i).length)return;var n=function(e){i[e].length&&i[e].forEach(function(i){t.collect.hook.emit(e,i)})};for(var o in i)n(o)}},a.loadMode=function(){},a.checkLocal=function(){var e=this.getABCache(),t=e.ab_version,i=e.ab_ext_version,n=e.ab_version_multilink,o=e.data,s=this.checkFromUrl();s?this.mulilinkVersions.push(s):this.mulilinkVersions=n||[],this.extVersions=i||[],this.versions=t||[],this.data=o;var r=this.versions.concat(this.extVersions);this.enable_multilink&&(r=r.concat(this.mulilinkVersions)),this.configVersions(r.join(","))},a.checkFromUrl=function(){var e=function(e){var t={};try{var i=s(e).search;(i=i.slice(1)).split("&").forEach(function(e){var i,n,o=e.split("=");o.length&&(i=o[0],n=o[1]);try{t[i]=decodeURIComponent(void 0===n?"":n)}catch(e){t[i]=n}})}catch(e){}return t}(window.location.href);return e&&e.vid?e.vid:""},a.updateVersions=function(){var e=this.extVersions.length?this.versions.concat(this.extVersions):this.versions;this.enable_multilink&&(e=e.concat(this.mulilinkVersions)),this.configVersions(e.join(",")),this.updateABCache(),this.changeListener.size>0&&this.changeListener.forEach(function(t){"function"==typeof t&&t(e)})},a.configVersions=function(e){this.collect.configManager.setAbVersion(e)},a.getVar=function(e,t,i){if(!e)throw new Error("variable must not be empty");if(void 0===t)throw new Error("variable no default value");if("function"!=typeof i)throw new Error("callback must be a function");var n={name:e,defaultValue:t,callback:i,type:u.Var};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealVar(n,e):this.callbacks.push(n)},a.getRealVar=function(e,t){var i=e.name,o=e.defaultValue,s=e.callback,r=this.data;if(r){if(null!=(c=r[i])&&"[object Object]"==Object.prototype.toString.call(c)){var a=r[i].vid;return"$ab_url"===t?this.mulilinkVersions.includes(a)||this.mulilinkVersions.push(a):this.versions.includes(a)||this.versions.push(a),this.updateVersions(),this.fechEvent(a,t,o),s(r[i].val),void this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 曝光了实验"+i,level:"info",time:Date.now(),data:r[i]})}var c;this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getVar",level:"info",time:Date.now(),data:o}),s(o)}else s(o)},a.getAllVars=function(e){if("function"!=typeof e)throw new Error("callback must be a function");var t={callback:e,type:u.All};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealAllVars(t):this.callbacks.push(t)},a.getRealAllVars=function(e){(0,e.callback)(this.data?JSON.parse(JSON.stringify(this.data)):{}),this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getAllVars",level:"info",time:Date.now(),data:this.data})},a.fechEvent=function(e,t,i){try{if(this.config.disable_track_event)return;if(!e)return;var o=this.collect.configManager.get(),s=o.header,r=o.user,a=this.getABCache();if(a&&a.uuid&&a.uuid!==r.user_unique_id)return;var c={event:"abtest_exposure",ab_sdk_version:""+e,params:JSON.stringify({app_id:this.config.appId,ab_url:"$ab_url"===t?i:window.location.href}),local_time_ms:Date.now()};s.custom=JSON.stringify(s.custom);var l={events:[c],user:r,header:s};"$ab_url"===t&&window.navigator.sendBeacon?window.navigator.sendBeacon(this.reportUrl,JSON.stringify([l])):this.reportExposure(l)}catch(e){this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},a.reportExposure=function(e){var t=this;this.exposureCache.push(e),this.reportTimeout&&clearTimeout(this.reportTimeout),this.exposureCache.length>=this.exposureLimit?this.report():this.reportTimeout=setTimeout(function(){t.report(),clearTimeout(t.reportTimeout)},this.ab_batch_time)},a.report=function(){var e=this,t=this.collect.cryptoData(this.exposureCache);this.collect.requestManager.useRequest({url:this.reportUrl,data:t,timeout:1e5,useBeacon:!1,encryption:this.config.enable_encryption,encryption_header:this.config.encryption_header,zip:!0,type:"event"}),this.exposureCache.forEach(function(t){e.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:[t],code:200,status:"success"})}),this.exposureCache=[]},a.setExternalAbVersion=function(e){this.extVersions=[e],this.updateVersions()},a.getABconfig=function(e,t){var i=Object.keys(e);i&&i.length&&this.collect.configManager.set(e),this.fetchAB(t)},a.get=function(e){if(this.ab_cross){var t=this.cacheStorgae.getCookie(e,this.ab_cookie_domain);return t?JSON.parse(t):null}return this.cacheStorgae.getLocalItem(e)},a.set=function(e,t){this.ab_cross?this.cacheStorgae.setCookie(e,t,f,this.ab_cookie_domain):this.cacheStorgae.setLocalItem(e,t),this.collect.configManager.setAbCache(t)},a.getABCache=function(e){var t={ab_version:[],ab_ext_version:[],ab_version_multilink:[],data:null,timestamp:+new Date,uuid:""};return t=this.get(this.abKey)||t,Date.now()-t.timestamp>=f?(this.cacheStorgae.removeLocalItem(this.abKey),null):e?t[e]:t},a.updateABCache=function(){var e=this.getABCache();e.ab_version_multilink=this.mulilinkVersions,e.ab_ext_version=this.extVersions,e.ab_version=this.versions,e.timestamp=Date.now(),this.set(this.abKey,e)},a.setAbCache=function(e){var t=this.getABCache();t.data=this.data,t.uuid=e,t.timestamp=Date.now(),this.set(this.abKey,t)},a.clearCache=function(){this.refreshFetchStatus="ing",this.data={},this.extVersions=[],this.mulilinkVersions=[],this.versions=[],this.collect.configManager.clearAbCache()},a.openOverlayer=function(e){var i=this;if(function(){if(!document.getElementById(t)){var e="body { opacity: 0 !important; }",i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.id=t,n.type="text/css",n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e)),i.appendChild(n)}}(),e)var n=setTimeout(function(){i.closeOverlayer(),clearTimeout(n)},e)},a.closeOverlayer=function(){var e;(e=document.getElementById(t))&&e.parentElement.removeChild(e)},a.fetchComplete=function(e,t){var i=this;if(e&&"[object Object]"==Object.prototype.toString.call(e)){this.data=e,this.setAbCache(t);var n=[];Object.keys(e).forEach(function(t){var i=e[t].vid;i&&n.push(i)}),this.versions=this.versions.filter(function(e){return n.includes(e)});var o=e.$ab_url,r=e.$ab_modification;if(r&&r.val&&this.enable_ab_visual){if(this.collect.destroy)return;this.getVar("$ab_modification",window.location.href,function(){i.closeOverlayer()})}else if(o&&this.enable_multilink){this.mulilinkVersions=this.mulilinkVersions.filter(function(e){return n.includes(e)});var a=o.val,c=o.vid;a&&c&&this.getVar("$ab_url",a,function(){i.editMode||(a!==window.location.href?setTimeout(function(){if(!i.collect.destroy){var e=""+a;e=-1===e.indexOf("http")?"https://"+e:e;var t=s(e).host;try{var n=new URL(e);t!==location.host?n.searchParams.append("vid",c):window.history.replaceState("","",e),window.location.href=n.href}catch(t){window.location.href=e}}},100):i.closeOverlayer())})}this.updateVersions()}else this.closeOverlayer();this.callbacks.forEach(function(e){return i[e.type===u.Var?"getRealVar":"getRealAllVars"](e,"")}),this.callbacks=[]},a.fetchAB=function(e){var t=this,i=this.collect.configManager.get(),o=i.header,s=i.user;this.config.enable_anonymousid&&delete s.web_id;var r=s.user_unique_id,a={header:Object.assign({aid:this.config.app_id},s||{},o||{},{ab_sdk_version:this.collect.configManager.getAbVersion(),ab_url:window.location.href})},c=this.collect.cryptoData(a);this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"SDK 发起AB实验请求",level:"info",logType:"fetch",time:Date.now(),data:a,infoType:"sdk"}),this.collect.requestManager.useRequest({url:this.fetchUrl,data:c,success:function(i){t.fetchStatus="complete",t.refreshFetchStatus="complete";var o=i.data;"success"===i.message?(t.fetchComplete(o,r),e&&e(o)):(t.fetchComplete(null,r),e&&e(null)),t.collect.emit(t.types.AbComplete,o),t.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求成功",level:"info",logType:"fetch",time:Date.now(),data:o,infoType:"sdk"})},fail:function(){t.fetchStatus="complete",t.refreshFetchStatus="complete",t.fetchComplete(null,r),e&&e(null),t.collect.emit(t.types.AbTimeout),t.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求网络异常",level:"error",logType:"fetch",time:Date.now(),infoType:"sdk"})},timeout:this.config.ab_timeout||1e4,encryption:this.config.enable_encryption,encryption_header:this.config.encryption_header})},a.filterUrl=function(e){try{var t="";-1!==e.indexOf("&multilink=true")?t="&multilink=true[\0-ÿ]*":-1!==e.indexOf("?multilink=true")&&(t="\\?multilink=true[\0-ÿ]*");var i=new RegExp(t,"g");e=e.replace(i,"")}catch(e){}return e},r}();module.exports=m;
@@ -1 +1 @@
1
- "use strict";function t(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var e=function(t){return Array.isArray(t)};Date.now(),Number((""+Math.random()).slice(2,8));function n(t,e){if(void 0===e&&(e="list"),!t)return!1;if(e&&"list"===e){if(["LI","TR","DL"].includes(t.nodeName))return!0;if(t.dataset&&t.dataset.hasOwnProperty("teaIdx"))return!0;if(t.hasAttribute&&t.hasAttribute("data-tea-idx"))return!0}else{if(["A","BUTTON"].includes(t.nodeName))return!0;if(t.dataset&&t.dataset.hasOwnProperty("teaContainer"))return!0;if(t.hasAttribute&&t.hasAttribute("data-tea-container"))return!0;if(t.hasAttribute&&s(t,"ss"))return!0}return!1}var i=function(t,e){return!!s(t,e)};function o(t){for(var e=t;e&&!n(e,"container");){if("HTML"===e.nodeName||"BODY"===e.nodeName)return t;e=e.parentElement}return e||t}function r(t){for(var e=t;e&&e.parentNode;){if(e.hasAttribute("data-tea-ignore"))return!0;if("HTML"===e.nodeName||"body"===e.nodeName)return!1;e=e.parentNode}return!1}var a=function(t,e){return t.hasAttribute?t.hasAttribute(e):t.attributes?!(!t.attributes[e]||!t.attributes[e].specified):void 0},s=function(t,n){if("string"==typeof n)return a(t,n);if(e(n)){for(var i=!1,o=0;o<n.length;o++){if(a(t,n[o])){i=!0;break}}return i}},c=function(t,n){var i={};if("string"==typeof n)a(t,n)&&(i[n]=t.getAttribute(n));else if(e(n))for(var o=0;o<n.length;o++){a(t,n[o])&&(i[n[o]]=t.getAttribute(n[o]))}return i};var u=function(){function e(e,o,r){var a=this;t(this,"config",void 0),t(this,"options",void 0),t(this,"beatTime",void 0),t(this,"statistics",void 0),t(this,"eventHandel",void 0),t(this,"collect",void 0),t(this,"clickEvent",function(t){(function(t,e){if(1!==t.nodeType)return!1;if(!e.svg&&function(t){if("svg"===t.tagName.toLowerCase())return!0;for(var e=t.parentElement,n=!1;e;)"svg"===e.tagName.toLowerCase()?(e=null,n=!0):e=e.parentElement;return n}(t))return!1;if(["HTML","BODY"].includes(t.tagName.toUpperCase()))return!1;var o=t;return!!("none"!==o.style.display&&(n(o,"container")||e.track_attr&&i(o,e.track_attr)||function(t){if(t.children.length){var e=t.children;return![].slice.call(e).some(function(t){return t.children.length>0})}return!0}(o)))})(t.target,a.options)&&a.eventHandel({eventType:"dom",eventName:"click"},t)}),t(this,"changeEvent",function(t){a.eventHandel({eventType:"dom",eventName:"change"},t)}),t(this,"submitEvent",function(t){a.eventHandel({eventType:"dom",eventName:"submit"},t)}),t(this,"getPageViewEvent",function(t,e){e&&"pushState"===e&&a.eventHandel({eventType:"dom",eventName:"beat"},Object.assign({beat_type:0},t)),a.eventHandel({eventType:"dom",eventName:"page_view"},t)}),t(this,"getPageLoadEvent",function(t){a.eventHandel({eventType:"dom",eventName:"page_statistics"},{lcp:t})}),this.config=r.getConfig().eventConfig,this.collect=o,this.options=e,this.beatTime=e.beat,this.statistics=!1}var o=e.prototype;return o.init=function(t){this.eventHandel=t;var e=this.config.mode;this.addListener(e)},o.addListener=function(t){var e=this;if("proxy-capturing"===t&&(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(t){var n=t.config,i=t.name;e.getPageViewEvent(n,i)}),this.config.beat)){try{"complete"===document.readyState?this.beatEvent(this.beatTime):window.addEventListener("load",function(){e.beatEvent(e.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&&e.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:1})}}catch(t){}try{var r=window.performance&&window.performance.getEntriesByType("paint");if(r&&r.length){var a=new PerformanceObserver(function(t){var n=t.getEntries(),i=n[n.length-1],o=i.renderTime||i.loadTime;e.statistics||(e.getPageLoadEvent(o),e.statistics=!0)});a.observe({entryTypes:["largest-contentful-paint"]}),setTimeout(function(){e.statistics||(e.getPageLoadEvent(r[0].startTime||0),e.statistics=!0)},2e3)}else this.getPageLoadEvent(0)}catch(t){this.getPageLoadEvent(0)}}},o.removeListener=function(){window.document.removeEventListener("click",this.clickEvent,!0),window.document.removeEventListener("change",this.changeEvent,!0),window.document.removeEventListener("submit",this.submitEvent,!0)},o.beatEvent=function(t){var e,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})},t)),e=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",e,!1):window.addEventListener("beforeunload",e,!1)}catch(t){}},e}(),l={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,n){t(this,"config",void 0),this.config=e,this.config.eventConfig=Object.assign(this.config.eventConfig,n)}var n=e.prototype;return n.getConfig=function(){return this.config},n.setConfig=function(t){return this.config=t},e}();function h(t){for(var e=[];null!==t.parentElement;)e.push(t),t=t.parentElement;var i=[],o=[];return e.forEach(function(t){var e=function(t){if(null===t)return{str:"",index:0};var e=0,i=t.parentElement;if(i)for(var o=i.children,r=0;r<o.length&&o[r]!==t;r++)o[r].nodeName===t.nodeName&&e++;return{str:[t.nodeName.toLowerCase(),n(t,"list")?"[]":""].join(""),index:e}}(t),r=e.str,a=e.index;i.unshift(r),o.unshift(a)}),{element_path:"/"+i.join("/"),positions:o}}function v(t,e,n,r){var a={},s=function(t){if(t){var e=t.getBoundingClientRect(),n=e.width,i=e.height;return{left:e.left,top:e.top,element_width:n,element_height:i}}}(e),u=function(t,e){void 0===t&&(t={}),void 0===e&&(e={});var n=t,i=n.clientX,o=n.clientY,r=e,a=r.left,s=r.top,c=i-a>=0?i-a:0,u=o-s>=0?o-s:0;return{touch_x:Math.floor(c),touch_y:Math.floor(u)}}(t,s),l=s.element_width,d=s.element_height,v=u.touch_x,p=u.touch_y,f=h(e),m=f.element_path,g=f.positions,b=function(t){var e=o(t),n=[];return function t(e){var i=function(t){var e="";return 3===t.nodeType?e=t.textContent.trim():t.dataset&&t.dataset.hasOwnProperty("teaTitle")||t.hasAttribute("ata-tea-title")?e=t.getAttribute("data-tea-title"):t.hasAttribute("title")?e=t.getAttribute("title"):"INPUT"===t.nodeName&&["button","submit"].includes(t.getAttribute("type"))?e=t.getAttribute("value"):"IMG"===t.nodeName&&t.getAttribute("alt")&&(e=t.getAttribute("alt")),e.slice(0,200)}(e);if(i&&-1===n.indexOf(i)&&n.push(i),e.childNodes.length>0)for(var o=e.childNodes,r=0;r<o.length;r++)8!==o[r].nodeType&&t(o[r])}(e),n}(e),y=window.performance.timing.navigationStart,_=Date.now()-y,E=g.map(function(t){return""+t}),w=null;if(window.TEAVisualEditor&&window.TEAVisualEditor.getOriginXpath&&(w=window.TEAVisualEditor.getOriginXpath({xpath:m,positions:E})),a.element_path=w&&w.xpath||m,a.positions=w&&w.positions||E,r&&!r.text&&(a.texts=b,a.element_title=function(t){if(!t)return"";var e="";return t.textContent?e=t.textContent.trim():t.innerText&&(e=t.innerText.trim()),"input"!==t.tagName&&"INPUT"!==t.tagName||(e=t.value||""),e}(e)),a.element_id=e.getAttribute("id")||"",a.element_class_name=e.getAttribute("class")||"",a.element_type=e.nodeType,a.element_width=Math.floor(l),a.element_height=Math.floor(d),a.touch_x=v,a.touch_y=p,a.page_manual_key="",a.elememt_manual_key="",a.since_page_start_ms=_,a.page_start_ms=y,a.page_path=location.pathname,a.page_host=location.host,n.track_attr&&i(e,n.track_attr)){var T=c(e,n.track_attr);for(var x in T)a[x]=T[x]}if(n.custom_attr)try{if(i(e,n.custom_attr)){var O=c(e,n.custom_attr),L=decodeURIComponent(O[n.custom_attr]),S=JSON.parse(L);if(Object.keys(S))for(var N in S)a[N]=S[N]}}catch(t){console.log("custom attr error")}var k=o(e);return"A"===k.tagName&&(a.href=k.getAttribute("href")),!1!==n.src&&("IMG"!==e.tagName||e.getAttribute("src").includes("base64")||(a.src=e.getAttribute("src"))),a}var p=function(t,e,n,i,o){return Object.assign({event:t},v(e,n,i,o),{is_html:1,page_key:window.location.href,page_title:document.title})},f=function(){function e(e,n){t(this,"eventName",void 0),t(this,"ignore",{text:!1}),t(this,"initConfig",void 0),t(this,"options",void 0),this.initConfig=e,this.options=n,this.eventName=n&&"tea"===n.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",scroll:"$bav2b_slide"},n&&!1===n.text&&(this.ignore.text=!0),n&&n.exposure&&n.exposure.eventName&&(this.eventName.exposure=n.exposure.eventName)}var n=e.prototype;return n.handleEvent=function(t,e){try{if(r(t.target))return null;var n="bav2b_click";switch(e){case"click":return n=this.eventName.click,p(n,t,t.target,this.options,this.ignore);case"exposure":return n=this.eventName.exposure,p(n,t,t.target,this.options,this.ignore);case"change":return n="bav2b_change",Object.assign({},p(n,t,t.target,this.options),function(t,e){try{if("bav2b_change"===t)return e.hasAttribute("data-tea-track")?{value:e.value}:{}}catch(t){return{}}}(n,t.target));case"submit":return p(n="bav2b_submit",t,t.target,this.options)}}catch(t){return console.error(t),null}},n.handleViewEvent=function(t){t.event=this.eventName.page,t.page_title=document.title,t.page_total_width=window.innerWidth,t.page_total_height=window.innerHeight;try{var e=window.sessionStorage.getItem("_tea_cache_duration");if(e){var n=JSON.parse(e);t.refer_page_duration_ms=n?n.duration:""}t.scroll_width=document.documentElement.scrollLeft?document.documentElement.scrollLeft+window.innerWidth:window.innerWidth,t.scroll_height=document.documentElement.scrollTop?document.documentElement.scrollTop+window.innerHeight:window.innerHeight,t.page_start_ms=window.performance.timing.navigationStart}catch(t){console.log("page event error "+JSON.stringify(t))}return t},n.handleStatisticsEvent=function(t){var e={};e.event=this.eventName.static,e.is_html=1,e.page_key=location.href,e.refer_page_key=document.referrer||"",e.page_title=document.title,e.page_manual_key=this.initConfig.autotrack.page_manual_key||"",e.refer_page_manual_key="";try{var n=t.lcp,i=window.performance.timing,o=i.loadEventEnd-i.navigationStart;e.page_init_cost_ms=parseInt(n||(o>0?o:0)),e.page_start_ms=i.navigationStart}catch(t){console.log("page_statistics event error "+JSON.stringify(t))}return e},n.handleBeadtEvent=function(t){t.event=this.eventName.beat,t.page_key=window.location.href,t.is_html=1,t.page_title=document.title,t.page_manual_key=this.initConfig.autotrack.page_manual_key||"";try{t.page_viewport_width=window.innerWidth,t.page_viewport_height=window.innerHeight,t.page_total_width=document.documentElement.scrollWidth,t.page_total_height=document.documentElement.scrollHeight,t.scroll_width=document.documentElement.scrollLeft+window.innerWidth,t.scroll_height=document.documentElement.scrollTop+window.innerHeight,t.since_page_start_ms=Date.now()-window.performance.timing.navigationStart,t.page_start_ms=window.performance.timing.navigationStart}catch(t){console.log("beat event error "+JSON.stringify(t))}return t},n.handleExposureEvent=function(t,e){if(r(e.target))return null;var n=p(t.event||this.eventName.exposure,e,e.target||e,this.options,this.ignore);if(n.$exposure_type=t.exposureType,this.options.exposure.callback){var i=this.options.exposure.callback(n);return i||Object.keys(i).length?i:(console.warn("exposure callback must return data!"),n)}return n},n.handleScrollEvent=function(t,e){var n=p(t.event||this.eventName.scroll,e,e.target||e,this.options,this.ignore);if(n=Object.assign(n,t.params),!this.options.scroll.callback||(n=this.options.scroll.callback(n))||Object.keys(n).length)return n;console.warn("scroll callback must return data!")},e}(),m=function(){function e(e){t(this,"logFunc",void 0),t(this,"logFuncBecon",void 0),t(this,"collect",void 0),this.collect=e}var n=e.prototype;return n.send=function(t,e){var n=e.event;delete e.event,t&&"becon"===t.eventSend?this.collect.beconEvent(n,e):this.collect.event(n,e)},n.get=function(t,e){var n=Object.assign({headers:{"content-type":"application/json"},method:"GET"},e);fetch(t,n)},n.post=function(t,e){var n=Object.assign({headers:{"content-type":"application/json"},method:"POST"},e);fetch(t,n)},e}(),g=function(){function e(e,n){t(this,"_instance",void 0),t(this,"_intersection",void 0),t(this,"config",void 0),this._instance=null,this._intersection=e,this.config=n,this._intersection&&this.init()}var n=e.prototype;return n.init=function(){var t=this;if(window.MutationObserver)try{if(this._instance=new MutationObserver(function(e){e.forEach(function(e){"attributes"===e.type&&t.attributeChangeObserve(e),"childList"===e.type&&t.modifyNodeObserve(e)})}),!document||!document.body)return void console.warn("please use sdk api init after body element");var e=!1!==this.config.autotrack.exposure.attributes;this._instance.observe(document.body,{childList:!0,attributes:e,subtree:!0,attributeOldValue:!1})}catch(t){console.log("your browser cannot support MutationObserver,so cannot report exposure event, please update")}else console.log("your browser cannot support MutationObserver,so cannot report exposure event, please update")},n.attributeChangeObserve=function(t){t.target.hasAttribute("data-exposure")?this.exposureAdd(t,"mutation"):this.exposureRemove(t)},n.modifyNodeObserve=function(t){var e=this;Array.prototype.forEach.call(t.addedNodes,function(t){1===t.nodeType&&t.hasAttribute("data-exposure")&&e.exposureAdd(t,"intersect"),e.mapChild(t,e.exposureAdd.bind(e))}),Array.prototype.forEach.call(t.removedNodes,function(t){1===t.nodeType&&t.hasAttribute("data-exposure")&&e.exposureRemove(t),e.mapChild(t,e.exposureRemove.bind(e))})},n.mapChild=function(t,e){var n=this;1===t.nodeType&&t.children.length&&Array.prototype.forEach.call(t.children,function(t){1===t.nodeType&&t.hasAttribute("data-exposure")&&e(t),n.mapChild(t,e)})},n.exposureAdd=function(t,e){try{this._intersection&&this._intersection.exposureAdd(t,e)}catch(t){console.log("intersection error",JSON.stringify(t.message))}},n.exposureRemove=function(t){try{this._intersection&&this._intersection.exposureRemove(t)}catch(t){console.log("intersection error",JSON.stringify(t.message))}},e}();t(g,"_exposure_observer",null);var b=function(t){return t?(t^16*Math.random()>>t/4).toString(10):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,b)},y=function(t){return t[t.EXPOSURE_ONCE=0]="EXPOSURE_ONCE",t[t.LIFECYCLE_SHOW_NEW=3]="LIFECYCLE_SHOW_NEW",t[t.RESUME_FORM_PAGE=6]="RESUME_FORM_PAGE",t[t.RESUME_FORM_BACK=7]="RESUME_FORM_BACK",t[t.NOT_EXPOSURE=-1]="NOT_EXPOSURE",t}(y||{}),_=function(){function e(n,i,o){var r=this;t(this,"count",void 0),t(this,"instance",void 0),t(this,"observeMap",void 0),t(this,"ratio",void 0),t(this,"eventHandle",void 0),t(this,"timeLimit",void 0),t(this,"exposureType",void 0),t(this,"hashMap",void 0),t(this,"lastState",void 0),t(this,"backStatus",!1),t(this,"customType",void 0),t(this,"collect",void 0),this.instance=this.buildObserver(),this.collect=n,this.observeMap=e._observer_map,i.autotrack.exposure.ratio?this.ratio=i.autotrack.exposure.ratio:0===i.autotrack.exposure.ratio?this.ratio=0:this.ratio=.5,this.timeLimit=i.autotrack.exposure.stay||0,this.exposureType=y.NOT_EXPOSURE,this.eventHandle=o,this.hashMap=new Map,this.backStatus=!1,this.lastState=null,this.collect.on("re-start-sdk",function(){r.visibilitychange()}),this.addListen()}var n=e.prototype;return n.buildObserver=function(){var t=this;if(e._observer_instance)return console.log("your browser cannot support IntersectionObserver, so cannot report exposure event, please update"),null;if(window.IntersectionObserver){for(var n=[],i=0;i<=1;i+=.01)n.push(i);n.push(1);try{e._observer_instance=new IntersectionObserver(function(e){e.forEach(function(e){var n=e.target.observeId,i=t.observeMap.get(n),o=(e.target,e.isIntersecting,e.intersectionRatio);if(i.intersectionRatio=o,o<=.1&&(e.target.backStatus=!1),t.observeMap.set(n,i),o<t.ratio)return i.isIntersecting=!1,i.added=!1,i.exposured=!1,i.startTime=Date.now(),void t.observeMap.set(n,i);if(!i.added){if(i.startTime=Date.now(),i.added=!0,i.isIntersecting=!0,t.timeLimit){var r=setTimeout(function(){try{if(i.isIntersecting&&!i.exposured&&t.observeMap.get(n)){var o=t.observeMap.get(n).intersectionRatio;t.exposureEvent(e,o,n,i)}}catch(t){console.log("IntersectionObserver setTimeout error,msg: "+JSON.stringify(t))}},t.timeLimit);i.wait=r}t.observeMap.set(n,i)}Date.now()-i.startTime>=t.timeLimit&&!i.exposured&&t.exposureEvent(e,o,n,i)})},{threshold:n})}catch(t){console.log("IntersectionObserver error,msg: "+JSON.stringify(t))}return e._observer_instance}return console.log("your browser cannot support IntersectionObserver, so cannot report exposure event, please update"),null},n.exposureAdd=function(t,e){var n="mutation"===e?t.target:t,i=n.observeId,o=b().replace(/-/g,"").slice(0,19);if(i||this.observeMap.has(i)){var r=this.observeMap.get(i);if(r&&n!==r.instance)this.unobserve(n),this.observeMap.delete(i),n.observeId=o,n.visible=!1,this.observeMap.set(o,{instance:n.cloneNode(!0),isIntersecting:!1}),this.observe(n);else{if(!0===n.visible)return;this.handleBoundingExposure(n)}}else n.observeId=o,n.visible=!1,this.observeMap.set(o,{instance:n.cloneNode(!0),isIntersecting:!1}),this.observe(n)},n.exposureRemove=function(t){this.observeMap.has(t.observeId)&&(this.observeMap.delete(t.observeId),this.unobserve(t),t.observeId="",t.visible=!1)},n.exposureEvent=function(t,e,n,i){if(e>=this.ratio){if("0"===t.target.style.opacity||"hidden"===t.target.style.visibility)return;if(!0===i.exposured)return;i.startWait&&clearTimeout(i.startWait);var o=t.target.getAttribute("data-exposure-event");this.eventHandle({eventType:"dom",eventName:"exposure",event:o,exposureType:this.getExposureType(t.target)},t),t.target.visible=!0,t.target.hasExposure=!0,i.startTime=Date.now(),i.exposured=!0}else i.startTime=Date.now(),i.exposured=!1;this.observeMap.set(n,i)},n.observe=function(t){this.instance&&this.instance.observe(t)},n.unobserve=function(t){this.instance&&this.instance.unobserve(t)},n.getExposureDomToExposure=function(){var t=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),function(e){t.handleBoundingExposure(e)})},n.visibilitychange=function(){var t=this,e=null;"visible"===document.visibilityState?this.timeLimit?e=setTimeout(function(){t.getExposureDomToExposure()},this.timeLimit):this.getExposureDomToExposure():(clearTimeout(e),this.customType=void 0)},n.handleBoundingExposure=function(t){if(this.getBoundingRatio(t)>=this.ratio){t.visible=!0;var e=t.getAttribute&&t.getAttribute("data-exposure-event");this.eventHandle({eventType:"dom",eventName:"exposure",event:e,exposureType:this.customType||y.RESUME_FORM_BACK},t)}},n.getBoundingRatio=function(t){var e=t.getBoundingClientRect(),n=e.top,i=e.left,o=e.width,r=e.height,a=window.innerWidth||document.documentElement.clientWidth,s=window.innerHeight||document.documentElement.clientHeight;return n>=0&&i>=0&&n<=s&&i<=a?(o>a?a:o)*(s-n)/(o*r):0},n.getExposureType=function(t){return t.visible?!1!==t.backStatus&&(this.backStatus||this.customType||2===window.performance.navigation.type)?this.exposureType=y.RESUME_FORM_PAGE:this.exposureType=y.LIFECYCLE_SHOW_NEW:(t.hasExposure,!1!==t.backStatus&&(this.backStatus||this.customType||2===window.performance.navigation.type)?this.exposureType=y.RESUME_FORM_PAGE:this.exposureType=y.EXPOSURE_ONCE),this.exposureType},n.addListen=function(){var t=this;this.collect.on("set-exposure-type",function(e){t.customType=e});var e,n,i,o,r=this.visibilitychange.bind(this);if(e=document,n="visibilitychange",i=r,o=!1,e.addEventListener?e.addEventListener(n,i,o):e.attachEven?e.attachEven("on"+n,i):e["on"+n]=i,window.addEventListener("hashchange",function(e){var n=t.hashMap.get(e.oldURL);n&&location.href===n.prev?(t.backStatus=!0,t.exposureType=y.RESUME_FORM_PAGE):(t.backStatus=!1,t.hashMap.set(location.href,{current:e.newURL,prev:e.oldURL}))}),this.collect.bridgeReport){var a=window.history.pushState;history.pushState=function(e){"function"==typeof history.onpushstate&&history.onpushstate({state:e});for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];var r=a.call.apply(a,[history,e].concat(i));return t.lastState=e,r};var s=history.replaceState;history.replaceState=function(e){"function"==typeof history.onreplacestate&&history.onreplacestate({state:e});for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];var r=s.call.apply(s,[history,e].concat(i));return t.lastState=e,r}}else this.collect.on("STATE_CHANGE",function(e){t.lastState=e});return window.addEventListener("popstate",function(e){var n=e.state;n&&n.current&&t.lastState&&t.lastState.back&&n.current===t.lastState.back?(t.backStatus=!0,t.exposureType=y.RESUME_FORM_PAGE):t.backStatus=!1}),function(){!function(t,e,n,i){t.addEventListener?t.removeEventListener(e,n,i):t.attachEven&&t.detachEven("on"+e,n)}(document,"visibilitychange",r,!1)}},e}();t(_,"_observer_instance",null),t(_,"_observer_map",new Map);var E=function(){function e(e,n,i){t(this,"_observer",void 0),t(this,"_intersection",void 0),n.autotrack&&n.autotrack.exposure&&(this._intersection=new _(e,n,i),this._observer=new g(this._intersection,n),this._intersection&&this._observer?this.initObserver():console.log("your browser version cannot support exposure event, please update~"))}return e.prototype.initObserver=function(){var t=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),function(e){t._intersection.exposureAdd(e,"intersect")})},e}(),w=function(t){return t[t.SCROLL_UP=1]="SCROLL_UP",t[t.SCROLL_DOWN=2]="SCROLL_DOWN",t[t.SCROLL_LEFT=3]="SCROLL_LEFT",t[t.SCROLL_RIGHT=4]="SCROLL_RIGHT",t[t.NOT_SCROLL=-1]="NOT_SCROLL",t}(w||{}),T=function(){function e(e,n){t(this,"eventHandle",void 0),t(this,"distance",30),t(this,"scrollType",void 0),e.autotrack&&e.autotrack.scroll&&(e.autotrack.scroll.distance&&(this.distance=e.autotrack.scroll.distance),this.eventHandle=n,this.addLinstenr(),this.mutation())}var n=e.prototype;return n.addLinstenr=function(){var t=this;Array.prototype.forEach.call(document.querySelectorAll("[data-scroll]"),function(e){t.scrollHandle(e)})},n.mutation=function(){var t=this;if(window.MutationObserver)try{var e=new MutationObserver(function(e){e.forEach(function(e){"childList"===e.type&&t.modifyNodeObserve(e)})});if(!document||!document.body)return void console.warn("please use sdk api init after body element");e.observe(document.body,{childList:!0,attributes:!0,subtree:!0,attributeOldValue:!1})}catch(t){console.log("your browser cannot support MutationObserver")}else console.log("your browser cannot support MutationObserver")},n.modifyNodeObserve=function(t){var e=this;Array.prototype.forEach.call(t.addedNodes,function(t){1===t.nodeType&&t.hasAttribute("data-scroll")&&e.scrollHandle(t),e.mapChild(t,e.scrollHandle.bind(e))}),Array.prototype.forEach.call(t.removedNodes,function(t){1===t.nodeType&&t.hasAttribute("data-scroll")&&e.scrollHandle(t,"remove"),e.mapChild(t,e.scrollHandle.bind(e))})},n.mapChild=function(t,e){var n=this;1===t.nodeType&&t.children.length&&Array.prototype.forEach.call(t.children,function(t){1===t.nodeType&&t.hasAttribute("data-scroll")&&e(t),n.mapChild(t,e)})},n.scrollHandle=function(t,e){var n=this;try{var i=t.scrollTop,o=t.scrollLeft,r=null,a=0,s=0,c=function(e){clearTimeout(r),r=setTimeout(function(){var r=t.scrollTop,d=t.scrollLeft,h=e.target&&e.target.getAttribute("data-scroll-event")||"";1===l||2===l?r===c&&(s=c-i,Math.abs(s)>=n.distance&&n.distance&&n.eventHandle({eventType:"dom",eventName:"scroll",event:h,params:{$direction:l,$offsetY:s,$offsetX:a}},e)):3!==l&&4!==l||d===u&&(a=u-o,Math.abs(a)>=n.distance&&n.distance&&n.eventHandle({eventType:"dom",eventName:"scroll",event:h,params:{$direction:l,$offsetY:s,$offsetX:a}},e)),i=c,o=u},100);var c=t.scrollTop,u=t.scrollLeft,l=w.NOT_SCROLL;c>i?l=w.SCROLL_DOWN:c<i?l=w.SCROLL_UP:u>o?l=w.SCROLL_LEFT:u<o&&(l=w.SCROLL_RIGHT)};return"remove"===e?t.removeEventListener("scroll",c,!1):t.addEventListener("scroll",c,!1),function(){t.removeEventListener("scroll",c,!1)}}catch(t){console.warn("scroll event error",JSON.stringify(t))}},e}(),x={hashTag:!1,impr:!1},O=function(){function e(){t(this,"engine",void 0),t(this,"Listener",void 0),t(this,"EventHandle",void 0),t(this,"Request",void 0),t(this,"Exposure",void 0),t(this,"Scroll",void 0),t(this,"Config",void 0),t(this,"options",void 0),t(this,"destroyed",void 0),t(this,"autoTrackStart",void 0),t(this,"collect",void 0),t(this,"config",void 0)}var n=e.prototype;return n.apply=function(t,e){if(this.autoTrackStart=!1,this.collect=t,this.config=e,e.autotrack&&(!e.autotrack||!e.autotrack.collect_url||e.autotrack.collect_url())){var n=t.Types;this.ready(n.Autotrack),this.collect.emit(n.AutotrackReady)}},n.ready=function(t){this.collect.set(t);var e=this.config.autotrack;e="object"==typeof e?e:{},e=Object.assign(x,e),this.destroyed=!1,this.options=e,this.Config=new d(l,this.options),this.Exposure=new E(this.collect,this.config,this.handle.bind(this)),this.Scroll=new T(this.config,this.handle.bind(this)),this.Listener=new u(e,this.collect,this.Config),this.EventHandle=new f(this.config,e),this.Request=new m(this.collect),this.autoTrackStart=!0,this.init()},n.init=function(){this.Listener.init(this.handle.bind(this))},n.handle=function(t,e){try{if(this.config.autotrack.collect_url&&!this.config.autotrack.collect_url())return}catch(t){}this.collect.sdkStop||"dom"===t.eventType&&this.handleDom(t,e)},n.handleDom=function(t,e){try{var n=t.eventName;if("click"===n||"change"===n||"submit"===n){var i=this.EventHandle.handleEvent(e,n);i&&this.Request.send({eventType:"custom"},i)}else if("page_view"===n||"page_statistics"===n){var o;(o="page_view"===n?this.EventHandle.handleViewEvent(e):this.EventHandle.handleStatisticsEvent(e))&&this.Request.send({eventType:"custom"},o)}else if("beat"===n){var r=this.EventHandle.handleBeadtEvent(e),a=t.eventSend;r&&this.Request.send({eventType:"custom",eventSend:a},r)}else if("exposure"===n){var s=this.EventHandle.handleExposureEvent(t,e);s&&this.Request.send({eventType:"custom"},s)}else if("scroll"===n){var c=this.EventHandle.handleScrollEvent(t,e);c&&this.Request.send({eventType:"custom"},c)}}catch(t){console.log("handel dom event error "+JSON.stringify(t))}},n.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=O;
1
+ "use strict";function e(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n;if("undefined"!=typeof Symbol&&void 0!==(n=e[Symbol.toPrimitive])){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var 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){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}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}},c=function(e,n){var i={};if("string"==typeof n)a(e,n)&&(i[n]=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};var u=function(){function t(t,o,r){var a=this;e(this,"config",void 0),e(this,"options",void 0),e(this,"beatTime",void 0),e(this,"statistics",void 0),e(this,"eventHandel",void 0),e(this,"collect",void 0),e(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)}),e(this,"changeEvent",function(e){a.eventHandel({eventType:"dom",eventName:"change"},e)}),e(this,"submitEvent",function(e){a.eventHandel({eventType:"dom",eventName:"submit"},e)}),e(this,"getPageViewEvent",function(e,t){t&&"pushState"===t&&a.eventHandel({eventType:"dom",eventName:"beat"},Object.assign({beat_type:0},e)),a.eventHandel({eventType:"dom",eventName:"page_view"},e)}),e(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}var o=t.prototype;return o.init=function(e){this.eventHandel=e;var t=this.config.mode;this.addListener(t)},o.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)}}},o.removeListener=function(){window.document.removeEventListener("click",this.clickEvent,!0),window.document.removeEventListener("change",this.changeEvent,!0),window.document.removeEventListener("submit",this.submitEvent,!0)},o.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}(),l={eventConfig:{mode:"proxy-capturing",submit:!1,click:!0,change:!1,pv:!0,beat:!0,hashTag:!1,impr:!1},scoutConfig:{mode:"xpath"}},d=function(){function t(t,n){e(this,"config",void 0),this.config=t,this.config.eventConfig=Object.assign(this.config.eventConfig,n)}var n=t.prototype;return n.getConfig=function(){return this.config},n.setConfig=function(e){return this.config=e},t}();function h(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 v(e,t,n,r){var a={},s=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}}}(t),u=function(e,t){void 0===e&&(e={}),void 0===t&&(t={});var n=e,i=n.clientX,o=n.clientY,r=t,a=r.left,s=r.top,c=i-a>=0?i-a:0,u=o-s>=0?o-s:0;return{touch_x:Math.floor(c),touch_y:Math.floor(u)}}(e,s),l=s.element_width,d=s.element_height,v=u.touch_x,p=u.touch_y,f=h(t),m=f.element_path,g=f.positions,b=function(e){var t=o(e),n=[];return function e(t){var i=function(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)}(t);if(i&&-1===n.indexOf(i)&&n.push(i),t.childNodes.length>0)for(var o=t.childNodes,r=0;r<o.length;r++)8!==o[r].nodeType&&e(o[r])}(t),n}(t),y=window.performance.timing.navigationStart,_=Date.now()-y,E=g.map(function(e){return""+e}),w=null;if(window.TEAVisualEditor&&window.TEAVisualEditor.getOriginXpath&&(w=window.TEAVisualEditor.getOriginXpath({xpath:m,positions:E})),a.element_path=w&&w.xpath||m,a.positions=w&&w.positions||E,r&&!r.text&&(a.texts=b,a.element_title=function(e){if(!e)return"";var t="";return e.textContent?t=e.textContent.trim():e.innerText&&(t=e.innerText.trim()),"input"!==e.tagName&&"INPUT"!==e.tagName||(t=e.value||""),t}(t)),a.element_id=t.getAttribute("id")||"",a.element_class_name=t.getAttribute("class")||"",a.element_type=t.nodeType,a.element_width=Math.floor(l),a.element_height=Math.floor(d),a.touch_x=v,a.touch_y=p,a.page_manual_key="",a.elememt_manual_key="",a.since_page_start_ms=_,a.page_start_ms=y,a.page_path=location.pathname,a.page_host=location.host,n.track_attr&&i(t,n.track_attr)){var T=c(t,n.track_attr);for(var x in T)a[x]=T[x]}if(n.custom_attr)try{if(i(t,n.custom_attr)){var O=c(t,n.custom_attr),L=decodeURIComponent(O[n.custom_attr]),S=JSON.parse(L);if(Object.keys(S))for(var N in S)a[N]=S[N]}}catch(e){console.log("custom attr error")}var k=o(t);return"A"===k.tagName&&(a.href=k.getAttribute("href")),!1!==n.src&&("IMG"!==t.tagName||t.getAttribute("src").includes("base64")||(a.src=t.getAttribute("src"))),a}var p=function(e,t,n,i,o){return Object.assign({event:e},v(t,n,i,o),{is_html:1,page_key:window.location.href,page_title:document.title})},f=function(){function t(t,n){e(this,"eventName",void 0),e(this,"ignore",{text:!1}),e(this,"initConfig",void 0),e(this,"options",void 0),this.initConfig=t,this.options=n,this.eventName=n&&"tea"===n.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",scroll:"$bav2b_slide"},n&&!1===n.text&&(this.ignore.text=!0),n&&n.exposure&&n.exposure.eventName&&(this.eventName.exposure=n.exposure.eventName)}var n=t.prototype;return n.handleEvent=function(e,t){try{if(r(e.target))return null;var n="bav2b_click";switch(t){case"click":return n=this.eventName.click,p(n,e,e.target,this.options,this.ignore);case"exposure":return n=this.eventName.exposure,p(n,e,e.target,this.options,this.ignore);case"change":return n="bav2b_change",Object.assign({},p(n,e,e.target,this.options),function(e,t){try{if("bav2b_change"===e)return t.hasAttribute("data-tea-track")?{value:t.value}:{}}catch(e){return{}}}(n,e.target));case"submit":return p(n="bav2b_submit",e,e.target,this.options)}}catch(e){return console.error(e),null}},n.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},n.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},n.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},n.handleExposureEvent=function(e,t){if(r(t.target))return null;var n=p(e.event||this.eventName.exposure,t,t.target||t,this.options,this.ignore);if(n.$exposure_type=e.exposureType,this.options.exposure.callback){var i=this.options.exposure.callback(n);return i||Object.keys(i).length?i:(console.warn("exposure callback must return data!"),n)}return n},n.handleScrollEvent=function(e,t){var n=p(e.event||this.eventName.scroll,t,t.target||t,this.options,this.ignore);if(n=Object.assign(n,e.params),!this.options.scroll.callback||(n=this.options.scroll.callback(n))||Object.keys(n).length)return n;console.warn("scroll callback must return data!")},t}(),m=function(){function t(t){e(this,"logFunc",void 0),e(this,"logFuncBecon",void 0),e(this,"collect",void 0),this.collect=t}var n=t.prototype;return n.send=function(e,t){var n=t.event;delete t.event,e&&"becon"===e.eventSend?this.collect.beconEvent(n,t):this.collect.event(n,t)},n.get=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"GET"},t);fetch(e,n)},n.post=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"POST"},t);fetch(e,n)},t}(),g=function(){function t(t,n){e(this,"_instance",void 0),e(this,"_intersection",void 0),e(this,"config",void 0),this._instance=null,this._intersection=t,this.config=n,this._intersection&&this.init()}var n=t.prototype;return n.init=function(){var e=this;if(window.MutationObserver)try{if(this._instance=new MutationObserver(function(t){t.forEach(function(t){"attributes"===t.type&&e.attributeChangeObserve(t),"childList"===t.type&&e.modifyNodeObserve(t)})}),!document||!document.body)return void console.warn("please use sdk api init after body element");var t=!1!==this.config.autotrack.exposure.attributes;this._instance.observe(document.body,{childList:!0,attributes:t,subtree:!0,attributeOldValue:!1})}catch(e){console.log("your browser cannot support MutationObserver,so cannot report exposure event, please update")}else console.log("your browser cannot support MutationObserver,so cannot report exposure event, please update")},n.attributeChangeObserve=function(e){e.target.hasAttribute("data-exposure")?this.exposureAdd(e,"mutation"):this.exposureRemove(e)},n.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.bind(t))}),Array.prototype.forEach.call(e.removedNodes,function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t.exposureRemove(e),t.mapChild(e,t.exposureRemove.bind(t))})},n.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)})},n.exposureAdd=function(e,t){try{this._intersection&&this._intersection.exposureAdd(e,t)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},n.exposureRemove=function(e){try{this._intersection&&this._intersection.exposureRemove(e)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},t}();e(g,"_exposure_observer",null);var b=function(e){return e?(e^16*Math.random()>>e/4).toString(10):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,b)},y=function(e){return e[e.EXPOSURE_ONCE=0]="EXPOSURE_ONCE",e[e.LIFECYCLE_SHOW_NEW=3]="LIFECYCLE_SHOW_NEW",e[e.RESUME_FORM_PAGE=6]="RESUME_FORM_PAGE",e[e.RESUME_FORM_BACK=7]="RESUME_FORM_BACK",e[e.NOT_EXPOSURE=-1]="NOT_EXPOSURE",e}(y||{}),_=function(){function t(n,i,o){var r=this;e(this,"count",void 0),e(this,"instance",void 0),e(this,"observeMap",void 0),e(this,"ratio",void 0),e(this,"eventHandle",void 0),e(this,"timeLimit",void 0),e(this,"exposureType",void 0),e(this,"hashMap",void 0),e(this,"lastState",void 0),e(this,"backStatus",!1),e(this,"customType",void 0),e(this,"collect",void 0),this.instance=this.buildObserver(),this.collect=n,this.observeMap=t._observer_map,i.autotrack.exposure.ratio?this.ratio=i.autotrack.exposure.ratio:0===i.autotrack.exposure.ratio?this.ratio=0:this.ratio=.5,this.timeLimit=i.autotrack.exposure.stay||0,this.exposureType=y.NOT_EXPOSURE,this.eventHandle=o,this.hashMap=new Map,this.backStatus=!1,this.lastState=null,this.collect.on("re-start-sdk",function(){r.visibilitychange()}),this.addListen()}var n=t.prototype;return n.buildObserver=function(){var e=this;if(t._observer_instance)return console.log("your browser cannot support IntersectionObserver, so cannot report exposure event, please update"),null;if(window.IntersectionObserver){for(var n=[],i=0;i<=1;i+=.01)n.push(i);n.push(1);try{t._observer_instance=new IntersectionObserver(function(t){t.forEach(function(t){var n=t.target.observeId,i=e.observeMap.get(n),o=(t.target,t.isIntersecting,t.intersectionRatio);if(i.intersectionRatio=o,o<=.1&&(t.target.backStatus=!1),e.observeMap.set(n,i),o<e.ratio)return i.isIntersecting=!1,i.added=!1,i.exposured=!1,i.startTime=Date.now(),void e.observeMap.set(n,i);if(!i.added){if(i.startTime=Date.now(),i.added=!0,i.isIntersecting=!0,e.timeLimit){var r=setTimeout(function(){try{if(i.isIntersecting&&!i.exposured&&e.observeMap.get(n)){var o=e.observeMap.get(n).intersectionRatio;e.exposureEvent(t,o,n,i)}}catch(e){console.log("IntersectionObserver setTimeout error,msg: "+JSON.stringify(e))}},e.timeLimit);i.wait=r}e.observeMap.set(n,i)}Date.now()-i.startTime>=e.timeLimit&&!i.exposured&&e.exposureEvent(t,o,n,i)})},{threshold:n})}catch(e){console.log("IntersectionObserver error,msg: "+JSON.stringify(e))}return t._observer_instance}return console.log("your browser cannot support IntersectionObserver, so cannot report exposure event, please update"),null},n.exposureAdd=function(e,t){var n="mutation"===t?e.target:e,i=n.observeId,o=b().replace(/-/g,"").slice(0,19);if(i||this.observeMap.has(i)){var r=this.observeMap.get(i);if(r&&n!==r.instance)this.unobserve(n),this.observeMap.delete(i),n.observeId=o,n.visible=!1,this.observeMap.set(o,{instance:n.cloneNode(!0),isIntersecting:!1}),this.observe(n);else{if(!0===n.visible)return;this.handleBoundingExposure(n)}}else n.observeId=o,n.visible=!1,this.observeMap.set(o,{instance:n.cloneNode(!0),isIntersecting:!1}),this.observe(n)},n.exposureRemove=function(e){this.observeMap.has(e.observeId)&&(this.observeMap.delete(e.observeId),this.unobserve(e),e.observeId="",e.visible=!1)},n.exposureEvent=function(e,t,n,i){if(t>=this.ratio){if("0"===e.target.style.opacity||"hidden"===e.target.style.visibility)return;if(!0===i.exposured)return;i.startWait&&clearTimeout(i.startWait);var o=e.target.getAttribute("data-exposure-event");this.eventHandle({eventType:"dom",eventName:"exposure",event:o,exposureType:this.getExposureType(e.target)},e),e.target.visible=!0,e.target.hasExposure=!0,i.startTime=Date.now(),i.exposured=!0}else i.startTime=Date.now(),i.exposured=!1;this.observeMap.set(n,i)},n.observe=function(e){this.instance&&this.instance.observe(e)},n.unobserve=function(e){this.instance&&this.instance.unobserve(e)},n.getExposureDomToExposure=function(){var e=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),function(t){e.handleBoundingExposure(t)})},n.visibilitychange=function(){var e=this,t=null;"visible"===document.visibilityState?this.timeLimit?t=setTimeout(function(){e.getExposureDomToExposure()},this.timeLimit):this.getExposureDomToExposure():(clearTimeout(t),this.customType=void 0)},n.handleBoundingExposure=function(e){if(this.getBoundingRatio(e)>=this.ratio){e.visible=!0;var t=e.getAttribute&&e.getAttribute("data-exposure-event");this.eventHandle({eventType:"dom",eventName:"exposure",event:t,exposureType:this.customType||y.RESUME_FORM_BACK},e)}},n.getBoundingRatio=function(e){var t=e.getBoundingClientRect(),n=t.top,i=t.left,o=t.width,r=t.height,a=window.innerWidth||document.documentElement.clientWidth,s=window.innerHeight||document.documentElement.clientHeight;return n>=0&&i>=0&&n<=s&&i<=a?(o>a?a:o)*(s-n)/(o*r):0},n.getExposureType=function(e){return e.visible?!1!==e.backStatus&&(this.backStatus||this.customType||2===window.performance.navigation.type)?this.exposureType=y.RESUME_FORM_PAGE:this.exposureType=y.LIFECYCLE_SHOW_NEW:(e.hasExposure,!1!==e.backStatus&&(this.backStatus||this.customType||2===window.performance.navigation.type)?this.exposureType=y.RESUME_FORM_PAGE:this.exposureType=y.EXPOSURE_ONCE),this.exposureType},n.addListen=function(){var e=this;this.collect.on("set-exposure-type",function(t){e.customType=t});var t,n,i,o,r=this.visibilitychange.bind(this);if(t=document,n="visibilitychange",i=r,o=!1,t.addEventListener?t.addEventListener(n,i,o):t.attachEven?t.attachEven("on"+n,i):t["on"+n]=i,window.addEventListener("hashchange",function(t){var n=e.hashMap.get(t.oldURL);n&&location.href===n.prev?(e.backStatus=!0,e.exposureType=y.RESUME_FORM_PAGE):(e.backStatus=!1,e.hashMap.set(location.href,{current:t.newURL,prev:t.oldURL}))}),this.collect.bridgeReport){var a=window.history.pushState;history.pushState=function(t){"function"==typeof history.onpushstate&&history.onpushstate({state:t});for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];var r=a.call.apply(a,[history,t].concat(i));return e.lastState=t,r};var s=history.replaceState;history.replaceState=function(t){"function"==typeof history.onreplacestate&&history.onreplacestate({state:t});for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];var r=s.call.apply(s,[history,t].concat(i));return e.lastState=t,r}}else this.collect.on("STATE_CHANGE",function(t){e.lastState=t});return window.addEventListener("popstate",function(t){var n=t.state;n&&n.current&&e.lastState&&e.lastState.back&&n.current===e.lastState.back?(e.backStatus=!0,e.exposureType=y.RESUME_FORM_PAGE):e.backStatus=!1}),function(){!function(e,t,n,i){e.addEventListener?e.removeEventListener(t,n,i):e.attachEven&&e.detachEven("on"+t,n)}(document,"visibilitychange",r,!1)}},t}();e(_,"_observer_instance",null),e(_,"_observer_map",new Map);var E=function(){function t(t,n,i){e(this,"_observer",void 0),e(this,"_intersection",void 0),n.autotrack&&n.autotrack.exposure&&(this._intersection=new _(t,n,i),this._observer=new g(this._intersection,n),this._intersection&&this._observer?this.initObserver():console.log("your browser version cannot support exposure event, please update~"))}return t.prototype.initObserver=function(){var e=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),function(t){e._intersection.exposureAdd(t,"intersect")})},t}(),w=function(e){return e[e.SCROLL_UP=1]="SCROLL_UP",e[e.SCROLL_DOWN=2]="SCROLL_DOWN",e[e.SCROLL_LEFT=3]="SCROLL_LEFT",e[e.SCROLL_RIGHT=4]="SCROLL_RIGHT",e[e.NOT_SCROLL=-1]="NOT_SCROLL",e}(w||{}),T=function(){function t(t,n){e(this,"eventHandle",void 0),e(this,"distance",30),e(this,"scrollType",void 0),t.autotrack&&t.autotrack.scroll&&(t.autotrack.scroll.distance&&(this.distance=t.autotrack.scroll.distance),this.eventHandle=n,this.addLinstenr(),this.mutation())}var n=t.prototype;return n.addLinstenr=function(){var e=this;Array.prototype.forEach.call(document.querySelectorAll("[data-scroll]"),function(t){e.scrollHandle(t)})},n.mutation=function(){var e=this;if(window.MutationObserver)try{var t=new MutationObserver(function(t){t.forEach(function(t){"childList"===t.type&&e.modifyNodeObserve(t)})});if(!document||!document.body)return void console.warn("please use sdk api init after body element");t.observe(document.body,{childList:!0,attributes:!0,subtree:!0,attributeOldValue:!1})}catch(e){console.log("your browser cannot support MutationObserver")}else console.log("your browser cannot support MutationObserver")},n.modifyNodeObserve=function(e){var t=this;Array.prototype.forEach.call(e.addedNodes,function(e){1===e.nodeType&&e.hasAttribute("data-scroll")&&t.scrollHandle(e),t.mapChild(e,t.scrollHandle.bind(t))}),Array.prototype.forEach.call(e.removedNodes,function(e){1===e.nodeType&&e.hasAttribute("data-scroll")&&t.scrollHandle(e,"remove"),t.mapChild(e,t.scrollHandle.bind(t))})},n.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-scroll")&&t(e),n.mapChild(e,t)})},n.scrollHandle=function(e,t){var n=this;try{var i=e.scrollTop,o=e.scrollLeft,r=null,a=0,s=0,c=function(t){clearTimeout(r),r=setTimeout(function(){var r=e.scrollTop,d=e.scrollLeft,h=t.target&&t.target.getAttribute("data-scroll-event")||"";1===l||2===l?r===c&&(s=c-i,Math.abs(s)>=n.distance&&n.distance&&n.eventHandle({eventType:"dom",eventName:"scroll",event:h,params:{$direction:l,$offsetY:s,$offsetX:a}},t)):3!==l&&4!==l||d===u&&(a=u-o,Math.abs(a)>=n.distance&&n.distance&&n.eventHandle({eventType:"dom",eventName:"scroll",event:h,params:{$direction:l,$offsetY:s,$offsetX:a}},t)),i=c,o=u},100);var c=e.scrollTop,u=e.scrollLeft,l=w.NOT_SCROLL;c>i?l=w.SCROLL_DOWN:c<i?l=w.SCROLL_UP:u>o?l=w.SCROLL_LEFT:u<o&&(l=w.SCROLL_RIGHT)};return"remove"===t?e.removeEventListener("scroll",c,!1):e.addEventListener("scroll",c,!1),function(){e.removeEventListener("scroll",c,!1)}}catch(e){console.warn("scroll event error",JSON.stringify(e))}},t}(),x={hashTag:!1,impr:!1},O=function(){function t(){e(this,"engine",void 0),e(this,"Listener",void 0),e(this,"EventHandle",void 0),e(this,"Request",void 0),e(this,"Exposure",void 0),e(this,"Scroll",void 0),e(this,"Config",void 0),e(this,"options",void 0),e(this,"destroyed",void 0),e(this,"autoTrackStart",void 0),e(this,"collect",void 0),e(this,"config",void 0)}var n=t.prototype;return n.apply=function(e,t){if(this.autoTrackStart=!1,this.collect=e,this.config=t,t.autotrack&&(!t.autotrack||!t.autotrack.collect_url||t.autotrack.collect_url())){var n=e.Types;this.ready(n.Autotrack),this.collect.emit(n.AutotrackReady)}},n.ready=function(e){this.collect.set(e);var t=this.config.autotrack;t="object"==typeof t?t:{},t=Object.assign(x,t),this.destroyed=!1,this.options=t,this.Config=new d(l,this.options),this.Exposure=new E(this.collect,this.config,this.handle.bind(this)),this.Scroll=new T(this.config,this.handle.bind(this)),this.Listener=new u(t,this.collect,this.Config),this.EventHandle=new f(this.config,t),this.Request=new m(this.collect),this.autoTrackStart=!0,this.init()},n.init=function(){this.Listener.init(this.handle.bind(this))},n.handle=function(e,t){try{if(this.config.autotrack.collect_url&&!this.config.autotrack.collect_url())return}catch(e){}this.collect.sdkStop||"dom"===e.eventType&&this.handleDom(e,t)},n.handleDom=function(e,t){try{var n=e.eventName;if("click"===n||"change"===n||"submit"===n){var i=this.EventHandle.handleEvent(t,n);i&&this.Request.send({eventType:"custom"},i)}else if("page_view"===n||"page_statistics"===n){var o;(o="page_view"===n?this.EventHandle.handleViewEvent(t):this.EventHandle.handleStatisticsEvent(t))&&this.Request.send({eventType:"custom"},o)}else if("beat"===n){var r=this.EventHandle.handleBeadtEvent(t),a=e.eventSend;r&&this.Request.send({eventType:"custom",eventSend:a},r)}else if("exposure"===n){var s=this.EventHandle.handleExposureEvent(e,t);s&&this.Request.send({eventType:"custom"},s)}else if("scroll"===n){var c=this.EventHandle.handleScrollEvent(e,t);c&&this.Request.send({eventType:"custom"},c)}}catch(e){console.log("handel dom event error "+JSON.stringify(e))}},n.destroy=function(){if(!this.autoTrackStart)return console.warn("engine is undefined, make sure you have called autoTrack.start()");this.autoTrackStart=!1,this.Listener.removeListener()},t}();module.exports=O;
@@ -1 +1 @@
1
- "use strict";function t(t,e,a){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var a=t[Symbol.toPrimitive];if(void 0!==a){var r=a.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[e]=a,t}var e=function(){function e(){t(this,"collector",void 0),t(this,"config",void 0),t(this,"TrackMap",void 0),t(this,"Types",void 0)}var a=e.prototype;return a.apply=function(t,e){var a=this;this.collector=t,this.config=e;var r=t.Types;t.on(r.TrackDurationStart,function(t){a.trackStart(t)}),t.on(r.TrackDurationEnd,function(t){a.trackEnd(t)}),t.on(r.TrackDurationPause,function(t){a.trackPause(t)}),t.on(r.TrackDurationResume,function(t){a.trackResume(t)}),this.Types=r,this.TrackMap=new Map,this.ready(r.TrackDuration)},a.ready=function(t){var e=this;if(this.collector.set(t),this.collector.hook._hooksCache.hasOwnProperty(t)){var a=this.collector.hook._hooksCache[t];if(!Object.keys(a).length)return;var r=function(t){a[t].length&&a[t].forEach(function(a){e.collector.hook.emit(t,a)})};for(var i in a)r(i)}},a.trackStart=function(t){this.TrackMap.set(t,{startTime:Date.now(),isPause:!1,pauseTime:0,resumeTime:0})},a.trackEnd=function(t){var e=t.eventName,a=t.params;if(this.TrackMap.has(e)){var r=this.TrackMap.get(e),i=0;i=r.isPause?r.pauseTime-r.startTime:r.resumeTime?r.pauseTime-r.startTime+(Date.now()-r.resumeTime):Date.now()-r.startTime;var o=Object.assign(a,{event_duration:i});this.collector.event(e,o),this.cleanTrack(e)}},a.trackPause=function(t){if(this.TrackMap.has(t)){var e=this.TrackMap.get(t);e.isPause||(e.isPause=!0,e.pauseTime=Date.now(),this.TrackMap.set(t,e))}},a.trackResume=function(t){if(this.TrackMap.has(t)){var e=this.TrackMap.get(t);e.isPause&&(e.isPause=!1,e.resumeTime=Date.now(),this.TrackMap.set(t,e))}},a.cleanTrack=function(t){this.TrackMap.delete(t)},e}();module.exports=e;
1
+ "use strict";function t(t,e,a){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var a;if("undefined"!=typeof Symbol&&void 0!==(a=t[Symbol.toPrimitive])){var r=a.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[e]=a,t}var e=function(){function e(){t(this,"collector",void 0),t(this,"config",void 0),t(this,"TrackMap",void 0),t(this,"Types",void 0)}var a=e.prototype;return a.apply=function(t,e){var a=this;this.collector=t,this.config=e;var r=t.Types;t.on(r.TrackDurationStart,function(t){a.trackStart(t)}),t.on(r.TrackDurationEnd,function(t){a.trackEnd(t)}),t.on(r.TrackDurationPause,function(t){a.trackPause(t)}),t.on(r.TrackDurationResume,function(t){a.trackResume(t)}),this.Types=r,this.TrackMap=new Map,this.ready(r.TrackDuration)},a.ready=function(t){var e=this;if(this.collector.set(t),this.collector.hook._hooksCache.hasOwnProperty(t)){var a=this.collector.hook._hooksCache[t];if(!Object.keys(a).length)return;var r=function(t){a[t].length&&a[t].forEach(function(a){e.collector.hook.emit(t,a)})};for(var i in a)r(i)}},a.trackStart=function(t){this.TrackMap.set(t,{startTime:Date.now(),isPause:!1,pauseTime:0,resumeTime:0})},a.trackEnd=function(t){var e=t.eventName,a=t.params;if(this.TrackMap.has(e)){var r=this.TrackMap.get(e),i=0;i=r.isPause?r.pauseTime-r.startTime:r.resumeTime?r.pauseTime-r.startTime+(Date.now()-r.resumeTime):Date.now()-r.startTime;var o=Object.assign(a,{event_duration:i});this.collector.event(e,o),this.cleanTrack(e)}},a.trackPause=function(t){if(this.TrackMap.has(t)){var e=this.TrackMap.get(t);e.isPause||(e.isPause=!0,e.pauseTime=Date.now(),this.TrackMap.set(t,e))}},a.trackResume=function(t){if(this.TrackMap.has(t)){var e=this.TrackMap.get(t);e.isPause&&(e.isPause=!1,e.resumeTime=Date.now(),this.TrackMap.set(t,e))}},a.cleanTrack=function(t){this.TrackMap.delete(t)},e}();module.exports=e;
@@ -1 +1 @@
1
- "use strict";function t(t,e,o){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var n=o.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}var e=function(t){return t.DEBUGGER_MESSAGE="debugger-message",t.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",t.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",t.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",t.DEBUGGER_MESSAGE_EVENT="debugger-message-event",t.DEVTOOL_WEB_READY="devtool-web-ready",t}({});var o=function(t,e){return t(e={exports:{}},e.exports),e.exports}(function(t,e){var o;o=function(){function t(){for(var t=0,e={};t<arguments.length;t++){var o=arguments[t];for(var n in o)e[n]=o[n]}return e}function e(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function o(n){function i(){}function a(e,o,a){if("undefined"!=typeof document){"number"==typeof(a=t({path:"/"},i.defaults,a)).expires&&(a.expires=new Date(1*new Date+864e5*a.expires)),a.expires=a.expires?a.expires.toUTCString():"";try{var r=JSON.stringify(o);/^[\{\[]/.test(r)&&(o=r)}catch(t){}o=n.write?n.write(o,e):encodeURIComponent(String(o)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var s="";for(var c in a)a[c]&&(s+="; "+c,!0!==a[c]&&(s+="="+a[c].split(";")[0]));return document.cookie=e+"="+o+s}}function r(t,o){if("undefined"!=typeof document){for(var i={},a=document.cookie?document.cookie.split("; "):[],r=0;r<a.length;r++){var s=a[r].split("="),c=s.slice(1).join("=");o||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var h=e(s[0]);if(c=(n.read||n)(c,h)||e(c),o)try{c=JSON.parse(c)}catch(t){}if(i[h]=c,t===h)break}catch(t){}}return t?i[t]:i}}return i.set=a,i.get=function(t){return r(t,!1)},i.getJSON=function(t){return r(t,!0)},i.remove=function(e,o){a(e,"",t(o,{expires:-1}))},i.defaults={},i.withConverter=o,i}(function(){})},t.exports=o()}),n=function(){function e(){t(this,"cache",void 0),this.cache={}}var o=e.prototype;return o.setItem=function(t,e){this.cache[t]=e},o.getItem=function(t){return this.cache[t]},o.removeItem=function(t){this.cache[t]=void 0},e}(),i=function(){function e(){t(this,"support",void 0),this.support=this.isSupportLS()}var o=e.prototype;return o.isSupportLS=function(){try{return localStorage.setItem("_applogtest-test-key","hi"),localStorage.getItem("_applogtest-test-key"),localStorage.removeItem("_applogtest-test-key"),!0}catch(t){return!1}},o.getItem=function(t){try{var e=localStorage.getItem(t),o=e;try{e&&"string"==typeof e&&(o=JSON.parse(e))}catch(t){}return o||{}}catch(t){}return{}},o.setItem=function(t,e){try{var o="string"==typeof e?e:JSON.stringify(e);localStorage.setItem(t,o)}catch(t){}},o.removeItem=function(t){try{localStorage.removeItem(t)}catch(t){}},e}(),a=function(){function e(){t(this,"support",void 0),this.support=this.isSupportSession()}var o=e.prototype;return o.isSupportSession=function(){try{return sessionStorage.setItem("_applogtest-test-key","hi"),sessionStorage.getItem("_applogtest-test-key"),sessionStorage.removeItem("_applogtest-test-key"),!0}catch(t){return!1}},o.getItem=function(t){try{var e=sessionStorage.getItem(t),o=e;try{e&&"string"==typeof e&&(o=JSON.parse(e))}catch(t){}return o||{}}catch(t){}return{}},o.setItem=function(t,e){try{var o="string"==typeof e?e:JSON.stringify(e);sessionStorage.setItem(t,o)}catch(t){}},o.removeItem=function(t){try{sessionStorage.removeItem(t)}catch(t){}},e}(),r=function(){function e(){t(this,"local",void 0),t(this,"session",void 0),t(this,"cache",void 0),t(this,"defaultExpireTime",void 0),this.defaultExpireTime=6048e5,this.local=new i,this.session=new a,this.cache=new n}var r=e.prototype;return r.getLocalItem=function(t){return this.local.getItem(t)},r.setLocalItem=function(t,e){this.local.setItem(t,e)},r.removeLocalItem=function(t){this.local.removeItem(t)},r.getSessionItem=function(t){return this.session.getItem(t)},r.setSessionItem=function(t,e){this.session.setItem(t,e)},r.removeSessionItem=function(t){this.session.removeItem(t)},r.getCacheItem=function(t){return this.cache.getItem(t)},r.setCacheItem=function(t,e){this.cache.setItem(t,e)},r.removeCacheItem=function(t){this.cache.removeItem(t)},r.getCookie=function(t,e){try{return o.get(t)}catch(t){return""}},r.setCookie=function(t,e,n,i){void 0===n&&(n=this.defaultExpireTime);try{var a=i||document.domain,r=+new Date+n;o.set(t,e,{expires:new Date(r),path:"/",domain:a})}catch(t){}},r.removeCookie=function(t,e){try{o.remove(t,{path:"/",domain:e||""})}catch(t){}},e}(),s=function(){function o(){t(this,"storage",void 0),t(this,"lastLocation",void 0),t(this,"autotrack",!1),t(this,"spa",!1),t(this,"fncArray",void 0),t(this,"collect",void 0),t(this,"config",void 0),t(this,"cache_key",void 0),t(this,"cache",{}),t(this,"appid",void 0),t(this,"allowHash",!1)}var n=o.prototype;return n.apply=function(t,e){if(e.spa||e.autotrack){var o=t.Types;this.collect=t,this.config=e,this.appid=e.app_id,this.allowHash=e.allow_hash,this.fncArray=new Map,this.setKey(),this.setLocation(),this.hack(),this.init(),this.listener(),t.emit(o.RouteReady)}},n.setKey=function(){this.storage=new r,this.cache_key="__tea_cache_refer_"+this.appid,this.cache={refer_key:"",refer_title:document.title||location.pathname,refer_manual_key:"",routeChange:!1},this.config.autotrack&&"object"==typeof this.config.autotrack&&this.config.autotrack.page_manual_key&&(this.cache.refer_manual_key=this.config.autotrack.page_manual_key),this.storage.setLocalItem(this.cache_key,this.cache)},n.hack=function(){var t=this,e=window.history.pushState;history.pushState=function(o){"function"==typeof history.onpushstate&&history.onpushstate({state:o});for(var n=arguments.length,i=new Array(n>1?n-1:0),a=1;a<n;a++)i[a-1]=arguments[a];var r=e.call.apply(e,[history,o].concat(i));if(t.lastLocation!==location.href){var s=t.getPopStateChangeEventData();return t.setReferCache(t.lastLocation),t.lastLocation=location.href,t.sendPv(s,"pushState"),r}};var o=history.replaceState;history.replaceState=function(e){"function"==typeof history.onreplacestate&&history.onreplacestate({state:e});for(var n=arguments.length,i=new Array(n>1?n-1:0),a=1;a<n;a++)i[a-1]=arguments[a];var r=o.call.apply(o,[history,e].concat(i));if(t.lastLocation!==location.href){var s=t.getPopStateChangeEventData();return t.setReferCache(t.lastLocation),t.lastLocation=location.href,t.sendPv(s),r}}},n.setLocation=function(){"undefined"!=typeof window&&(this.lastLocation=window.location.href)},n.getLocation=function(){return this.lastLocation},n.init=function(){var t=this.getPopStateChangeEventData();this.collect.emit("route-change",{config:t,init:!0})},n.listener=function(){var t=this,e=null;window.addEventListener("hashchange",function(o){if(t.lastLocation!==window.location.href&&(clearTimeout(e),t.allowHash)){t.setReferCache(t.lastLocation),t.lastLocation=window.location.href;var n=t.getPopStateChangeEventData();t.sendPv(n)}}),window.addEventListener("popstate",function(o){t.lastLocation!==window.location.href&&(e=setTimeout(function(){t.setReferCache(t.lastLocation),t.lastLocation=window.location.href;var e=t.getPopStateChangeEventData();t.sendPv(e)},10))})},n.getPopStateChangeEventData=function(){var t=this.pageConfig();return t.is_back=0,t},n.pageConfig=function(){try{var t=this.storage.getLocalItem(this.cache_key)||{},o=!1,n=this.storage.getLocalItem("__tea_cache_first_"+this.appid);return o=!n||1!=n,{is_html:1,url:location.href,referrer:this.handleRefer(),page_key:location.href,refer_page_key:this.handleRefer(),page_title:document.title||location.pathname,page_manual_key:this.config.autotrack&&this.config.autotrack.page_manual_key||"",refer_page_manual_key:t&&t.refer_manual_key||"",refer_page_title:t&&t.refer_title||"",page_path:location.pathname,page_host:location.host,is_first_time:""+o}}catch(t){return this.collect.emit(e.DEBUGGER_MESSAGE,{type:e.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message}),{}}},n.sendPv=function(t,e){this.collect.emit("route-change",{config:t,init:!1})},n.handleRefer=function(){var t="";try{var e=this.storage.getLocalItem()||{};t=e.routeChange?e.refer_key:this.collect.configManager.get("referrer")}catch(e){t=document.referrer}return t},n.setReferCache=function(t){var e=this.storage.getLocalItem(this.cache_key)||{};e.refer_key=t,e.routeChange=!0,this.storage.setLocalItem(this.cache_key,e)},o}();module.exports=s;
1
+ "use strict";function t(t,e,o){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var o;if("undefined"!=typeof Symbol&&void 0!==(o=t[Symbol.toPrimitive])){var n=o.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}var e=function(t){return t.DEBUGGER_MESSAGE="debugger-message",t.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",t.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",t.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",t.DEBUGGER_MESSAGE_EVENT="debugger-message-event",t.DEVTOOL_WEB_READY="devtool-web-ready",t}({});var o=function(t,e){return t(e={exports:{}},e.exports),e.exports}(function(t,e){var o;o=function(){function t(){for(var t=0,e={};t<arguments.length;t++){var o=arguments[t];for(var n in o)e[n]=o[n]}return e}function e(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function o(n){function i(){}function a(e,o,a){if("undefined"!=typeof document){"number"==typeof(a=t({path:"/"},i.defaults,a)).expires&&(a.expires=new Date(1*new Date+864e5*a.expires)),a.expires=a.expires?a.expires.toUTCString():"";try{var r=JSON.stringify(o);/^[\{\[]/.test(r)&&(o=r)}catch(t){}o=n.write?n.write(o,e):encodeURIComponent(String(o)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var s="";for(var c in a)a[c]&&(s+="; "+c,!0!==a[c]&&(s+="="+a[c].split(";")[0]));return document.cookie=e+"="+o+s}}function r(t,o){if("undefined"!=typeof document){for(var i={},a=document.cookie?document.cookie.split("; "):[],r=0;r<a.length;r++){var s=a[r].split("="),c=s.slice(1).join("=");o||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var h=e(s[0]);if(c=(n.read||n)(c,h)||e(c),o)try{c=JSON.parse(c)}catch(t){}if(i[h]=c,t===h)break}catch(t){}}return t?i[t]:i}}return i.set=a,i.get=function(t){return r(t,!1)},i.getJSON=function(t){return r(t,!0)},i.remove=function(e,o){a(e,"",t(o,{expires:-1}))},i.defaults={},i.withConverter=o,i}(function(){})},t.exports=o()}),n=function(){function e(){t(this,"cache",void 0),this.cache={}}var o=e.prototype;return o.setItem=function(t,e){this.cache[t]=e},o.getItem=function(t){return this.cache[t]},o.removeItem=function(t){this.cache[t]=void 0},e}(),i=function(){function e(){t(this,"support",void 0),this.support=this.isSupportLS()}var o=e.prototype;return o.isSupportLS=function(){try{return localStorage.setItem("_applogtest-test-key","hi"),localStorage.getItem("_applogtest-test-key"),localStorage.removeItem("_applogtest-test-key"),!0}catch(t){return!1}},o.getItem=function(t){try{var e=localStorage.getItem(t),o=e;try{e&&"string"==typeof e&&(o=JSON.parse(e))}catch(t){}return o||{}}catch(t){}return{}},o.setItem=function(t,e){try{var o="string"==typeof e?e:JSON.stringify(e);localStorage.setItem(t,o)}catch(t){}},o.removeItem=function(t){try{localStorage.removeItem(t)}catch(t){}},e}(),a=function(){function e(){t(this,"support",void 0),this.support=this.isSupportSession()}var o=e.prototype;return o.isSupportSession=function(){try{return sessionStorage.setItem("_applogtest-test-key","hi"),sessionStorage.getItem("_applogtest-test-key"),sessionStorage.removeItem("_applogtest-test-key"),!0}catch(t){return!1}},o.getItem=function(t){try{var e=sessionStorage.getItem(t),o=e;try{e&&"string"==typeof e&&(o=JSON.parse(e))}catch(t){}return o||{}}catch(t){}return{}},o.setItem=function(t,e){try{var o="string"==typeof e?e:JSON.stringify(e);sessionStorage.setItem(t,o)}catch(t){}},o.removeItem=function(t){try{sessionStorage.removeItem(t)}catch(t){}},e}(),r=function(){function e(){t(this,"local",void 0),t(this,"session",void 0),t(this,"cache",void 0),t(this,"defaultExpireTime",void 0),this.defaultExpireTime=6048e5,this.local=new i,this.session=new a,this.cache=new n}var r=e.prototype;return r.getLocalItem=function(t){return this.local.getItem(t)},r.setLocalItem=function(t,e){this.local.setItem(t,e)},r.removeLocalItem=function(t){this.local.removeItem(t)},r.getSessionItem=function(t){return this.session.getItem(t)},r.setSessionItem=function(t,e){this.session.setItem(t,e)},r.removeSessionItem=function(t){this.session.removeItem(t)},r.getCacheItem=function(t){return this.cache.getItem(t)},r.setCacheItem=function(t,e){this.cache.setItem(t,e)},r.removeCacheItem=function(t){this.cache.removeItem(t)},r.getCookie=function(t,e){try{return o.get(t)}catch(t){return""}},r.setCookie=function(t,e,n,i){void 0===n&&(n=this.defaultExpireTime);try{var a=i||document.domain,r=+new Date+n;o.set(t,e,{expires:new Date(r),path:"/",domain:a})}catch(t){}},r.removeCookie=function(t,e){try{o.remove(t,{path:"/",domain:e||""})}catch(t){}},e}(),s=function(){function o(){t(this,"storage",void 0),t(this,"lastLocation",void 0),t(this,"autotrack",!1),t(this,"spa",!1),t(this,"fncArray",void 0),t(this,"collect",void 0),t(this,"config",void 0),t(this,"cache_key",void 0),t(this,"cache",{}),t(this,"appid",void 0),t(this,"allowHash",!1)}var n=o.prototype;return n.apply=function(t,e){if(e.spa||e.autotrack){var o=t.Types;this.collect=t,this.config=e,this.appid=e.app_id,this.allowHash=e.allow_hash,this.fncArray=new Map,this.setKey(),this.setLocation(),this.hack(),this.init(),this.listener(),t.emit(o.RouteReady)}},n.setKey=function(){this.storage=new r,this.cache_key="__tea_cache_refer_"+this.appid,this.cache={refer_key:"",refer_title:document.title||location.pathname,refer_manual_key:"",routeChange:!1},this.config.autotrack&&"object"==typeof this.config.autotrack&&this.config.autotrack.page_manual_key&&(this.cache.refer_manual_key=this.config.autotrack.page_manual_key),this.storage.setLocalItem(this.cache_key,this.cache)},n.hack=function(){var t=this,e=window.history.pushState;history.pushState=function(o){"function"==typeof history.onpushstate&&history.onpushstate({state:o});for(var n=arguments.length,i=new Array(n>1?n-1:0),a=1;a<n;a++)i[a-1]=arguments[a];var r=e.call.apply(e,[history,o].concat(i));if(t.lastLocation!==location.href){var s=t.getPopStateChangeEventData();return t.setReferCache(t.lastLocation),t.lastLocation=location.href,t.sendPv(s,"pushState"),r}};var o=history.replaceState;history.replaceState=function(e){"function"==typeof history.onreplacestate&&history.onreplacestate({state:e});for(var n=arguments.length,i=new Array(n>1?n-1:0),a=1;a<n;a++)i[a-1]=arguments[a];var r=o.call.apply(o,[history,e].concat(i));if(t.lastLocation!==location.href){var s=t.getPopStateChangeEventData();return t.setReferCache(t.lastLocation),t.lastLocation=location.href,t.sendPv(s),r}}},n.setLocation=function(){"undefined"!=typeof window&&(this.lastLocation=window.location.href)},n.getLocation=function(){return this.lastLocation},n.init=function(){var t=this.getPopStateChangeEventData();this.collect.emit("route-change",{config:t,init:!0})},n.listener=function(){var t=this,e=null;window.addEventListener("hashchange",function(o){if(t.lastLocation!==window.location.href&&(clearTimeout(e),t.allowHash)){t.setReferCache(t.lastLocation),t.lastLocation=window.location.href;var n=t.getPopStateChangeEventData();t.sendPv(n)}}),window.addEventListener("popstate",function(o){t.lastLocation!==window.location.href&&(e=setTimeout(function(){t.setReferCache(t.lastLocation),t.lastLocation=window.location.href;var e=t.getPopStateChangeEventData();t.sendPv(e)},10))})},n.getPopStateChangeEventData=function(){var t=this.pageConfig();return t.is_back=0,t},n.pageConfig=function(){try{var t=this.storage.getLocalItem(this.cache_key)||{},o=!1,n=this.storage.getLocalItem("__tea_cache_first_"+this.appid);return o=!n||1!=n,{is_html:1,url:location.href,referrer:this.handleRefer(),page_key:location.href,refer_page_key:this.handleRefer(),page_title:document.title||location.pathname,page_manual_key:this.config.autotrack&&this.config.autotrack.page_manual_key||"",refer_page_manual_key:t&&t.refer_manual_key||"",refer_page_title:t&&t.refer_title||"",page_path:location.pathname,page_host:location.host,is_first_time:""+o}}catch(t){return this.collect.emit(e.DEBUGGER_MESSAGE,{type:e.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message}),{}}},n.sendPv=function(t,e){this.collect.emit("route-change",{config:t,init:!1})},n.handleRefer=function(){var t="";try{var e=this.storage.getLocalItem()||{};t=e.routeChange?e.refer_key:this.collect.configManager.get("referrer")}catch(e){t=document.referrer}return t},n.setReferCache=function(t){var e=this.storage.getLocalItem(this.cache_key)||{};e.refer_key=t,e.routeChange=!0,this.storage.setLocalItem(this.cache_key,e)},o}();module.exports=s;
@@ -1 +1 @@
1
- "use strict";function t(t,i,e){return(i=function(t){var i=function(t,i){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var s=e.call(t,i||"default");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===i?String:Number)(t)}(t,"string");return"symbol"==typeof i?i:i+""}(i))in t?Object.defineProperty(t,i,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[i]=e,t}var i=function(t){return null!=t&&"[object Object]"==Object.prototype.toString.call(t)};Date.now(),Number((""+Math.random()).slice(2,8));var e=function(){var t=0;return["hidden","msHidden","webkitHidden"].forEach(function(i){void 0!==document[i]&&(t=1)}),t},s=function(){function s(e,s){t(this,"collect",void 0),t(this,"config",void 0),t(this,"pageStartTime",void 0),t(this,"maxDuration",432e5),t(this,"sessionStartTime",void 0),t(this,"timerHandler",void 0),t(this,"url_path",void 0),t(this,"url",void 0),t(this,"title",void 0),t(this,"set_path",void 0),t(this,"set_url",void 0),t(this,"set_title",void 0),t(this,"aliveDTime",6e4),t(this,"aliveName",void 0),t(this,"disableCallback",void 0),t(this,"customParmas",void 0),t(this,"options",{aliveName:"predefine_page_alive",params:{}}),this.collect=e,this.config=s,this.pageStartTime=Date.now(),this.sessionStartTime=this.pageStartTime,this.timerHandler=null,i(s.enable_stay_duration)&&(this.options=Object.assign(this.options,s.enable_stay_duration))}var a=s.prototype;return a.setParams=function(t,i,e){this.set_path=t,this.set_url=e,this.set_title=i},a.resetParams=function(t,i,e){this.url_path=t,this.url=e,this.title=i},a.enable=function(t,i,e){this.url_path=t||this.url_path,this.url=e||this.url,this.title=i||this.title,this.disableCallback=this.enablePageAlive(),this.options.params instanceof Function?this.customParmas=this.options.params():this.customParmas=this.options.params},a.disable=function(){this.disableCallback(),this.pageStartTime=Date.now()},a.sendEvent=function(t,i){void 0===i&&(i=!1);var s=i?this.aliveDTime:Date.now()-this.sessionStartTime;s<0||s>this.aliveDTime||Date.now()-this.pageStartTime>this.maxDuration||(this.collect.beconEvent(this.options.aliveName,Object.assign({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),duration:s,is_support_visibility_change:e(),startTime:this.sessionStartTime,hidden:document.visibilityState,leave:t},this.customParmas)),this.sessionStartTime=Date.now(),this.resetParams(location.pathname,document.title,location.href))},a.getParams=function(t){switch(t){case"url_path":return this.set_path||this.url_path||location.pathname;case"title":return this.set_title||this.title||document.title||location.pathname;case"url":return this.set_url||this.url||location.href}},a.setUpTimer=function(){var t=this;return this.timerHandler&&clearInterval(this.timerHandler),setInterval(function(){Date.now()-t.sessionStartTime>t.aliveDTime&&t.sendEvent(!1,!0)},1e3)},a.visibilitychange=function(){"hidden"===document.visibilityState?this.timerHandler&&(clearInterval(this.timerHandler),this.sendEvent(!1)):"visible"===document.visibilityState&&(this.sessionStartTime=Date.now(),this.timerHandler=this.setUpTimer())},a.beforeunload=function(){document.hidden||this.sendEvent(!0)},a.enablePageAlive=function(){var t=this;this.timerHandler=this.setUpTimer();var i=this.visibilitychange.bind(this),e=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",i),window.addEventListener("pagehide",e),function(){t.beforeunload(),document.removeEventListener("visibilitychange",i),window.removeEventListener("beforeunload",e),window.removeEventListener("pagehide",e)}},s}(),a=function(){function s(e,s){var a=this;t(this,"collect",void 0),t(this,"config",void 0),t(this,"pageStartTime",void 0),t(this,"maxDuration",432e5),t(this,"sessionStartTime",void 0),t(this,"timerHandler",void 0),t(this,"url_path",void 0),t(this,"url",void 0),t(this,"title",void 0),t(this,"set_path",void 0),t(this,"set_url",void 0),t(this,"set_title",void 0),t(this,"aliveDTime",6e4),t(this,"aliveName",void 0),t(this,"options",{closeName:"predefine_page_close",params:{}}),t(this,"activeStartTime",void 0),t(this,"activeEndTime",void 0),t(this,"activeTimes",void 0),t(this,"totalTime",void 0),t(this,"disableCallback",void 0),t(this,"customParmas",void 0),t(this,"visibilitychange",function(){"hidden"===document.visibilityState?a.activeEndTime=Date.now():"visible"===document.visibilityState&&(a.activeEndTime&&(a.totalTime+=a.activeEndTime-a.activeStartTime,a.activeTimes+=1),a.activeEndTime=void 0,a.activeStartTime=Date.now())}),t(this,"beforeunload",function(){if(a.totalTime+=(a.activeEndTime||Date.now())-a.activeStartTime,a.config.autotrack){try{window.sessionStorage.setItem("_tea_cache_duration",JSON.stringify({duration:a.totalTime,page_title:document.title||location.pathname}))}catch(t){}}a.sendEventPageClose()}),this.collect=e,this.config=s,this.maxDuration=s.maxDuration||864e5,this.pageStartTime=Date.now(),i(s.enable_stay_duration)&&(this.options=Object.assign(this.options,s.enable_stay_duration)),this.resetData()}var a=s.prototype;return a.setParams=function(t,i,e){this.set_path=t,this.set_url=e,this.set_title=i},a.resetParams=function(t,i,e){this.url_path=t,this.url=e,this.title=i},a.enable=function(t,i,e){this.url_path=t||this.url_path,this.url=e||this.url,this.title=i||this.title,this.disableCallback=this.enablePageClose()},a.disable=function(){this.disableCallback()},a.resetData=function(){this.activeStartTime=void 0===this.activeStartTime?this.pageStartTime:Date.now(),this.activeEndTime=void 0,this.activeTimes=1,this.totalTime=0,this.options.params instanceof Function?this.customParmas=this.options.params():this.customParmas=this.options.params,this.resetParams(location.pathname,document.title,location.href)},a.sendEventPageClose=function(){var t=Date.now()-this.pageStartTime;this.totalTime<0||t<0||this.totalTime>=this.maxDuration||(this.collect.beconEvent(this.options.closeName,Object.assign({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),active_times:this.activeTimes,duration:this.totalTime,total_duration:t,is_support_visibility_change:e()},this.customParmas)),this.pageStartTime=Date.now(),this.resetData())},a.getParams=function(t){switch(t){case"url_path":return this.set_path||this.url_path||location.pathname;case"title":return this.set_title||this.title||document.title||location.pathname;case"url":return this.set_url||this.url||location.href}},a.enablePageClose=function(){var t=this,i=this.visibilitychange.bind(this),e=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",i),window.addEventListener("pagehide",e),function(){t.beforeunload(),document.removeEventListener("visibilitychange",i),window.removeEventListener("beforeunload",e),window.removeEventListener("pagehide",e)}},s}(),n=function(t){return t.DEBUGGER_MESSAGE="debugger-message",t.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",t.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",t.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",t.DEBUGGER_MESSAGE_EVENT="debugger-message-event",t.DEVTOOL_WEB_READY="devtool-web-ready",t}({}),o=function(){function i(){t(this,"collect",void 0),t(this,"config",void 0),t(this,"title",void 0),t(this,"url",void 0),t(this,"url_path",void 0),t(this,"pageAlive",void 0),t(this,"pageClose",void 0)}var e=i.prototype;return e.apply=function(t,i){var e=this;if(this.collect=t,this.config=i,this.config.enable_stay_duration){this.title=document.title||location.pathname,this.url=location.href,this.url_path=location.pathname,this.pageAlive=new s(t,i),this.pageClose=new a(t,i);var n=this.collect.Types;this.collect.on(n.ResetStay,function(t){var i=t.url_path,s=t.title,a=t.url;e.resetStayDuration(i,s,a)}),this.collect.on(n.RouteChange,function(t){t.init||i.disable_route_report||e.resetStayDuration()}),this.collect.on(n.SetStay,function(t){var i=t.url_path,s=t.title,a=t.url;e.setStayParmas(i,s,a)}),this.enable(this.url_path,this.title,this.url),this.ready(n.Stay),this.collect.emit(n.StayReady)}},e.ready=function(t){var i=this;if(this.collect.set(t),this.collect.hook._hooksCache.hasOwnProperty(t)){var e=this.collect.hook._hooksCache[t];if(!Object.keys(e).length)return;var s=function(t){e[t].length&&e[t].forEach(function(e){i.collect.hook.emit(t,e)})};for(var a in e)s(a)}},e.enable=function(t,i,e){this.pageAlive.enable(t,i,e),this.pageClose.enable(t,i,e)},e.disable=function(){this.pageAlive.disable(),this.pageClose.disable()},e.setStayParmas=function(t,i,e){void 0===t&&(t=""),void 0===i&&(i=""),void 0===e&&(e=""),this.pageAlive.setParams(t,i,e),this.pageClose.setParams(t,i,e),this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayParams",level:"info",time:Date.now(),data:{url_path:t,title:i,url:e}})},e.reset=function(t,i,e){this.disable(),this.enable(t,i,e)},e.resetStayDuration=function(t,i,e){this.reset(t,i,e),this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayDuration",level:"info",time:Date.now(),data:{url_path:t,title:i,url:e}})},i}();module.exports=o;
1
+ "use strict";function t(t,i,e){return(i=function(t){var i=function(t,i){if("object"!=typeof t||!t)return t;var e;if("undefined"!=typeof Symbol&&void 0!==(e=t[Symbol.toPrimitive])){var s=e.call(t,i||"default");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===i?String:Number)(t)}(t,"string");return"symbol"==typeof i?i:i+""}(i))in t?Object.defineProperty(t,i,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[i]=e,t}var i=function(t){return null!=t&&"[object Object]"==Object.prototype.toString.call(t)};Date.now(),Number((""+Math.random()).slice(2,8));var e=function(){var t=0;return["hidden","msHidden","webkitHidden"].forEach(function(i){void 0!==document[i]&&(t=1)}),t},s=function(){function s(e,s){t(this,"collect",void 0),t(this,"config",void 0),t(this,"pageStartTime",void 0),t(this,"maxDuration",432e5),t(this,"sessionStartTime",void 0),t(this,"timerHandler",void 0),t(this,"url_path",void 0),t(this,"url",void 0),t(this,"title",void 0),t(this,"set_path",void 0),t(this,"set_url",void 0),t(this,"set_title",void 0),t(this,"aliveDTime",6e4),t(this,"aliveName",void 0),t(this,"disableCallback",void 0),t(this,"customParmas",void 0),t(this,"options",{aliveName:"predefine_page_alive",params:{}}),this.collect=e,this.config=s,this.pageStartTime=Date.now(),this.sessionStartTime=this.pageStartTime,this.timerHandler=null,i(s.enable_stay_duration)&&(this.options=Object.assign(this.options,s.enable_stay_duration))}var a=s.prototype;return a.setParams=function(t,i,e){this.set_path=t,this.set_url=e,this.set_title=i},a.resetParams=function(t,i,e){this.url_path=t,this.url=e,this.title=i},a.enable=function(t,i,e){this.url_path=t||this.url_path,this.url=e||this.url,this.title=i||this.title,this.disableCallback=this.enablePageAlive(),this.options.params instanceof Function?this.customParmas=this.options.params():this.customParmas=this.options.params},a.disable=function(){this.disableCallback(),this.pageStartTime=Date.now()},a.sendEvent=function(t,i){void 0===i&&(i=!1);var s=i?this.aliveDTime:Date.now()-this.sessionStartTime;s<0||s>this.aliveDTime||Date.now()-this.pageStartTime>this.maxDuration||(this.collect.beconEvent(this.options.aliveName,Object.assign({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),duration:s,is_support_visibility_change:e(),startTime:this.sessionStartTime,hidden:document.visibilityState,leave:t},this.customParmas)),this.sessionStartTime=Date.now(),this.resetParams(location.pathname,document.title,location.href))},a.getParams=function(t){switch(t){case"url_path":return this.set_path||this.url_path||location.pathname;case"title":return this.set_title||this.title||document.title||location.pathname;case"url":return this.set_url||this.url||location.href}},a.setUpTimer=function(){var t=this;return this.timerHandler&&clearInterval(this.timerHandler),setInterval(function(){Date.now()-t.sessionStartTime>t.aliveDTime&&t.sendEvent(!1,!0)},1e3)},a.visibilitychange=function(){"hidden"===document.visibilityState?this.timerHandler&&(clearInterval(this.timerHandler),this.sendEvent(!1)):"visible"===document.visibilityState&&(this.sessionStartTime=Date.now(),this.timerHandler=this.setUpTimer())},a.beforeunload=function(){document.hidden||this.sendEvent(!0)},a.enablePageAlive=function(){var t=this;this.timerHandler=this.setUpTimer();var i=this.visibilitychange.bind(this),e=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",i),window.addEventListener("pagehide",e),function(){t.beforeunload(),document.removeEventListener("visibilitychange",i),window.removeEventListener("beforeunload",e),window.removeEventListener("pagehide",e)}},s}(),a=function(){function s(e,s){var a=this;t(this,"collect",void 0),t(this,"config",void 0),t(this,"pageStartTime",void 0),t(this,"maxDuration",432e5),t(this,"sessionStartTime",void 0),t(this,"timerHandler",void 0),t(this,"url_path",void 0),t(this,"url",void 0),t(this,"title",void 0),t(this,"set_path",void 0),t(this,"set_url",void 0),t(this,"set_title",void 0),t(this,"aliveDTime",6e4),t(this,"aliveName",void 0),t(this,"options",{closeName:"predefine_page_close",params:{}}),t(this,"activeStartTime",void 0),t(this,"activeEndTime",void 0),t(this,"activeTimes",void 0),t(this,"totalTime",void 0),t(this,"disableCallback",void 0),t(this,"customParmas",void 0),t(this,"visibilitychange",function(){"hidden"===document.visibilityState?a.activeEndTime=Date.now():"visible"===document.visibilityState&&(a.activeEndTime&&(a.totalTime+=a.activeEndTime-a.activeStartTime,a.activeTimes+=1),a.activeEndTime=void 0,a.activeStartTime=Date.now())}),t(this,"beforeunload",function(){if(a.totalTime+=(a.activeEndTime||Date.now())-a.activeStartTime,a.config.autotrack){try{window.sessionStorage.setItem("_tea_cache_duration",JSON.stringify({duration:a.totalTime,page_title:document.title||location.pathname}))}catch(t){}}a.sendEventPageClose()}),this.collect=e,this.config=s,this.maxDuration=s.maxDuration||864e5,this.pageStartTime=Date.now(),i(s.enable_stay_duration)&&(this.options=Object.assign(this.options,s.enable_stay_duration)),this.resetData()}var a=s.prototype;return a.setParams=function(t,i,e){this.set_path=t,this.set_url=e,this.set_title=i},a.resetParams=function(t,i,e){this.url_path=t,this.url=e,this.title=i},a.enable=function(t,i,e){this.url_path=t||this.url_path,this.url=e||this.url,this.title=i||this.title,this.disableCallback=this.enablePageClose()},a.disable=function(){this.disableCallback()},a.resetData=function(){this.activeStartTime=void 0===this.activeStartTime?this.pageStartTime:Date.now(),this.activeEndTime=void 0,this.activeTimes=1,this.totalTime=0,this.options.params instanceof Function?this.customParmas=this.options.params():this.customParmas=this.options.params,this.resetParams(location.pathname,document.title,location.href)},a.sendEventPageClose=function(){var t=Date.now()-this.pageStartTime;this.totalTime<0||t<0||this.totalTime>=this.maxDuration||(this.collect.beconEvent(this.options.closeName,Object.assign({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),active_times:this.activeTimes,duration:this.totalTime,total_duration:t,is_support_visibility_change:e()},this.customParmas)),this.pageStartTime=Date.now(),this.resetData())},a.getParams=function(t){switch(t){case"url_path":return this.set_path||this.url_path||location.pathname;case"title":return this.set_title||this.title||document.title||location.pathname;case"url":return this.set_url||this.url||location.href}},a.enablePageClose=function(){var t=this,i=this.visibilitychange.bind(this),e=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",i),window.addEventListener("pagehide",e),function(){t.beforeunload(),document.removeEventListener("visibilitychange",i),window.removeEventListener("beforeunload",e),window.removeEventListener("pagehide",e)}},s}(),n=function(t){return t.DEBUGGER_MESSAGE="debugger-message",t.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",t.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",t.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",t.DEBUGGER_MESSAGE_EVENT="debugger-message-event",t.DEVTOOL_WEB_READY="devtool-web-ready",t}({}),o=function(){function i(){t(this,"collect",void 0),t(this,"config",void 0),t(this,"title",void 0),t(this,"url",void 0),t(this,"url_path",void 0),t(this,"pageAlive",void 0),t(this,"pageClose",void 0)}var e=i.prototype;return e.apply=function(t,i){var e=this;if(this.collect=t,this.config=i,this.config.enable_stay_duration){this.title=document.title||location.pathname,this.url=location.href,this.url_path=location.pathname,this.pageAlive=new s(t,i),this.pageClose=new a(t,i);var n=this.collect.Types;this.collect.on(n.ResetStay,function(t){var i=t.url_path,s=t.title,a=t.url;e.resetStayDuration(i,s,a)}),this.collect.on(n.RouteChange,function(t){t.init||i.disable_route_report||e.resetStayDuration()}),this.collect.on(n.SetStay,function(t){var i=t.url_path,s=t.title,a=t.url;e.setStayParmas(i,s,a)}),this.enable(this.url_path,this.title,this.url),this.ready(n.Stay),this.collect.emit(n.StayReady)}},e.ready=function(t){var i=this;if(this.collect.set(t),this.collect.hook._hooksCache.hasOwnProperty(t)){var e=this.collect.hook._hooksCache[t];if(!Object.keys(e).length)return;var s=function(t){e[t].length&&e[t].forEach(function(e){i.collect.hook.emit(t,e)})};for(var a in e)s(a)}},e.enable=function(t,i,e){this.pageAlive.enable(t,i,e),this.pageClose.enable(t,i,e)},e.disable=function(){this.pageAlive.disable(),this.pageClose.disable()},e.setStayParmas=function(t,i,e){void 0===t&&(t=""),void 0===i&&(i=""),void 0===e&&(e=""),this.pageAlive.setParams(t,i,e),this.pageClose.setParams(t,i,e),this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayParams",level:"info",time:Date.now(),data:{url_path:t,title:i,url:e}})},e.reset=function(t,i,e){this.disable(),this.enable(t,i,e)},e.resetStayDuration=function(t,i,e){this.reset(t,i,e),this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayDuration",level:"info",time:Date.now(),data:{url_path:t,title:i,url:e}})},i}();module.exports=o;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarangers/sdk-javascript",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "scripts": {
5
5
  "nclean": "rimraf es lib core",
6
6
  "build": "export NODE_ENV=production && npm run nclean && npx rollup -c rollup.config.js",
@@ -9,7 +9,7 @@
9
9
  "main": "lib/index.min.js",
10
10
  "module": "es/index.min.js",
11
11
  "types": "./types/types.d.ts",
12
- "license": "ISC",
12
+ "license": "SEE LICENSE IN LICENSE",
13
13
  "dependencies": {
14
14
  "sm-crypto": "^0.3.12"
15
15
  },