@datarangers/sdk-javascript 0.0.1 → 0.0.3-lite
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/README.md +10 -10
- package/core/es/index.min.js +1 -1
- package/core/lib/index.min.js +1 -1
- package/es/index.min.js +1 -1
- package/lib/index.min.js +1 -1
- package/package.json +4 -1
- package/es/index-base.min.js +0 -1
- package/es/plugin/ab.js +0 -1
- package/es/plugin/autotrack.js +0 -1
- package/es/plugin/duration.js +0 -1
- package/es/plugin/route.js +0 -1
- package/es/plugin/stay.js +0 -1
- package/es/plugin/store.js +0 -1
- package/lib/index-base.min.js +0 -1
- package/lib/plugin/ab.js +0 -1
- package/lib/plugin/autotrack.js +0 -1
- package/lib/plugin/duration.js +0 -1
- package/lib/plugin/route.js +0 -1
- package/lib/plugin/stay.js +0 -1
- package/lib/plugin/store.js +0 -1
package/es/plugin/ab.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=function(){return e=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},e.apply(this,arguments)},t="__rangers_ab_style__";var n,i,r={cn:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"},o="https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/visual-ab-core.js",a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(e){var t=function(){try{return!!Symbol.iterator}catch(e){return!1}}(),n=function(e){var n={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return t&&(n[Symbol.iterator]=function(){return n}),n},i=function(e){return encodeURIComponent(e).replace(/%20/g,"+")},r=function(e){return decodeURIComponent(String(e).replace(/\+/g," "))};(function(){try{var t=e.URLSearchParams;return"a=1"===new t("?a=1").toString()&&"function"==typeof t.prototype.set&&"function"==typeof t.prototype.entries}catch(t){return!1}})()||function(){var r=function e(t){Object.defineProperty(this,"_entries",{writable:!0,value:{}});var n=typeof t;if("undefined"===n);else if("string"===n)""!==t&&this._fromString(t);else if(t instanceof e){var i=this;t.forEach((function(e,t){i.append(t,e)}))}else{if(null===t||"object"!==n)throw new TypeError("Unsupported input's type for URLSearchParams");if("[object Array]"===Object.prototype.toString.call(t))for(var r=0;r<t.length;r++){var o=t[r];if("[object Array]"!==Object.prototype.toString.call(o)&&2===o.length)throw new TypeError("Expected [string, any] as entry at index "+r+" of URLSearchParams's input");this.append(o[0],o[1])}else for(var a in t)t.hasOwnProperty(a)&&this.append(a,t[a])}},o=r.prototype;o.append=function(e,t){e in this._entries?this._entries[e].push(String(t)):this._entries[e]=[String(t)]},o.delete=function(e){delete this._entries[e]},o.get=function(e){return e in this._entries?this._entries[e][0]:null},o.getAll=function(e){return e in this._entries?this._entries[e].slice(0):[]},o.has=function(e){return e in this._entries},o.set=function(e,t){this._entries[e]=[String(t)]},o.forEach=function(e,t){var n;for(var i in this._entries)if(this._entries.hasOwnProperty(i)){n=this._entries[i];for(var r=0;r<n.length;r++)e.call(t,n[r],i,this)}},o.keys=function(){var e=[];return this.forEach((function(t,n){e.push(n)})),n(e)},o.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),n(e)},o.entries=function(){var e=[];return this.forEach((function(t,n){e.push([n,t])})),n(e)},t&&(o[Symbol.iterator]=o.entries),o.toString=function(){var e=[];return this.forEach((function(t,n){e.push(i(n)+"="+i(t))})),e.join("&")},e.URLSearchParams=r}();var o=e.URLSearchParams.prototype;"function"!=typeof o.sort&&(o.sort=function(){var e=this,t=[];this.forEach((function(n,i){t.push([i,n]),e._entries||e.delete(i)})),t.sort((function(e,t){return e[0]<t[0]?-1:e[0]>t[0]?1:0})),e._entries&&(e._entries={});for(var n=0;n<t.length;n++)this.append(t[n][0],t[n][1])}),"function"!=typeof o._fromString&&Object.defineProperty(o,"_fromString",{enumerable:!1,configurable:!1,writable:!1,value:function(e){if(this._entries)this._entries={};else{var t=[];this.forEach((function(e,n){t.push(n)}));for(var n=0;n<t.length;n++)this.delete(t[n])}var i,o=(e=e.replace(/^\?/,"")).split("&");for(n=0;n<o.length;n++)i=o[n].split("="),this.append(r(i[0]),i.length>1?r(i[1]):"")}})}(void 0!==a?a:"undefined"!=typeof window?window:"undefined"!=typeof self?self:a),function(e){if(function(){try{var t=new e.URL("b","http://a");return t.pathname="c d","http://a/c%20d"===t.href&&t.searchParams}catch(t){return!1}}()||function(){var t=e.URL,n=function t(n,i){"string"!=typeof n&&(n=String(n)),i&&"string"!=typeof i&&(i=String(i));var r,o=document;if(i&&(void 0===e.location||i!==e.location.href)){i=i.toLowerCase(),(r=(o=document.implementation.createHTMLDocument("")).createElement("base")).href=i,o.head.appendChild(r);try{if(0!==r.href.indexOf(i))throw new Error(r.href)}catch(t){throw new Error("URL unable to set base "+i+" due to "+t)}}var a=o.createElement("a");a.href=n,r&&(o.body.appendChild(a),a.href=a.href);var s=o.createElement("input");if(s.type="url",s.value=n,":"===a.protocol||!/:/.test(a.href)||!s.checkValidity()&&!i)throw new TypeError("Invalid URL");Object.defineProperty(this,"_anchorElement",{value:a});var c=new e.URLSearchParams(this.search),l=!0,h=!0,u=this;["append","delete","set"].forEach((function(e){var t=c[e];c[e]=function(){t.apply(c,arguments),l&&(h=!1,u.search=c.toString(),h=!0)}})),Object.defineProperty(this,"searchParams",{value:c,enumerable:!0});var f=void 0;Object.defineProperty(this,"_updateSearchParams",{enumerable:!1,configurable:!1,writable:!1,value:function(){this.search!==f&&(f=this.search,h&&(l=!1,this.searchParams._fromString(this.search),l=!0))}})},i=n.prototype;["hash","host","hostname","port","protocol"].forEach((function(e){!function(e){Object.defineProperty(i,e,{get:function(){return this._anchorElement[e]},set:function(t){this._anchorElement[e]=t},enumerable:!0})}(e)})),Object.defineProperty(i,"search",{get:function(){return this._anchorElement.search},set:function(e){this._anchorElement.search=e,this._updateSearchParams()},enumerable:!0}),Object.defineProperties(i,{toString:{get:function(){var e=this;return function(){return e.href}}},href:{get:function(){return this._anchorElement.href.replace(/\?$/,"")},set:function(e){this._anchorElement.href=e,this._updateSearchParams()},enumerable:!0},pathname:{get:function(){return this._anchorElement.pathname.replace(/(^\/?)/,"/")},set:function(e){this._anchorElement.pathname=e},enumerable:!0},origin:{get:function(){var e={"http:":80,"https:":443,"ftp:":21}[this._anchorElement.protocol],t=this._anchorElement.port!=e&&""!==this._anchorElement.port;return this._anchorElement.protocol+"//"+this._anchorElement.hostname+(t?":"+this._anchorElement.port:"")},enumerable:!0},password:{get:function(){return""},set:function(e){},enumerable:!0},username:{get:function(){return""},set:function(e){},enumerable:!0}}),n.createObjectURL=function(e){return t.createObjectURL.apply(t,arguments)},n.revokeObjectURL=function(e){return t.revokeObjectURL.apply(t,arguments)},e.URL=n}(),void 0!==e.location&&!("origin"in e.location)){var t=function(){return e.location.protocol+"//"+e.location.hostname+(e.location.port?":"+e.location.port:"")};try{Object.defineProperty(e.location,"origin",{get:t,enumerable:!0})}catch(n){setInterval((function(){e.location.origin=t()}),100)}}}(void 0!==a?a:"undefined"!=typeof window?window:"undefined"!=typeof self?self:a),function(e){e.Init="init",e.Config="config",e.Start="start",e.Ready="ready",e.TokenComplete="token-complete",e.TokenStorage="token-storage",e.TokenFetch="token-fetch",e.TokenError="token-error",e.ConfigUuid="config-uuid",e.ConfigWebId="config-webid",e.ConfigDomain="config-domain",e.CustomWebId="custom-webid",e.TokenChange="token-change",e.TokenReset="token-reset",e.ConfigTransform="config-transform",e.EnvTransform="env-transform",e.SessionReset="session-reset",e.SessionResetTime="session-reset-time",e.Event="event",e.Events="events",e.EventNow="event-now",e.CleanEvents="clean-events",e.BeconEvent="becon-event",e.SubmitBefore="submit-before",e.SubmitScuess="submit-scuess",e.SubmitAfter="submit-after",e.SubmitError="submit-error",e.SubmitVerify="submit-verify",e.SubmitVerifyH="submit-verify-h5",e.Stay="stay",e.ResetStay="reset-stay",e.StayReady="stay-ready",e.SetStay="set-stay",e.RouteChange="route-change",e.RouteReady="route-ready",e.Ab="ab",e.AbVar="ab-var",e.AbAllVars="ab-all-vars",e.AbConfig="ab-config",e.AbExternalVersion="ab-external-version",e.AbVersionChangeOn="ab-version-change-on",e.AbVersionChangeOff="ab-version-change-off",e.AbOpenLayer="ab-open-layer",e.AbCloseLayer="ab-close-layer",e.AbReady="ab-ready",e.AbComplete="ab-complete",e.AbTimeout="ab-timeout",e.Profile="profile",e.ProfileSet="profile-set",e.ProfileSetOnce="profile-set-once",e.ProfileUnset="profile-unset",e.ProfileIncrement="profile-increment",e.ProfileAppend="profile-append",e.ProfileClear="profile-clear",e.TrackDuration="track-duration",e.TrackDurationStart="track-duration-start",e.TrackDurationEnd="track-duration-end",e.TrackDurationPause="track-duration-pause",e.TrackDurationResume="tracl-duration-resume",e.Autotrack="autotrack",e.AutotrackReady="autotrack-ready"}(n||(n={})),function(e){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"}(i||(i={}));Date.now(),Number((""+Math.random()).slice(2,8));var s=function(e){return function(e,t,n){if("string"==typeof e&&"number"==typeof t&&"number"==typeof n){var i,r=[];n=n<=25?n:n%25;var o=String.fromCharCode(n+97);i=e.split(o);for(var a=0;a<i.length;a++){var s=parseInt(i[a],n);s=1*s^t;var c=String.fromCharCode(s);r.push(c)}return r.join("")}}(e,64,25)},c=function(e,t,n){var i=document.createElement("script");i.src=e,i.onerror=function(){n(e)},i.onload=function(){t()},document.getElementsByTagName("head")[0].appendChild(i)},l=function(e){var t=document.createElement("a");return t.href=e,t},h={},u=[];function f(e,t,n,i){var r=e&&e.source||window.opener||window.parent,o=e&&e.origin||i||"*",a={type:t,payload:n};r.postMessage(JSON.stringify(a),o)}function p(e,t){h[e]=h[e]||[],h[e].push(t)}function d(e){if(u.some((function(e){return"*"===e}))||u.some((function(t){return e.origin.indexOf(t)>-1}))){var t=e.data;if("string"==typeof e.data)try{t=JSON.parse(e.data)}catch(e){t=void 0}if(!t)return;var n=t.type,i=t.payload;h[n]&&h[n].forEach((function(t){"function"==typeof t&&t(e,i)}))}}var m="",v=!1;function b(e){var t=e.event,n=e.editorUrl;e.collectInstance,e.fromSession,v||(v=!0,c(n,(function(){f(t,"abEditorScriptloadSuccess")}),(function(){t&&f(t,"abEditorScriptloadError"),v=!1})))}function g(t,n){var i;window.TEAVisualEditor=window.TEAVisualEditor||{},(i=["*"]).length&&i.forEach((function(e){u.push(e)}));var r,a="";!function(t,n){var i=e({},t);i.filter&&delete i.filter,"object"==typeof i.autotrack&&i.autotrack.collect_url&&delete i.autotrack.collect_url,(window.opener||window.parent).postMessage({type:"tea:sdk:info",config:i,version:n},"*"),window.addEventListener("message",d,!1)}(n,"0.0.1");var s="";try{var c=window.performance.getEntriesByType("resource");if(c&&c.length&&(c.forEach((function(e){"script"===e.initiatorType&&e.name&&-1!==e.name.indexOf("collect")&&(s=e.name)})),s||document.currentScript&&(s=document.currentScript.src),s&&(r=s.split("/"))&&r.length)){a="https:/";for(var l=2;l<r.length&&l!==r.length-1;l++)a=a+"/"+r[l];a+="/visual-ab-core"}}catch(e){}p("tea:openVisualABEditor",(function(e){var i=e.data;if("string"==typeof e.data)try{i=JSON.parse(e.data)}catch(e){i=void 0}if(i){var r=i.lang;if(i.appId!==n.app_id)return f(e,"appIdError"),void console.error("abtest appid is not belong the page appid please check");var s=i.version;if(s)m=a?""+a+(s?"."+s:".1.0.1")+".js?query="+Date.now():o+"?query="+Date.now();else m=o+"?query="+Date.now();window.TEAVisualEditor.lang=r,window.TEAVisualEditor.__ab_domin=n.channel_domain||"",b({event:e,editorUrl:m,collectInstance:t})}}))}var y;!function(e){e[e.Var=0]="Var",e[e.All=1]="All"}(y||(y={}));var _=function(){function n(){this.fetchStatus="no",this.refreshFetchStatus="complete",this.versions=[],this.extVersions=[],this.mulilinkVersions=[],this.enable_multilink=!1,this.enable_ab_visual=!1,this.editMode=!1,this.callbacks=[],this.data=null,this.changeListener=new Map,this.readyStatus=!1,this.exposureCache=[]}return n.prototype.apply=function(e,t){var n=this;if(this.collect=e,this.config=t,this.config.enable_ab_test){var i=t.enable_multilink,o=t.ab_channel_domain,a=t.enable_ab_visual,c=t.ab_cross,l=t.ab_cookie_domain,h=t.disable_ab_reset,u=o||s(r[t.channel||"cn"]),f=e.adapters,p=f.storage,d=f.fetch;this.cacheStorgae=new p(!1),this.fetch=d,this.enable_multilink=i,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=u+"/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){h||"uuid"===e&&n.readyStatus&&(n.clearCache(),n.fetchAB())})),this.collect.on(m.AbVar,(function(e){var t=e.name,i=e.defaultValue,r=e.callback;n.getVar(t,i,r)})),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)}},n.prototype.ready=function(e){var t=this;if(this.collect.set(e),this.collect.hook._hooksCache.hasOwnProperty(e)){var n=this.collect.hook._hooksCache[e];if(!Object.keys(n).length)return;var i=function(e){n[e].length&&n[e].forEach((function(n){t.collect.hook.emit(e,n)}))};for(var r in n)i(r)}},n.prototype.loadMode=function(){var e,t,n=function(){try{return JSON.parse(atob(window.name))||void 0}catch(e){return}}(),i="";if(n){var r=n.scenario,o=n.href;r?(this.editMode=!0,i=r):!o||-1===o.indexOf("datatester")&&-1===o.indexOf("visual-editor")||(this.editMode=!0,i="visual-editor")}this.enable_ab_visual&&(g(this.collect,this.config),"visual-editor"===i)?this.collect.destoryInstace():this.enable_multilink&&(e=this.collect,t=this.config,window.TEAVisualEditor=window.TEAVisualEditor||{},window.TEAVisualEditor.appId=t.app_id,p("tea:openTesterEventInspector",(function(t){var n=t.data;if("string"==typeof t.data)try{n=JSON.parse(t.data)}catch(e){n=void 0}if(n){var i=n.referrer,r=n.lang,o=n.appId;window.TEAVisualEditor.__editor_ajax_domain=i||"",window.TEAVisualEditor.__ab_appId=o||"",window.TEAVisualEditor.lang=r||"",b({event:t,editorUrl:"https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/tester-event-inspector.js?query="+Date.now(),collectInstance:e})}})))},n.prototype.checkLocal=function(){var e=this.getABCache(),t=e.ab_version,n=e.ab_ext_version,i=e.ab_version_multilink,r=e.data,o=this.checkFromUrl();o?this.mulilinkVersions.push(o):this.mulilinkVersions=i||[],this.extVersions=n||[],this.versions=t||[],this.data=r;var a=this.versions.concat(this.extVersions);this.enable_multilink&&(a=a.concat(this.mulilinkVersions)),this.configVersions(a.join(","))},n.prototype.checkFromUrl=function(){var e=function(e){var t={};try{var n=l(e).search;(n=n.slice(1)).split("&").forEach((function(e){var n,i,r=e.split("=");r.length&&(n=r[0],i=r[1]);try{t[n]=decodeURIComponent(void 0===i?"":i)}catch(e){t[n]=i}}))}catch(e){}return t}(window.location.href);return e&&e.vid?e.vid:""},n.prototype.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)}))},n.prototype.configVersions=function(e){this.collect.configManager.setAbVersion(e)},n.prototype.getVar=function(e,t,n){if(!e)throw new Error("variable must not be empty");if(void 0===t)throw new Error("variable no default value");if("function"!=typeof n)throw new Error("callback must be a function");var i={name:e,defaultValue:t,callback:n,type:y.Var};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealVar(i,e):this.callbacks.push(i)},n.prototype.getRealVar=function(e,t){var n=e.name,r=e.defaultValue,o=e.callback,a=this.data;if(a){if(null!=(c=a[n])&&"[object Object]"==Object.prototype.toString.call(c)){var s=a[n].vid;return"$ab_url"===t?this.mulilinkVersions.includes(s)||this.mulilinkVersions.push(s):this.versions.includes(s)||this.versions.push(s),this.updateVersions(),this.fechEvent(s,t,r),o(a[n].val),void this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 曝光了实验"+n,level:"info",time:Date.now(),data:a[n]})}var c;this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getVar",level:"info",time:Date.now(),data:r}),o(r)}else o(r)},n.prototype.getAllVars=function(e){if("function"!=typeof e)throw new Error("callback must be a function");var t={callback:e,type:y.All};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealAllVars(t):this.callbacks.push(t)},n.prototype.getRealAllVars=function(e){(0,e.callback)(this.data?JSON.parse(JSON.stringify(this.data)):{}),this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getAllVars",level:"info",time:Date.now(),data:this.data})},n.prototype.fechEvent=function(e,t,n){try{if(this.config.disable_track_event)return;if(!e)return;var r=this.collect.configManager.get(),o=r.header,a=r.user,s=this.getABCache();if(s&&s.uuid&&s.uuid!==a.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?n:window.location.href}),local_time_ms:Date.now()};o.custom=JSON.stringify(o.custom);var l={events:[c],user:a,header:o};"$ab_url"===t&&window.navigator.sendBeacon?window.navigator.sendBeacon(this.reportUrl,JSON.stringify([l])):this.reportExposure(l)}catch(e){this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},n.prototype.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)},n.prototype.report=function(){var e=this;this.fetch(this.reportUrl,this.exposureCache,2e4),this.exposureCache.forEach((function(t){e.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:[t],code:200,status:"success"})})),this.exposureCache=[]},n.prototype.setExternalAbVersion=function(e){this.extVersions=[e],this.updateVersions()},n.prototype.getABconfig=function(e,t){var n=Object.keys(e);n&&n.length&&this.collect.configManager.set(e),this.fetchAB(t)},n.prototype.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.getItem(e)},n.prototype.set=function(e,t){this.ab_cross?this.cacheStorgae.setCookie(e,t,2592e6,this.ab_cookie_domain):this.cacheStorgae.setItem(e,t),this.collect.configManager.setAbCache(t)},n.prototype.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>=2592e6?(this.cacheStorgae.removeItem(this.abKey),null):e?t[e]:t},n.prototype.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)},n.prototype.setAbCache=function(e){var t=this.getABCache();t.data=this.data,t.uuid=e,t.timestamp=Date.now(),this.set(this.abKey,t)},n.prototype.clearCache=function(){this.refreshFetchStatus="ing",this.data={},this.extVersions=[],this.mulilinkVersions=[],this.versions=[]},n.prototype.openOverlayer=function(e){var n=this;if(function(){if(!document.getElementById(t)){var e="body { opacity: 0 !important; }",n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.id=t,i.type="text/css",i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e)),n.appendChild(i)}}(),e)var i=setTimeout((function(){n.closeOverlayer(),clearTimeout(i)}),e)},n.prototype.closeOverlayer=function(){var e;(e=document.getElementById(t))&&e.parentElement.removeChild(e)},n.prototype.fetchComplete=function(e,t){var n=this;if(e&&"[object Object]"==Object.prototype.toString.call(e)){this.data=e,this.setAbCache(t);var i=[];Object.keys(e).forEach((function(t){var n=e[t].vid;n&&i.push(n)})),this.versions=this.versions.filter((function(e){return i.includes(e)}));var r=e.$ab_url,o=e.$ab_modification;if(o&&o.val&&this.enable_ab_visual){if(this.collect.destroyInstance)return;this.getVar("$ab_modification",window.location.href,(function(){var e;e=o.val,window.TEAVisualEditor=window.TEAVisualEditor||{},window.TEAVisualEditor.__ab_config=e,c("https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/visual-ab-loader.js?query="+Date.now(),(function(){console.log("load visual render success")}),(function(){console.log("load visual render fail")})),n.closeOverlayer()}))}else if(r&&this.enable_multilink){this.mulilinkVersions=this.mulilinkVersions.filter((function(e){return i.includes(e)}));var a=r.val,s=r.vid;a&&s&&this.getVar("$ab_url",a,(function(){n.editMode||(a!==window.location.href?setTimeout((function(){if(!n.collect.destroyInstance){var e=""+a;e=-1===e.indexOf("http")?"https://"+e:e;var t=l(e).host;try{var i=new URL(e);t!==location.host?i.searchParams.append("vid",s):window.history.replaceState("","",e),window.location.href=i.href}catch(t){window.location.href=e}}}),100):n.closeOverlayer())}))}this.updateVersions()}else this.closeOverlayer();this.callbacks.forEach((function(e){return n[e.type===y.Var?"getRealVar":"getRealAllVars"](e,"")})),this.callbacks=[]},n.prototype.fetchAB=function(t){var n=this,r=this.collect.configManager.get(),o={header:e({aid:this.config.app_id},r.user||{},r.header||{},{ab_sdk_version:this.collect.configManager.getAbVersion(),ab_url:window.location.href})};this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,info:"SDK 发起AB实验请求",level:"info",logType:"fetch",time:Date.now(),data:o}),this.fetch(this.fetchUrl,o,this.config.ab_timeout||3e3,!1,(function(e){n.fetchStatus="complete",n.refreshFetchStatus="complete";var o=e.data;"success"===e.message?(n.fetchComplete(o,r.user.user_unique_id),t&&t(o)):(n.fetchComplete(null,r.user.user_unique_id),t&&t(null)),n.collect.emit(n.types.AbComplete,o),n.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求成功",level:"info",logType:"fetch",time:Date.now(),data:o})}),(function(){n.fetchStatus="complete",n.refreshFetchStatus="complete",n.fetchComplete(null,r.user.user_unique_id),t&&t(null),n.collect.emit(n.types.AbTimeout),n.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求网络异常",level:"error",logType:"fetch",time:Date.now()})}))},n.prototype.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 n=new RegExp(t,"g");e=e.replace(n,"")}catch(e){}return e},n}();export{_ as default};
|
package/es/plugin/autotrack.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=function(){return e=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)},t=function(e){return Array.isArray(e)};Date.now(),Number((""+Math.random()).slice(2,8));function n(e,t){if(void 0===t&&(t="list"),!e)return!1;if(t&&"list"===t){if(["LI","TR","DL"].includes(e.nodeName))return!0;if(e.dataset&&e.dataset.hasOwnProperty("teaIdx"))return!0;if(e.hasAttribute&&e.hasAttribute("data-tea-idx"))return!0}else{if(["A","BUTTON"].includes(e.nodeName))return!0;if(e.dataset&&e.dataset.hasOwnProperty("teaContainer"))return!0;if(e.hasAttribute&&e.hasAttribute("data-tea-container"))return!0;if(e.hasAttribute&&s(e,"ss"))return!0}return!1}var i=function(e,t){return!!s(e,t)};function o(e){for(var t=e;t&&!n(t,"container");){if("HTML"===t.nodeName||"BODY"===t.nodeName)return e;t=t.parentElement}return t||e}function r(e){var t="";return 3===e.nodeType?t=e.textContent.trim():e.dataset&&e.dataset.hasOwnProperty("teaTitle")||e.hasAttribute("ata-tea-title")?t=e.getAttribute("data-tea-title"):e.hasAttribute("title")?t=e.getAttribute("title"):"INPUT"===e.nodeName&&["button","submit"].includes(e.getAttribute("type"))?t=e.getAttribute("value"):"IMG"===e.nodeName&&e.getAttribute("alt")&&(t=e.getAttribute("alt")),t.slice(0,200)}var a=function(e,t){return e.hasAttribute?e.hasAttribute(t):e.attributes?!(!e.attributes[t]||!e.attributes[t].specified):void 0},s=function(e,n){if("string"==typeof n)return a(e,n);if(t(n)){for(var i=!1,o=0;o<n.length;o++){if(a(e,n[o])){i=!0;break}}return i}};var c=function(){function t(t,o,r){var a=this;this.clickEvent=function(e){(function(e,t){if(1!==e.nodeType)return!1;if(!t.svg&&function(e){if("svg"===e.tagName.toLowerCase())return!0;for(var t=e.parentElement,n=!1;t;)"svg"===t.tagName.toLowerCase()?(t=null,n=!0):t=t.parentElement;return n}(e))return!1;if(["HTML","BODY"].includes(e.tagName.toUpperCase()))return!1;var o=e;return!!("none"!==o.style.display&&(n(o,"container")||t.track_attr&&i(o,t.track_attr)||function(e){if(e.children.length){var t=e.children;return![].slice.call(t).some((function(e){return e.children.length>0}))}return!0}(o)))})(e.target,a.options)&&a.eventHandel({eventType:"dom",eventName:"click"},e)},this.changeEvent=function(e){a.eventHandel({eventType:"dom",eventName:"change"},e)},this.submitEvent=function(e){a.eventHandel({eventType:"dom",eventName:"submit"},e)},this.getPageViewEvent=function(t,n){n&&"pushState"===n&&a.eventHandel({eventType:"dom",eventName:"beat"},e({beat_type:0},t)),a.eventHandel({eventType:"dom",eventName:"page_view"},t)},this.getPageLoadEvent=function(e){a.eventHandel({eventType:"dom",eventName:"page_statistics"},{lcp:e})},this.config=r.getConfig().eventConfig,this.collect=o,this.options=t,this.beatTime=t.beat,this.statistics=!1}return t.prototype.init=function(e){this.eventHandel=e;var t=this.config.mode;this.addListener(t)},t.prototype.addListener=function(e){var t=this;if("proxy-capturing"===e&&(this.config.click&&window.document.addEventListener("click",this.clickEvent,!0),this.config.change&&window.document.addEventListener("change",this.changeEvent,!0),this.config.submit&&window.document.addEventListener("submit",this.submitEvent,!0),this.config.pv&&this.collect.on("route-change",(function(e){var n=e.config,i=e.name;t.getPageViewEvent(n,i)})),this.config.beat)){try{"complete"===document.readyState?this.beatEvent(this.beatTime):window.addEventListener("load",(function(){t.beatEvent(t.beatTime)}));var n=0,i=null;window.addEventListener("scroll",(function(){clearTimeout(i),i=setTimeout(o,500),n=document.documentElement.scrollTop||document.body.scrollTop}));var o=function(){(document.documentElement.scrollTop||document.body.scrollTop)==n&&t.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:1})}}catch(e){}try{var r=window.performance&&window.performance.getEntriesByType("paint");if(r&&r.length){var a=new PerformanceObserver((function(e){var n=e.getEntries(),i=n[n.length-1],o=i.renderTime||i.loadTime;t.statistics||(t.getPageLoadEvent(o),t.statistics=!0)}));a.observe({entryTypes:["largest-contentful-paint"]}),setTimeout((function(){t.statistics||(t.getPageLoadEvent(r[0].startTime||0),t.statistics=!0)}),2e3)}else this.getPageLoadEvent(0)}catch(e){this.getPageLoadEvent(0)}}},t.prototype.removeListener=function(){window.document.removeEventListener("click",this.clickEvent,!0),window.document.removeEventListener("change",this.changeEvent,!0),window.document.removeEventListener("submit",this.submitEvent,!0)},t.prototype.beatEvent=function(e){var t,n=this;try{var i;this.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:3}),this.beatTime&&(i=setInterval((function(){n.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:2})}),e)),t=function(){n.eventHandel({eventType:"dom",eventName:"beat",eventSend:"becon"},{beat_type:0}),n.beatTime&&clearInterval(i)},navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?window.addEventListener("pagehide",t,!1):window.addEventListener("beforeunload",t,!1)}catch(e){}},t}(),u={eventConfig:{mode:"proxy-capturing",submit:!1,click:!0,change:!1,pv:!0,beat:!0,hashTag:!1,impr:!1},scoutConfig:{mode:"xpath"}},d=function(){function e(e,t){this.config=e,this.config.eventConfig=Object.assign(this.config.eventConfig,t)}return e.prototype.getConfig=function(){return this.config},e.prototype.setConfig=function(e){return this.config=e},e}();function l(e){for(var t=[];null!==e.parentElement;)t.push(e),e=e.parentElement;var i=[],o=[];return t.forEach((function(e){var t=function(e){if(null===e)return{str:"",index:0};var t=0,i=e.parentElement;if(i)for(var o=i.children,r=0;r<o.length&&o[r]!==e;r++)o[r].nodeName===e.nodeName&&t++;return{str:[e.nodeName.toLowerCase(),n(e,"list")?"[]":""].join(""),index:t}}(e),r=t.str,a=t.index;i.unshift(r),o.unshift(a)})),{element_path:"/"+i.join("/"),positions:o}}function p(e,n,s,c){var u={},d=function(e){if(e){var t=e.getBoundingClientRect(),n=t.width,i=t.height;return{left:t.left,top:t.top,element_width:n,element_height:i}}}(n),p=function(e,t){void 0===e&&(e={}),void 0===t&&(t={});var n=e.clientX,i=e.clientY,o=t.left,r=t.top,a=n-o>=0?n-o:0,s=i-r>=0?i-r:0;return{touch_x:Math.floor(a),touch_y:Math.floor(s)}}(e,d),h=d.element_width,v=d.element_height,f=p.touch_x,g=p.touch_y,m=l(n),_=m.element_path,b=m.positions,y=function(e){var t=o(e),n=[];return function e(t){var i=r(t);if(i&&-1===n.indexOf(i)&&n.push(i),t.childNodes.length>0)for(var o=t.childNodes,a=0;a<o.length;a++)8!==o[a].nodeType&&e(o[a])}(t),n}(n),w=window.performance.timing.navigationStart,E=Date.now()-w,T=b.map((function(e){return""+e})),x=null;if(window.TEAVisualEditor.getOriginXpath&&(x=window.TEAVisualEditor.getOriginXpath({xpath:_,positions:T})),u.element_path=x&&x.xpath||_,u.positions=x&&x.positions||T,c&&!c.text&&(u.texts=y,u.element_title=function(e){var t=o(e),n="";return function e(t){var i=r(t);if(i&&(n+=i),t.childNodes.length>0)for(var o=t.childNodes,a=0;a<o.length;a++)3===o[a].nodeType&&e(o[a])}(t),n}(n)),u.element_id=n.getAttribute("id")||"",u.element_class_name=n.getAttribute("class")||"",u.element_type=n.nodeType,u.element_width=Math.floor(h),u.element_height=Math.floor(v),u.touch_x=f,u.touch_y=g,u.page_manual_key="",u.elememt_manual_key="",u.since_page_start_ms=E,u.page_start_ms=w,u.page_path=location.pathname,u.page_host=location.host,s.track_attr&&i(n,s.track_attr)){var A=function(e,n){var i={};if("string"==typeof n)a(e,n)&&(i.attrs=e.getAttribute(n));else if(t(n))for(var o=0;o<n.length;o++)a(e,n[o])&&(i[n[o]]=e.getAttribute(n[o]));return i}(n,s.track_attr);for(var k in A)u[k]=A[k]}var N=o(n);return"A"===N.tagName&&(u.href=N.getAttribute("href")),"IMG"===n.tagName&&(u.src=n.getAttribute("src")),u}var h=function(t,n,i,o,r){return e({event:t},p(n,i,o,r),{is_html:1,page_key:window.location.href,page_title:document.title})},v=function(){function t(e,t){this.ignore={text:!1},this.initConfig=e,this.options=t,this.eventName=t&&"tea"===t.custom?{click:"__bav_click",page:"__bav_page",beat:"__bav_beat",static:"__bav_page_statistics",exposure:"__bav_page_exposure"}:{click:"bav2b_click",page:"bav2b_page",beat:"bav2b_beat",static:"bav2b_page_statistics",exposure:"bav2b_exposure"},t&&!1===t.text&&(this.ignore.text=!0),t&&t.exposure&&t.exposure.eventName&&(this.eventName.exposure=t.exposure.eventName)}return t.prototype.handleEvent=function(t,n){try{if(function(e){for(var t=e;t&&t.parentNode;){if(t.hasAttribute("data-tea-ignore"))return!0;if("HTML"===t.nodeName||"body"===t.nodeName)return!1;t=t.parentNode}return!1}(t.target))return null;var i="bav2b_click";switch(n){case"click":return i=this.eventName.click,h(i,t,t.target,this.options,this.ignore);case"exposure":return i=this.eventName.exposure,h(i,t,t.target,this.options,this.ignore);case"change":return e({},h(i="bav2b_change",t,t.target,this.options),function(e,t){try{if("bav2b_change"===e)return t.hasAttribute("data-tea-track")?{value:t.value}:{}}catch(e){return{}}}(i,t.target));case"submit":return h(i="bav2b_submit",t,t.target,this.options)}}catch(e){return console.error(e),null}},t.prototype.handleViewEvent=function(e){e.event=this.eventName.page,e.page_title=document.title,e.page_total_width=window.innerWidth,e.page_total_height=window.innerHeight;try{var t=window.sessionStorage.getItem("_tea_cache_duration");if(t){var n=JSON.parse(t);e.refer_page_duration_ms=n?n.duration:""}e.scroll_width=document.documentElement.scrollLeft?document.documentElement.scrollLeft+window.innerWidth:window.innerWidth,e.scroll_height=document.documentElement.scrollTop?document.documentElement.scrollTop+window.innerHeight:window.innerHeight,e.page_start_ms=window.performance.timing.navigationStart}catch(e){console.log("page event error "+JSON.stringify(e))}return e},t.prototype.handleStatisticsEvent=function(e){var t={};t.event=this.eventName.static,t.is_html=1,t.page_key=location.href,t.refer_page_key=document.referrer||"",t.page_title=document.title,t.page_manual_key=this.initConfig.autotrack.page_manual_key||"",t.refer_page_manual_key="";try{var n=e.lcp,i=window.performance.timing,o=i.loadEventEnd-i.navigationStart;t.page_init_cost_ms=parseInt(n||(o>0?o:0)),t.page_start_ms=i.navigationStart}catch(e){console.log("page_statistics event error "+JSON.stringify(e))}return t},t.prototype.handleBeadtEvent=function(e){e.event=this.eventName.beat,e.page_key=window.location.href,e.is_html=1,e.page_title=document.title,e.page_manual_key=this.initConfig.autotrack.page_manual_key||"";try{e.page_viewport_width=window.innerWidth,e.page_viewport_height=window.innerHeight,e.page_total_width=document.documentElement.scrollWidth,e.page_total_height=document.documentElement.scrollHeight,e.scroll_width=document.documentElement.scrollLeft+window.innerWidth,e.scroll_height=document.documentElement.scrollTop+window.innerHeight,e.since_page_start_ms=Date.now()-window.performance.timing.navigationStart,e.page_start_ms=window.performance.timing.navigationStart}catch(e){console.log("beat event error "+JSON.stringify(e))}return e},t}(),f=function(){function e(e){this.collect=e,this.eventNameList=["report_click_event","report_change_event","report_submit_event","report_exposure_event","report_page_view_event","report_page_statistics_event","report_beat_event"]}return e.prototype.send=function(e,t){var n=e.eventSend,i=t.event;delete t.event,n&&"becon"===n?this.collect.beconEvent(i,t):this.collect.event(i,t)},e.prototype.get=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"GET"},t);fetch(e,n)},e.prototype.post=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"POST"},t);fetch(e,n)},e}(),g={},m=[];function _(e,t,n,i){var o=e&&e.source||window.opener||window.parent,r=e&&e.origin||i||"*",a={type:t,payload:n};o.postMessage(JSON.stringify(a),r)}function b(e,t){g[e]=g[e]||[],g[e].push(t)}function y(e){if(m.some((function(e){return"*"===e}))||m.some((function(t){return e.origin.indexOf(t)>-1}))){var t=e.data;if("string"==typeof e.data)try{t=JSON.parse(e.data)}catch(e){t=void 0}if(!t)return;var n=t.type,i=t.payload;g[n]&&g[n].forEach((function(t){"function"==typeof t&&t(e,i)}))}}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var w,E,T=(w=function(e,t){e.exports=function(){function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)e[i]=n[i]}return e}function t(n,i){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=e({},i,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var s in r)r[s]&&(a+="; "+s,!0!==r[s]&&(a+="="+r[s].split(";")[0]));return document.cookie=t+"="+n.write(o,t)+a}}function r(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],i={},o=0;o<t.length;o++){var r=t[o].split("="),a=r.slice(1).join("=");try{var s=decodeURIComponent(r[0]);if(i[s]=n.read(a,s),e===s)break}catch(e){}}return e?i[e]:i}}return Object.create({set:o,get:r,remove:function(t,n){o(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(i)},converter:{value:Object.freeze(n)}})}return t({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}()},w(E={exports:{}},E.exports),E.exports),x=T;function A(){try{var e=window.TEAVisualEditor.lang=window.TEAVisualEditor.lang||x.get("lang"),t=window.TEAVisualEditor.__editor_ajax_domain=window.TEAVisualEditor.__editor_ajax_domain||x.get("_TEA_VE_APIHOST"),n=window.TEAVisualEditor.__editor_verison=window.TEAVisualEditor.__editor_verison||x.get("_VISUAL_EDITOR_V"),i=window.TEAVisualEditor.__editor_url=window.TEAVisualEditor.__editor_url||x.get("_VISUAL_EDITOR_U"),o=+new Date,r=new Date(o+18e5);x.set("_TEA_VE_OPEN","1",{expires:r}),x.set("_TEA_VE_APIHOST",t,{expires:r}),x.set("_VISUAL_EDITOR_U",i,{expires:r}),x.set("lang",e,{expires:r}),x.set("_VISUAL_EDITOR_V",n||"",{expires:r})}catch(e){console.log("set cookie err")}}var k=!1;function N(e){var t,n,i,o,r=e.event,a=e.editorUrl,s=e.autoTrackInstance;k||(k=!0,t=a,n=function(){_(r,"editorScriptloadSuccess"),s.destroy()},i=function(){r&&_(r,"editorScriptloadError"),k=!1},(o=document.createElement("script")).src=t,o.onerror=function(){i(t)},o.onload=function(){n()},document.getElementsByTagName("head")[0].appendChild(o))}function O(t,n){window.TEAVisualEditor=window.TEAVisualEditor||{};var i="",o="https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/visual-editor-rangers.js?query="+Date.now();window.TEAVisualEditor.appId=n.app_id;var r,a,s,c=n.channel_domain,u="";if((r=["*"]).length&&r.forEach((function(e){m.push(e)})),c){var d,l="";try{var p=window.performance.getEntriesByType("resource");if(p&&p.length&&(p.forEach((function(e){"script"===e.initiatorType&&e.name&&-1!==e.name.indexOf("collect")&&(l=e.name)})),l||document.currentScript&&(l=document.currentScript.src),l&&(d=l.split("/"))&&d.length)){u="https:/";for(var h=2;h<d.length&&h!==d.length-1;h++)u=u+"/"+d[h];if(u&&u.indexOf("/5.0")){var v=u.split("/5.0");u=v[0]||u}}}catch(e){}}if(a="0.0.1",(s=e({},n)).filter&&delete s.filter,"object"==typeof s.autotrack&&s.autotrack.collect_url&&delete s.autotrack.collect_url,(window.opener||window.parent).postMessage({type:"tea:sdk:info",config:s,version:a},"*"),window.addEventListener("message",y,!1),"1"===x.get("_TEA_VE_OPEN")){var f=function(){var e=x.get("_TEA_VE_APIHOST");try{e=JSON.parse(e)}catch(e){}return e}(),g="";f&&(window.TEAVisualEditor.__editor_ajax_domain=f,g=x.get("_VISUAL_EDITOR_U")),N({event:null,editorUrl:g||o,autoTrackInstance:t}),A()}else try{b("tea:openVisualEditor",(function(e){var n=e.data;if("string"==typeof e.data)try{n=JSON.parse(e.data)}catch(e){n=void 0}if(n){var r=n.referrer,a=n.lang;if(r&&(window.TEAVisualEditor.__editor_ajax_domain=r),i=o,c){var s=n.version;i=u?""+u+(s?"/visual-editor-rangers-v"+s:"/visual-editor-rangers-v1.0.0")+".js":o,window.TEAVisualEditor.__editor_verison=s}window.TEAVisualEditor.__editor_url=i,window.TEAVisualEditor.lang=a,N({event:e,editorUrl:i,autoTrackInstance:t}),A()}})),window.TEAVisualEditor.openAutotrackEditor=function(){N({event:null,editorUrl:window.TEAVisualEditor.__editor_url,autoTrackInstance:t})}}catch(e){console.log("receive message error")}try{b("tea:openHeatMapCore",(function(e){N({event:e,editorUrl:"https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/heatmap-core.js?query="+Date.now(),autoTrackInstance:t})}))}catch(e){console.log("openHeatMapCore error")}}var S=function(){function e(e){this._instance=null,this._intersection=e,this._intersection&&this.init()}return e.prototype.init=function(){var e=this;MutationObserver?(this._instance=new MutationObserver((function(t){t.forEach((function(t){"attributes"===t.type&&e.attributeChangeObserve(t),"childList"===t.type&&e.modifyNodeObserve(t)}))})),this._instance.observe(document.body,{childList:!0,attributes:!0,subtree:!0,attributeOldValue:!1})):console.log("your browser cannot support MutationObserver")},e.prototype.attributeChangeObserve=function(e){e.target.hasAttribute("data-exposure")?this.exposureAdd(e,"mutation"):this.exposureRemove(e)},e.prototype.modifyNodeObserve=function(e){var t=this;Array.prototype.forEach.call(e.addedNodes,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t.exposureAdd(e,"intersect"),t.mapChild(e,t.exposureAdd)})),Array.prototype.forEach.call(e.removedNodes,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t.exposureRemove(e),t.mapChild(e,t.exposureRemove)}))},e.prototype.mapChild=function(e,t){var n=this;1===e.nodeType&&e.children.length&&Array.prototype.forEach.call(e.children,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t(e),n.mapChild(e,t)}))},e.prototype.exposureAdd=function(e,t){try{this._intersection&&this._intersection.exposureAdd(e,t)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},e.prototype.exposureRemove=function(e){try{this._intersection&&this._intersection.exposureRemove(e)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},e._exposure_observer=null,e}(),I=function(){function e(t,n){this.count=1,this.instance=this.buildObserver(),this.observeMap=e._observer_map,t.autotrack.exposure.ratio?this.Ratio=t.autotrack.exposure.ratio:0===t.autotrack.exposure.ratio?this.Ratio=0:this.Ratio=.5,this.EventHandle=n}return e.prototype.buildObserver=function(){var t=this;return e._observer_instance?(console.log("your browser cannot support IntersectionObserver"),null):(IntersectionObserver&&(e._observer_instance=new IntersectionObserver((function(e){e.forEach((function(e){t.observeMap.get(e.target._observeId)&&t.exposureEvent(e)}))}),{threshold:[.01,.25,.5,.75,1]})),e._observer_instance)},e.prototype.exposureAdd=function(e,t){var n=e;"mutation"===t&&(n=e.target);var i=n._observeId;if(i||this.observeMap.has(i)){if(!1===n.visible){var o=n.getBoundingClientRect(),r=o.top,a=o.left,s=o.right,c=o.bottom;r>=0&&c<=window.innerHeight&&a>=0&&s<=window.innerWidth&&(n.visible=!0,this.EventHandle({eventType:"dom",eventName:"exposure"},e))}}else n._observeId=this.count,n.visible=!1,this.observeMap.set(this.count,n),this.observe(n),this.count++},e.prototype.exposureRemove=function(e){this.observeMap.has(e._observeId)&&(this.observeMap.delete(e._observeId),this.unobserve(e))},e.prototype.exposureEvent=function(e){if(e.intersectionRatio>=this.Ratio&&e.isIntersecting){if("0"===e.target.style.opacity||"hidden"===e.target.style.visibility)return;if(!0===e.target.visible)return;e.target.visible=!0,this.EventHandle({eventType:"dom",eventName:"exposure"},e)}else e.target.visible=!1},e.prototype.observe=function(e){this.instance&&this.instance.observe(e)},e.prototype.unobserve=function(e){this.instance&&this.instance.unobserve(e)},e._observer_instance=null,e._observer_map=new Map,e}(),C=function(){function e(e,t){e.autotrack&&e.autotrack.exposure&&(this._intersection=new I(e,t),this._observer=new S(this._intersection),this._intersection&&this._observer?this.initObserver():console.log("your browser version cannot support exposure, please update~"))}return e.prototype.initObserver=function(){var e=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),(function(t){e._intersection.exposureAdd(t,"intersect")}))},e}(),L={hashTag:!1,impr:!1},V=function(){function e(){}return e.prototype.apply=function(e,t){if(this.autoTrackStart=!1,this.collect=e,this.config=t,t.autotrack){var n=e.Types;t.autotrack&&t.autotrack.collect_url&&!t.autotrack.collect_url()||(this.ready(n.Autotrack),this.collect.emit(n.AutotrackReady))}},e.prototype.ready=function(e){this.collect.set(e);var t=this.config.autotrack;t="object"==typeof t?t:{},t=Object.assign(L,t),this.destroyed=!1,this.options=t,this.Config=new d(u,this.options),this.Exposure=new C(this.config,this.handle.bind(this)),this.Listener=new c(t,this.collect,this.Config),this.EventHandle=new v(this.config,t),this.Request=new f(this.collect),this.autoTrackStart=!0,this.init(),O(this,this.config)},e.prototype.init=function(){this.Listener.init(this.handle.bind(this))},e.prototype.handle=function(e,t){"dom"===e.eventType&&this.handleDom(e,t)},e.prototype.handleDom=function(e,t){try{var n=e.eventName;if("click"===n||"exposure"===n||"change"===n||"submit"===n){var i=this.EventHandle.handleEvent(t,n);null!==i&&this.Request.send({eventType:"custom",eventName:"report_"+n+"_event",extra:{methods:"GET"}},i)}else if("page_view"===n||"page_statistics"===n){var o=void 0;o="page_view"===n?this.EventHandle.handleViewEvent(t):this.EventHandle.handleStatisticsEvent(t),this.Request.send({eventType:"custom",eventName:"report_${eventName}_event",extra:{methods:"GET"}},o)}else if("beat"===n){var r=this.EventHandle.handleBeadtEvent(t),a=e.eventSend;this.Request.send({eventType:"custom",eventName:"report_${eventName}_event",extra:{methods:"GET"},eventSend:a},r)}}catch(e){console.log("handel dom event error "+JSON.stringify(e))}},e.prototype.destroy=function(){if(!this.autoTrackStart)return console.warn("engine is undefined, make sure you have called autoTrack.start()");this.autoTrackStart=!1,this.Listener.removeListener()},e}();export{V as default};
|
package/es/plugin/duration.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t=function(){function t(){}return t.prototype.apply=function(t,a){var e=this;this.collector=t,this.config=a;var r=t.Types;t.on(r.TrackDurationStart,(function(t){e.trackStart(t)})),t.on(r.TrackDurationEnd,(function(t){e.trackEnd(t)})),t.on(r.TrackDurationPause,(function(t){e.trackPause(t)})),t.on(r.TrackDurationResume,(function(t){e.trackResume(t)})),this.Types=r,this.TrackMap=new Map,this.ready(r.TrackDuration)},t.prototype.ready=function(t){var a=this;if(this.collector.set(t),this.collector.hook._hooksCache.hasOwnProperty(t)){var e=this.collector.hook._hooksCache[t];if(!Object.keys(e).length)return;var r=function(t){e[t].length&&e[t].forEach((function(e){a.collector.hook.emit(t,e)}))};for(var o in e)r(o)}},t.prototype.trackStart=function(t){this.TrackMap.set(t,{startTime:Date.now(),isPause:!1,pauseTime:0,resumeTime:0})},t.prototype.trackEnd=function(t){var a=t.eventName,e=t.params;if(this.TrackMap.has(a)){var r=this.TrackMap.get(a),o=0;o=r.isPause?r.pauseTime-r.startTime:r.resumeTime?r.pauseTime-r.startTime+(Date.now()-r.resumeTime):Date.now()-r.startTime;var i=Object.assign(e,{event_duration:o});this.collector.event(a,i),this.cleanTrack(a)}},t.prototype.trackPause=function(t){if(this.TrackMap.has(t)){var a=this.TrackMap.get(t);a.isPause||(a.isPause=!0,a.pauseTime=Date.now(),this.TrackMap.set(t,a))}},t.prototype.trackResume=function(t){if(this.TrackMap.has(t)){var a=this.TrackMap.get(t);a.isPause&&(a.isPause=!1,a.resumeTime=Date.now(),this.TrackMap.set(t,a))}},t.prototype.cleanTrack=function(t){this.TrackMap.delete(t)},t}();export{t as default};
|
package/es/plugin/route.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e,t){var a="function"==typeof Symbol&&e[Symbol.iterator];if(!a)return e;var o,r,n=a.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(a=n.return)&&a.call(n)}finally{if(r)throw r.error}}return i}function t(){for(var t=[],a=0;a<arguments.length;a++)t=t.concat(e(arguments[a]));return t}var a,o;!function(e){e.Init="init",e.Config="config",e.Start="start",e.Ready="ready",e.TokenComplete="token-complete",e.TokenStorage="token-storage",e.TokenFetch="token-fetch",e.TokenError="token-error",e.ConfigUuid="config-uuid",e.ConfigWebId="config-webid",e.ConfigDomain="config-domain",e.CustomWebId="custom-webid",e.TokenChange="token-change",e.TokenReset="token-reset",e.ConfigTransform="config-transform",e.EnvTransform="env-transform",e.SessionReset="session-reset",e.SessionResetTime="session-reset-time",e.Event="event",e.Events="events",e.EventNow="event-now",e.CleanEvents="clean-events",e.BeconEvent="becon-event",e.SubmitBefore="submit-before",e.SubmitScuess="submit-scuess",e.SubmitAfter="submit-after",e.SubmitError="submit-error",e.SubmitVerify="submit-verify",e.SubmitVerifyH="submit-verify-h5",e.Stay="stay",e.ResetStay="reset-stay",e.StayReady="stay-ready",e.SetStay="set-stay",e.RouteChange="route-change",e.RouteReady="route-ready",e.Ab="ab",e.AbVar="ab-var",e.AbAllVars="ab-all-vars",e.AbConfig="ab-config",e.AbExternalVersion="ab-external-version",e.AbVersionChangeOn="ab-version-change-on",e.AbVersionChangeOff="ab-version-change-off",e.AbOpenLayer="ab-open-layer",e.AbCloseLayer="ab-close-layer",e.AbReady="ab-ready",e.AbComplete="ab-complete",e.AbTimeout="ab-timeout",e.Profile="profile",e.ProfileSet="profile-set",e.ProfileSetOnce="profile-set-once",e.ProfileUnset="profile-unset",e.ProfileIncrement="profile-increment",e.ProfileAppend="profile-append",e.ProfileClear="profile-clear",e.TrackDuration="track-duration",e.TrackDurationStart="track-duration-start",e.TrackDurationEnd="track-duration-end",e.TrackDurationPause="track-duration-pause",e.TrackDurationResume="tracl-duration-resume",e.Autotrack="autotrack",e.AutotrackReady="autotrack-ready"}(a||(a={})),function(e){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"}(o||(o={}));var r=function(){function e(){this.autotrack=!1,this.spa=!1,this.cache={},this.allowHash=!1}return e.prototype.apply=function(e,t){if(t.spa||t.autotrack){this.collect=e,this.config=t,this.appid=t.app_id,this.allowHash=t.allow_hash,this.fncArray=new Map,this.setKey(),this.setLocation(),this.hack(),this.init(),this.listener();var a=e.Types;e.emit(a.RouteReady)}},e.prototype.setKey=function(){var e=this.collect.adapters.storage;this.storage=new e(!1),this.cache_key="__tea_cache_refer_"+this.appid,this.cache={refer_key:location.href,refer_title:document.title||location.pathname,refer_manual_key:""},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.setItem(this.cache_key,this.cache)},e.prototype.hack=function(){var e=this,a=window.history.pushState;history.pushState=function(o){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];"function"==typeof history.onpushstate&&history.onpushstate({state:o});var i=a.call.apply(a,t([history,o],r));if(e.lastLocation!==location.href){var s=e.getPopStateChangeEventData();return e.lastLocation=location.href,e.sendPv(s,"pushState"),i}};var o=history.replaceState;history.replaceState=function(a){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];"function"==typeof history.onreplacestate&&history.onreplacestate({state:a});var i=o.call.apply(o,t([history,a],r));if(e.lastLocation!==location.href){var s=e.getPopStateChangeEventData();return e.lastLocation=location.href,e.sendPv(s),i}}},e.prototype.setLocation=function(){"undefined"!=typeof window&&(this.lastLocation=window.location.href)},e.prototype.init=function(){var e=this.getPopStateChangeEventData();this.collect.emit("route-change",{config:e,init:!0})},e.prototype.listener=function(){var e=this,t=null;window.addEventListener("hashchange",(function(a){if(e.lastLocation!==window.location.href&&(clearTimeout(t),e.allowHash)){e.lastLocation=window.location.href;var o=e.getPopStateChangeEventData();e.sendPv(o)}})),window.addEventListener("popstate",(function(a){e.lastLocation!==window.location.href&&(t=setTimeout((function(){e.lastLocation=window.location.href;var t=e.getPopStateChangeEventData();e.sendPv(t)}),10))}))},e.prototype.getPopStateChangeEventData=function(){var e=this.pageConfig();return e.is_back=0,e},e.prototype.pageConfig=function(){try{var e="",t=this.storage.getItem(this.cache_key)||{},a=!1;e=document.referrer?document.referrer:t&&t.refer_key||"";var r=this.storage.getItem("__tea_cache_first_"+this.appid);return a=!r||1!=r,{is_html:1,url:location.href,referrer:e,page_key:location.href,refer_page_key:e,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:""+a}}catch(e){return this.collect.emit(o.DEBUGGER_MESSAGE,{type:o.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),{}}},e.prototype.sendPv=function(e,t){this.collect.emit("route-change",{config:e,init:!1})},e}();export{r as default};
|
package/es/plugin/stay.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t=function(){return t=Object.assign||function(t){for(var e,i=1,a=arguments.length;i<a;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},t.apply(this,arguments)},e=function(t){return null!=t&&"[object Object]"==Object.prototype.toString.call(t)};Date.now(),Number((""+Math.random()).slice(2,8));var i,a,n=function(t){!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?window.addEventListener("pagehide",t,!1):window.addEventListener("beforeunload",t,!1)},o=function(){var t=0;return["hidden","msHidden","webkitHidden"].forEach((function(e){void 0!==document[e]&&(t=1)})),t},s=function(){function i(t,i){this.maxDuration=432e5,this.aliveDTime=6e4,this.options={aliveName:"predefine_page_alive",params:{}},this.collect=t,this.config=i,this.pageStartTime=Date.now(),this.sessionStartTime=this.pageStartTime,this.timerHandler=null,e(i.enable_stay_duration)&&(this.options=Object.assign(this.options,i.enable_stay_duration))}return i.prototype.setParams=function(t,e,i){this.set_path=t,this.set_url=i,this.set_title=e},i.prototype.enable=function(t,e,i){this.url_path=t,this.url=i,this.title=e,this.disableCallback=this.enablePageAlive()},i.prototype.disable=function(){this.disableCallback(),this.pageStartTime=Date.now()},i.prototype.sendEvent=function(e,i){void 0===i&&(i=!1);var a=i?this.aliveDTime:Date.now()-this.sessionStartTime;a<0||a>this.aliveDTime||Date.now()-this.pageStartTime>this.maxDuration||(this.collect.beconEvent(this.options.aliveName,t({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),duration:a,is_support_visibility_change:o(),startTime:this.sessionStartTime,hidden:document.visibilityState,leave:e},this.options.params)),this.sessionStartTime=Date.now())},i.prototype.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}},i.prototype.setUpTimer=function(){var t=this;return this.timerHandler&&clearInterval(this.timerHandler),setInterval((function(){Date.now()-t.sessionStartTime>t.aliveDTime&&t.sendEvent(!1,!0)}),1e3)},i.prototype.visibilitychange=function(){"hidden"===document.visibilityState?this.timerHandler&&(clearInterval(this.timerHandler),this.sendEvent(!1)):"visible"===document.visibilityState&&(this.sessionStartTime=Date.now(),this.timerHandler=this.setUpTimer())},i.prototype.beforeunload=function(){document.hidden||this.sendEvent(!0)},i.prototype.enablePageAlive=function(){var t=this;this.timerHandler=this.setUpTimer();var e=this.visibilitychange.bind(this),i=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",e),n(i),function(){t.beforeunload(),document.removeEventListener("visibilitychange",e),window.removeEventListener("beforeunload",i),window.removeEventListener("pagehide",i)}},i}(),r=function(){function i(t,i){var a=this;this.maxDuration=432e5,this.aliveDTime=6e4,this.options={closeName:"predefine_page_close",params:{}},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())},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=t,this.config=i,this.maxDuration=i.maxDuration||864e5,this.pageStartTime=Date.now(),e(i.enable_stay_duration)&&(this.options=Object.assign(this.options,i.enable_stay_duration)),this.resetData()}return i.prototype.setParams=function(t,e,i){this.set_path=t,this.set_url=i,this.set_title=e},i.prototype.enable=function(t,e,i){this.url_path=t,this.url=i,this.title=e,this.disableCallback=this.enablePageClose()},i.prototype.disable=function(){this.disableCallback()},i.prototype.resetData=function(){this.activeStartTime=void 0===this.activeStartTime?this.pageStartTime:Date.now(),this.activeEndTime=void 0,this.activeTimes=1,this.totalTime=0},i.prototype.sendEventPageClose=function(){var e=Date.now()-this.pageStartTime;this.totalTime<0||e<0||this.totalTime>=this.maxDuration||(this.collect.beconEvent(this.options.closeName,t({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),active_times:this.activeTimes,duration:this.totalTime,total_duration:e,is_support_visibility_change:o()},this.options.params)),this.pageStartTime=Date.now(),this.resetData())},i.prototype.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}},i.prototype.enablePageClose=function(){var t=this,e=this.visibilitychange.bind(this),i=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",e),n(i),function(){t.beforeunload(),document.removeEventListener("visibilitychange",e),window.removeEventListener("beforeunload",i),window.removeEventListener("pagehide",i)}},i}();!function(t){t.Init="init",t.Config="config",t.Start="start",t.Ready="ready",t.TokenComplete="token-complete",t.TokenStorage="token-storage",t.TokenFetch="token-fetch",t.TokenError="token-error",t.ConfigUuid="config-uuid",t.ConfigWebId="config-webid",t.ConfigDomain="config-domain",t.CustomWebId="custom-webid",t.TokenChange="token-change",t.TokenReset="token-reset",t.ConfigTransform="config-transform",t.EnvTransform="env-transform",t.SessionReset="session-reset",t.SessionResetTime="session-reset-time",t.Event="event",t.Events="events",t.EventNow="event-now",t.CleanEvents="clean-events",t.BeconEvent="becon-event",t.SubmitBefore="submit-before",t.SubmitScuess="submit-scuess",t.SubmitAfter="submit-after",t.SubmitError="submit-error",t.SubmitVerify="submit-verify",t.SubmitVerifyH="submit-verify-h5",t.Stay="stay",t.ResetStay="reset-stay",t.StayReady="stay-ready",t.SetStay="set-stay",t.RouteChange="route-change",t.RouteReady="route-ready",t.Ab="ab",t.AbVar="ab-var",t.AbAllVars="ab-all-vars",t.AbConfig="ab-config",t.AbExternalVersion="ab-external-version",t.AbVersionChangeOn="ab-version-change-on",t.AbVersionChangeOff="ab-version-change-off",t.AbOpenLayer="ab-open-layer",t.AbCloseLayer="ab-close-layer",t.AbReady="ab-ready",t.AbComplete="ab-complete",t.AbTimeout="ab-timeout",t.Profile="profile",t.ProfileSet="profile-set",t.ProfileSetOnce="profile-set-once",t.ProfileUnset="profile-unset",t.ProfileIncrement="profile-increment",t.ProfileAppend="profile-append",t.ProfileClear="profile-clear",t.TrackDuration="track-duration",t.TrackDurationStart="track-duration-start",t.TrackDurationEnd="track-duration-end",t.TrackDurationPause="track-duration-pause",t.TrackDurationResume="tracl-duration-resume",t.Autotrack="autotrack",t.AutotrackReady="autotrack-ready"}(i||(i={})),function(t){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"}(a||(a={}));var l=function(){function t(){}return t.prototype.apply=function(t,e){var i=this;if(this.collect=t,this.config=e,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,e),this.pageClose=new r(t,e);var a=this.collect.Types;this.collect.on(a.ResetStay,(function(t){var e=t.url_path,a=t.title,n=t.url;i.resetStayDuration(e,a,n)})),this.collect.on(a.RouteChange,(function(t){t.init||e.disable_route_report||i.resetStayDuration()})),this.collect.on(a.SetStay,(function(t){var e=t.url_path,a=t.title,n=t.url;i.setStayParmas(e,a,n)})),this.enable(this.url_path,this.title,this.url),this.ready(a.Stay),this.collect.emit(a.StayReady)}},t.prototype.ready=function(t){var e=this;if(this.collect.set(t),this.collect.hook._hooksCache.hasOwnProperty(t)){var i=this.collect.hook._hooksCache[t];if(!Object.keys(i).length)return;var a=function(t){i[t].length&&i[t].forEach((function(i){e.collect.hook.emit(t,i)}))};for(var n in i)a(n)}},t.prototype.enable=function(t,e,i){this.pageAlive.enable(t,e,i),this.pageClose.enable(t,e,i)},t.prototype.disable=function(){this.pageAlive.disable(),this.pageClose.disable()},t.prototype.setStayParmas=function(t,e,i){void 0===t&&(t=""),void 0===e&&(e=""),void 0===i&&(i=""),this.pageAlive.setParams(t,e,i),this.pageClose.setParams(t,e,i),this.collect.emit(a.DEBUGGER_MESSAGE,{type:a.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayParams",level:"info",time:Date.now(),data:{url_path:t,title:e,url:i}})},t.prototype.reset=function(t,e,i){this.disable(),this.enable(t,e,i)},t.prototype.resetStayDuration=function(t,e,i){this.reset(t,e,i),this.collect.emit(a.DEBUGGER_MESSAGE,{type:a.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayDuration",level:"info",time:Date.now(),data:{url_path:t,title:e,url:i}})},t}();export{l as default};
|
package/es/plugin/store.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t=function(){function t(){this.retryWaitTime=3e3,this.retryStatus=!1,this.retryCacheStatus=!1}return t.prototype.apply=function(t,e){var r=this;if(e.enable_storage&&!e.disable_storage&&(this.collect=t,this.config=e,!this.collect.destroyInstance)){var a=t.Types,n=t.adapters,o=n.storage,i=n.fetch;this.storage=new o(!1),this.fetch=i,this.eventUrl=this.collect.configManager.getUrl("event"),this.eventKey="__tea_cache_events_"+e.app_id,this.storageNum=e.storage_num||50,this.retryNum=e.retry_num||3,this.retryInterval=1e3,t.on(a.SubmitError,(function(t){"f_data"===t.type&&r.storeData(t)})),t.on(a.Ready,(function(){r.checkStorage()}))}},t.prototype.retryRightNow=function(t){var e=this;if(this.retryStatus)this.errorCache.push(t);else{var r=0;this.retryStatus=!0;var a=setInterval((function(){if(3===r)return e.storeData(e.errorCache),e.retryStatus=!1,void clearInterval(a);var n=t.eventData;e.fetchData(n,(function(){e.retryStatus=!1,clearInterval(a),e.retryCacheStatus&&e.errorCache.splice(0,1),e.errorCache.length&&(e.retryCacheStatus=!0,e.retryRightNow(e.errorCache[0]))}),(function(){r++}))}),this.retryInterval)}},t.prototype.storeData=function(t){var e=this.storage.getItem(this.eventKey),r=t.eventData;Object.keys(e).length!==this.storageNum&&(e[Date.now()]=r,this.storage.setItem(this.eventKey,e))},t.prototype.checkStorage=function(){var t=this;try{if(!window.navigator.onLine)return;var e=this.storage.getItem(this.eventKey);if(!e||!Object.keys(e).length)return;var r={events:[{event:"ontest",params:{app_id:this.config.app_id},local_time_ms:Date.now()}],user:{user_unique_id:this.collect.configManager.get("web_id")},header:{}};this.fetchData([r],(function(){var r=JSON.parse(JSON.stringify(e)),a=function(a){t.fetchData(e[a],(function(){delete r[a],t.storage.setItem(t.eventKey,r)}),(function(){}),!1)};for(var n in e)a(n)}),(function(){}),!0)}catch(t){console.warn("error check storage")}},t.prototype.fetchData=function(t,e,r,a){this.fetch(this.eventUrl,t,3e4,!1,(function(){e&&e()}),(function(){r&&r(),console.log("network error,compensate report failk")}),a&&!this.config.channel_domain?"566f58151b0ed37e":"")},t}();export{t as default};
|
package/lib/index-base.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=function(){return e=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var o in t=arguments[i])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var n,o,r=i.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=r.next()).done;)s.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(i=r.return)&&i.call(r)}finally{if(o)throw o.error}}return s}function i(){for(var e=[],i=0;i<arguments.length;i++)e=e.concat(t(arguments[i]));return e}var n,o=function(){function e(){this._hooks={},this._cache=[],this._hooksCache={}}return e.prototype.on=function(e,t){e&&t&&"function"==typeof t&&(this._hooks[e]||(this._hooks[e]=[]),this._hooks[e].push(t))},e.prototype.once=function(e,t){var i=this;if(e&&t&&"function"==typeof t){this.on(e,(function n(o){t(o),i.off(e,n)}))}},e.prototype.off=function(e,t){if(e&&this._hooks[e]&&this._hooks[e].length)if(t){var i=this._hooks[e].indexOf(t);-1!==i&&this._hooks[e].splice(i,1)}else this._hooks[e]=[]},e.prototype.emit=function(e,t,i){if(i){if(!e)return;-1!==this._cache.indexOf(i)?this._emit(e,t):(this._hooksCache.hasOwnProperty(i)||(this._hooksCache[i]={}),this._hooksCache[i].hasOwnProperty(e)||(this._hooksCache[i][e]=[]),this._hooksCache[i][e].push(t))}else this._emit(e,t)},e.prototype._emit=function(e,t){e&&this._hooks[e]&&this._hooks[e].length&&i(this._hooks[e]).forEach((function(e){try{e(t)}catch(e){}}))},e.prototype.set=function(e){e&&-1===this._cache.indexOf(e)&&this._cache.push(e)},e}(),r=function(e){return null!=e&&"[object Object]"==Object.prototype.toString.call(e)},s=function(e){return Array.isArray(e)},a=(n=+Date.now()+Number((""+Math.random()).slice(2,8)),function(){return n+=1}),c=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 r=String.fromCharCode(i+97);n=e.split(r);for(var s=0;s<n.length;s++){var a=parseInt(n[s],i);a=1*a^t;var c=String.fromCharCode(a);o.push(c)}return o.join("")}}(e,64,25)},h=function(e){!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?window.addEventListener("pagehide",e,!1):window.addEventListener("beforeunload",e,!1)},f=function(e){var t=document.createElement("a");return t.href=e,t},p=function(e){var t={};try{var i=f(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},l=function(e){for(var t=0,i=0,n=(e+="").length,o=0;o<n;o++)((t=31*t+e.charCodeAt(i++))>0x7fffffffffff||t<-0x800000000000)&&(t&=0xffffffffffff);return t<0&&(t+=0x7ffffffffffff),t};"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var u,d,g=(u=function(e,t){e.exports=function(){function e(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)e[n]=i[n]}return e}function t(i,n){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=e({},n,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in r)r[a]&&(s+="; "+a,!0!==r[a]&&(s+="="+r[a].split(";")[0]));return document.cookie=t+"="+i.write(o,t)+s}}function r(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],n={},o=0;o<t.length;o++){var r=t[o].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(n[a]=i.read(s,a),e===a)break}catch(e){}}return e?n[e]:n}}return Object.create({set:o,get:r,remove:function(t,i){o(t,"",e({},i,{expires:-1}))},withAttributes:function(i){return t(this.converter,e({},this.attributes,i))},withConverter:function(i){return t(e({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(i)}})}return t({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}()},u(d={exports:{}},d.exports),d.exports),_=g,m=function(){function e(){this.cache={}}return e.prototype.setItem=function(e,t){this.cache[e]=t},e.prototype.getItem=function(e){return this.cache[e]},e.prototype.removeItem=function(e){this.cache[e]=void 0},e.prototype.getCookie=function(e){this.getItem(e)},e.prototype.setCookie=function(e,t){this.setItem(e,t)},e}();var v,y,b={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{}},setItem:function(e,t){try{var i="string"==typeof t?t:JSON.stringify(t);localStorage.setItem(e,i)}catch(e){}},removeItem:function(e){try{localStorage.removeItem(e)}catch(e){}},getCookie:function(e,t){try{return _.get(e,{domain:t||document.domain})}catch(e){return""}},setCookie:function(e,t,i,n){try{var o=n||document.domain,r=+new Date+i;_.set(e,t,{expires:new Date(r),path:"/",domain:o})}catch(e){}},isSupportLS:function(){try{return localStorage.setItem("_ranger-test-key","hi"),localStorage.getItem("_ranger-test-key"),localStorage.removeItem("_ranger-test-key"),!0}catch(e){return!1}}()},E={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{}},setItem:function(e,t){try{var i="string"==typeof t?t:JSON.stringify(t);sessionStorage.setItem(e,i)}catch(e){}},removeItem:function(e){try{sessionStorage.removeItem(e)}catch(e){}},getCookie:function(e){this.getItem(e)},setCookie:function(e,t){this.setItem(e,t)},isSupportSession:function(){try{return sessionStorage.setItem("_ranger-test-key","hi"),sessionStorage.getItem("_ranger-test-key"),sessionStorage.removeItem("_ranger-test-key"),!0}catch(e){return!1}}()},S=function(){function e(e,t){this._storage=t&&"session"===t?E:!e&&b.isSupportLS?b:new m}return e.prototype.getItem=function(e){return this._storage.getItem(e)},e.prototype.setItem=function(e,t){this._storage.setItem(e,t)},e.prototype.getCookie=function(e,t){return this._storage.getCookie(e,t)},e.prototype.setCookie=function(e,t,i,n){this._storage.setCookie(e,t,i,n)},e.prototype.removeItem=function(e){this._storage.removeItem(e)},e}(),w=function(){function e(e,t,i){this.appid=e,this.domain=t,this.userAgent=window.navigator.userAgent,this.appVersion=window.navigator.appVersion,this.cookie_expire=i}return e.prototype.init=function(){var e=window.navigator.userAgent,t=window.navigator.language,i=document.referrer,n=i?f(i).hostname:"",o=p(window.location.href),r=/Mobile|htc|mini|Android|iP(ad|od|hone)/.test(this.appVersion)?"wap":"web";this.utm=function(e,t,i,n){var o=new S(!1),r=new S(!1,"session"),s=e?"_tea_utm_cache_"+e:"_tea_utm_cache",a=e?"_$utm_from_url_"+e:"_$utm_from_url",c={},h=["tr_shareuser","tr_admaster","tr_param1","tr_param2","tr_param3","tr_param4","$utm_from_url"],f={ad_id:Number(t.ad_id)||void 0,campaign_id:Number(t.campaign_id)||void 0,creative_id:Number(t.creative_id)||void 0,utm_source:t.utm_source,utm_medium:t.utm_medium,utm_campaign:t.utm_campaign,utm_term:t.utm_term,utm_content:t.utm_content,tr_shareuser:t.tr_shareuser,tr_admaster:t.tr_admaster,tr_param1:t.tr_param1,tr_param2:t.tr_param2,tr_param3:t.tr_param3,tr_param4:t.tr_param4};try{var p=!1;for(var l in f)f[l]&&(-1!==h.indexOf(l)?(c.hasOwnProperty("tracer_data")||(c.tracer_data={}),c.tracer_data[l]=f[l]):c[l]=f[l],p=!0);if(p)r.setItem(a,"1"),o.setCookie(s,JSON.stringify(c),n,i);else{var u=o.getCookie(s,i);u&&(c=JSON.parse(u))}r.getItem(a)&&(c.hasOwnProperty("tracer_data")||(c.tracer_data={}),c.tracer_data.$utm_from_url=1)}catch(e){return f}return c}(this.appid,o,this.domain,this.cookie_expire);var s=this.browser(),a=this.os();return{browser:s.browser,browser_version:s.browser_version,platform:r,os_name:a.os_name,os_version:a.os_version,userAgent:e,screen_width:window.screen&&window.screen.width,screen_height:window.screen&&window.screen.height,device_model:this.getDeviceModel(a.os_name),language:t,referrer:i,referrer_host:n,utm:this.utm,latest_data:this.last(i,n)}},e.prototype.last=function(e,t){var i="",n="",o="",r=location.hostname,s=!1;if(e&&t&&r!==t){i=e,n=t,s=!0;var a=p(e);a.keyword&&(o=a.keyword)}return{$latest_referrer:i,$latest_referrer_host:n,$latest_search_keyword:o,isLast:s}},e.prototype.browser=function(){var e,t,i="",n=""+parseFloat(this.appVersion),o=this.userAgent;return-1!==o.indexOf("Edge")||-1!==o.indexOf("Edg")?(i="Microsoft Edge",-1!==o.indexOf("Edge")?(e=o.indexOf("Edge"),n=o.substring(e+5)):(e=o.indexOf("Edg"),n=o.substring(e+4))):-1!==(e=o.indexOf("MSIE"))?(i="Microsoft Internet Explorer",n=o.substring(e+5)):-1!==(e=o.indexOf("Lark"))?(i="Lark",n=o.substring(e+5,e+11)):-1!==(e=o.indexOf("MetaSr"))?(i="sougoubrowser",n=o.substring(e+7,e+10)):-1!==o.indexOf("MQQBrowser")||-1!==o.indexOf("QQBrowser")?(i="qqbrowser",-1!==o.indexOf("MQQBrowser")?(e=o.indexOf("MQQBrowser"),n=o.substring(e+11,e+15)):-1!==o.indexOf("QQBrowser")&&(e=o.indexOf("QQBrowser"),n=o.substring(e+10,e+17))):-1!==o.indexOf("Chrome")?-1!==(e=o.indexOf("MicroMessenger"))?(i="weixin",n=o.substring(e+15,e+20)):-1!==(e=o.indexOf("360"))?(i="360browser",n=o.substring(o.indexOf("Chrome")+7)):-1!==o.indexOf("baidubrowser")||-1!==o.indexOf("BIDUBrowser")?(-1!==o.indexOf("baidubrowser")?(e=o.indexOf("baidubrowser"),n=o.substring(e+13,e+16)):-1!==o.indexOf("BIDUBrowser")&&(e=o.indexOf("BIDUBrowser"),n=o.substring(e+12,e+15)),i="baidubrowser"):-1!==(e=o.indexOf("xiaomi"))?-1!==o.indexOf("openlanguagexiaomi")?(i="openlanguage xiaomi",n=o.substring(e+7,e+13)):(i="xiaomi",n=o.substring(e-7,e-1)):-1!==(e=o.indexOf("TTWebView"))?(i="TTWebView",n=o.substring(e+10,e+23)):(-1!==(e=o.indexOf("Chrome"))||-1!==(e=o.indexOf("Chrome")))&&(i="Chrome",n=o.substring(e+7)):-1!==o.indexOf("Safari")?-1!==(e=o.indexOf("QQ"))?(i="qqbrowser",n=o.substring(e+10,e+16)):-1!==(e=o.indexOf("Safari"))&&(i="Safari",n=o.substring(e+7),-1!==(e=o.indexOf("Version"))&&(n=o.substring(e+8))):-1!==(e=o.indexOf("Firefox"))?(i="Firefox",n=o.substring(e+8)):-1!==(e=o.indexOf("MicroMessenger"))?(i="weixin",n=o.substring(e+15,e+20)):-1!==(e=o.indexOf("QQ"))?(i="qqbrowser",n=o.substring(e+3,e+8)):-1!==(e=o.indexOf("Opera"))&&(i="Opera",n=o.substring(e+6),-1!==(e=o.indexOf("Version"))&&(n=o.substring(e+8))),-1!==(t=n.indexOf(";"))&&(n=n.substring(0,t)),-1!==(t=n.indexOf(" "))&&(n=n.substring(0,t)),-1!==(t=n.indexOf(")"))&&(n=n.substring(0,t)),{browser:i,browser_version:n}},e.prototype.os=function(){for(var e="",t="",i=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0|Windows NT 10.1)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Android",r:/Android/},{s:"Sun OS",r:/SunOS/},{s:"Linux",r:/(Linux|X11)/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/}],n=0;n<i.length;n++){var o=i[n];if(o.r.test(this.userAgent)){"Mac OS X"===(e=o.s)&&this.isNewIpad()&&(e="iOS");break}}var r=function(e,t){var i=e.exec(t);return i&&i[1]?i[1]:""},s=function(e,t){var i=RegExp("(?:^|[^A-Z0-9-_]|[^A-Z0-9-]_|sprd-)(?:"+e+")","i").exec(t);return i?i.slice(1)[0]:""};/Windows/.test(e)&&(t=r(/Windows (.*)/,e),e="windows");var a,c;switch(e){case"Mac OS X":t=s("Mac[ +]OS[ +]X(?:[ /](?:Version )?(\\d+(?:[_\\.]\\d+)+))?",this.userAgent),e="mac";break;case"Android":a=this.userAgent,(c=r(/Android ([\.\_\d]+)/,a))||(c=r(/Android\/([\.\_\d]+)/,a)),t=c,e="android";break;case"iOS":t=this.isNewIpad()?s("Mac[ +]OS[ +]X(?:[ /](?:Version )?(\\d+(?:[_\\.]\\d+)+))?",this.userAgent):(t=/OS (\d+)_(\d+)_?(\d+)?/.exec(this.appVersion))?t[1]+"."+t[2]+"."+(0|t[3]):"",e="ios"}return{os_name:e,os_version:t}},e.prototype.getDeviceModel=function(e){var t="";try{if("android"===e)navigator.userAgent.split(";").forEach((function(e){e.indexOf("Build/")>-1&&(t=e.slice(0,e.indexOf("Build/")))}));else if("ios"===e||"mac"===e||"windows"===e)if(this.isNewIpad())t="iPad";else{var i=navigator.userAgent.replace("Mozilla/5.0 (",""),n=i.indexOf(";");t=i.slice(0,n)}}catch(e){return t.trim()}return t.trim()},e.prototype.isNewIpad=function(){return void 0!==this.userAgent&&"MacIntel"===navigator.platform&&"number"==typeof navigator.maxTouchPoints&&navigator.maxTouchPoints>1},e}(),k={cn:"1fz22z22z1nz21z4mz4bz4bz1kz1az21z4az24z1mz1jz1az1cz18z1nz1nz1jz1mz1ez4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz1kz1az21z4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz1kz1az21z4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"},D={cn:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"},A=function(){function e(e,t){this.collector=e,this.config=t,this.eventNameWhiteList=["__bav_page","__bav_beat","__bav_page_statistics","__bav_click","__bav_page_exposure","_be_active"],this.paramsNameWhiteList=["$inactive","$inline","$target_uuid_list","$source_uuid","$is_spider","$source_id","$is_first_time","$user_unique_id_type","_staging_flag"],this.regStr=new RegExp("^[a-zA-Z0-9][a-z0-9A-Z_.-]{1,255}$")}return e.prototype.checkVerify=function(e){var t=this;if(!e||!e.length)return!1;var i=e[0];if(!i)return!1;var n=i.events,o=i.header;if(!n||!n.length)return!1;var r=!0;return n.forEach((function(e){t.checkEventName(e.event)||(r=!1,e.checkEvent="事件名不能以 $ or __开头"),t.checkEventParams(e.params)||(r=!1,e.checkParams="属性名不能以 $ or __开头")})),this.checkEventParams(o)||(r=!1),r},e.prototype.checkEventName=function(e){return!!e&&this.calculate(e,"event")},e.prototype.checkEventParams=function(e){var t=e;"string"==typeof e&&(t=JSON.parse(t));var i=!0;if(!Object.keys(t).length)return i;for(var n in t){if(!this.calculate(n,"params")){i=!1;break}if("string"==typeof t[n]&&t[n].length>1024){console.warn("params: "+n+" can not over 1024 byte, please check;"),i=!1;break}}return i},e.prototype.calculate=function(e,t){return-1!==("event"===t?this.eventNameWhiteList:"params"===t?this.paramsNameWhiteList:[]).indexOf(e)||(!new RegExp("^\\$").test(e)&&!new RegExp("^__").test(e)||(console.warn(t+" name: "+e+" can not start with $ or __, pleace check;"),!1))},e}();!function(e){e.Init="init",e.Config="config",e.Start="start",e.Ready="ready",e.TokenComplete="token-complete",e.TokenStorage="token-storage",e.TokenFetch="token-fetch",e.TokenError="token-error",e.ConfigUuid="config-uuid",e.ConfigWebId="config-webid",e.ConfigDomain="config-domain",e.CustomWebId="custom-webid",e.TokenChange="token-change",e.TokenReset="token-reset",e.ConfigTransform="config-transform",e.EnvTransform="env-transform",e.SessionReset="session-reset",e.SessionResetTime="session-reset-time",e.Event="event",e.Events="events",e.EventNow="event-now",e.CleanEvents="clean-events",e.BeconEvent="becon-event",e.SubmitBefore="submit-before",e.SubmitScuess="submit-scuess",e.SubmitAfter="submit-after",e.SubmitError="submit-error",e.SubmitVerify="submit-verify",e.SubmitVerifyH="submit-verify-h5",e.Stay="stay",e.ResetStay="reset-stay",e.StayReady="stay-ready",e.SetStay="set-stay",e.RouteChange="route-change",e.RouteReady="route-ready",e.Ab="ab",e.AbVar="ab-var",e.AbAllVars="ab-all-vars",e.AbConfig="ab-config",e.AbExternalVersion="ab-external-version",e.AbVersionChangeOn="ab-version-change-on",e.AbVersionChangeOff="ab-version-change-off",e.AbOpenLayer="ab-open-layer",e.AbCloseLayer="ab-close-layer",e.AbReady="ab-ready",e.AbComplete="ab-complete",e.AbTimeout="ab-timeout",e.Profile="profile",e.ProfileSet="profile-set",e.ProfileSetOnce="profile-set-once",e.ProfileUnset="profile-unset",e.ProfileIncrement="profile-increment",e.ProfileAppend="profile-append",e.ProfileClear="profile-clear",e.TrackDuration="track-duration",e.TrackDurationStart="track-duration-start",e.TrackDurationEnd="track-duration-end",e.TrackDurationPause="track-duration-pause",e.TrackDurationResume="tracl-duration-resume",e.Autotrack="autotrack",e.AutotrackReady="autotrack-ready"}(v||(v={})),function(e){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"}(y||(y={}));var G=v,I=void 0,M=(new Date).getTimezoneOffset(),O=parseInt(""+-M/60,10),T=60*M,x=function(){function t(e,t){this.is_first_time=!0,this.configPersist=!1,this.initConfig=t,this.collect=e;var i=new w(t.app_id,t.cookie_domain||"",t.cookie_expire||7776e6).init();this.eventCheck=new A(e,t);var n="__tea_cache_first_"+t.app_id;this.configKey="__tea_cache_config_"+t.app_id,this.sessionStorage=new S(!1,"session"),this.localStorage=new S(!1,"local"),t.configPersist&&(this.configPersist=!0,this.storage=1===t.configPersist?this.sessionStorage:this.localStorage);var o=this.localStorage.getItem(n);o&&1==o?this.is_first_time=!1:(this.is_first_time=!0,this.localStorage.setItem(n,"1")),this.envInfo={user:{user_unique_id:I,user_type:I,user_id:I,user_is_auth:I,user_is_login:I,device_id:I,web_id:I,ip_addr_id:I,user_unique_id_type:I},header:{app_id:I,app_name:I,app_install_id:I,install_id:I,app_package:I,app_channel:I,app_version:I,ab_version:I,os_name:i.os_name,os_version:i.os_version,device_model:i.device_model,ab_client:I,traffic_type:I,client_ip:I,device_brand:I,os_api:I,access:I,language:i.language,region:I,app_language:I,app_region:I,creative_id:i.utm.creative_id,ad_id:i.utm.ad_id,campaign_id:i.utm.campaign_id,log_type:I,rnd:I,platform:i.platform,sdk_version:"0.0.1",sdk_lib:"js",province:I,city:I,timezone:O,tz_offset:T,tz_name:I,sim_region:I,carrier:I,resolution:i.screen_width+"x"+i.screen_height,browser:i.browser,browser_version:i.browser_version,referrer:i.referrer,referrer_host:i.referrer_host,width:i.screen_width,height:i.screen_height,screen_width:i.screen_width,screen_height:i.screen_height,utm_term:i.utm.utm_term,utm_content:i.utm.utm_content,utm_source:i.utm.utm_source,utm_medium:i.utm.utm_medium,utm_campaign:i.utm.utm_campaign,tracer_data:JSON.stringify(i.utm.tracer_data),custom:{},wechat_unionid:I,wechat_openid:I}},this.ab_version="",this.evtParams={},this.reportErrorCallback=function(){},this.isLast=!1,this.setCustom(i),this.initDomain(),this.initABData()}return t.prototype.initDomain=function(){var e=this.initConfig.channel_domain;if(e)this.domain=e;else{var t=this.initConfig.channel;this.domain=c(k[t])}},t.prototype.setDomain=function(e){this.domain=e},t.prototype.getDomain=function(){return this.domain},t.prototype.initABData=function(){var e="__tea_sdk_ab_version_"+this.initConfig.app_id,t=null;if(this.initConfig.ab_cross){var i=this.localStorage.getCookie(e,this.initConfig.ab_cookie_domain);t=i?JSON.parse(i):null}else t=this.localStorage.getItem(e);this.setAbCache(t)},t.prototype.setAbCache=function(e){this.ab_cache=e},t.prototype.getAbCache=function(){return this.ab_cache},t.prototype.setAbVersion=function(e){this.ab_version=e},t.prototype.getAbVersion=function(){return this.ab_version},t.prototype.getUrl=function(e){var t="";switch(e){case"event":t=this.initConfig.report_url||"/list";break;case"webid":t="/webid";break;case"tobid":t="/tobid"}var i="";return this.initConfig.caller&&(i="?sdk_version=0.0.1&sdk_name=web&app_id="+this.initConfig.app_id+"&caller="+this.initConfig.caller),""+this.getDomain()+t+i},t.prototype.setCustom=function(e){if(e&&e.latest_data&&e.latest_data.isLast)for(var t in delete e.latest_data.isLast,this.isLast=!0,e.latest_data)this.envInfo.header.custom[t]=e.latest_data[t]},t.prototype.set=function(t){var i=this;Object.keys(t).forEach((function(n){void 0!==t[n]&&null!==t[n]||i.delete(n);try{i.eventCheck.calculate(n,"config")}catch(e){}if("traffic_type"===n&&i.isLast&&(i.envInfo.header.custom.$latest_traffic_source_type=t[n]),"evtParams"===n)i.evtParams=e({},i.evtParams||{},t.evtParams||{});else if("_staging_flag"===n)i.evtParams=e({},i.evtParams||{},{_staging_flag:t._staging_flag});else if("reportErrorCallback"===n&&"function"==typeof t[n])i.reportErrorCallback=t[n];else{var o="",r="";if(n.indexOf(".")>-1){var s=n.split(".");o=s[0],r=s[1]}o?"user"===o||"header"===o?i.envInfo[o][r]=t[n]:i.envInfo.header.custom[r]=t[n]:Object.hasOwnProperty.call(i.envInfo.user,n)?["user_type","ip_addr_id"].indexOf(n)>-1?i.envInfo.user[n]=t[n]?Number(t[n]):t[n]:["user_id","web_id","user_unique_id","user_unique_id_type"].indexOf(n)>-1?i.envInfo.user[n]=t[n]?String(t[n]):t[n]:["user_is_auth","user_is_login"].indexOf(n)>-1?i.envInfo.user[n]=Boolean(t[n]):"device_id"===n&&(i.envInfo.user[n]=t[n]):Object.hasOwnProperty.call(i.envInfo.header,n)?i.envInfo.header[n]=t[n]:i.envInfo.header.custom[n]=t[n]}}))},t.prototype.get=function(e){try{return e?"evtParams"===e?this.evtParams:"reportErrorCallback"===e?this[e]:Object.hasOwnProperty.call(this.envInfo.user,e)?this.envInfo.user[e]:Object.hasOwnProperty.call(this.envInfo.header,e)?this.envInfo.header[e]:JSON.parse(JSON.stringify(this.envInfo[e])):JSON.parse(JSON.stringify(this.envInfo))}catch(e){console.log("get config stringify error "),this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},t.prototype.setStore=function(e){try{if(!this.configPersist)return;var t=this.storage.getItem(this.configKey)||{};if(t&&Object.keys(e).length){var i=Object.assign(e,t);this.storage.setItem(this.configKey,i)}}catch(e){console.log("setStore error"),this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},t.prototype.getStore=function(){try{if(!this.configPersist)return null;var e=this.storage.getItem(this.configKey)||{};return e&&Object.keys(e).length?e:null}catch(e){return this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),null}},t.prototype.delete=function(e){try{if(!this.configPersist)return;var t=this.storage.getItem(this.configKey)||{};t&&Object.hasOwnProperty.call(t,e)&&(delete t[e],this.storage.setItem(this.configKey,t))}catch(e){this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),console.log("delete error")}},t}(),C=function(){function e(e,t){this.isLog=t||!1,this.name=e||""}return e.prototype.info=function(e){this.isLog&&console.log("%c %s","color: yellow; background-color: black;","[instance: "+this.name+"] "+e)},e.prototype.warn=function(e){this.isLog&&console.warn("%c %s","color: yellow; background-color: black;","[instance: "+this.name+"] "+e)},e.prototype.error=function(e){this.isLog&&console.error("[instance: "+this.name+"] "+e)},e.prototype.throw=function(e){throw this.error(this.name),new Error(e)},e}(),R=function(){function e(e,t){this.native=e.enable_native||e["evitaN".split("").reverse().join("")],this.os=t.get("os_name")}var t=e.prototype;return t.bridgeInject=function(){try{return!!this.native&&(AppLogBridge?(console.log("AppLogBridge is injected"),!0):(console.log("AppLogBridge is not inject"),!1))}catch(e){return console.log("AppLogBridge is not inject"),!1}},t.bridgeReady=function(){var e=this;return new Promise((function(t,i){try{e.bridgeInject()?AppLogBridge.hasStarted((function(e){console.log("AppLogBridge is started? : "+e),e?t(!0):i(!1)})):i(!1)}catch(e){console.log("AppLogBridge, error:"+JSON.stringify(e.stack)),i(!1)}}))},t.setNativeAppId=function(e){try{AppLogBridge.setNativeAppId(JSON.stringify(e)),console.log("change bridge appid, event report with appid: "+e)}catch(e){console.error("setNativeAppId error")}},t.setConfig=function(e){var t=this;try{Object.keys(e).forEach((function(i){"user_unique_id"===i?t.setUserUniqueId(e[i]):e[i]?t.addHeaderInfo(i,e[i]):t.removeHeaderInfo(i)}))}catch(e){console.error("setConfig error")}},t.setUserUniqueId=function(e){try{AppLogBridge.setUserUniqueId(e)}catch(e){console.error("setUserUniqueId error")}},t.addHeaderInfo=function(e,t){try{AppLogBridge.addHeaderInfo(e,t)}catch(e){console.error("addHeaderInfo error")}},t.setHeaderInfo=function(e){try{AppLogBridge.setHeaderInfo(JSON.stringify(e))}catch(e){console.error("setHeaderInfo error")}},t.removeHeaderInfo=function(e){try{AppLogBridge.removeHeaderInfo(e)}catch(e){console.error("removeHeaderInfo error")}},t.reportPv=function(e){this.onEventV3("predefine_pageview",e)},t.onEventV3=function(e,t){try{AppLogBridge.onEventV3(e,t)}catch(e){console.error("onEventV3 error")}},t.profileSet=function(e){try{AppLogBridge.profileSet(e)}catch(e){console.error("profileSet error")}},t.profileSetOnce=function(e){try{AppLogBridge.profileSetOnce(e)}catch(e){console.error("profileSetOnce error")}},t.profileIncrement=function(e){try{AppLogBridge.profileIncrement(e)}catch(e){console.error("profileIncrement error")}},t.profileUnset=function(e){try{AppLogBridge.profileUnset(e)}catch(e){console.error("profileUnset error")}},t.profileAppend=function(e){try{AppLogBridge.profileAppend(e)}catch(e){console.error("profileAppend error")}},t.setExternalAbVersion=function(e){try{AppLogBridge.setExternalAbVersion(e)}catch(e){console.error("setExternalAbVersion error")}},t.getVar=function(e,t,i){try{"android"===this.os?i(AppLogBridge.getABTestConfigValueForKey(e,t)):AppLogBridge.getABTestConfigValueForKey(e,t,(function(e){i(e)}))}catch(e){console.error("getVar error"),i(t)}},t.getAllVars=function(e){try{"android"===this.os?e(AppLogBridge.getAllAbTestConfigs()):AppLogBridge.getAllAbTestConfigs((function(t){e(t)}))}catch(t){console.error("getAllVars error"),e(null)}},t.getAbSdkVersion=function(e){try{"android"===this.os?e(AppLogBridge.getAbSdkVersion()):AppLogBridge.getAbSdkVersion((function(t){e(t)}))}catch(t){console.error("getAbSdkVersion error"),e("")}},e}(),z=500,B=5005;function U(e,t,i,n,o,r,s,a,c){try{var h=new XMLHttpRequest,f=a||"POST";h.open(f,""+e,!0),h.setRequestHeader("Content-Type","application/json; charset=utf-8"),s&&h.setRequestHeader("X-MCS-AppKey",""+s),n&&(h.withCredentials=!0),i&&(h.timeout=i,h.ontimeout=function(){r&&r(t,B)}),h.onload=function(){if(o){var e=null;if(h.responseText){try{e=JSON.parse(h.responseText)}catch(t){e={}}o(e,t)}}},h.onerror=function(){h.abort(),r&&r(t,z)},c?h.send(t):h.send(JSON.stringify(t))}catch(e){}}var N=4001,P=4e3,V=4002,K=4003,L=function(e,t,i,n){try{var o=e.match(/\/v\d\//),r="";r=o?o[0]:-1!==e.indexOf("/v1/")?"/v1/":"/v2/";var s=e.split(r)[0];if(!s)return void n(e,t,N);t.forEach((function(o){var r=function(e){var t="";for(var i in e)e.hasOwnProperty(i)&&void 0!==e[i]&&(t+="&"+i+"="+encodeURIComponent(JSON.stringify(e[i])));return"&"===t[0]?t.slice(1):t}(o),a=new Image(1,1);a.onload=function(){a=null,i&&i()},a.onerror=function(){a=null,n&&n(e,t,P)},a.src=s+"/gif?"+r}))}catch(i){n&&n(e,t,V,i.message)}},q=function(e,t,i,n,o,r,s,a){var c=window.navigator.userAgent;if(-1===window.navigator.appName.indexOf("Microsoft Internet Explorer")||-1===c.indexOf("MSIE 8.0")&&-1===c.indexOf("MSIE 9.0")){if(s)return window.navigator&&window.navigator.sendBeacon?void(window.navigator.sendBeacon(e,JSON.stringify(t))?o():r(e,t,K)):void L(e,t,o,r)}else L(e,t,o,r);U(e,t,i,n,o,r,"","",a)},j=function(){function t(){this.eventLimit=50,this.eventCache=[],this.beconEventCache=[]}return t.prototype.apply=function(e,t){var i=this;this.collect=e,this.config=t,this.configManager=e.configManager,this.cacheStorgae=new S(!0),this.localStorage=new S(!1),this.eventCheck=new A(e,t),this.maxReport=t.max_report||20,this.reportTime=t.reportTime||30,this.timeout=t.timeout||1e5,this.reportUrl=this.configManager.getUrl("event"),this.eventKey="__tea_cache_events_"+this.configManager.get("app_id"),this.beconKey="__tea_cache_events_becon_"+this.configManager.get("app_id"),this.abKey="__tea_sdk_ab_version_"+this.configManager.get("app_id"),this.collect.on(G.Ready,(function(){i.reportAll(!1)})),this.collect.on(G.ConfigDomain,(function(){i.reportUrl=i.configManager.getUrl("event")})),this.collect.on(G.Event,(function(e){i.event(e)})),this.collect.on(G.BeconEvent,(function(e){i.beconEvent(e)})),this.collect.on(G.CleanEvents,(function(){i.reportAll(!1)})),this.linster()},t.prototype.linster=function(){var e=this;window.addEventListener("unload",(function(){e.reportAll(!0)}),!1),h((function(){e.reportAll(!0)})),document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState&&e.reportAll(!0)}),!1)},t.prototype.reportAll=function(e){this.report(e),this.reportBecon()},t.prototype.event=function(e){var t=this;try{var n=i(e,this.cacheStorgae.getItem(this.eventKey)||[]);if(this.cacheStorgae.setItem(this.eventKey,n),this.reportTimeout&&clearTimeout(this.reportTimeout),n.length>=this.maxReport)this.report(!1);else{var o=this.reportTime;this.reportTimeout=setTimeout((function(){t.report(!1),t.reportTimeout=null}),o)}}catch(e){this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},t.prototype.beconEvent=function(e){var t=i(e,this.cacheStorgae.getItem(this.beconKey)||[]);this.cacheStorgae.setItem(this.beconKey,t),this.collect.destroyInstance||this.collect.tokenManager.getReady()&&this.collect.sdkReady&&(this.cacheStorgae.removeItem(this.beconKey),this.send(this.split(this.merge(t)),!0))},t.prototype.reportBecon=function(){var e=this.cacheStorgae.getItem(this.beconKey)||[];e&&e.length&&(this.cacheStorgae.removeItem(this.beconKey),this.send(this.split(this.merge(e)),!0))},t.prototype.report=function(e){if(!this.collect.destroyInstance&&this.collect.tokenManager.getReady()&&this.collect.sdkReady){var t=this.cacheStorgae.getItem(this.eventKey)||[];t.length&&(this.cacheStorgae.removeItem(this.eventKey),this.sliceEvent(t,e))}},t.prototype.sliceEvent=function(e,t){if(e.length>this.eventLimit)for(var i=0;i<e.length;i+=this.eventLimit){var n;n=e.slice(i,i+this.eventLimit);var o=this.split(this.merge(n));this.send(o,t)}else{o=this.split(this.merge(e));this.send(o,t)}},t.prototype.merge=function(t,i){var n=this,o=this.configManager.get(),r=o.header,s=o.user;r.custom=JSON.stringify(r.custom);var a=this.configManager.get("evtParams"),c=this.configManager.get("user_unique_id_type"),h=t.map((function(t){try{Object.keys(a).length&&!i&&(t.params=e({},a,t.params)),c&&(t.params.$user_unique_id_type=c);var o=n.configManager.getAbCache(),r=n.configManager.getAbVersion();return r&&o&&(n.config.disable_ab_reset||o.uuid===s.user_unique_id)&&(t.ab_sdk_version=r),t.session_id=n.collect.sessionManager.getSessionId(),t.params=JSON.stringify(t.params),t}catch(e){return n.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),t}})),f=[];if(!Object.keys(s).length)return console.warn("user info error,cant report"),f;var p=JSON.parse(JSON.stringify({events:h,user:s,header:r}));return p.local_time=Math.floor(Date.now()/1e3),p.verbose=1,p.user_unique_type=this.config.enable_ttwebid?this.config.user_unique_type:void 0,f.push(p),f},t.prototype.split=function(e){return e=e.map((function(e){var t=[];return t.push(e),t}))},t.prototype.send=function(e,t){var i=this;e.length&&e.forEach((function(e){try{var n=JSON.parse(JSON.stringify(e));i.config.filter&&((n=i.config.filter(n))||console.warn("filter must return data !!")),i.collect.eventFilter&&n&&((n=i.collect.eventFilter(n))||console.warn("filterEvent api must return data !!"));var o=n||e,r=JSON.parse(JSON.stringify(o));if(i.eventCheck.checkVerify(r),!o.length)return;i.collect.emit(G.SubmitBefore,o),i.collect.emit(G.SubmitVerify,o),q(i.reportUrl,o,i.timeout,!1,(function(e,t){e&&0!==e.e?(i.collect.emit(G.SubmitError,{type:"f_data",eventData:t,errorCode:e.e,response:e}),i.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_EVENT,info:"埋点上报失败",time:Date.now(),data:r,code:e.e,failType:"数据异常",status:"fail"})):(i.collect.emit(G.SubmitScuess,{eventData:t,res:e}),i.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:r,code:200,status:"success"}))}),(function(e,t){i.configManager.get("reportErrorCallback")(e,t),i.collect.emit(G.SubmitError,{type:"f_net",eventData:e,errorCode:t}),i.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_EVENT,info:"埋点上报网络异常",time:Date.now(),data:r,code:t,failType:"网络异常",status:"fail"})}),t,!1),i.eventCheck.checkVerify(o),i.collect.emit(G.SubmitVerify,o),i.collect.emit(G.SubmitVerifyH,o),i.collect.emit(G.SubmitAfter,o)}catch(e){console.warn("something error, "+JSON.stringify(e.stack)),i.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}}))},t}(),W=function e(t){return t?(t^16*Math.random()>>t/4).toString(10):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e)},J=function(){return W().replace(/-/g,"").slice(0,19)},H=function(){function e(){this.cacheToken={},this.enableCookie=!1,this.enable_ttwebid=!1,this.enableCustomWebid=!1}return e.prototype.apply=function(e,t){var i=this;this.collect=e,this.config=t,this.configManager=this.collect.configManager,this.storage=new S(!1),this.tokenKey="__tea_cache_tokens_"+t.app_id,this.enable_ttwebid=t.enable_ttwebid,this.enableCustomWebid=t.enable_custom_webid,this.collect.on(G.ConfigUuid,(function(e){i.setUuid(e)})),this.collect.on(G.ConfigWebId,(function(e){i.setWebId(e)})),this.enableCookie=t.cross_subdomain,this.expiresTime=t.cookie_expire||6048e5,this.cookieDomain=t.cookie_domain||"",this.checkStorage()},e.prototype.checkStorage=function(){var e=this;if(this.enableCookie){var t=this.storage.getCookie(this.tokenKey,this.cookieDomain);this.cacheToken=t&&"string"==typeof t?JSON.parse(t):{}}else this.cacheToken=this.storage.getItem(this.tokenKey)||{};this.tokenType=this.cacheToken&&this.cacheToken._type_?this.cacheToken._type_:"default","custom"!==this.tokenType||this.enableCustomWebid?this.enableCustomWebid?this.collect.on(G.CustomWebId,(function(){e.tokenReady=!0,e.collect.emit(G.TokenComplete)})):this.checkEnv()||(this.enable_ttwebid?this.completeTtWid(this.cacheToken):this.check()):this.remoteWebid()},e.prototype.check=function(){this.cacheToken&&this.cacheToken.web_id?this.complete(this.cacheToken):this.config.disable_webid?this.complete({web_id:J(),user_unique_id:this.configManager.get("user_unique_id")||J()}):this.remoteWebid()},e.prototype.checkEnv=function(){var e=window.navigator.userAgent;if(-1!==e.indexOf("miniProgram")||-1!==e.indexOf("MiniProgram")){var t=p(window.location.href);return!(!t||!t.Web_ID)&&(this.complete({web_id:""+t.Web_ID,user_unique_id:this.configManager.get("user_unique_id")||""+t.Web_ID}),!0)}return!1},e.prototype.remoteWebid=function(){var e=this,t=this.configManager.getUrl("webid"),i={app_key:this.config.app_key,app_id:this.config.app_id,url:location.href,user_agent:window.navigator.userAgent,referer:document.referrer,user_unique_id:""};this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 发起WEBID请求",logType:"fetch",level:"info",time:Date.now(),data:i});var n=J();U(t,i,3e5,!1,(function(t){var i;t&&0===t.e?(i=t.web_id,e.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"WEBID请求成功",logType:"fetch",level:"info",time:Date.now(),data:t})):(i=n,e.collect.configManager.set({localWebId:n}),e.collect.emit(G.TokenError),e.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"WEBID请求返回值异常",logType:"fetch",level:"warn",time:Date.now(),data:t}),e.collect.logger.warn("appid: "+e.config.app_id+" get webid error, use local webid~")),e.complete({web_id:e.configManager.get("web_id")||i,user_unique_id:e.configManager.get("user_unique_id")||i})}),(function(){e.complete({web_id:e.configManager.get("web_id")||n,user_unique_id:e.configManager.get("user_unique_id")||n}),e.collect.configManager.set({localWebId:n}),e.collect.emit(G.TokenError),e.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"WEBID请求网络异常",logType:"fetch",level:"error",time:Date.now(),data:null}),e.collect.logger.warn("appid: "+e.config.app_id+", get webid error, use local webid~")}))},e.prototype.complete=function(e){var t=e.web_id,i=e.user_unique_id;if(!t&&!i)return this.collect.emit(G.TokenError),void console.warn("token error");e.timestamp=Date.now(),this.collect.configManager.set({web_id:t,user_unique_id:i}),this.setStorage(e),this.tokenReady=!0,this.collect.emit(G.TokenComplete)},e.prototype.completeTtWid=function(e){var t=e.user_unique_id||"",i=this.configManager.get("user_unique_id");this.configManager.set({user_unique_id:i||t}),this.setStorage(e),this.tokenReady=!0,this.collect.emit(G.TokenComplete)},e.prototype.setUuid=function(e){if(e&&-1===["null","undefined","Null","None"].indexOf(e)){var t=String(e),i=this.configManager.get("user_unique_id"),n=this.cacheToken&&this.cacheToken.user_unique_id;if(t===i&&t===n)return;this.configManager.set({user_unique_id:t}),this.cacheToken||(this.cacheToken={}),this.cacheToken.user_unique_id=t,this.cacheToken.timestamp=Date.now(),this.setStorage(this.cacheToken),this.collect.emit(G.TokenChange,"uuid"),this.collect.emit(G.SessionReset)}else this.clearUuid()},e.prototype.clearUuid=function(){this.config.enable_ttwebid||this.configManager.get("web_id")&&(this.configManager.set({user_unique_id:this.configManager.get("web_id")}),this.cacheToken&&this.cacheToken.web_id&&(this.cacheToken.user_unique_id=this.cacheToken.web_id,this.cacheToken.timestamp=Date.now(),this.setStorage(this.cacheToken)),this.collect.emit(G.TokenReset))},e.prototype.setWebId=function(e){if(e&&!this.config.enable_ttwebid){this.cacheToken&&this.cacheToken.web_id?this.cacheToken.web_id!==e&&(this.cacheToken.user_unique_id=this.cacheToken.web_id===this.cacheToken.user_unique_id?e:this.cacheToken.user_unique_id,this.cacheToken.web_id=e):(this.cacheToken={},this.cacheToken.web_id=e,this.cacheToken.user_unique_id=e),this.cacheToken.timestamp=Date.now();var t=this.configManager.get("web_id"),i=this.configManager.get("user_unique_id");i&&i!==t||(this.configManager.set({user_unique_id:e}),this.collect.emit(G.TokenChange,"uuid")),t!==e&&(this.configManager.set({web_id:e}),this.collect.emit(G.TokenChange,"webid")),this.setStorage(this.cacheToken)}},e.prototype.setStorage=function(e){e._type_=this.enableCustomWebid?"custom":"default",delete e["diss".split("").reverse().join("")],this.enableCookie||this.enable_ttwebid?this.storage.setCookie(this.tokenKey,e,this.expiresTime,this.cookieDomain):this.storage.setItem(this.tokenKey,e),this.cacheToken=e},e.prototype.getReady=function(){return this.tokenReady},e.prototype.getTobId=function(){var e=this,t=this.configManager.getUrl("tobid");return new Promise((function(i){U(t,{app_id:e.config.app_id,user_unique_id:e.configManager.get("user_unique_id"),web_id:e.configManager.get("web_id"),user_unique_id_type:e.configManager.get("user_unique_id_type")},3e4,e.enable_ttwebid,(function(e){e&&0===e.e?i(e.tobid):i("")}),(function(){i("")}))}))},e}(),$=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))},F=function(){function e(){}return e.prototype.apply=function(e,t){var i=this;this.collect=e,this.storage=new S(!1,"session"),this.sessionKey="__tea_session_id_"+t.app_id,this.expireTime=t.expireTime||18e5,this.disableSession=t.disable_session,this.disableSession||(this.setSessionId(),this.collect.on(G.SessionReset,(function(){i.resetSessionId()})),this.collect.on(G.SessionResetTime,(function(){i.updateSessionIdTime()})))},e.prototype.updateSessionIdTime=function(){var e=this.storage.getItem(this.sessionKey);if(e&&e.sessionId){var t=e.timestamp;Date.now()-t>this.expireTime?e={sessionId:$(),timestamp:Date.now()}:e.timestamp=Date.now(),this.storage.setItem(this.sessionKey,e),this.resetExpTime()}},e.prototype.setSessionId=function(){var e=this,t=this.storage.getItem(this.sessionKey);t&&t.sessionId?t.timestamp=Date.now():t={sessionId:$(),timestamp:Date.now()},this.storage.setItem(this.sessionKey,t),this.sessionExp=setInterval((function(){e.checkEXp()}),this.expireTime)},e.prototype.getSessionId=function(){var e=this.storage.getItem(this.sessionKey);return this.disableSession?"":e&&e.sessionId?e.sessionId:""},e.prototype.resetExpTime=function(){var e=this;this.sessionExp&&(clearInterval(this.sessionExp),this.sessionExp=setInterval((function(){e.checkEXp()}),this.expireTime))},e.prototype.resetSessionId=function(){var e={sessionId:$(),timestamp:Date.now()};this.storage.setItem(this.sessionKey,e)},e.prototype.checkEXp=function(){var e=this.storage.getItem(this.sessionKey);e&&e.sessionId&&(Date.now()-e.timestamp+30>=this.expireTime&&(e={sessionId:$(),timestamp:Date.now()},this.storage.setItem(this.sessionKey,e)))},e}(),Q=function(){function e(e,t){this.devToolReady=!1,this.devToolOrigin="*",this.sendAlready=!1,this.collect=e,this.config=t,this.app_id=t.app_id,this.filterEvent=["__bav_page","__bav_beat","__bav_page_statistics","__bav_click","__bav_page_exposure","bav2b_page","bav2b_beat","bav2b_page_statistics","bav2b_click","bav2b_page_exposure","_be_active","predefine_pageview","__profile_set","__profile_set_once","__profile_increment","__profile_unset","__profile_append","predefine_page_alive","predefine_page_close","abtest_exposure"],this.load()}return e.prototype.loadScript=function(e){try{var t=document.createElement("script");t.src=e,t.onerror=function(){console.log("load DevTool render fail")},t.onload=function(){console.log("load DevTool render success")},document.getElementsByTagName("body")[0].appendChild(t)}catch(e){console.log("devTool load fail, "+e.message)}},e.prototype.load=function(){try{this.loadBaseInfo(),this.loadHook();var e=p(window.location.href);if(!e.open_devtool_web||parseInt(e.app_id)!==this.app_id)return;this.addLintener(),this.loadDebuggerModule(),this.loadDevTool()}catch(e){console.log("debug fail, "+e.message)}},e.prototype.loadDevTool=function(){this.loadScript("https://lf3-cdn-tos.bytescm.com/obj/static/log-sdk/collect/devtool/debug-web.js")},e.prototype.loadBaseInfo=function(){var e=this;this.info=[{title:"基本信息",type:1,infoName:{app_id:this.config.app_id,channel:this.config.channel,"上报域名":this.collect.configManager.getDomain(),"SDK版本":"0.0.1","SDK引入方式":"npm"}},{title:"用户信息",type:2,infoName:{uuid:this.collect.configManager.get("user").user_unique_id||"",web_id:this.collect.configManager.get("user").web_id||"",ssid:"点击获取SSID"}},{title:"公共参数信息",type:2,infoName:{"浏览器":this.collect.configManager.get("browser"),"浏览器版本":this.collect.configManager.get("browser_version"),"平台":this.collect.configManager.get("platform"),"设备型号":this.collect.configManager.get("device_model"),"操作系统":this.collect.configManager.get("os_name"),"操作系统版本":this.collect.configManager.get("os_version"),"屏幕分辨率":this.collect.configManager.get("os_version"),"来源":this.collect.configManager.get("referrer"),"自定义信息":""}},{title:"配置信息",type:3,infoName:{"全埋点":!!this.config.autotrack,"停留时长":!!this.config.enable_stay_duration}},{title:"A/B配置信息",type:4,infoName:{"A/B实验":!!this.config.enable_ab_test}},{title:"客户端信息",type:3,infoName:{"打通开关":!!this.config.Native}}],this.log=[],this.event=[],this.collect.on(G.Ready,(function(){e.info[1].infoName.uuid=e.collect.configManager.get("user").user_unique_id,e.info[1].infoName.web_id=e.collect.configManager.get("user").web_id,e.info[2].infoName["自定义信息"]=JSON.stringify(e.collect.configManager.get("custom")),e.config.enable_ab_test&&(e.info[4].infoName["已曝光VID"]=e.collect.configManager.getAbVersion(),e.info[4].infoName["A/B域名"]=e.config.ab_channel_domain||c(D[e.config.channel]),e.info[4].infoName["全部配置"]=e.collect.configManager.getAbData()),e.config.Native&&(e.info[5].infoName["是否打通"]=!!e.collect.bridgeReport)}))},e.prototype.loadHook=function(){var e=this;this.collect.on(y.DEBUGGER_MESSAGE,(function(t){switch(t.type){case y.DEBUGGER_MESSAGE_SDK:var i={time:t.time,type:t.logType||"sdk",level:t.level,name:t.info,show:!0,levelShow:!0,needDesc:!!t.data};return t.data&&(i.desc={content:JSON.stringify(t.data)}),e.updateLog(i),t.secType&&"AB"===t.secType?(e.info[4].infoName["已曝光VID"]=e.collect.configManager.getAbVersion(),e.info[4].infoName["全部配置"]=e.collect.configManager.getAbData()):"USER"===t.secType&&(e.info[1].infoName.uuid=e.collect.configManager.get("user").user_unique_id,e.info[1].infoName.web_id=e.collect.configManager.get("user").web_id),void e.updateInfo();case y.DEBUGGER_MESSAGE_EVENT:if(t.data&&t.data.length){var n=t.data[0],o=n.events;if(!o.length)return;o.forEach((function(i){i.checkShow=!0,i.searchShow=!0,i.success=t.status,i.type=-1!==e.filterEvent.indexOf(i.event)?"sdk":"cus",i.type=e.collect.bridgeReport?"bridge":i.type,i.info="","fail"===t.status&&(i.info={message:"code: "+t.code+", msg: "+t.failType})})),e.updateEvent(n)}return}}))},e.prototype.addLintener=function(){var e=this;window.addEventListener("message",(function(t){if(t&&t.data&&"devtool:web:ready"===t.data.type){if(e.devToolOrigin=t.origin,e.devToolReady=!0,e.sendAlready)return;console.log("inittttt"),e.sendData("devtool:web:init",{info:e.info,log:e.log,event:e.event}),e.sendAlready=!0}t&&t.data&&"devtool:web:ssid"===t.data.type&&e.collect.getToken((function(t){e.info[1].infoName.ssid=t.tobid,e.updateInfo()}))}))},e.prototype.sendData=function(e,t){try{var i={type:e,payload:t};(window.opener||window.parent).postMessage(i,this.devToolOrigin)}catch(e){}},e.prototype.updateInfo=function(){this.devToolReady&&this.sendData("devtool:web:info",this.info)},e.prototype.updateLog=function(e){this.devToolReady?this.sendData("devtool:web:log",e):this.log.push(e)},e.prototype.updateEvent=function(e){this.devToolReady?this.sendData("devtool:web:event",e):this.event.push(e)},e.prototype.loadDebuggerModule=function(){var e=document.head||document.getElementsByTagName("head")[0],t=document.createElement("style");t.appendChild(document.createTextNode("#debugger-applog-web {\n position: fixed;\n width: 90px;\n height: 30px;\n background: #23c243;\n border-radius: 6px;\n color: #fff;\n font-size: 12px;\n bottom: 5%;\n right: 10%;\n text-align: center;\n line-height: 30px;\n cursor: pointer;\n z-index:100;\n }")),e.appendChild(t);var i=document.createElement("div");i.innerHTML='<div id="debugger-applog-web" class="debugger-applog-web">AppLog调试</div>';var n=document.createElement("div");n.innerHTML='<div id="debugger-container" class="debugger-container"></div>',document.getElementsByTagName("body")[0].appendChild(i),document.getElementsByTagName("body")[0].appendChild(n),document.getElementById("debugger-applog-web").addEventListener("click",(function(){(window.opener||window.parent).postMessage({type:"devtool:web:open-draw"},location.origin)}))},e}(),X=function(){function t(e){this.disableAutoPageView=!1,this.bridgeReport=!1,this.staging=!1,this.pluginInstances=[],this.sended=!1,this.started=!1,this.destroyInstance=!1,this.adapters={},this.sdkReady=!1,this.name=e,this.hook=new o,this.logger=new C(e),this.remotePlugin=new Map,this.Types=G,this.adapters.fetch=U,this.adapters.storage=S}return t.usePlugin=function(e,i,n){if(i){for(var o=!1,r=0,s=t.plugins.length;r<s;r++){if(t.plugins[r].name===i){t.plugins[r].plugin=e,t.plugins[r].options=n||{},o=!0;break}}o||t.plugins.push({name:i,plugin:e,options:n})}else t.plugins.push({plugin:e})},t.prototype.init=function(e){var i,n=this;this.inited?console.log("init can be call only one time"):e&&r(e)?e.app_id&&("number"==typeof(i=e.app_id)&&!isNaN(i))?!e.app_key||function(e){return"string"==typeof e}(e.app_key)?(e.channel_domain||-1!==["cn","sg","va"].indexOf(e.channel)||(console.warn("channel must be `cn`, `sg`,`va` !!!"),e.channel="cn"),this.inited=!0,this.logger=new C(this.name,e.log),this.configManager=new x(this,e),this.appBridge=new R(e,this.configManager),this.bridgeReport=this.appBridge.bridgeInject(),this.debugger=new Q(this,e),this.initConfig=e,this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 执行INIT",data:e,level:"info",time:Date.now()}),e.disable_auto_pv&&(this.disableAutoPageView=!0),this.bridgeReport||(this.configManager.set({app_id:e.app_id}),this.eventManager=new j,this.tokenManager=new H,this.sessionManager=new F,Promise.all([new Promise((function(e){n.once(G.TokenComplete,(function(){e(!0)}))})),new Promise((function(e){n.once(G.Start,(function(){e(!0)}))}))]).then((function(){try{t.plugins.reduce((function(e,t){var i=t.plugin,o=t.options,r=Object.assign(n.initConfig,o),s=new i;return s.apply(n,r),e.push(s),e}),n.pluginInstances)}catch(e){console.log("load plugin error, "+e.message),n.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}n.sdkReady=!0,n.emit(G.Ready),n.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 初始化完成",time:Date.now(),level:"info",data:n.configManager.get("user")}),n.logger.info("appid: "+e.app_id+", userInfo:"+JSON.stringify(n.configManager.get("user"))),n.logger.info("appid: "+e.app_id+", sdk is ready, version is 0.0.1, you can report now !!!");try{(window.opener||window.parent).postMessage("[tea-sdk]ready","*")}catch(e){n.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}n.pageView(),n.on(G.TokenChange,(function(t){"webid"===t&&n.pageView(),n.logger.info("appid: "+e.app_id+" token change, new userInfo:"+JSON.stringify(n.configManager.get("user"))),n.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 设置了用户信息",time:Date.now(),secType:"USER",level:"info",data:n.configManager.get("user")})})),n.on(G.TokenReset,(function(){n.logger.info("appid: "+e.app_id+" token reset, new userInfo:"+JSON.stringify(n.configManager.get("user"))),n.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 重置了用户信息",time:Date.now(),secType:"USER",level:"info",data:n.configManager.get("user")})})),n.on(G.RouteChange,(function(t){t.init||e.disable_route_report||n.pageView()}))})),this.tokenManager.apply(this,e),this.eventManager.apply(this,e),this.sessionManager.apply(this,e),this.emit(G.Init))):console.warn("app_key param is error, must be string, please check!"):console.warn("app_id param is error, must be number, please check!"):console.warn("init params error,please check")},t.prototype.config=function(t){if(this.inited)if(t&&r(t))if(this.bridgeReport)this.appBridge.setConfig(t);else{t._staging_flag&&1===t._staging_flag&&(this.staging=!0),t.disable_auto_pv&&(this.disableAutoPageView=!0,delete t.disable_auto_pv);var i=e({},t);if(this.initConfig&&this.initConfig.configPersist){var n=this.configManager.getStore();n&&(i=Object.assign(n,t)),this.configManager.setStore(t)}i.web_id,i.user_unique_id;var o=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(i,["web_id","user_unique_id"]);i.hasOwnProperty("web_id")&&this.emit(G.ConfigWebId,i.web_id),i.hasOwnProperty("user_unique_id")&&this.emit(G.ConfigUuid,i.user_unique_id),this.configManager.set(o),this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 执行CONFIG",level:"info",time:Date.now(),data:i})}else this.logger.warn("config params is error, please check");else this.logger.warn("config must be use after function init")},t.prototype.setDomain=function(e){this.configManager&&this.configManager.setDomain(e),this.emit(G.ConfigDomain)},t.prototype.getConfig=function(e){return this.configManager.get(e)},t.prototype.send=function(){this.start()},t.prototype.start=function(){this.inited&&!this.sended&&(this.sended=!0,this.emit(G.Start),this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 执行START",level:"info",time:Date.now()}),this.bridgeReport&&(this.pageView(),this.emit(G.Ready)))},t.prototype.event=function(e,t){var i=this;try{if(this.initConfig&&this.initConfig.disable_track_event)return;var n=[];Array.isArray(e)?e.forEach((function(e){n.push(i.processEvent(e[0],e[1]||{}))})):n.push(this.processEvent(e,t)),this.bridgeReport?n.forEach((function(e){var t=e.event,n=e.params;i.appBridge.onEventV3(t,JSON.stringify(n))})):n.length&&(this.emit(G.Event,n),this.emit(G.SessionResetTime))}catch(e){this.logger.warn("something error, please check"),this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},t.prototype.beconEvent=function(e,t){if(!this.initConfig||!this.initConfig.disable_track_event)if(Array.isArray(e))console.warn("beconEvent not support batch report, please check");else{var i=[];i.push(this.processEvent(e,t||{})),i.length&&(this.emit(G.BeconEvent,i),this.emit(G.SessionResetTime))}},t.prototype.processEvent=function(e,t){void 0===t&&(t={});try{var i=e;/^event\./.test(e)&&(i=e.slice(6));var n=t;"object"!=typeof n&&(n={}),n.profile?delete n.profile:n.event_index=a();var o=void 0;return n.local_ms?(o=n.local_ms,delete n.local_ms):o=+new Date,{event:i,params:n,local_time_ms:o,is_bav:this.initConfig&&this.initConfig.autotrack?1:0}}catch(i){return this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:i.message}),{event:e,params:t}}},t.prototype.filterEvent=function(e){this.eventFilter=e},t.prototype.on=function(e,t){this.hook.on(e,t)},t.prototype.once=function(e,t){this.hook.once(e,t)},t.prototype.off=function(e,t){this.hook.off(e,t)},t.prototype.emit=function(e,t,i){this.hook.emit(e,t,i)},t.prototype.set=function(e){this.hook.set(e)},t.prototype.pageView=function(){this.disableAutoPageView||this.predefinePageView()},t.prototype.predefinePageView=function(t){void 0===t&&(t={});var i={title:document.title||location.pathname,url:location.href,url_path:location.pathname,time:Date.now(),referrer:window.document.referrer,$is_first_time:""+this.configManager.is_first_time},n=e({},i,t);this.event("predefine_pageview",n)},t.prototype.clearEventCache=function(){this.emit(G.CleanEvents)},t.prototype.setWebIDviaUnionID=function(e){if(e){var t=l(e);this.config({web_id:""+t,wechat_unionid:e}),this.emit(G.CustomWebId)}},t.prototype.setWebIDviaOpenID=function(e){if(e){var t=l(e);this.config({web_id:""+t,wechat_openid:e}),this.emit(G.CustomWebId)}},t.prototype.setNativeAppId=function(e){this.bridgeReport&&this.appBridge.setNativeAppId(e)},t.prototype.resetStayDuration=function(e,t,i){void 0===e&&(e=""),void 0===t&&(t=""),void 0===i&&(i=""),this.emit(G.ResetStay,{url_path:e,title:t,url:i},G.Stay)},t.prototype.resetStayParams=function(e,t,i){void 0===e&&(e=""),void 0===t&&(t=""),void 0===i&&(i=""),this.emit(G.SetStay,{url_path:e,title:t,url:i},G.Stay)},t.prototype.getToken=function(t,i){var n=this,o=!1,r=function(i){if(!o){o=!0;var r=n.configManager.get().user;return i&&(r.tobid=i,r["diss".split("").reverse().join("")]=i),t(e({},r))}},s=function(){n.tokenManager.getTobId().then((function(e){r(e)}))};this.sdkReady?s():(i&&setTimeout((function(){r()}),i),this.on(G.Ready,(function(){s()})))},t.prototype.startTrackEvent=function(e){e&&this.emit(G.TrackDurationStart,e,G.TrackDuration)},t.prototype.endTrackEvent=function(e,t){void 0===t&&(t={}),e&&this.emit(G.TrackDurationEnd,{eventName:e,params:t},G.TrackDuration)},t.prototype.pauseTrackEvent=function(e){e&&this.emit(G.TrackDurationPause,e,G.TrackDuration)},t.prototype.resumeTrackEvent=function(e){e&&this.emit(G.TrackDurationResume,e,G.TrackDuration)},t.prototype.profileSet=function(e){this.bridgeReport?this.appBridge.profileSet(JSON.stringify(e)):this.emit(G.ProfileSet,e,G.Profile),this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileSet",level:"info",time:Date.now(),data:e})},t.prototype.profileSetOnce=function(e){this.bridgeReport?this.appBridge.profileSetOnce(JSON.stringify(e)):this.emit(G.ProfileSetOnce,e,G.Profile),this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileSetOnce",level:"info",time:Date.now(),data:e})},t.prototype.profileIncrement=function(e){this.bridgeReport?this.appBridge.profileIncrement(JSON.stringify(e)):this.emit(G.ProfileIncrement,e,G.Profile),this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileIncrement",level:"info",time:Date.now(),data:e})},t.prototype.profileUnset=function(e){this.bridgeReport?this.appBridge.profileUnset(e):this.emit(G.ProfileUnset,e,G.Profile),this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileUnset",level:"info",time:Date.now(),data:e})},t.prototype.profileAppend=function(e){this.bridgeReport?this.appBridge.profileAppend(JSON.stringify(e)):this.emit(G.ProfileAppend,e,G.Profile),this.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"SDK 执行profileAppend",level:"info",time:Date.now(),data:e})},t.prototype.setExternalAbVersion=function(e){this.bridgeReport?this.appBridge.setExternalAbVersion(e):this.emit(G.AbExternalVersion,"string"==typeof e&&e?(""+e).trim():null,G.Ab)},t.prototype.getVar=function(e,t,i){this.bridgeReport?this.appBridge.getVar(e,t,i):this.emit(G.AbVar,{name:e,defaultValue:t,callback:i},G.Ab)},t.prototype.getAllVars=function(e){this.bridgeReport?this.appBridge.getAllVars(e):this.emit(G.AbAllVars,e,G.Ab)},t.prototype.getABconfig=function(e,t){this.emit(G.AbConfig,{params:e,callback:t},G.Ab)},t.prototype.getAbSdkVersion=function(e){if(!this.bridgeReport||!e)return this.configManager.getAbVersion()||"";this.appBridge.getAbSdkVersion(e)},t.prototype.onAbSdkVersionChange=function(e){var t=this;return this.emit(G.AbVersionChangeOn,e,G.Ab),function(){t.emit(G.AbVersionChangeOff,e,G.Ab)}},t.prototype.offAbSdkVersionChange=function(e){this.emit(G.AbVersionChangeOff,e,G.Ab)},t.prototype.openOverlayer=function(){this.emit(G.AbOpenLayer,"",G.Ab)},t.prototype.closeOverlayer=function(){this.emit(G.AbCloseLayer,"",G.Ab)},t.prototype.destoryInstace=function(){this.destroyInstance||(this.destroyInstance=!0,this.off(G.TokenComplete))},t.plugins=[],t}(),Z=function(){function t(){}return t.prototype.apply=function(e,t){var i=this;this.collect=e,this.config=t,this.duration=6e4,this.reportUrl=e.configManager.getDomain()+"/profile/list";var n=e.Types,o=e.adapters.fetch;this.eventCheck=new A(e,t),this.fetch=o,this.cache={},this.collect.on(n.ProfileSet,(function(e){i.setProfile(e)})),this.collect.on(n.ProfileSetOnce,(function(e){i.setOnceProfile(e)})),this.collect.on(n.ProfileUnset,(function(e){i.unsetProfile(e)})),this.collect.on(n.ProfileIncrement,(function(e){i.incrementProfile(e)})),this.collect.on(n.ProfileAppend,(function(e){i.appendProfile(e)})),this.collect.on(n.ProfileClear,(function(){i.cache={}})),this.ready(n.Profile)},t.prototype.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)}},t.prototype.report=function(e,t){void 0===t&&(t={});try{if(this.config.disable_track_event)return;var i=[];i.push(this.collect.processEvent(e,t));var n=this.collect.eventManager.merge(i,!0);this.fetch(this.reportUrl,n),this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:n,code:200,status:"success"})}catch(e){this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},t.prototype.setProfile=function(t){var i=this.formatParams(t);i&&Object.keys(i).length&&(this.pushCache(i),this.report("__profile_set",e({},i,{profile:!0})))},t.prototype.setOnceProfile=function(t){var i=this.formatParams(t,!0);i&&Object.keys(i).length&&(this.pushCache(i),this.report("__profile_set_once",e({},i,{profile:!0})))},t.prototype.incrementProfile=function(t){t?this.report("__profile_increment",e({},t,{profile:!0})):console.warn("please check the params, must be object!!!")},t.prototype.unsetProfile=function(t){if(t){var i={};i[t]="1",this.report("__profile_unset",e({},i,{profile:!0}))}else console.warn("please check the key, must be string!!!")},t.prototype.appendProfile=function(t){if(t){var i={};for(var n in t)"string"==typeof t[n]||"Array"===Object.prototype.toString.call(t[n]).slice(8,-1)?i[n]=t[n]:console.warn("please check the value of param: "+n+", must be string or array !!!");Object.keys(i).length&&this.report("__profile_append",e({},i,{profile:!0}))}else console.warn("please check the params, must be object!!!")},t.prototype.pushCache=function(e){var t=this;Object.keys(e).forEach((function(i){t.cache[i]={val:t.clone(e[i]),timestamp:Date.now()}}))},t.prototype.formatParams=function(e,t){var i=this;void 0===t&&(t=!1);try{if(!e||"[object Object]"!==Object.prototype.toString.call(e))return void console.warn("please check the params type, must be object !!!");var n={};for(var o in e)"string"==typeof e[o]||"number"==typeof e[o]||"Array"===Object.prototype.toString.call(e[o]).slice(8,-1)?n[o]=e[o]:console.warn("please check the value of params:"+o+", must be string,number,Array !!!");var r=Object.keys(n);if(!r.length)return;var s=Date.now();return r.filter((function(n){var o=i.cache[n];return t?!o:!(o&&i.compare(o.val,e[n])&&s-o.timestamp<i.duration)})).reduce((function(e,t){return e[t]=n[t],e}),{})}catch(e){this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),console.log("error")}},t.prototype.compare=function(e,t){try{return JSON.stringify(e)===JSON.stringify(t)}catch(e){return this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),!1}},t.prototype.clone=function(e){try{return JSON.parse(JSON.stringify(e))}catch(t){return this.collect.emit(y.DEBUGGER_MESSAGE,{type:y.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message}),e}},t.prototype.unReady=function(){console.warn("sdk is not ready, please use this api after start")},t}(),Y=function(){function e(){var e=this;this.setInterval=function(){e.clearIntervalFunc=function(e,t){void 0===e&&(e=function(){}),void 0===t&&(t=1e3);var i,n=Date.now()+t;return i=window.setTimeout((function o(){var r=Date.now()-n;e(),n+=t,i=window.setTimeout(o,Math.max(0,t-r))}),t),function(){window.clearTimeout(i)}}((function(){e.isSessionhasEvent&&e.endCurrentSession()}),e.sessionInterval)},this.clearInterval=function(){e.clearIntervalFunc&&e.clearIntervalFunc()}}return e.prototype.apply=function(e,t){var i=this;if(this.collect=e,!t.disable_heartbeat){this.sessionInterval=6e4,this.startTime=0,this.lastTime=0,this.setInterval();var n=this.collect.Types;this.collect.on(n.SessionReset,(function(){i.process()}))}},e.prototype.endCurrentSession=function(){this.collect.event("_be_active",{start_time:this.startTime,end_time:this.lastTime,url:window.location.href,referrer:window.document.referrer,title:document.title||location.pathname}),this.isSessionhasEvent=!1,this.startTime=0},e.prototype.process=function(){this.isSessionhasEvent||(this.isSessionhasEvent=!0,this.startTime=+new Date);var e=this.lastTime||+new Date;this.lastTime=+new Date,this.lastTime-e>this.sessionInterval&&(this.clearInterval(),this.endCurrentSession(),this.setInterval())},e}(),ee=function(){function e(){}return e.prototype.apply=function(e,t){var i=this;if(this.collect=e,this.config=t,!this.config.channel_domain&&!this.config.disable_track_event&&!this.config.disable_sdk_monitor){var n=e.adapters.fetch;this.fetch=n,this.url=e.configManager.getUrl("event");var o=this.collect.Types;this.collect.on(o.Ready,(function(){i.sdkOnload()})),this.collect.on(o.SubmitError,(function(e){var t=e.type,n=e.eventData,o=e.errorCode;"f_data"===t&&i.sdkError(n,o)}))}},e.prototype.sdkOnload=function(){var e=this;try{var t=this.collect.configManager.get(),i=t.header,n=t.user,o=i.app_id,r=i.app_name,s=i.sdk_version,a=n.web_id,c={events:[{event:"onload",params:JSON.stringify({app_id:o,app_name:r||"",sdk_version:s,sdk_type:"npm",sdk_config:this.config,sdk_desc:"TOB"}),local_time_ms:Date.now()}],user:{user_unique_id:a},header:{}};setTimeout((function(){e.fetch(e.url,[c],3e4,!1,(function(){}),(function(){}),"566f58151b0ed37e")}),16)}catch(e){}},e.prototype.sdkError=function(e,t){var i=this;try{var n=e[0],o=n.user,r=n.header,s=[];e.forEach((function(e){e.events.forEach((function(e){s.push(e)}))}));var a={events:s.map((function(e){return{event:"on_error",params:JSON.stringify({error_code:t,app_id:r.app_id,app_name:r.app_name||"",error_event:e.event,sdk_version:r.sdk_version,local_time_ms:e.local_time_ms,tea_event_index:Date.now(),params:e.params,header:JSON.stringify(r),user:JSON.stringify(o)}),local_time_ms:Date.now()}})),user:{user_unique_id:o.user_unique_id},header:{}};setTimeout((function(){i.fetch(i.url,[a],3e4,!1,(function(){}),(function(){}),"566f58151b0ed37e")}),16)}catch(e){}},e}(),te=function(){function e(){this.verifyReady=!1,this.waitTime=5e3,this.cleanStatus=!1}return e.prototype.apply=function(e,t){var i=this;this.collector=e,this.config=t;var n=e.adapters.storage;this.cacheStorgae=new n(!1,"session"),this.eventStorage=[],this.collector.on("submit-verify",(function(e){e&&e.length&&i.eventStore(e[0])})),this.checkCache()},e.prototype.checkCache=function(){var e=this;this.verifyCookieKey="__applog_verify_set_"+this.config.app_id,this.cacheStorgae.getCookie(this.verifyCookieKey);var t=this.cacheStorgae.getItem(this.verifyCookieKey);this.sign=t&&t.sign||"",this.origin=t&&t.origin||"*";var i=setTimeout((function(){e.cleanVerify(),clearTimeout(i),e.collector.off("submit-verify")}),this.waitTime);window.addEventListener("message",(function(t){t&&t.data&&"simulator:verify"===t.data.type&&(clearTimeout(i),e.receMessage(t))}),!0)},e.prototype.receMessage=function(e){if(!this.cleanStatus){var t=e.data;this.verifyReady=!0,this.sign=t.sign,this.origin=e.origin,this.cacheStorgae.setItem(this.verifyCookieKey,JSON.stringify({sign:t.sign,origin:e.origin})),this.eventStorage.length&&this.postVerify(this.eventStorage,t.sign,e.origin)}},e.prototype.eventStore=function(e){this.cleanStatus||(this.verifyReady?this.postVerify(e,this.sign,this.origin):this.eventStorage.push(e))},e.prototype.cleanVerify=function(){this.cleanStatus=!0,this.eventStorage=[]},e.prototype.postVerify=function(e,t,i){try{var n=[];s(e)?e.forEach((function(e){n.push(e)})):n.push(e);var o={type:"simulator:verify:event",sign:t,pageUrl:window.location.href,events:n};(window.opener||window.parent).postMessage(o,i)}catch(e){console.log("web verify post message error ~")}},e}(),ie=function(){function e(){this.verifyReady=!1,this.cleanStatus=!1}return e.prototype.apply=function(e,t){var i=this;this.collector=e,this.config=t,this.eventStorage=[],this.collector.on("submit-verify-h5",(function(e){e&&e.length&&i.eventStore(e[0])})),this.checkUrl(),this.heartbeat()},e.prototype.checkUrl=function(){var e=window.location.href,t=p(e);t._r_d_&&t._r_c_k_?(this.verifyReady=!0,this.domain=t._r_d_,this.key=t._r_c_k_,this.checkCache()):this.collector.off("submit-verify-h5")},e.prototype.checkCache=function(){this.eventStorage.length&&this.postVerify(this.eventStorage)},e.prototype.heartbeat=function(){var e=this;this.heart=setInterval((function(){var t={event:"simulator_test__",local_time_ms:Date.now()},i=e.collector.configManager.get(),n=i.header,o={events:[t],user:i.user,header:n};e.eventStore(o)}),6e4)},e.prototype.eventStore=function(e){this.cleanStatus||(this.verifyReady?this.postVerify(e):this.eventStorage.push(e))},e.prototype.cleanVerify=function(){this.cleanStatus=!0,this.eventStorage=[],clearInterval(this.heart)},e.prototype.postVerify=function(e){var t=this;try{var i=JSON.parse(JSON.stringify(e));s(e)?i.forEach((function(e){t.fetchLog(e)})):this.fetchLog(i)}catch(e){console.log("web verify post error ~")}},e.prototype.fetchLog=function(e){U(this.domain+"/simulator/h5/log?connection_key="+this.key,e,2e4,!1)},e.prototype.leave=function(){var e=this;document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState&&e.cleanVerify()})),h((function(){e.cleanVerify()}))},e}();X.usePlugin(te,"verify"),X.usePlugin(ie,"verifyH"),X.usePlugin(Z,"profile"),X.usePlugin(Y,"heartbeat"),X.usePlugin(ee,"monitor");var ne=new X("default"),oe=X;exports.Collector=oe,exports.default=ne;
|
package/lib/plugin/ab.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},e.apply(this,arguments)},t="__rangers_ab_style__";var n,i,r={cn:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"},o="https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/visual-ab-core.js",a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(e){var t=function(){try{return!!Symbol.iterator}catch(e){return!1}}(),n=function(e){var n={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return t&&(n[Symbol.iterator]=function(){return n}),n},i=function(e){return encodeURIComponent(e).replace(/%20/g,"+")},r=function(e){return decodeURIComponent(String(e).replace(/\+/g," "))};(function(){try{var t=e.URLSearchParams;return"a=1"===new t("?a=1").toString()&&"function"==typeof t.prototype.set&&"function"==typeof t.prototype.entries}catch(t){return!1}})()||function(){var r=function e(t){Object.defineProperty(this,"_entries",{writable:!0,value:{}});var n=typeof t;if("undefined"===n);else if("string"===n)""!==t&&this._fromString(t);else if(t instanceof e){var i=this;t.forEach((function(e,t){i.append(t,e)}))}else{if(null===t||"object"!==n)throw new TypeError("Unsupported input's type for URLSearchParams");if("[object Array]"===Object.prototype.toString.call(t))for(var r=0;r<t.length;r++){var o=t[r];if("[object Array]"!==Object.prototype.toString.call(o)&&2===o.length)throw new TypeError("Expected [string, any] as entry at index "+r+" of URLSearchParams's input");this.append(o[0],o[1])}else for(var a in t)t.hasOwnProperty(a)&&this.append(a,t[a])}},o=r.prototype;o.append=function(e,t){e in this._entries?this._entries[e].push(String(t)):this._entries[e]=[String(t)]},o.delete=function(e){delete this._entries[e]},o.get=function(e){return e in this._entries?this._entries[e][0]:null},o.getAll=function(e){return e in this._entries?this._entries[e].slice(0):[]},o.has=function(e){return e in this._entries},o.set=function(e,t){this._entries[e]=[String(t)]},o.forEach=function(e,t){var n;for(var i in this._entries)if(this._entries.hasOwnProperty(i)){n=this._entries[i];for(var r=0;r<n.length;r++)e.call(t,n[r],i,this)}},o.keys=function(){var e=[];return this.forEach((function(t,n){e.push(n)})),n(e)},o.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),n(e)},o.entries=function(){var e=[];return this.forEach((function(t,n){e.push([n,t])})),n(e)},t&&(o[Symbol.iterator]=o.entries),o.toString=function(){var e=[];return this.forEach((function(t,n){e.push(i(n)+"="+i(t))})),e.join("&")},e.URLSearchParams=r}();var o=e.URLSearchParams.prototype;"function"!=typeof o.sort&&(o.sort=function(){var e=this,t=[];this.forEach((function(n,i){t.push([i,n]),e._entries||e.delete(i)})),t.sort((function(e,t){return e[0]<t[0]?-1:e[0]>t[0]?1:0})),e._entries&&(e._entries={});for(var n=0;n<t.length;n++)this.append(t[n][0],t[n][1])}),"function"!=typeof o._fromString&&Object.defineProperty(o,"_fromString",{enumerable:!1,configurable:!1,writable:!1,value:function(e){if(this._entries)this._entries={};else{var t=[];this.forEach((function(e,n){t.push(n)}));for(var n=0;n<t.length;n++)this.delete(t[n])}var i,o=(e=e.replace(/^\?/,"")).split("&");for(n=0;n<o.length;n++)i=o[n].split("="),this.append(r(i[0]),i.length>1?r(i[1]):"")}})}(void 0!==a?a:"undefined"!=typeof window?window:"undefined"!=typeof self?self:a),function(e){if(function(){try{var t=new e.URL("b","http://a");return t.pathname="c d","http://a/c%20d"===t.href&&t.searchParams}catch(t){return!1}}()||function(){var t=e.URL,n=function t(n,i){"string"!=typeof n&&(n=String(n)),i&&"string"!=typeof i&&(i=String(i));var r,o=document;if(i&&(void 0===e.location||i!==e.location.href)){i=i.toLowerCase(),(r=(o=document.implementation.createHTMLDocument("")).createElement("base")).href=i,o.head.appendChild(r);try{if(0!==r.href.indexOf(i))throw new Error(r.href)}catch(t){throw new Error("URL unable to set base "+i+" due to "+t)}}var a=o.createElement("a");a.href=n,r&&(o.body.appendChild(a),a.href=a.href);var s=o.createElement("input");if(s.type="url",s.value=n,":"===a.protocol||!/:/.test(a.href)||!s.checkValidity()&&!i)throw new TypeError("Invalid URL");Object.defineProperty(this,"_anchorElement",{value:a});var c=new e.URLSearchParams(this.search),l=!0,h=!0,u=this;["append","delete","set"].forEach((function(e){var t=c[e];c[e]=function(){t.apply(c,arguments),l&&(h=!1,u.search=c.toString(),h=!0)}})),Object.defineProperty(this,"searchParams",{value:c,enumerable:!0});var f=void 0;Object.defineProperty(this,"_updateSearchParams",{enumerable:!1,configurable:!1,writable:!1,value:function(){this.search!==f&&(f=this.search,h&&(l=!1,this.searchParams._fromString(this.search),l=!0))}})},i=n.prototype;["hash","host","hostname","port","protocol"].forEach((function(e){!function(e){Object.defineProperty(i,e,{get:function(){return this._anchorElement[e]},set:function(t){this._anchorElement[e]=t},enumerable:!0})}(e)})),Object.defineProperty(i,"search",{get:function(){return this._anchorElement.search},set:function(e){this._anchorElement.search=e,this._updateSearchParams()},enumerable:!0}),Object.defineProperties(i,{toString:{get:function(){var e=this;return function(){return e.href}}},href:{get:function(){return this._anchorElement.href.replace(/\?$/,"")},set:function(e){this._anchorElement.href=e,this._updateSearchParams()},enumerable:!0},pathname:{get:function(){return this._anchorElement.pathname.replace(/(^\/?)/,"/")},set:function(e){this._anchorElement.pathname=e},enumerable:!0},origin:{get:function(){var e={"http:":80,"https:":443,"ftp:":21}[this._anchorElement.protocol],t=this._anchorElement.port!=e&&""!==this._anchorElement.port;return this._anchorElement.protocol+"//"+this._anchorElement.hostname+(t?":"+this._anchorElement.port:"")},enumerable:!0},password:{get:function(){return""},set:function(e){},enumerable:!0},username:{get:function(){return""},set:function(e){},enumerable:!0}}),n.createObjectURL=function(e){return t.createObjectURL.apply(t,arguments)},n.revokeObjectURL=function(e){return t.revokeObjectURL.apply(t,arguments)},e.URL=n}(),void 0!==e.location&&!("origin"in e.location)){var t=function(){return e.location.protocol+"//"+e.location.hostname+(e.location.port?":"+e.location.port:"")};try{Object.defineProperty(e.location,"origin",{get:t,enumerable:!0})}catch(n){setInterval((function(){e.location.origin=t()}),100)}}}(void 0!==a?a:"undefined"!=typeof window?window:"undefined"!=typeof self?self:a),function(e){e.Init="init",e.Config="config",e.Start="start",e.Ready="ready",e.TokenComplete="token-complete",e.TokenStorage="token-storage",e.TokenFetch="token-fetch",e.TokenError="token-error",e.ConfigUuid="config-uuid",e.ConfigWebId="config-webid",e.ConfigDomain="config-domain",e.CustomWebId="custom-webid",e.TokenChange="token-change",e.TokenReset="token-reset",e.ConfigTransform="config-transform",e.EnvTransform="env-transform",e.SessionReset="session-reset",e.SessionResetTime="session-reset-time",e.Event="event",e.Events="events",e.EventNow="event-now",e.CleanEvents="clean-events",e.BeconEvent="becon-event",e.SubmitBefore="submit-before",e.SubmitScuess="submit-scuess",e.SubmitAfter="submit-after",e.SubmitError="submit-error",e.SubmitVerify="submit-verify",e.SubmitVerifyH="submit-verify-h5",e.Stay="stay",e.ResetStay="reset-stay",e.StayReady="stay-ready",e.SetStay="set-stay",e.RouteChange="route-change",e.RouteReady="route-ready",e.Ab="ab",e.AbVar="ab-var",e.AbAllVars="ab-all-vars",e.AbConfig="ab-config",e.AbExternalVersion="ab-external-version",e.AbVersionChangeOn="ab-version-change-on",e.AbVersionChangeOff="ab-version-change-off",e.AbOpenLayer="ab-open-layer",e.AbCloseLayer="ab-close-layer",e.AbReady="ab-ready",e.AbComplete="ab-complete",e.AbTimeout="ab-timeout",e.Profile="profile",e.ProfileSet="profile-set",e.ProfileSetOnce="profile-set-once",e.ProfileUnset="profile-unset",e.ProfileIncrement="profile-increment",e.ProfileAppend="profile-append",e.ProfileClear="profile-clear",e.TrackDuration="track-duration",e.TrackDurationStart="track-duration-start",e.TrackDurationEnd="track-duration-end",e.TrackDurationPause="track-duration-pause",e.TrackDurationResume="tracl-duration-resume",e.Autotrack="autotrack",e.AutotrackReady="autotrack-ready"}(n||(n={})),function(e){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"}(i||(i={}));Date.now(),Number((""+Math.random()).slice(2,8));var s=function(e){return function(e,t,n){if("string"==typeof e&&"number"==typeof t&&"number"==typeof n){var i,r=[];n=n<=25?n:n%25;var o=String.fromCharCode(n+97);i=e.split(o);for(var a=0;a<i.length;a++){var s=parseInt(i[a],n);s=1*s^t;var c=String.fromCharCode(s);r.push(c)}return r.join("")}}(e,64,25)},c=function(e,t,n){var i=document.createElement("script");i.src=e,i.onerror=function(){n(e)},i.onload=function(){t()},document.getElementsByTagName("head")[0].appendChild(i)},l=function(e){var t=document.createElement("a");return t.href=e,t},h={},u=[];function f(e,t,n,i){var r=e&&e.source||window.opener||window.parent,o=e&&e.origin||i||"*",a={type:t,payload:n};r.postMessage(JSON.stringify(a),o)}function p(e,t){h[e]=h[e]||[],h[e].push(t)}function d(e){if(u.some((function(e){return"*"===e}))||u.some((function(t){return e.origin.indexOf(t)>-1}))){var t=e.data;if("string"==typeof e.data)try{t=JSON.parse(e.data)}catch(e){t=void 0}if(!t)return;var n=t.type,i=t.payload;h[n]&&h[n].forEach((function(t){"function"==typeof t&&t(e,i)}))}}var m="",v=!1;function b(e){var t=e.event,n=e.editorUrl;e.collectInstance,e.fromSession,v||(v=!0,c(n,(function(){f(t,"abEditorScriptloadSuccess")}),(function(){t&&f(t,"abEditorScriptloadError"),v=!1})))}function g(t,n){var i;window.TEAVisualEditor=window.TEAVisualEditor||{},(i=["*"]).length&&i.forEach((function(e){u.push(e)}));var r,a="";!function(t,n){var i=e({},t);i.filter&&delete i.filter,"object"==typeof i.autotrack&&i.autotrack.collect_url&&delete i.autotrack.collect_url,(window.opener||window.parent).postMessage({type:"tea:sdk:info",config:i,version:n},"*"),window.addEventListener("message",d,!1)}(n,"0.0.1");var s="";try{var c=window.performance.getEntriesByType("resource");if(c&&c.length&&(c.forEach((function(e){"script"===e.initiatorType&&e.name&&-1!==e.name.indexOf("collect")&&(s=e.name)})),s||document.currentScript&&(s=document.currentScript.src),s&&(r=s.split("/"))&&r.length)){a="https:/";for(var l=2;l<r.length&&l!==r.length-1;l++)a=a+"/"+r[l];a+="/visual-ab-core"}}catch(e){}p("tea:openVisualABEditor",(function(e){var i=e.data;if("string"==typeof e.data)try{i=JSON.parse(e.data)}catch(e){i=void 0}if(i){var r=i.lang;if(i.appId!==n.app_id)return f(e,"appIdError"),void console.error("abtest appid is not belong the page appid please check");var s=i.version;if(s)m=a?""+a+(s?"."+s:".1.0.1")+".js?query="+Date.now():o+"?query="+Date.now();else m=o+"?query="+Date.now();window.TEAVisualEditor.lang=r,window.TEAVisualEditor.__ab_domin=n.channel_domain||"",b({event:e,editorUrl:m,collectInstance:t})}}))}var y;!function(e){e[e.Var=0]="Var",e[e.All=1]="All"}(y||(y={}));var _=function(){function n(){this.fetchStatus="no",this.refreshFetchStatus="complete",this.versions=[],this.extVersions=[],this.mulilinkVersions=[],this.enable_multilink=!1,this.enable_ab_visual=!1,this.editMode=!1,this.callbacks=[],this.data=null,this.changeListener=new Map,this.readyStatus=!1,this.exposureCache=[]}return n.prototype.apply=function(e,t){var n=this;if(this.collect=e,this.config=t,this.config.enable_ab_test){var i=t.enable_multilink,o=t.ab_channel_domain,a=t.enable_ab_visual,c=t.ab_cross,l=t.ab_cookie_domain,h=t.disable_ab_reset,u=o||s(r[t.channel||"cn"]),f=e.adapters,p=f.storage,d=f.fetch;this.cacheStorgae=new p(!1),this.fetch=d,this.enable_multilink=i,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=u+"/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){h||"uuid"===e&&n.readyStatus&&(n.clearCache(),n.fetchAB())})),this.collect.on(m.AbVar,(function(e){var t=e.name,i=e.defaultValue,r=e.callback;n.getVar(t,i,r)})),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)}},n.prototype.ready=function(e){var t=this;if(this.collect.set(e),this.collect.hook._hooksCache.hasOwnProperty(e)){var n=this.collect.hook._hooksCache[e];if(!Object.keys(n).length)return;var i=function(e){n[e].length&&n[e].forEach((function(n){t.collect.hook.emit(e,n)}))};for(var r in n)i(r)}},n.prototype.loadMode=function(){var e,t,n=function(){try{return JSON.parse(atob(window.name))||void 0}catch(e){return}}(),i="";if(n){var r=n.scenario,o=n.href;r?(this.editMode=!0,i=r):!o||-1===o.indexOf("datatester")&&-1===o.indexOf("visual-editor")||(this.editMode=!0,i="visual-editor")}this.enable_ab_visual&&(g(this.collect,this.config),"visual-editor"===i)?this.collect.destoryInstace():this.enable_multilink&&(e=this.collect,t=this.config,window.TEAVisualEditor=window.TEAVisualEditor||{},window.TEAVisualEditor.appId=t.app_id,p("tea:openTesterEventInspector",(function(t){var n=t.data;if("string"==typeof t.data)try{n=JSON.parse(t.data)}catch(e){n=void 0}if(n){var i=n.referrer,r=n.lang,o=n.appId;window.TEAVisualEditor.__editor_ajax_domain=i||"",window.TEAVisualEditor.__ab_appId=o||"",window.TEAVisualEditor.lang=r||"",b({event:t,editorUrl:"https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/tester-event-inspector.js?query="+Date.now(),collectInstance:e})}})))},n.prototype.checkLocal=function(){var e=this.getABCache(),t=e.ab_version,n=e.ab_ext_version,i=e.ab_version_multilink,r=e.data,o=this.checkFromUrl();o?this.mulilinkVersions.push(o):this.mulilinkVersions=i||[],this.extVersions=n||[],this.versions=t||[],this.data=r;var a=this.versions.concat(this.extVersions);this.enable_multilink&&(a=a.concat(this.mulilinkVersions)),this.configVersions(a.join(","))},n.prototype.checkFromUrl=function(){var e=function(e){var t={};try{var n=l(e).search;(n=n.slice(1)).split("&").forEach((function(e){var n,i,r=e.split("=");r.length&&(n=r[0],i=r[1]);try{t[n]=decodeURIComponent(void 0===i?"":i)}catch(e){t[n]=i}}))}catch(e){}return t}(window.location.href);return e&&e.vid?e.vid:""},n.prototype.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)}))},n.prototype.configVersions=function(e){this.collect.configManager.setAbVersion(e)},n.prototype.getVar=function(e,t,n){if(!e)throw new Error("variable must not be empty");if(void 0===t)throw new Error("variable no default value");if("function"!=typeof n)throw new Error("callback must be a function");var i={name:e,defaultValue:t,callback:n,type:y.Var};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealVar(i,e):this.callbacks.push(i)},n.prototype.getRealVar=function(e,t){var n=e.name,r=e.defaultValue,o=e.callback,a=this.data;if(a){if(null!=(c=a[n])&&"[object Object]"==Object.prototype.toString.call(c)){var s=a[n].vid;return"$ab_url"===t?this.mulilinkVersions.includes(s)||this.mulilinkVersions.push(s):this.versions.includes(s)||this.versions.push(s),this.updateVersions(),this.fechEvent(s,t,r),o(a[n].val),void this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 曝光了实验"+n,level:"info",time:Date.now(),data:a[n]})}var c;this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getVar",level:"info",time:Date.now(),data:r}),o(r)}else o(r)},n.prototype.getAllVars=function(e){if("function"!=typeof e)throw new Error("callback must be a function");var t={callback:e,type:y.All};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealAllVars(t):this.callbacks.push(t)},n.prototype.getRealAllVars=function(e){(0,e.callback)(this.data?JSON.parse(JSON.stringify(this.data)):{}),this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getAllVars",level:"info",time:Date.now(),data:this.data})},n.prototype.fechEvent=function(e,t,n){try{if(this.config.disable_track_event)return;if(!e)return;var r=this.collect.configManager.get(),o=r.header,a=r.user,s=this.getABCache();if(s&&s.uuid&&s.uuid!==a.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?n:window.location.href}),local_time_ms:Date.now()};o.custom=JSON.stringify(o.custom);var l={events:[c],user:a,header:o};"$ab_url"===t&&window.navigator.sendBeacon?window.navigator.sendBeacon(this.reportUrl,JSON.stringify([l])):this.reportExposure(l)}catch(e){this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},n.prototype.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)},n.prototype.report=function(){var e=this;this.fetch(this.reportUrl,this.exposureCache,2e4),this.exposureCache.forEach((function(t){e.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:[t],code:200,status:"success"})})),this.exposureCache=[]},n.prototype.setExternalAbVersion=function(e){this.extVersions=[e],this.updateVersions()},n.prototype.getABconfig=function(e,t){var n=Object.keys(e);n&&n.length&&this.collect.configManager.set(e),this.fetchAB(t)},n.prototype.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.getItem(e)},n.prototype.set=function(e,t){this.ab_cross?this.cacheStorgae.setCookie(e,t,2592e6,this.ab_cookie_domain):this.cacheStorgae.setItem(e,t),this.collect.configManager.setAbCache(t)},n.prototype.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>=2592e6?(this.cacheStorgae.removeItem(this.abKey),null):e?t[e]:t},n.prototype.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)},n.prototype.setAbCache=function(e){var t=this.getABCache();t.data=this.data,t.uuid=e,t.timestamp=Date.now(),this.set(this.abKey,t)},n.prototype.clearCache=function(){this.refreshFetchStatus="ing",this.data={},this.extVersions=[],this.mulilinkVersions=[],this.versions=[]},n.prototype.openOverlayer=function(e){var n=this;if(function(){if(!document.getElementById(t)){var e="body { opacity: 0 !important; }",n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.id=t,i.type="text/css",i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e)),n.appendChild(i)}}(),e)var i=setTimeout((function(){n.closeOverlayer(),clearTimeout(i)}),e)},n.prototype.closeOverlayer=function(){var e;(e=document.getElementById(t))&&e.parentElement.removeChild(e)},n.prototype.fetchComplete=function(e,t){var n=this;if(e&&"[object Object]"==Object.prototype.toString.call(e)){this.data=e,this.setAbCache(t);var i=[];Object.keys(e).forEach((function(t){var n=e[t].vid;n&&i.push(n)})),this.versions=this.versions.filter((function(e){return i.includes(e)}));var r=e.$ab_url,o=e.$ab_modification;if(o&&o.val&&this.enable_ab_visual){if(this.collect.destroyInstance)return;this.getVar("$ab_modification",window.location.href,(function(){var e;e=o.val,window.TEAVisualEditor=window.TEAVisualEditor||{},window.TEAVisualEditor.__ab_config=e,c("https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/visual-ab-loader.js?query="+Date.now(),(function(){console.log("load visual render success")}),(function(){console.log("load visual render fail")})),n.closeOverlayer()}))}else if(r&&this.enable_multilink){this.mulilinkVersions=this.mulilinkVersions.filter((function(e){return i.includes(e)}));var a=r.val,s=r.vid;a&&s&&this.getVar("$ab_url",a,(function(){n.editMode||(a!==window.location.href?setTimeout((function(){if(!n.collect.destroyInstance){var e=""+a;e=-1===e.indexOf("http")?"https://"+e:e;var t=l(e).host;try{var i=new URL(e);t!==location.host?i.searchParams.append("vid",s):window.history.replaceState("","",e),window.location.href=i.href}catch(t){window.location.href=e}}}),100):n.closeOverlayer())}))}this.updateVersions()}else this.closeOverlayer();this.callbacks.forEach((function(e){return n[e.type===y.Var?"getRealVar":"getRealAllVars"](e,"")})),this.callbacks=[]},n.prototype.fetchAB=function(t){var n=this,r=this.collect.configManager.get(),o={header:e({aid:this.config.app_id},r.user||{},r.header||{},{ab_sdk_version:this.collect.configManager.getAbVersion(),ab_url:window.location.href})};this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,info:"SDK 发起AB实验请求",level:"info",logType:"fetch",time:Date.now(),data:o}),this.fetch(this.fetchUrl,o,this.config.ab_timeout||3e3,!1,(function(e){n.fetchStatus="complete",n.refreshFetchStatus="complete";var o=e.data;"success"===e.message?(n.fetchComplete(o,r.user.user_unique_id),t&&t(o)):(n.fetchComplete(null,r.user.user_unique_id),t&&t(null)),n.collect.emit(n.types.AbComplete,o),n.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求成功",level:"info",logType:"fetch",time:Date.now(),data:o})}),(function(){n.fetchStatus="complete",n.refreshFetchStatus="complete",n.fetchComplete(null,r.user.user_unique_id),t&&t(null),n.collect.emit(n.types.AbTimeout),n.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求网络异常",level:"error",logType:"fetch",time:Date.now()})}))},n.prototype.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 n=new RegExp(t,"g");e=e.replace(n,"")}catch(e){}return e},n}();module.exports=_;
|
package/lib/plugin/autotrack.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)},t=function(e){return Array.isArray(e)};Date.now(),Number((""+Math.random()).slice(2,8));function n(e,t){if(void 0===t&&(t="list"),!e)return!1;if(t&&"list"===t){if(["LI","TR","DL"].includes(e.nodeName))return!0;if(e.dataset&&e.dataset.hasOwnProperty("teaIdx"))return!0;if(e.hasAttribute&&e.hasAttribute("data-tea-idx"))return!0}else{if(["A","BUTTON"].includes(e.nodeName))return!0;if(e.dataset&&e.dataset.hasOwnProperty("teaContainer"))return!0;if(e.hasAttribute&&e.hasAttribute("data-tea-container"))return!0;if(e.hasAttribute&&s(e,"ss"))return!0}return!1}var i=function(e,t){return!!s(e,t)};function o(e){for(var t=e;t&&!n(t,"container");){if("HTML"===t.nodeName||"BODY"===t.nodeName)return e;t=t.parentElement}return t||e}function r(e){var t="";return 3===e.nodeType?t=e.textContent.trim():e.dataset&&e.dataset.hasOwnProperty("teaTitle")||e.hasAttribute("ata-tea-title")?t=e.getAttribute("data-tea-title"):e.hasAttribute("title")?t=e.getAttribute("title"):"INPUT"===e.nodeName&&["button","submit"].includes(e.getAttribute("type"))?t=e.getAttribute("value"):"IMG"===e.nodeName&&e.getAttribute("alt")&&(t=e.getAttribute("alt")),t.slice(0,200)}var a=function(e,t){return e.hasAttribute?e.hasAttribute(t):e.attributes?!(!e.attributes[t]||!e.attributes[t].specified):void 0},s=function(e,n){if("string"==typeof n)return a(e,n);if(t(n)){for(var i=!1,o=0;o<n.length;o++){if(a(e,n[o])){i=!0;break}}return i}};var c=function(){function t(t,o,r){var a=this;this.clickEvent=function(e){(function(e,t){if(1!==e.nodeType)return!1;if(!t.svg&&function(e){if("svg"===e.tagName.toLowerCase())return!0;for(var t=e.parentElement,n=!1;t;)"svg"===t.tagName.toLowerCase()?(t=null,n=!0):t=t.parentElement;return n}(e))return!1;if(["HTML","BODY"].includes(e.tagName.toUpperCase()))return!1;var o=e;return!!("none"!==o.style.display&&(n(o,"container")||t.track_attr&&i(o,t.track_attr)||function(e){if(e.children.length){var t=e.children;return![].slice.call(t).some((function(e){return e.children.length>0}))}return!0}(o)))})(e.target,a.options)&&a.eventHandel({eventType:"dom",eventName:"click"},e)},this.changeEvent=function(e){a.eventHandel({eventType:"dom",eventName:"change"},e)},this.submitEvent=function(e){a.eventHandel({eventType:"dom",eventName:"submit"},e)},this.getPageViewEvent=function(t,n){n&&"pushState"===n&&a.eventHandel({eventType:"dom",eventName:"beat"},e({beat_type:0},t)),a.eventHandel({eventType:"dom",eventName:"page_view"},t)},this.getPageLoadEvent=function(e){a.eventHandel({eventType:"dom",eventName:"page_statistics"},{lcp:e})},this.config=r.getConfig().eventConfig,this.collect=o,this.options=t,this.beatTime=t.beat,this.statistics=!1}return t.prototype.init=function(e){this.eventHandel=e;var t=this.config.mode;this.addListener(t)},t.prototype.addListener=function(e){var t=this;if("proxy-capturing"===e&&(this.config.click&&window.document.addEventListener("click",this.clickEvent,!0),this.config.change&&window.document.addEventListener("change",this.changeEvent,!0),this.config.submit&&window.document.addEventListener("submit",this.submitEvent,!0),this.config.pv&&this.collect.on("route-change",(function(e){var n=e.config,i=e.name;t.getPageViewEvent(n,i)})),this.config.beat)){try{"complete"===document.readyState?this.beatEvent(this.beatTime):window.addEventListener("load",(function(){t.beatEvent(t.beatTime)}));var n=0,i=null;window.addEventListener("scroll",(function(){clearTimeout(i),i=setTimeout(o,500),n=document.documentElement.scrollTop||document.body.scrollTop}));var o=function(){(document.documentElement.scrollTop||document.body.scrollTop)==n&&t.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:1})}}catch(e){}try{var r=window.performance&&window.performance.getEntriesByType("paint");if(r&&r.length){var a=new PerformanceObserver((function(e){var n=e.getEntries(),i=n[n.length-1],o=i.renderTime||i.loadTime;t.statistics||(t.getPageLoadEvent(o),t.statistics=!0)}));a.observe({entryTypes:["largest-contentful-paint"]}),setTimeout((function(){t.statistics||(t.getPageLoadEvent(r[0].startTime||0),t.statistics=!0)}),2e3)}else this.getPageLoadEvent(0)}catch(e){this.getPageLoadEvent(0)}}},t.prototype.removeListener=function(){window.document.removeEventListener("click",this.clickEvent,!0),window.document.removeEventListener("change",this.changeEvent,!0),window.document.removeEventListener("submit",this.submitEvent,!0)},t.prototype.beatEvent=function(e){var t,n=this;try{var i;this.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:3}),this.beatTime&&(i=setInterval((function(){n.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:2})}),e)),t=function(){n.eventHandel({eventType:"dom",eventName:"beat",eventSend:"becon"},{beat_type:0}),n.beatTime&&clearInterval(i)},navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?window.addEventListener("pagehide",t,!1):window.addEventListener("beforeunload",t,!1)}catch(e){}},t}(),u={eventConfig:{mode:"proxy-capturing",submit:!1,click:!0,change:!1,pv:!0,beat:!0,hashTag:!1,impr:!1},scoutConfig:{mode:"xpath"}},d=function(){function e(e,t){this.config=e,this.config.eventConfig=Object.assign(this.config.eventConfig,t)}return e.prototype.getConfig=function(){return this.config},e.prototype.setConfig=function(e){return this.config=e},e}();function l(e){for(var t=[];null!==e.parentElement;)t.push(e),e=e.parentElement;var i=[],o=[];return t.forEach((function(e){var t=function(e){if(null===e)return{str:"",index:0};var t=0,i=e.parentElement;if(i)for(var o=i.children,r=0;r<o.length&&o[r]!==e;r++)o[r].nodeName===e.nodeName&&t++;return{str:[e.nodeName.toLowerCase(),n(e,"list")?"[]":""].join(""),index:t}}(e),r=t.str,a=t.index;i.unshift(r),o.unshift(a)})),{element_path:"/"+i.join("/"),positions:o}}function p(e,n,s,c){var u={},d=function(e){if(e){var t=e.getBoundingClientRect(),n=t.width,i=t.height;return{left:t.left,top:t.top,element_width:n,element_height:i}}}(n),p=function(e,t){void 0===e&&(e={}),void 0===t&&(t={});var n=e.clientX,i=e.clientY,o=t.left,r=t.top,a=n-o>=0?n-o:0,s=i-r>=0?i-r:0;return{touch_x:Math.floor(a),touch_y:Math.floor(s)}}(e,d),h=d.element_width,v=d.element_height,f=p.touch_x,g=p.touch_y,m=l(n),_=m.element_path,b=m.positions,y=function(e){var t=o(e),n=[];return function e(t){var i=r(t);if(i&&-1===n.indexOf(i)&&n.push(i),t.childNodes.length>0)for(var o=t.childNodes,a=0;a<o.length;a++)8!==o[a].nodeType&&e(o[a])}(t),n}(n),w=window.performance.timing.navigationStart,E=Date.now()-w,T=b.map((function(e){return""+e})),x=null;if(window.TEAVisualEditor.getOriginXpath&&(x=window.TEAVisualEditor.getOriginXpath({xpath:_,positions:T})),u.element_path=x&&x.xpath||_,u.positions=x&&x.positions||T,c&&!c.text&&(u.texts=y,u.element_title=function(e){var t=o(e),n="";return function e(t){var i=r(t);if(i&&(n+=i),t.childNodes.length>0)for(var o=t.childNodes,a=0;a<o.length;a++)3===o[a].nodeType&&e(o[a])}(t),n}(n)),u.element_id=n.getAttribute("id")||"",u.element_class_name=n.getAttribute("class")||"",u.element_type=n.nodeType,u.element_width=Math.floor(h),u.element_height=Math.floor(v),u.touch_x=f,u.touch_y=g,u.page_manual_key="",u.elememt_manual_key="",u.since_page_start_ms=E,u.page_start_ms=w,u.page_path=location.pathname,u.page_host=location.host,s.track_attr&&i(n,s.track_attr)){var A=function(e,n){var i={};if("string"==typeof n)a(e,n)&&(i.attrs=e.getAttribute(n));else if(t(n))for(var o=0;o<n.length;o++)a(e,n[o])&&(i[n[o]]=e.getAttribute(n[o]));return i}(n,s.track_attr);for(var k in A)u[k]=A[k]}var N=o(n);return"A"===N.tagName&&(u.href=N.getAttribute("href")),"IMG"===n.tagName&&(u.src=n.getAttribute("src")),u}var h=function(t,n,i,o,r){return e({event:t},p(n,i,o,r),{is_html:1,page_key:window.location.href,page_title:document.title})},v=function(){function t(e,t){this.ignore={text:!1},this.initConfig=e,this.options=t,this.eventName=t&&"tea"===t.custom?{click:"__bav_click",page:"__bav_page",beat:"__bav_beat",static:"__bav_page_statistics",exposure:"__bav_page_exposure"}:{click:"bav2b_click",page:"bav2b_page",beat:"bav2b_beat",static:"bav2b_page_statistics",exposure:"bav2b_exposure"},t&&!1===t.text&&(this.ignore.text=!0),t&&t.exposure&&t.exposure.eventName&&(this.eventName.exposure=t.exposure.eventName)}return t.prototype.handleEvent=function(t,n){try{if(function(e){for(var t=e;t&&t.parentNode;){if(t.hasAttribute("data-tea-ignore"))return!0;if("HTML"===t.nodeName||"body"===t.nodeName)return!1;t=t.parentNode}return!1}(t.target))return null;var i="bav2b_click";switch(n){case"click":return i=this.eventName.click,h(i,t,t.target,this.options,this.ignore);case"exposure":return i=this.eventName.exposure,h(i,t,t.target,this.options,this.ignore);case"change":return e({},h(i="bav2b_change",t,t.target,this.options),function(e,t){try{if("bav2b_change"===e)return t.hasAttribute("data-tea-track")?{value:t.value}:{}}catch(e){return{}}}(i,t.target));case"submit":return h(i="bav2b_submit",t,t.target,this.options)}}catch(e){return console.error(e),null}},t.prototype.handleViewEvent=function(e){e.event=this.eventName.page,e.page_title=document.title,e.page_total_width=window.innerWidth,e.page_total_height=window.innerHeight;try{var t=window.sessionStorage.getItem("_tea_cache_duration");if(t){var n=JSON.parse(t);e.refer_page_duration_ms=n?n.duration:""}e.scroll_width=document.documentElement.scrollLeft?document.documentElement.scrollLeft+window.innerWidth:window.innerWidth,e.scroll_height=document.documentElement.scrollTop?document.documentElement.scrollTop+window.innerHeight:window.innerHeight,e.page_start_ms=window.performance.timing.navigationStart}catch(e){console.log("page event error "+JSON.stringify(e))}return e},t.prototype.handleStatisticsEvent=function(e){var t={};t.event=this.eventName.static,t.is_html=1,t.page_key=location.href,t.refer_page_key=document.referrer||"",t.page_title=document.title,t.page_manual_key=this.initConfig.autotrack.page_manual_key||"",t.refer_page_manual_key="";try{var n=e.lcp,i=window.performance.timing,o=i.loadEventEnd-i.navigationStart;t.page_init_cost_ms=parseInt(n||(o>0?o:0)),t.page_start_ms=i.navigationStart}catch(e){console.log("page_statistics event error "+JSON.stringify(e))}return t},t.prototype.handleBeadtEvent=function(e){e.event=this.eventName.beat,e.page_key=window.location.href,e.is_html=1,e.page_title=document.title,e.page_manual_key=this.initConfig.autotrack.page_manual_key||"";try{e.page_viewport_width=window.innerWidth,e.page_viewport_height=window.innerHeight,e.page_total_width=document.documentElement.scrollWidth,e.page_total_height=document.documentElement.scrollHeight,e.scroll_width=document.documentElement.scrollLeft+window.innerWidth,e.scroll_height=document.documentElement.scrollTop+window.innerHeight,e.since_page_start_ms=Date.now()-window.performance.timing.navigationStart,e.page_start_ms=window.performance.timing.navigationStart}catch(e){console.log("beat event error "+JSON.stringify(e))}return e},t}(),f=function(){function e(e){this.collect=e,this.eventNameList=["report_click_event","report_change_event","report_submit_event","report_exposure_event","report_page_view_event","report_page_statistics_event","report_beat_event"]}return e.prototype.send=function(e,t){var n=e.eventSend,i=t.event;delete t.event,n&&"becon"===n?this.collect.beconEvent(i,t):this.collect.event(i,t)},e.prototype.get=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"GET"},t);fetch(e,n)},e.prototype.post=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"POST"},t);fetch(e,n)},e}(),g={},m=[];function _(e,t,n,i){var o=e&&e.source||window.opener||window.parent,r=e&&e.origin||i||"*",a={type:t,payload:n};o.postMessage(JSON.stringify(a),r)}function b(e,t){g[e]=g[e]||[],g[e].push(t)}function y(e){if(m.some((function(e){return"*"===e}))||m.some((function(t){return e.origin.indexOf(t)>-1}))){var t=e.data;if("string"==typeof e.data)try{t=JSON.parse(e.data)}catch(e){t=void 0}if(!t)return;var n=t.type,i=t.payload;g[n]&&g[n].forEach((function(t){"function"==typeof t&&t(e,i)}))}}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var w=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){e.exports=function(){function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)e[i]=n[i]}return e}function t(n,i){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=e({},i,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var s in r)r[s]&&(a+="; "+s,!0!==r[s]&&(a+="="+r[s].split(";")[0]));return document.cookie=t+"="+n.write(o,t)+a}}function r(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],i={},o=0;o<t.length;o++){var r=t[o].split("="),a=r.slice(1).join("=");try{var s=decodeURIComponent(r[0]);if(i[s]=n.read(a,s),e===s)break}catch(e){}}return e?i[e]:i}}return Object.create({set:o,get:r,remove:function(t,n){o(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(i)},converter:{value:Object.freeze(n)}})}return t({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}()})),E=w;function T(){try{var e=window.TEAVisualEditor.lang=window.TEAVisualEditor.lang||E.get("lang"),t=window.TEAVisualEditor.__editor_ajax_domain=window.TEAVisualEditor.__editor_ajax_domain||E.get("_TEA_VE_APIHOST"),n=window.TEAVisualEditor.__editor_verison=window.TEAVisualEditor.__editor_verison||E.get("_VISUAL_EDITOR_V"),i=window.TEAVisualEditor.__editor_url=window.TEAVisualEditor.__editor_url||E.get("_VISUAL_EDITOR_U"),o=+new Date,r=new Date(o+18e5);E.set("_TEA_VE_OPEN","1",{expires:r}),E.set("_TEA_VE_APIHOST",t,{expires:r}),E.set("_VISUAL_EDITOR_U",i,{expires:r}),E.set("lang",e,{expires:r}),E.set("_VISUAL_EDITOR_V",n||"",{expires:r})}catch(e){console.log("set cookie err")}}var x=!1;function A(e){var t,n,i,o,r=e.event,a=e.editorUrl,s=e.autoTrackInstance;x||(x=!0,t=a,n=function(){_(r,"editorScriptloadSuccess"),s.destroy()},i=function(){r&&_(r,"editorScriptloadError"),x=!1},(o=document.createElement("script")).src=t,o.onerror=function(){i(t)},o.onload=function(){n()},document.getElementsByTagName("head")[0].appendChild(o))}function k(t,n){window.TEAVisualEditor=window.TEAVisualEditor||{};var i="",o="https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/visual-editor-rangers.js?query="+Date.now();window.TEAVisualEditor.appId=n.app_id;var r,a,s,c=n.channel_domain,u="";if((r=["*"]).length&&r.forEach((function(e){m.push(e)})),c){var d,l="";try{var p=window.performance.getEntriesByType("resource");if(p&&p.length&&(p.forEach((function(e){"script"===e.initiatorType&&e.name&&-1!==e.name.indexOf("collect")&&(l=e.name)})),l||document.currentScript&&(l=document.currentScript.src),l&&(d=l.split("/"))&&d.length)){u="https:/";for(var h=2;h<d.length&&h!==d.length-1;h++)u=u+"/"+d[h];if(u&&u.indexOf("/5.0")){var v=u.split("/5.0");u=v[0]||u}}}catch(e){}}if(a="0.0.1",(s=e({},n)).filter&&delete s.filter,"object"==typeof s.autotrack&&s.autotrack.collect_url&&delete s.autotrack.collect_url,(window.opener||window.parent).postMessage({type:"tea:sdk:info",config:s,version:a},"*"),window.addEventListener("message",y,!1),"1"===E.get("_TEA_VE_OPEN")){var f=function(){var e=E.get("_TEA_VE_APIHOST");try{e=JSON.parse(e)}catch(e){}return e}(),g="";f&&(window.TEAVisualEditor.__editor_ajax_domain=f,g=E.get("_VISUAL_EDITOR_U")),A({event:null,editorUrl:g||o,autoTrackInstance:t}),T()}else try{b("tea:openVisualEditor",(function(e){var n=e.data;if("string"==typeof e.data)try{n=JSON.parse(e.data)}catch(e){n=void 0}if(n){var r=n.referrer,a=n.lang;if(r&&(window.TEAVisualEditor.__editor_ajax_domain=r),i=o,c){var s=n.version;i=u?""+u+(s?"/visual-editor-rangers-v"+s:"/visual-editor-rangers-v1.0.0")+".js":o,window.TEAVisualEditor.__editor_verison=s}window.TEAVisualEditor.__editor_url=i,window.TEAVisualEditor.lang=a,A({event:e,editorUrl:i,autoTrackInstance:t}),T()}})),window.TEAVisualEditor.openAutotrackEditor=function(){A({event:null,editorUrl:window.TEAVisualEditor.__editor_url,autoTrackInstance:t})}}catch(e){console.log("receive message error")}try{b("tea:openHeatMapCore",(function(e){A({event:e,editorUrl:"https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/heatmap-core.js?query="+Date.now(),autoTrackInstance:t})}))}catch(e){console.log("openHeatMapCore error")}}var N=function(){function e(e){this._instance=null,this._intersection=e,this._intersection&&this.init()}return e.prototype.init=function(){var e=this;MutationObserver?(this._instance=new MutationObserver((function(t){t.forEach((function(t){"attributes"===t.type&&e.attributeChangeObserve(t),"childList"===t.type&&e.modifyNodeObserve(t)}))})),this._instance.observe(document.body,{childList:!0,attributes:!0,subtree:!0,attributeOldValue:!1})):console.log("your browser cannot support MutationObserver")},e.prototype.attributeChangeObserve=function(e){e.target.hasAttribute("data-exposure")?this.exposureAdd(e,"mutation"):this.exposureRemove(e)},e.prototype.modifyNodeObserve=function(e){var t=this;Array.prototype.forEach.call(e.addedNodes,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t.exposureAdd(e,"intersect"),t.mapChild(e,t.exposureAdd)})),Array.prototype.forEach.call(e.removedNodes,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t.exposureRemove(e),t.mapChild(e,t.exposureRemove)}))},e.prototype.mapChild=function(e,t){var n=this;1===e.nodeType&&e.children.length&&Array.prototype.forEach.call(e.children,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t(e),n.mapChild(e,t)}))},e.prototype.exposureAdd=function(e,t){try{this._intersection&&this._intersection.exposureAdd(e,t)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},e.prototype.exposureRemove=function(e){try{this._intersection&&this._intersection.exposureRemove(e)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},e._exposure_observer=null,e}(),O=function(){function e(t,n){this.count=1,this.instance=this.buildObserver(),this.observeMap=e._observer_map,t.autotrack.exposure.ratio?this.Ratio=t.autotrack.exposure.ratio:0===t.autotrack.exposure.ratio?this.Ratio=0:this.Ratio=.5,this.EventHandle=n}return e.prototype.buildObserver=function(){var t=this;return e._observer_instance?(console.log("your browser cannot support IntersectionObserver"),null):(IntersectionObserver&&(e._observer_instance=new IntersectionObserver((function(e){e.forEach((function(e){t.observeMap.get(e.target._observeId)&&t.exposureEvent(e)}))}),{threshold:[.01,.25,.5,.75,1]})),e._observer_instance)},e.prototype.exposureAdd=function(e,t){var n=e;"mutation"===t&&(n=e.target);var i=n._observeId;if(i||this.observeMap.has(i)){if(!1===n.visible){var o=n.getBoundingClientRect(),r=o.top,a=o.left,s=o.right,c=o.bottom;r>=0&&c<=window.innerHeight&&a>=0&&s<=window.innerWidth&&(n.visible=!0,this.EventHandle({eventType:"dom",eventName:"exposure"},e))}}else n._observeId=this.count,n.visible=!1,this.observeMap.set(this.count,n),this.observe(n),this.count++},e.prototype.exposureRemove=function(e){this.observeMap.has(e._observeId)&&(this.observeMap.delete(e._observeId),this.unobserve(e))},e.prototype.exposureEvent=function(e){if(e.intersectionRatio>=this.Ratio&&e.isIntersecting){if("0"===e.target.style.opacity||"hidden"===e.target.style.visibility)return;if(!0===e.target.visible)return;e.target.visible=!0,this.EventHandle({eventType:"dom",eventName:"exposure"},e)}else e.target.visible=!1},e.prototype.observe=function(e){this.instance&&this.instance.observe(e)},e.prototype.unobserve=function(e){this.instance&&this.instance.unobserve(e)},e._observer_instance=null,e._observer_map=new Map,e}(),S=function(){function e(e,t){e.autotrack&&e.autotrack.exposure&&(this._intersection=new O(e,t),this._observer=new N(this._intersection),this._intersection&&this._observer?this.initObserver():console.log("your browser version cannot support exposure, please update~"))}return e.prototype.initObserver=function(){var e=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),(function(t){e._intersection.exposureAdd(t,"intersect")}))},e}(),I={hashTag:!1,impr:!1},C=function(){function e(){}return e.prototype.apply=function(e,t){if(this.autoTrackStart=!1,this.collect=e,this.config=t,t.autotrack){var n=e.Types;t.autotrack&&t.autotrack.collect_url&&!t.autotrack.collect_url()||(this.ready(n.Autotrack),this.collect.emit(n.AutotrackReady))}},e.prototype.ready=function(e){this.collect.set(e);var t=this.config.autotrack;t="object"==typeof t?t:{},t=Object.assign(I,t),this.destroyed=!1,this.options=t,this.Config=new d(u,this.options),this.Exposure=new S(this.config,this.handle.bind(this)),this.Listener=new c(t,this.collect,this.Config),this.EventHandle=new v(this.config,t),this.Request=new f(this.collect),this.autoTrackStart=!0,this.init(),k(this,this.config)},e.prototype.init=function(){this.Listener.init(this.handle.bind(this))},e.prototype.handle=function(e,t){"dom"===e.eventType&&this.handleDom(e,t)},e.prototype.handleDom=function(e,t){try{var n=e.eventName;if("click"===n||"exposure"===n||"change"===n||"submit"===n){var i=this.EventHandle.handleEvent(t,n);null!==i&&this.Request.send({eventType:"custom",eventName:"report_"+n+"_event",extra:{methods:"GET"}},i)}else if("page_view"===n||"page_statistics"===n){var o=void 0;o="page_view"===n?this.EventHandle.handleViewEvent(t):this.EventHandle.handleStatisticsEvent(t),this.Request.send({eventType:"custom",eventName:"report_${eventName}_event",extra:{methods:"GET"}},o)}else if("beat"===n){var r=this.EventHandle.handleBeadtEvent(t),a=e.eventSend;this.Request.send({eventType:"custom",eventName:"report_${eventName}_event",extra:{methods:"GET"},eventSend:a},r)}}catch(e){console.log("handel dom event error "+JSON.stringify(e))}},e.prototype.destroy=function(){if(!this.autoTrackStart)return console.warn("engine is undefined, make sure you have called autoTrack.start()");this.autoTrackStart=!1,this.Listener.removeListener()},e}();module.exports=C;
|
package/lib/plugin/duration.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var t=function(){function t(){}return t.prototype.apply=function(t,a){var e=this;this.collector=t,this.config=a;var r=t.Types;t.on(r.TrackDurationStart,(function(t){e.trackStart(t)})),t.on(r.TrackDurationEnd,(function(t){e.trackEnd(t)})),t.on(r.TrackDurationPause,(function(t){e.trackPause(t)})),t.on(r.TrackDurationResume,(function(t){e.trackResume(t)})),this.Types=r,this.TrackMap=new Map,this.ready(r.TrackDuration)},t.prototype.ready=function(t){var a=this;if(this.collector.set(t),this.collector.hook._hooksCache.hasOwnProperty(t)){var e=this.collector.hook._hooksCache[t];if(!Object.keys(e).length)return;var r=function(t){e[t].length&&e[t].forEach((function(e){a.collector.hook.emit(t,e)}))};for(var o in e)r(o)}},t.prototype.trackStart=function(t){this.TrackMap.set(t,{startTime:Date.now(),isPause:!1,pauseTime:0,resumeTime:0})},t.prototype.trackEnd=function(t){var a=t.eventName,e=t.params;if(this.TrackMap.has(a)){var r=this.TrackMap.get(a),o=0;o=r.isPause?r.pauseTime-r.startTime:r.resumeTime?r.pauseTime-r.startTime+(Date.now()-r.resumeTime):Date.now()-r.startTime;var i=Object.assign(e,{event_duration:o});this.collector.event(a,i),this.cleanTrack(a)}},t.prototype.trackPause=function(t){if(this.TrackMap.has(t)){var a=this.TrackMap.get(t);a.isPause||(a.isPause=!0,a.pauseTime=Date.now(),this.TrackMap.set(t,a))}},t.prototype.trackResume=function(t){if(this.TrackMap.has(t)){var a=this.TrackMap.get(t);a.isPause&&(a.isPause=!1,a.resumeTime=Date.now(),this.TrackMap.set(t,a))}},t.prototype.cleanTrack=function(t){this.TrackMap.delete(t)},t}();module.exports=t;
|
package/lib/plugin/route.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function e(e,t){var a="function"==typeof Symbol&&e[Symbol.iterator];if(!a)return e;var o,r,n=a.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(a=n.return)&&a.call(n)}finally{if(r)throw r.error}}return i}function t(){for(var t=[],a=0;a<arguments.length;a++)t=t.concat(e(arguments[a]));return t}var a,o;!function(e){e.Init="init",e.Config="config",e.Start="start",e.Ready="ready",e.TokenComplete="token-complete",e.TokenStorage="token-storage",e.TokenFetch="token-fetch",e.TokenError="token-error",e.ConfigUuid="config-uuid",e.ConfigWebId="config-webid",e.ConfigDomain="config-domain",e.CustomWebId="custom-webid",e.TokenChange="token-change",e.TokenReset="token-reset",e.ConfigTransform="config-transform",e.EnvTransform="env-transform",e.SessionReset="session-reset",e.SessionResetTime="session-reset-time",e.Event="event",e.Events="events",e.EventNow="event-now",e.CleanEvents="clean-events",e.BeconEvent="becon-event",e.SubmitBefore="submit-before",e.SubmitScuess="submit-scuess",e.SubmitAfter="submit-after",e.SubmitError="submit-error",e.SubmitVerify="submit-verify",e.SubmitVerifyH="submit-verify-h5",e.Stay="stay",e.ResetStay="reset-stay",e.StayReady="stay-ready",e.SetStay="set-stay",e.RouteChange="route-change",e.RouteReady="route-ready",e.Ab="ab",e.AbVar="ab-var",e.AbAllVars="ab-all-vars",e.AbConfig="ab-config",e.AbExternalVersion="ab-external-version",e.AbVersionChangeOn="ab-version-change-on",e.AbVersionChangeOff="ab-version-change-off",e.AbOpenLayer="ab-open-layer",e.AbCloseLayer="ab-close-layer",e.AbReady="ab-ready",e.AbComplete="ab-complete",e.AbTimeout="ab-timeout",e.Profile="profile",e.ProfileSet="profile-set",e.ProfileSetOnce="profile-set-once",e.ProfileUnset="profile-unset",e.ProfileIncrement="profile-increment",e.ProfileAppend="profile-append",e.ProfileClear="profile-clear",e.TrackDuration="track-duration",e.TrackDurationStart="track-duration-start",e.TrackDurationEnd="track-duration-end",e.TrackDurationPause="track-duration-pause",e.TrackDurationResume="tracl-duration-resume",e.Autotrack="autotrack",e.AutotrackReady="autotrack-ready"}(a||(a={})),function(e){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"}(o||(o={}));var r=function(){function e(){this.autotrack=!1,this.spa=!1,this.cache={},this.allowHash=!1}return e.prototype.apply=function(e,t){if(t.spa||t.autotrack){this.collect=e,this.config=t,this.appid=t.app_id,this.allowHash=t.allow_hash,this.fncArray=new Map,this.setKey(),this.setLocation(),this.hack(),this.init(),this.listener();var a=e.Types;e.emit(a.RouteReady)}},e.prototype.setKey=function(){var e=this.collect.adapters.storage;this.storage=new e(!1),this.cache_key="__tea_cache_refer_"+this.appid,this.cache={refer_key:location.href,refer_title:document.title||location.pathname,refer_manual_key:""},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.setItem(this.cache_key,this.cache)},e.prototype.hack=function(){var e=this,a=window.history.pushState;history.pushState=function(o){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];"function"==typeof history.onpushstate&&history.onpushstate({state:o});var i=a.call.apply(a,t([history,o],r));if(e.lastLocation!==location.href){var s=e.getPopStateChangeEventData();return e.lastLocation=location.href,e.sendPv(s,"pushState"),i}};var o=history.replaceState;history.replaceState=function(a){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];"function"==typeof history.onreplacestate&&history.onreplacestate({state:a});var i=o.call.apply(o,t([history,a],r));if(e.lastLocation!==location.href){var s=e.getPopStateChangeEventData();return e.lastLocation=location.href,e.sendPv(s),i}}},e.prototype.setLocation=function(){"undefined"!=typeof window&&(this.lastLocation=window.location.href)},e.prototype.init=function(){var e=this.getPopStateChangeEventData();this.collect.emit("route-change",{config:e,init:!0})},e.prototype.listener=function(){var e=this,t=null;window.addEventListener("hashchange",(function(a){if(e.lastLocation!==window.location.href&&(clearTimeout(t),e.allowHash)){e.lastLocation=window.location.href;var o=e.getPopStateChangeEventData();e.sendPv(o)}})),window.addEventListener("popstate",(function(a){e.lastLocation!==window.location.href&&(t=setTimeout((function(){e.lastLocation=window.location.href;var t=e.getPopStateChangeEventData();e.sendPv(t)}),10))}))},e.prototype.getPopStateChangeEventData=function(){var e=this.pageConfig();return e.is_back=0,e},e.prototype.pageConfig=function(){try{var e="",t=this.storage.getItem(this.cache_key)||{},a=!1;e=document.referrer?document.referrer:t&&t.refer_key||"";var r=this.storage.getItem("__tea_cache_first_"+this.appid);return a=!r||1!=r,{is_html:1,url:location.href,referrer:e,page_key:location.href,refer_page_key:e,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:""+a}}catch(e){return this.collect.emit(o.DEBUGGER_MESSAGE,{type:o.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),{}}},e.prototype.sendPv=function(e,t){this.collect.emit("route-change",{config:e,init:!1})},e}();module.exports=r;
|
package/lib/plugin/stay.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var t=function(){return t=Object.assign||function(t){for(var e,i=1,a=arguments.length;i<a;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},t.apply(this,arguments)},e=function(t){return null!=t&&"[object Object]"==Object.prototype.toString.call(t)};Date.now(),Number((""+Math.random()).slice(2,8));var i,a,n=function(t){!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?window.addEventListener("pagehide",t,!1):window.addEventListener("beforeunload",t,!1)},o=function(){var t=0;return["hidden","msHidden","webkitHidden"].forEach((function(e){void 0!==document[e]&&(t=1)})),t},s=function(){function i(t,i){this.maxDuration=432e5,this.aliveDTime=6e4,this.options={aliveName:"predefine_page_alive",params:{}},this.collect=t,this.config=i,this.pageStartTime=Date.now(),this.sessionStartTime=this.pageStartTime,this.timerHandler=null,e(i.enable_stay_duration)&&(this.options=Object.assign(this.options,i.enable_stay_duration))}return i.prototype.setParams=function(t,e,i){this.set_path=t,this.set_url=i,this.set_title=e},i.prototype.enable=function(t,e,i){this.url_path=t,this.url=i,this.title=e,this.disableCallback=this.enablePageAlive()},i.prototype.disable=function(){this.disableCallback(),this.pageStartTime=Date.now()},i.prototype.sendEvent=function(e,i){void 0===i&&(i=!1);var a=i?this.aliveDTime:Date.now()-this.sessionStartTime;a<0||a>this.aliveDTime||Date.now()-this.pageStartTime>this.maxDuration||(this.collect.beconEvent(this.options.aliveName,t({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),duration:a,is_support_visibility_change:o(),startTime:this.sessionStartTime,hidden:document.visibilityState,leave:e},this.options.params)),this.sessionStartTime=Date.now())},i.prototype.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}},i.prototype.setUpTimer=function(){var t=this;return this.timerHandler&&clearInterval(this.timerHandler),setInterval((function(){Date.now()-t.sessionStartTime>t.aliveDTime&&t.sendEvent(!1,!0)}),1e3)},i.prototype.visibilitychange=function(){"hidden"===document.visibilityState?this.timerHandler&&(clearInterval(this.timerHandler),this.sendEvent(!1)):"visible"===document.visibilityState&&(this.sessionStartTime=Date.now(),this.timerHandler=this.setUpTimer())},i.prototype.beforeunload=function(){document.hidden||this.sendEvent(!0)},i.prototype.enablePageAlive=function(){var t=this;this.timerHandler=this.setUpTimer();var e=this.visibilitychange.bind(this),i=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",e),n(i),function(){t.beforeunload(),document.removeEventListener("visibilitychange",e),window.removeEventListener("beforeunload",i),window.removeEventListener("pagehide",i)}},i}(),r=function(){function i(t,i){var a=this;this.maxDuration=432e5,this.aliveDTime=6e4,this.options={closeName:"predefine_page_close",params:{}},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())},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=t,this.config=i,this.maxDuration=i.maxDuration||864e5,this.pageStartTime=Date.now(),e(i.enable_stay_duration)&&(this.options=Object.assign(this.options,i.enable_stay_duration)),this.resetData()}return i.prototype.setParams=function(t,e,i){this.set_path=t,this.set_url=i,this.set_title=e},i.prototype.enable=function(t,e,i){this.url_path=t,this.url=i,this.title=e,this.disableCallback=this.enablePageClose()},i.prototype.disable=function(){this.disableCallback()},i.prototype.resetData=function(){this.activeStartTime=void 0===this.activeStartTime?this.pageStartTime:Date.now(),this.activeEndTime=void 0,this.activeTimes=1,this.totalTime=0},i.prototype.sendEventPageClose=function(){var e=Date.now()-this.pageStartTime;this.totalTime<0||e<0||this.totalTime>=this.maxDuration||(this.collect.beconEvent(this.options.closeName,t({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),active_times:this.activeTimes,duration:this.totalTime,total_duration:e,is_support_visibility_change:o()},this.options.params)),this.pageStartTime=Date.now(),this.resetData())},i.prototype.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}},i.prototype.enablePageClose=function(){var t=this,e=this.visibilitychange.bind(this),i=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",e),n(i),function(){t.beforeunload(),document.removeEventListener("visibilitychange",e),window.removeEventListener("beforeunload",i),window.removeEventListener("pagehide",i)}},i}();!function(t){t.Init="init",t.Config="config",t.Start="start",t.Ready="ready",t.TokenComplete="token-complete",t.TokenStorage="token-storage",t.TokenFetch="token-fetch",t.TokenError="token-error",t.ConfigUuid="config-uuid",t.ConfigWebId="config-webid",t.ConfigDomain="config-domain",t.CustomWebId="custom-webid",t.TokenChange="token-change",t.TokenReset="token-reset",t.ConfigTransform="config-transform",t.EnvTransform="env-transform",t.SessionReset="session-reset",t.SessionResetTime="session-reset-time",t.Event="event",t.Events="events",t.EventNow="event-now",t.CleanEvents="clean-events",t.BeconEvent="becon-event",t.SubmitBefore="submit-before",t.SubmitScuess="submit-scuess",t.SubmitAfter="submit-after",t.SubmitError="submit-error",t.SubmitVerify="submit-verify",t.SubmitVerifyH="submit-verify-h5",t.Stay="stay",t.ResetStay="reset-stay",t.StayReady="stay-ready",t.SetStay="set-stay",t.RouteChange="route-change",t.RouteReady="route-ready",t.Ab="ab",t.AbVar="ab-var",t.AbAllVars="ab-all-vars",t.AbConfig="ab-config",t.AbExternalVersion="ab-external-version",t.AbVersionChangeOn="ab-version-change-on",t.AbVersionChangeOff="ab-version-change-off",t.AbOpenLayer="ab-open-layer",t.AbCloseLayer="ab-close-layer",t.AbReady="ab-ready",t.AbComplete="ab-complete",t.AbTimeout="ab-timeout",t.Profile="profile",t.ProfileSet="profile-set",t.ProfileSetOnce="profile-set-once",t.ProfileUnset="profile-unset",t.ProfileIncrement="profile-increment",t.ProfileAppend="profile-append",t.ProfileClear="profile-clear",t.TrackDuration="track-duration",t.TrackDurationStart="track-duration-start",t.TrackDurationEnd="track-duration-end",t.TrackDurationPause="track-duration-pause",t.TrackDurationResume="tracl-duration-resume",t.Autotrack="autotrack",t.AutotrackReady="autotrack-ready"}(i||(i={})),function(t){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"}(a||(a={}));var l=function(){function t(){}return t.prototype.apply=function(t,e){var i=this;if(this.collect=t,this.config=e,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,e),this.pageClose=new r(t,e);var a=this.collect.Types;this.collect.on(a.ResetStay,(function(t){var e=t.url_path,a=t.title,n=t.url;i.resetStayDuration(e,a,n)})),this.collect.on(a.RouteChange,(function(t){t.init||e.disable_route_report||i.resetStayDuration()})),this.collect.on(a.SetStay,(function(t){var e=t.url_path,a=t.title,n=t.url;i.setStayParmas(e,a,n)})),this.enable(this.url_path,this.title,this.url),this.ready(a.Stay),this.collect.emit(a.StayReady)}},t.prototype.ready=function(t){var e=this;if(this.collect.set(t),this.collect.hook._hooksCache.hasOwnProperty(t)){var i=this.collect.hook._hooksCache[t];if(!Object.keys(i).length)return;var a=function(t){i[t].length&&i[t].forEach((function(i){e.collect.hook.emit(t,i)}))};for(var n in i)a(n)}},t.prototype.enable=function(t,e,i){this.pageAlive.enable(t,e,i),this.pageClose.enable(t,e,i)},t.prototype.disable=function(){this.pageAlive.disable(),this.pageClose.disable()},t.prototype.setStayParmas=function(t,e,i){void 0===t&&(t=""),void 0===e&&(e=""),void 0===i&&(i=""),this.pageAlive.setParams(t,e,i),this.pageClose.setParams(t,e,i),this.collect.emit(a.DEBUGGER_MESSAGE,{type:a.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayParams",level:"info",time:Date.now(),data:{url_path:t,title:e,url:i}})},t.prototype.reset=function(t,e,i){this.disable(),this.enable(t,e,i)},t.prototype.resetStayDuration=function(t,e,i){this.reset(t,e,i),this.collect.emit(a.DEBUGGER_MESSAGE,{type:a.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayDuration",level:"info",time:Date.now(),data:{url_path:t,title:e,url:i}})},t}();module.exports=l;
|
package/lib/plugin/store.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var t=function(){function t(){this.retryWaitTime=3e3,this.retryStatus=!1,this.retryCacheStatus=!1}return t.prototype.apply=function(t,e){var r=this;if(e.enable_storage&&!e.disable_storage&&(this.collect=t,this.config=e,!this.collect.destroyInstance)){var a=t.Types,n=t.adapters,o=n.storage,i=n.fetch;this.storage=new o(!1),this.fetch=i,this.eventUrl=this.collect.configManager.getUrl("event"),this.eventKey="__tea_cache_events_"+e.app_id,this.storageNum=e.storage_num||50,this.retryNum=e.retry_num||3,this.retryInterval=1e3,t.on(a.SubmitError,(function(t){"f_data"===t.type&&r.storeData(t)})),t.on(a.Ready,(function(){r.checkStorage()}))}},t.prototype.retryRightNow=function(t){var e=this;if(this.retryStatus)this.errorCache.push(t);else{var r=0;this.retryStatus=!0;var a=setInterval((function(){if(3===r)return e.storeData(e.errorCache),e.retryStatus=!1,void clearInterval(a);var n=t.eventData;e.fetchData(n,(function(){e.retryStatus=!1,clearInterval(a),e.retryCacheStatus&&e.errorCache.splice(0,1),e.errorCache.length&&(e.retryCacheStatus=!0,e.retryRightNow(e.errorCache[0]))}),(function(){r++}))}),this.retryInterval)}},t.prototype.storeData=function(t){var e=this.storage.getItem(this.eventKey),r=t.eventData;Object.keys(e).length!==this.storageNum&&(e[Date.now()]=r,this.storage.setItem(this.eventKey,e))},t.prototype.checkStorage=function(){var t=this;try{if(!window.navigator.onLine)return;var e=this.storage.getItem(this.eventKey);if(!e||!Object.keys(e).length)return;var r={events:[{event:"ontest",params:{app_id:this.config.app_id},local_time_ms:Date.now()}],user:{user_unique_id:this.collect.configManager.get("web_id")},header:{}};this.fetchData([r],(function(){var r=JSON.parse(JSON.stringify(e)),a=function(a){t.fetchData(e[a],(function(){delete r[a],t.storage.setItem(t.eventKey,r)}),(function(){}),!1)};for(var n in e)a(n)}),(function(){}),!0)}catch(t){console.warn("error check storage")}},t.prototype.fetchData=function(t,e,r,a){this.fetch(this.eventUrl,t,3e4,!1,(function(){e&&e()}),(function(){r&&r(),console.log("network error,compensate report failk")}),a&&!this.config.channel_domain?"566f58151b0ed37e":"")},t}();module.exports=t;
|