@datarangers/sdk-javascript 0.1.2 → 0.1.4
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/es/index-base.min.js +6629 -1
- package/es/index.min.js +9570 -1
- package/es/plugin/ab.js +1114 -1
- package/es/plugin/autotrack.js +1608 -1
- package/es/plugin/duration.js +100 -1
- package/es/plugin/route.js +605 -1
- package/es/plugin/stay.js +476 -1
- package/lib/index-base.min.js +6634 -1
- package/lib/index.min.js +9575 -1
- package/lib/plugin/ab.js +1116 -1
- package/lib/plugin/autotrack.js +1610 -1
- package/lib/plugin/duration.js +102 -1
- package/lib/plugin/route.js +607 -1
- package/lib/plugin/stay.js +478 -1
- package/package.json +1 -1
- package/types/types.d.ts +2 -0
package/lib/plugin/ab.js
CHANGED
|
@@ -1 +1,1116 @@
|
|
|
1
|
-
"use strict";var e=function(){return e=Object.assign||function(e){for(var t,o=1,i=arguments.length;o<i;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},e.apply(this,arguments)},t="__rangers_ab_style__";var o,i,n={cn:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"};!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.AnonymousId="anonymous-id",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.SubmitSuccess="submit-success",e.SubmitAfter="submit-after",e.SubmitError="submit-error",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",e.CustomHeader="custom-request-header",e.TracerReady="tracer-ready"}(o||(o={})),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 r=function(e){return function(e,t,o){if("string"==typeof e&&"number"==typeof t&&"number"==typeof o){var i,n=[];o=o<=25?o:o%25;var r=String.fromCharCode(o+97);i=e.split(r);for(var a=0;a<i.length;a++){var s=parseInt(i[a],o);s=1*s^t;var c=String.fromCharCode(s);n.push(c)}return n.join("")}}(e,64,25)},a=function(e){var t=document.createElement("a");return t.href=e,t};var s,c=function(e,t){return e(t={exports:{}},t.exports),t.exports}(function(e,t){var o;o=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var o=arguments[e];for(var i in o)t[i]=o[i]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function o(i){function n(){}function r(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=e({path:"/"},n.defaults,r)).expires&&(r.expires=new Date(1*new Date+864e5*r.expires)),r.expires=r.expires?r.expires.toUTCString():"";try{var a=JSON.stringify(o);/^[\{\[]/.test(a)&&(o=a)}catch(e){}o=i.write?i.write(o,t):encodeURIComponent(String(o)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var s="";for(var c in r)r[c]&&(s+="; "+c,!0!==r[c]&&(s+="="+r[c].split(";")[0]));return document.cookie=t+"="+o+s}}function a(e,o){if("undefined"!=typeof document){for(var n={},r=document.cookie?document.cookie.split("; "):[],a=0;a<r.length;a++){var s=r[a].split("="),c=s.slice(1).join("=");o||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var l=t(s[0]);if(c=(i.read||i)(c,l)||t(c),o)try{c=JSON.parse(c)}catch(e){}if(n[l]=c,e===l)break}catch(e){}}return e?n[e]:n}}return n.set=r,n.get=function(e){return a(e,!1)},n.getJSON=function(e){return a(e,!0)},n.remove=function(t,o){r(t,"",e(o,{expires:-1}))},n.defaults={},n.withConverter=o,n}(function(){})},e.exports=o()}),l=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}(),h=function(){function e(){this.support=this.isSupportLS()}return e.prototype.isSupportLS=function(){try{return localStorage.setItem("_applogtest-test-key","hi"),localStorage.getItem("_applogtest-test-key"),localStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},e.prototype.getItem=function(e){try{var t=localStorage.getItem(e),o=t;try{t&&"string"==typeof t&&(o=JSON.parse(t))}catch(e){}return o||{}}catch(e){}return{}},e.prototype.setItem=function(e,t){try{var o="string"==typeof t?t:JSON.stringify(t);localStorage.setItem(e,o)}catch(e){}},e.prototype.removeItem=function(e){try{localStorage.removeItem(e)}catch(e){}},e}(),u=function(){function e(){this.support=this.isSupportSession()}return e.prototype.isSupportSession=function(){try{return sessionStorage.setItem("_applogtest-test-key","hi"),sessionStorage.getItem("_applogtest-test-key"),sessionStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},e.prototype.getItem=function(e){try{var t=sessionStorage.getItem(e),o=t;try{t&&"string"==typeof t&&(o=JSON.parse(t))}catch(e){}return o||{}}catch(e){}return{}},e.prototype.setItem=function(e,t){try{var o="string"==typeof t?t:JSON.stringify(t);sessionStorage.setItem(e,o)}catch(e){}},e.prototype.removeItem=function(e){try{sessionStorage.removeItem(e)}catch(e){}},e}(),p=function(){function e(){this.defaultExpireTime=6048e5,this.local=new h,this.session=new u,this.cache=new l}return e.prototype.getLocalItem=function(e){return this.local.getItem(e)},e.prototype.setLocalItem=function(e,t){this.local.setItem(e,t)},e.prototype.removeLocalItem=function(e){this.local.removeItem(e)},e.prototype.getSessionItem=function(e){return this.session.getItem(e)},e.prototype.setSessionItem=function(e,t){this.session.setItem(e,t)},e.prototype.removeSessionItem=function(e){this.session.removeItem(e)},e.prototype.getCacheItem=function(e){return this.cache.getItem(e)},e.prototype.setCacheItem=function(e,t){this.cache.setItem(e,t)},e.prototype.removeCacheItem=function(e){this.cache.removeItem(e)},e.prototype.getCookie=function(e,t){try{return c.get(e)}catch(e){return""}},e.prototype.setCookie=function(e,t,o,i){void 0===o&&(o=this.defaultExpireTime);try{var n=i||document.domain,r=+new Date+o;c.set(e,t,{expires:new Date(r),path:"/",domain:n})}catch(e){}},e.prototype.removeCookie=function(e,t){try{c.remove(e,{path:"/",domain:t||""})}catch(e){}},e}();!function(e){e[e.Var=0]="Var",e[e.All=1]="All"}(s||(s={}));var f=2592e6,m=function(){function o(){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 o.prototype.apply=function(e,t){var o=this;if(this.collect=e,this.config=t,this.config.enable_ab_test){var i=t.enable_multilink,a=t.ab_channel_domain,s=t.enable_ab_visual,c=t.ab_cross,l=t.ab_cookie_domain,h=t.disable_ab_reset,u=a||r(n[t.channel||"cn"]);this.cacheStorgae=new p,this.enable_multilink=i,this.enable_ab_visual=s,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 f=this.collect.Types;this.types=f,this.collect.on(f.TokenChange,function(e){h||"uuid"===e.type&&o.readyStatus&&(o.clearCache(),o.fetchAB())}),this.collect.on(f.TokenReset,function(){h||o.readyStatus&&(o.clearCache(),o.fetchAB())}),this.collect.on(f.AbVar,function(e){var t=e.name,i=e.defaultValue,n=e.callback;o.getVar(t,i,n)}),this.collect.on(f.AbAllVars,function(e){o.getAllVars(e)}),this.collect.on(f.AbConfig,function(e){var t=e.params,i=e.callback;o.getABconfig(t,i)}),this.collect.on(f.AbExternalVersion,function(e){o.setExternalAbVersion(e)}),this.collect.on(f.AbOpenLayer,function(){o.openOverlayer()}),this.collect.on(f.AbCloseLayer,function(){o.closeOverlayer()}),this.collect.on(f.AbVersionChangeOn,function(e){o.changeListener.set(e,e)}),this.collect.on(f.AbVersionChangeOff,function(e){o.changeListener.get(e)&&o.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(f.AbReady)}},o.prototype.ready=function(e){var t=this;if(this.collect.set(e),this.collect.hook._hooksCache.hasOwnProperty(e)){var o=this.collect.hook._hooksCache[e];if(!Object.keys(o).length)return;var i=function(e){o[e].length&&o[e].forEach(function(o){t.collect.hook.emit(e,o)})};for(var n in o)i(n)}},o.prototype.loadMode=function(){},o.prototype.checkLocal=function(){var e=this.getABCache(),t=e.ab_version,o=e.ab_ext_version,i=e.ab_version_multilink,n=e.data,r=this.checkFromUrl();r?this.mulilinkVersions.push(r):this.mulilinkVersions=i||[],this.extVersions=o||[],this.versions=t||[],this.data=n;var a=this.versions.concat(this.extVersions);this.enable_multilink&&(a=a.concat(this.mulilinkVersions)),this.configVersions(a.join(","))},o.prototype.checkFromUrl=function(){var e=function(e){var t={};try{var o=a(e).search;(o=o.slice(1)).split("&").forEach(function(e){var o,i,n=e.split("=");n.length&&(o=n[0],i=n[1]);try{t[o]=decodeURIComponent(void 0===i?"":i)}catch(e){t[o]=i}})}catch(e){}return t}(window.location.href);return e&&e.vid?e.vid:""},o.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)})},o.prototype.configVersions=function(e){this.collect.configManager.setAbVersion(e)},o.prototype.getVar=function(e,t,o){if(!e)throw new Error("variable must not be empty");if(void 0===t)throw new Error("variable no default value");if("function"!=typeof o)throw new Error("callback must be a function");var i={name:e,defaultValue:t,callback:o,type:s.Var};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealVar(i,e):this.callbacks.push(i)},o.prototype.getRealVar=function(e,t){var o=e.name,n=e.defaultValue,r=e.callback,a=this.data;if(a){if(null!=(c=a[o])&&"[object Object]"==Object.prototype.toString.call(c)){var s=a[o].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,n),r(a[o].val),void this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 曝光了实验"+o,level:"info",time:Date.now(),data:a[o]})}var c;this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getVar",level:"info",time:Date.now(),data:n}),r(n)}else r(n)},o.prototype.getAllVars=function(e){if("function"!=typeof e)throw new Error("callback must be a function");var t={callback:e,type:s.All};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealAllVars(t):this.callbacks.push(t)},o.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})},o.prototype.fechEvent=function(e,t,o){try{if(this.config.disable_track_event)return;if(!e)return;var n=this.collect.configManager.get(),r=n.header,a=n.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?o:window.location.href}),local_time_ms:Date.now()};r.custom=JSON.stringify(r.custom);var l={events:[c],user:a,header:r};"$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})}},o.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)},o.prototype.report=function(){var e=this,t=this.collect.cryptoData(this.exposureCache);this.collect.requestManager.useRequest({url:this.reportUrl,data:t,timeout:1e5,useBeacon:!1,encryption:this.config.enable_encryption,encryption_header:this.config.encryption_header,zip:!0,type:"event"}),this.exposureCache.forEach(function(t){e.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:[t],code:200,status:"success"})}),this.exposureCache=[]},o.prototype.setExternalAbVersion=function(e){this.extVersions=[e],this.updateVersions()},o.prototype.getABconfig=function(e,t){var o=Object.keys(e);o&&o.length&&this.collect.configManager.set(e),this.fetchAB(t)},o.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.getLocalItem(e)},o.prototype.set=function(e,t){this.ab_cross?this.cacheStorgae.setCookie(e,t,f,this.ab_cookie_domain):this.cacheStorgae.setLocalItem(e,t),this.collect.configManager.setAbCache(t)},o.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>=f?(this.cacheStorgae.removeLocalItem(this.abKey),null):e?t[e]:t},o.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)},o.prototype.setAbCache=function(e){var t=this.getABCache();t.data=this.data,t.uuid=e,t.timestamp=Date.now(),this.set(this.abKey,t)},o.prototype.clearCache=function(){this.refreshFetchStatus="ing",this.data={},this.extVersions=[],this.mulilinkVersions=[],this.versions=[],this.collect.configManager.clearAbCache()},o.prototype.openOverlayer=function(e){var o=this;if(function(){if(!document.getElementById(t)){var e="body { opacity: 0 !important; }",o=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)),o.appendChild(i)}}(),e)var i=setTimeout(function(){o.closeOverlayer(),clearTimeout(i)},e)},o.prototype.closeOverlayer=function(){var e;(e=document.getElementById(t))&&e.parentElement.removeChild(e)},o.prototype.fetchComplete=function(e,t){var o=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 o=e[t].vid;o&&i.push(o)}),this.versions=this.versions.filter(function(e){return i.includes(e)});var n=e.$ab_url,r=e.$ab_modification;if(r&&r.val&&this.enable_ab_visual){if(this.collect.destroyInstance)return;this.getVar("$ab_modification",window.location.href,function(){o.closeOverlayer()})}else if(n&&this.enable_multilink){this.mulilinkVersions=this.mulilinkVersions.filter(function(e){return i.includes(e)});var c=n.val,l=n.vid;c&&l&&this.getVar("$ab_url",c,function(){o.editMode||(c!==window.location.href?setTimeout(function(){if(!o.collect.destroyInstance){var e=""+c;e=-1===e.indexOf("http")?"https://"+e:e;var t=a(e).host;try{var i=new URL(e);t!==location.host?i.searchParams.append("vid",l):window.history.replaceState("","",e),window.location.href=i.href}catch(t){window.location.href=e}}},100):o.closeOverlayer())})}this.updateVersions()}else this.closeOverlayer();this.callbacks.forEach(function(e){return o[e.type===s.Var?"getRealVar":"getRealAllVars"](e,"")}),this.callbacks=[]},o.prototype.fetchAB=function(t){var o=this,n=this.collect.configManager.get(),r=n.header,a=n.user;this.config.enable_anonymousid&&delete a.web_id;var s=a.user_unique_id,c={header:e({aid:this.config.app_id},a||{},r||{},{ab_sdk_version:this.collect.configManager.getAbVersion(),ab_url:window.location.href})},l=this.collect.cryptoData(c);this.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,info:"SDK 发起AB实验请求",level:"info",logType:"fetch",time:Date.now(),data:c,infoType:"sdk"}),this.collect.requestManager.useRequest({url:this.fetchUrl,data:l,success:function(e){o.fetchStatus="complete",o.refreshFetchStatus="complete";var n=e.data;"success"===e.message?(o.fetchComplete(n,s),t&&t(n)):(o.fetchComplete(null,s),t&&t(null)),o.collect.emit(o.types.AbComplete,n),o.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求成功",level:"info",logType:"fetch",time:Date.now(),data:n,infoType:"sdk"})},fail:function(){o.fetchStatus="complete",o.refreshFetchStatus="complete",o.fetchComplete(null,s),t&&t(null),o.collect.emit(o.types.AbTimeout),o.collect.emit(i.DEBUGGER_MESSAGE,{type:i.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求网络异常",level:"error",logType:"fetch",time:Date.now(),infoType:"sdk"})},timeout:this.config.ab_timeout||1e4,encryption:this.config.enable_encryption,encryption_header:this.config.encryption_header})},o.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 o=new RegExp(t,"g");e=e.replace(o,"")}catch(e){}return e},o}();module.exports=m;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
|
|
18
|
+
var __assign = function() {
|
|
19
|
+
__assign = Object.assign || function __assign(t) {
|
|
20
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
+
s = arguments[i];
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
30
|
+
var e = new Error(message);
|
|
31
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
35
|
+
var STYLE_ID = '__rangers_ab_style__';
|
|
36
|
+
function openOverlayer() {
|
|
37
|
+
if (document.getElementById(STYLE_ID)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var css = 'body { opacity: 0 !important; }';
|
|
41
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
42
|
+
var style = document.createElement('style');
|
|
43
|
+
style.id = STYLE_ID;
|
|
44
|
+
style.type = 'text/css';
|
|
45
|
+
if (style.styleSheet) {
|
|
46
|
+
style.styleSheet.cssText = css;
|
|
47
|
+
} else {
|
|
48
|
+
style.appendChild(document.createTextNode(css));
|
|
49
|
+
}
|
|
50
|
+
head.appendChild(style);
|
|
51
|
+
}
|
|
52
|
+
function closeOverlayer() {
|
|
53
|
+
var style = document.getElementById(STYLE_ID);
|
|
54
|
+
if (style) {
|
|
55
|
+
style.parentElement.removeChild(style);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
60
|
+
var AB_DOMAINS = {
|
|
61
|
+
cn: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k',
|
|
62
|
+
va: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k',
|
|
63
|
+
sg: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k'
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
67
|
+
var Types;
|
|
68
|
+
(function (Types) {
|
|
69
|
+
Types["Init"] = "init";
|
|
70
|
+
Types["Config"] = "config";
|
|
71
|
+
Types["Start"] = "start";
|
|
72
|
+
Types["Ready"] = "ready";
|
|
73
|
+
Types["TokenComplete"] = "token-complete";
|
|
74
|
+
Types["TokenStorage"] = "token-storage";
|
|
75
|
+
Types["TokenFetch"] = "token-fetch";
|
|
76
|
+
Types["TokenError"] = "token-error";
|
|
77
|
+
Types["ConfigUuid"] = "config-uuid";
|
|
78
|
+
Types["ConfigWebId"] = "config-webid";
|
|
79
|
+
Types["ConfigDomain"] = "config-domain";
|
|
80
|
+
Types["CustomWebId"] = "custom-webid";
|
|
81
|
+
Types["AnonymousId"] = "anonymous-id";
|
|
82
|
+
Types["TokenChange"] = "token-change";
|
|
83
|
+
Types["TokenReset"] = "token-reset";
|
|
84
|
+
Types["ConfigTransform"] = "config-transform";
|
|
85
|
+
Types["EnvTransform"] = "env-transform";
|
|
86
|
+
Types["SessionReset"] = "session-reset";
|
|
87
|
+
Types["SessionResetTime"] = "session-reset-time";
|
|
88
|
+
Types["Event"] = "event";
|
|
89
|
+
Types["Events"] = "events";
|
|
90
|
+
Types["EventNow"] = "event-now";
|
|
91
|
+
Types["CleanEvents"] = "clean-events";
|
|
92
|
+
Types["BeconEvent"] = "becon-event";
|
|
93
|
+
Types["SubmitBefore"] = "submit-before";
|
|
94
|
+
Types["SubmitScuess"] = "submit-scuess";
|
|
95
|
+
Types["SubmitSuccess"] = "submit-success";
|
|
96
|
+
Types["SubmitAfter"] = "submit-after";
|
|
97
|
+
Types["SubmitError"] = "submit-error";
|
|
98
|
+
Types["SubmitVerifyH"] = "submit-verify-h5";
|
|
99
|
+
Types["Stay"] = "stay";
|
|
100
|
+
Types["ResetStay"] = "reset-stay";
|
|
101
|
+
Types["StayReady"] = "stay-ready";
|
|
102
|
+
Types["SetStay"] = "set-stay";
|
|
103
|
+
Types["RouteChange"] = "route-change";
|
|
104
|
+
Types["RouteReady"] = "route-ready";
|
|
105
|
+
Types["Ab"] = "ab";
|
|
106
|
+
Types["AbVar"] = "ab-var";
|
|
107
|
+
Types["AbAllVars"] = "ab-all-vars";
|
|
108
|
+
Types["AbConfig"] = "ab-config";
|
|
109
|
+
Types["AbExternalVersion"] = "ab-external-version";
|
|
110
|
+
Types["AbVersionChangeOn"] = "ab-version-change-on";
|
|
111
|
+
Types["AbVersionChangeOff"] = "ab-version-change-off";
|
|
112
|
+
Types["AbOpenLayer"] = "ab-open-layer";
|
|
113
|
+
Types["AbCloseLayer"] = "ab-close-layer";
|
|
114
|
+
Types["AbReady"] = "ab-ready";
|
|
115
|
+
Types["AbComplete"] = "ab-complete";
|
|
116
|
+
Types["AbTimeout"] = "ab-timeout";
|
|
117
|
+
Types["Profile"] = "profile";
|
|
118
|
+
Types["ProfileSet"] = "profile-set";
|
|
119
|
+
Types["ProfileSetOnce"] = "profile-set-once";
|
|
120
|
+
Types["ProfileUnset"] = "profile-unset";
|
|
121
|
+
Types["ProfileIncrement"] = "profile-increment";
|
|
122
|
+
Types["ProfileAppend"] = "profile-append";
|
|
123
|
+
Types["ProfileClear"] = "profile-clear";
|
|
124
|
+
Types["TrackDuration"] = "track-duration";
|
|
125
|
+
Types["TrackDurationStart"] = "track-duration-start";
|
|
126
|
+
Types["TrackDurationEnd"] = "track-duration-end";
|
|
127
|
+
Types["TrackDurationPause"] = "track-duration-pause";
|
|
128
|
+
Types["TrackDurationResume"] = "tracl-duration-resume";
|
|
129
|
+
Types["Autotrack"] = "autotrack";
|
|
130
|
+
Types["AutotrackReady"] = "autotrack-ready";
|
|
131
|
+
Types["CustomHeader"] = "custom-request-header";
|
|
132
|
+
Types["TracerReady"] = "tracer-ready";
|
|
133
|
+
})(Types || (Types = {}));
|
|
134
|
+
var DebuggerMesssge;
|
|
135
|
+
(function (DebuggerMesssge) {
|
|
136
|
+
DebuggerMesssge["DEBUGGER_MESSAGE"] = "debugger-message";
|
|
137
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_SDK"] = "debugger-message-sdk";
|
|
138
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH"] = "debugger-message-fetch";
|
|
139
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH_RESULT"] = "debugger-message-fetch-result";
|
|
140
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_EVENT"] = "debugger-message-event";
|
|
141
|
+
DebuggerMesssge["DEVTOOL_WEB_READY"] = "devtool-web-ready";
|
|
142
|
+
})(DebuggerMesssge || (DebuggerMesssge = {}));
|
|
143
|
+
|
|
144
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
145
|
+
// @ts-nocheck
|
|
146
|
+
// @ts-nocheck
|
|
147
|
+
var isObject = function isObject(obj) {
|
|
148
|
+
return obj != null && Object.prototype.toString.call(obj) == '[object Object]';
|
|
149
|
+
};
|
|
150
|
+
(function () {
|
|
151
|
+
var lastEventId = +Date.now() + Number(("" + Math.random()).slice(2, 8));
|
|
152
|
+
return function () {
|
|
153
|
+
lastEventId += 1;
|
|
154
|
+
return lastEventId;
|
|
155
|
+
};
|
|
156
|
+
})();
|
|
157
|
+
/* eslint-disable no-param-reassign */
|
|
158
|
+
var decrypto = function decrypto(str, xor, hex) {
|
|
159
|
+
if (typeof str !== 'string' || typeof xor !== 'number' || typeof hex !== 'number') {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
var strCharList = [];
|
|
163
|
+
var resultList = [];
|
|
164
|
+
hex = hex <= 25 ? hex : hex % 25;
|
|
165
|
+
var splitStr = String.fromCharCode(hex + 97);
|
|
166
|
+
strCharList = str.split(splitStr);
|
|
167
|
+
for (var i = 0; i < strCharList.length; i++) {
|
|
168
|
+
var charCode = parseInt(strCharList[i], hex);
|
|
169
|
+
charCode = charCode * 1 ^ xor;
|
|
170
|
+
var strChar = String.fromCharCode(charCode);
|
|
171
|
+
resultList.push(strChar);
|
|
172
|
+
}
|
|
173
|
+
var resultStr = resultList.join('');
|
|
174
|
+
return resultStr;
|
|
175
|
+
};
|
|
176
|
+
var decodeUrl = function decodeUrl(string) {
|
|
177
|
+
return decrypto(string, 64, 25);
|
|
178
|
+
};
|
|
179
|
+
var parseURL = function parseURL(url) {
|
|
180
|
+
var a = document.createElement('a');
|
|
181
|
+
a.href = url;
|
|
182
|
+
return a;
|
|
183
|
+
};
|
|
184
|
+
var parseUrlQuery = function parseUrlQuery(url) {
|
|
185
|
+
var queryObj = {};
|
|
186
|
+
try {
|
|
187
|
+
var queryString = parseURL(url).search;
|
|
188
|
+
queryString = queryString.slice(1);
|
|
189
|
+
queryString.split('&').forEach(function (keyValue) {
|
|
190
|
+
var _keyValue = keyValue.split('=');
|
|
191
|
+
var key;
|
|
192
|
+
var value;
|
|
193
|
+
if (_keyValue.length) {
|
|
194
|
+
key = _keyValue[0];
|
|
195
|
+
value = _keyValue[1];
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
queryObj[key] = decodeURIComponent(typeof value === 'undefined' ? '' : value);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
queryObj[key] = value;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
} catch (e) {}
|
|
204
|
+
return queryObj;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
function createCommonjsModule(fn, module) {
|
|
208
|
+
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
var cookie = createCommonjsModule(function (module, exports) {
|
|
212
|
+
(function (factory) {
|
|
213
|
+
var registeredInModuleLoader;
|
|
214
|
+
{
|
|
215
|
+
module.exports = factory();
|
|
216
|
+
registeredInModuleLoader = true;
|
|
217
|
+
}
|
|
218
|
+
if (!registeredInModuleLoader) {
|
|
219
|
+
var OldCookies = window.Cookies;
|
|
220
|
+
var api = window.Cookies = factory();
|
|
221
|
+
api.noConflict = function () {
|
|
222
|
+
window.Cookies = OldCookies;
|
|
223
|
+
return api;
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
})(function () {
|
|
227
|
+
function extend() {
|
|
228
|
+
var i = 0;
|
|
229
|
+
var result = {};
|
|
230
|
+
for (; i < arguments.length; i++) {
|
|
231
|
+
var attributes = arguments[i];
|
|
232
|
+
for (var key in attributes) {
|
|
233
|
+
result[key] = attributes[key];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
function decode(s) {
|
|
239
|
+
return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
|
|
240
|
+
}
|
|
241
|
+
function init(converter) {
|
|
242
|
+
function api() {}
|
|
243
|
+
function set(key, value, attributes) {
|
|
244
|
+
if (typeof document === 'undefined') {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
attributes = extend({
|
|
248
|
+
path: '/'
|
|
249
|
+
}, api.defaults, attributes);
|
|
250
|
+
if (typeof attributes.expires === 'number') {
|
|
251
|
+
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
|
|
252
|
+
}
|
|
253
|
+
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
|
|
254
|
+
try {
|
|
255
|
+
var result = JSON.stringify(value);
|
|
256
|
+
if (/^[\{\[]/.test(result)) {
|
|
257
|
+
value = result;
|
|
258
|
+
}
|
|
259
|
+
} catch (e) {}
|
|
260
|
+
value = converter.write ? converter.write(value, key) : encodeURIComponent(String(value)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
|
|
261
|
+
key = encodeURIComponent(String(key)).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
|
|
262
|
+
var stringifiedAttributes = '';
|
|
263
|
+
for (var attributeName in attributes) {
|
|
264
|
+
if (!attributes[attributeName]) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
stringifiedAttributes += '; ' + attributeName;
|
|
268
|
+
if (attributes[attributeName] === true) {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
272
|
+
}
|
|
273
|
+
return document.cookie = key + '=' + value + stringifiedAttributes;
|
|
274
|
+
}
|
|
275
|
+
function get(key, json) {
|
|
276
|
+
if (typeof document === 'undefined') {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
var jar = {};
|
|
280
|
+
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
281
|
+
var i = 0;
|
|
282
|
+
for (; i < cookies.length; i++) {
|
|
283
|
+
var parts = cookies[i].split('=');
|
|
284
|
+
var cookie = parts.slice(1).join('=');
|
|
285
|
+
if (!json && cookie.charAt(0) === '"') {
|
|
286
|
+
cookie = cookie.slice(1, -1);
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
var name = decode(parts[0]);
|
|
290
|
+
cookie = (converter.read || converter)(cookie, name) || decode(cookie);
|
|
291
|
+
if (json) {
|
|
292
|
+
try {
|
|
293
|
+
cookie = JSON.parse(cookie);
|
|
294
|
+
} catch (e) {}
|
|
295
|
+
}
|
|
296
|
+
jar[name] = cookie;
|
|
297
|
+
if (key === name) {
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
} catch (e) {}
|
|
301
|
+
}
|
|
302
|
+
return key ? jar[key] : jar;
|
|
303
|
+
}
|
|
304
|
+
api.set = set;
|
|
305
|
+
api.get = function (key) {
|
|
306
|
+
return get(key, false );
|
|
307
|
+
};
|
|
308
|
+
api.getJSON = function (key) {
|
|
309
|
+
return get(key, true );
|
|
310
|
+
};
|
|
311
|
+
api.remove = function (key, attributes) {
|
|
312
|
+
set(key, '', extend(attributes, {
|
|
313
|
+
expires: -1
|
|
314
|
+
}));
|
|
315
|
+
};
|
|
316
|
+
api.defaults = {};
|
|
317
|
+
api.withConverter = init;
|
|
318
|
+
return api;
|
|
319
|
+
}
|
|
320
|
+
return init(function () {});
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
325
|
+
/**
|
|
326
|
+
* cacheStorage
|
|
327
|
+
*/
|
|
328
|
+
var Memory = /** @class */function () {
|
|
329
|
+
function Memory() {
|
|
330
|
+
this.cache = {};
|
|
331
|
+
}
|
|
332
|
+
Memory.prototype.setItem = function (cacheKey, data) {
|
|
333
|
+
this.cache[cacheKey] = data;
|
|
334
|
+
};
|
|
335
|
+
Memory.prototype.getItem = function (cacheKey) {
|
|
336
|
+
return this.cache[cacheKey];
|
|
337
|
+
};
|
|
338
|
+
Memory.prototype.removeItem = function (cacheKey) {
|
|
339
|
+
this.cache[cacheKey] = undefined;
|
|
340
|
+
};
|
|
341
|
+
return Memory;
|
|
342
|
+
}();
|
|
343
|
+
/**
|
|
344
|
+
* localStorage
|
|
345
|
+
*/
|
|
346
|
+
var Local = /** @class */function () {
|
|
347
|
+
function Local() {
|
|
348
|
+
this.support = this.isSupportLS();
|
|
349
|
+
}
|
|
350
|
+
Local.prototype.isSupportLS = function () {
|
|
351
|
+
try {
|
|
352
|
+
localStorage.setItem('_applogtest-test-key', 'hi');
|
|
353
|
+
localStorage.getItem('_applogtest-test-key');
|
|
354
|
+
localStorage.removeItem('_applogtest-test-key');
|
|
355
|
+
return true;
|
|
356
|
+
} catch (e) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
Local.prototype.getItem = function (key) {
|
|
361
|
+
try {
|
|
362
|
+
var value = localStorage.getItem(key);
|
|
363
|
+
var ret = value;
|
|
364
|
+
try {
|
|
365
|
+
if (value && typeof value === 'string') {
|
|
366
|
+
ret = JSON.parse(value);
|
|
367
|
+
}
|
|
368
|
+
} catch (e) {}
|
|
369
|
+
return ret || {};
|
|
370
|
+
} catch (e) {}
|
|
371
|
+
return {};
|
|
372
|
+
};
|
|
373
|
+
Local.prototype.setItem = function (key, value) {
|
|
374
|
+
try {
|
|
375
|
+
var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
376
|
+
localStorage.setItem(key, stringValue);
|
|
377
|
+
} catch (e) {}
|
|
378
|
+
};
|
|
379
|
+
Local.prototype.removeItem = function (key) {
|
|
380
|
+
try {
|
|
381
|
+
localStorage.removeItem(key);
|
|
382
|
+
} catch (e) {}
|
|
383
|
+
};
|
|
384
|
+
return Local;
|
|
385
|
+
}();
|
|
386
|
+
/**
|
|
387
|
+
* sessionStorage
|
|
388
|
+
*/
|
|
389
|
+
var Session = /** @class */function () {
|
|
390
|
+
function Session() {
|
|
391
|
+
this.support = this.isSupportSession();
|
|
392
|
+
}
|
|
393
|
+
Session.prototype.isSupportSession = function () {
|
|
394
|
+
try {
|
|
395
|
+
sessionStorage.setItem('_applogtest-test-key', 'hi');
|
|
396
|
+
sessionStorage.getItem('_applogtest-test-key');
|
|
397
|
+
sessionStorage.removeItem('_applogtest-test-key');
|
|
398
|
+
return true;
|
|
399
|
+
} catch (e) {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
Session.prototype.getItem = function (key) {
|
|
404
|
+
try {
|
|
405
|
+
var value = sessionStorage.getItem(key);
|
|
406
|
+
var ret = value;
|
|
407
|
+
try {
|
|
408
|
+
if (value && typeof value === 'string') {
|
|
409
|
+
ret = JSON.parse(value);
|
|
410
|
+
}
|
|
411
|
+
} catch (e) {}
|
|
412
|
+
return ret || {};
|
|
413
|
+
} catch (e) {}
|
|
414
|
+
return {};
|
|
415
|
+
};
|
|
416
|
+
Session.prototype.setItem = function (key, value) {
|
|
417
|
+
try {
|
|
418
|
+
var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
419
|
+
sessionStorage.setItem(key, stringValue);
|
|
420
|
+
} catch (e) {}
|
|
421
|
+
};
|
|
422
|
+
Session.prototype.removeItem = function (key) {
|
|
423
|
+
try {
|
|
424
|
+
sessionStorage.removeItem(key);
|
|
425
|
+
} catch (e) {}
|
|
426
|
+
};
|
|
427
|
+
return Session;
|
|
428
|
+
}();
|
|
429
|
+
var StorageManager = /** @class */function () {
|
|
430
|
+
function StorageManager() {
|
|
431
|
+
this.defaultExpireTime = 7 * 1000 * 60 * 60 * 24;
|
|
432
|
+
this.local = new Local();
|
|
433
|
+
this.session = new Session();
|
|
434
|
+
this.cache = new Memory();
|
|
435
|
+
}
|
|
436
|
+
StorageManager.prototype.getLocalItem = function (key) {
|
|
437
|
+
return this.local.getItem(key);
|
|
438
|
+
};
|
|
439
|
+
StorageManager.prototype.setLocalItem = function (key, value) {
|
|
440
|
+
this.local.setItem(key, value);
|
|
441
|
+
};
|
|
442
|
+
StorageManager.prototype.removeLocalItem = function (key) {
|
|
443
|
+
this.local.removeItem(key);
|
|
444
|
+
};
|
|
445
|
+
StorageManager.prototype.getSessionItem = function (key) {
|
|
446
|
+
return this.session.getItem(key);
|
|
447
|
+
};
|
|
448
|
+
StorageManager.prototype.setSessionItem = function (key, value) {
|
|
449
|
+
this.session.setItem(key, value);
|
|
450
|
+
};
|
|
451
|
+
StorageManager.prototype.removeSessionItem = function (key) {
|
|
452
|
+
this.session.removeItem(key);
|
|
453
|
+
};
|
|
454
|
+
StorageManager.prototype.getCacheItem = function (key) {
|
|
455
|
+
return this.cache.getItem(key);
|
|
456
|
+
};
|
|
457
|
+
StorageManager.prototype.setCacheItem = function (key, value) {
|
|
458
|
+
this.cache.setItem(key, value);
|
|
459
|
+
};
|
|
460
|
+
StorageManager.prototype.removeCacheItem = function (key) {
|
|
461
|
+
this.cache.removeItem(key);
|
|
462
|
+
};
|
|
463
|
+
StorageManager.prototype.getCookie = function (key, domain) {
|
|
464
|
+
try {
|
|
465
|
+
// const _matches = Cookies.get(name, { domain: domain || document.domain })
|
|
466
|
+
var _matches = cookie.get(key);
|
|
467
|
+
return _matches;
|
|
468
|
+
} catch (e) {
|
|
469
|
+
return '';
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
StorageManager.prototype.setCookie = function (key, value, expiresTime, domain) {
|
|
473
|
+
if (expiresTime === void 0) {
|
|
474
|
+
expiresTime = this.defaultExpireTime;
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
var _domain = domain || document.domain;
|
|
478
|
+
var timestamp = +new Date();
|
|
479
|
+
var furureTimestamp = timestamp + expiresTime;
|
|
480
|
+
cookie.set(key, value, {
|
|
481
|
+
expires: new Date(furureTimestamp),
|
|
482
|
+
path: '/',
|
|
483
|
+
domain: _domain
|
|
484
|
+
});
|
|
485
|
+
} catch (e) {}
|
|
486
|
+
};
|
|
487
|
+
StorageManager.prototype.removeCookie = function (key, domain) {
|
|
488
|
+
try {
|
|
489
|
+
cookie.remove(key, {
|
|
490
|
+
path: '/',
|
|
491
|
+
domain: domain || ''
|
|
492
|
+
});
|
|
493
|
+
} catch (e) {}
|
|
494
|
+
};
|
|
495
|
+
return StorageManager;
|
|
496
|
+
}();
|
|
497
|
+
|
|
498
|
+
var CallbackType;
|
|
499
|
+
(function (CallbackType) {
|
|
500
|
+
CallbackType[CallbackType["Var"] = 0] = "Var";
|
|
501
|
+
CallbackType[CallbackType["All"] = 1] = "All";
|
|
502
|
+
})(CallbackType || (CallbackType = {}));
|
|
503
|
+
var STORAGE_EXPRIRE = 1 * 30 * 24 * 60 * 60 * 1000;
|
|
504
|
+
var API = '/service/2/abtest_config/';
|
|
505
|
+
var Ab = /** @class */function () {
|
|
506
|
+
function Ab() {
|
|
507
|
+
this.fetchStatus = 'no';
|
|
508
|
+
this.refreshFetchStatus = 'complete';
|
|
509
|
+
this.versions = [];
|
|
510
|
+
this.extVersions = [];
|
|
511
|
+
this.mulilinkVersions = [];
|
|
512
|
+
this.enable_multilink = false;
|
|
513
|
+
this.enable_ab_visual = false;
|
|
514
|
+
this.editMode = false;
|
|
515
|
+
this.callbacks = [];
|
|
516
|
+
this.data = null;
|
|
517
|
+
this.changeListener = new Map();
|
|
518
|
+
this.readyStatus = false;
|
|
519
|
+
this.exposureCache = [];
|
|
520
|
+
}
|
|
521
|
+
Ab.prototype.apply = function (collect, config) {
|
|
522
|
+
var _this = this;
|
|
523
|
+
this.collect = collect;
|
|
524
|
+
this.config = config;
|
|
525
|
+
if (!this.config.enable_ab_test) return;
|
|
526
|
+
var enable_multilink = config.enable_multilink,
|
|
527
|
+
ab_channel_domain = config.ab_channel_domain,
|
|
528
|
+
enable_ab_visual = config.enable_ab_visual,
|
|
529
|
+
ab_cross = config.ab_cross,
|
|
530
|
+
ab_cookie_domain = config.ab_cookie_domain,
|
|
531
|
+
disable_ab_reset = config.disable_ab_reset;
|
|
532
|
+
var abDomain = ab_channel_domain || decodeUrl(AB_DOMAINS[config.channel || 'cn']);
|
|
533
|
+
this.cacheStorgae = new StorageManager();
|
|
534
|
+
this.enable_multilink = enable_multilink;
|
|
535
|
+
this.enable_ab_visual = enable_ab_visual;
|
|
536
|
+
this.abKey = "__tea_sdk_ab_version_" + config.app_id;
|
|
537
|
+
this.ab_cross = ab_cross;
|
|
538
|
+
this.ab_cookie_domain = ab_cookie_domain || '';
|
|
539
|
+
this.fetchUrl = "" + abDomain + API;
|
|
540
|
+
this.reportUrl = "" + collect.configManager.getUrl('event');
|
|
541
|
+
this.exposureLimit = config.exposure_limit || 20;
|
|
542
|
+
this.ab_batch_time = config.ab_batch_time || 500;
|
|
543
|
+
var Types = this.collect.Types;
|
|
544
|
+
this.types = Types;
|
|
545
|
+
this.collect.on(Types.TokenChange, function (tokenInfo) {
|
|
546
|
+
if (disable_ab_reset) return;
|
|
547
|
+
if (tokenInfo.type !== 'uuid') return;
|
|
548
|
+
if (!_this.readyStatus) return;
|
|
549
|
+
_this.clearCache();
|
|
550
|
+
_this.fetchAB();
|
|
551
|
+
});
|
|
552
|
+
this.collect.on(Types.TokenReset, function () {
|
|
553
|
+
if (disable_ab_reset) return;
|
|
554
|
+
if (!_this.readyStatus) return;
|
|
555
|
+
_this.clearCache();
|
|
556
|
+
_this.fetchAB();
|
|
557
|
+
});
|
|
558
|
+
this.collect.on(Types.AbVar, function (_a) {
|
|
559
|
+
var name = _a.name,
|
|
560
|
+
defaultValue = _a.defaultValue,
|
|
561
|
+
callback = _a.callback;
|
|
562
|
+
_this.getVar(name, defaultValue, callback);
|
|
563
|
+
});
|
|
564
|
+
this.collect.on(Types.AbAllVars, function (callback) {
|
|
565
|
+
_this.getAllVars(callback);
|
|
566
|
+
});
|
|
567
|
+
this.collect.on(Types.AbConfig, function (_a) {
|
|
568
|
+
var params = _a.params,
|
|
569
|
+
callback = _a.callback;
|
|
570
|
+
_this.getABconfig(params, callback);
|
|
571
|
+
});
|
|
572
|
+
this.collect.on(Types.AbExternalVersion, function (vids) {
|
|
573
|
+
_this.setExternalAbVersion(vids);
|
|
574
|
+
});
|
|
575
|
+
this.collect.on(Types.AbOpenLayer, function () {
|
|
576
|
+
_this.openOverlayer();
|
|
577
|
+
});
|
|
578
|
+
this.collect.on(Types.AbCloseLayer, function () {
|
|
579
|
+
_this.closeOverlayer();
|
|
580
|
+
});
|
|
581
|
+
this.collect.on(Types.AbVersionChangeOn, function (cb) {
|
|
582
|
+
_this.changeListener.set(cb, cb);
|
|
583
|
+
});
|
|
584
|
+
this.collect.on(Types.AbVersionChangeOff, function (cb) {
|
|
585
|
+
if (_this.changeListener.get(cb)) {
|
|
586
|
+
_this.changeListener["delete"](cb);
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
this.loadMode();
|
|
590
|
+
(this.enable_ab_visual || this.enable_multilink) && this.openOverlayer(this.config.multilink_timeout_ms || 500);
|
|
591
|
+
this.checkLocal();
|
|
592
|
+
this.ready('ab');
|
|
593
|
+
if (!this.readyStatus) {
|
|
594
|
+
this.fetchAB();
|
|
595
|
+
this.readyStatus = true;
|
|
596
|
+
}
|
|
597
|
+
this.collect.emit(Types.AbReady);
|
|
598
|
+
};
|
|
599
|
+
Ab.prototype.ready = function (name) {
|
|
600
|
+
var _this = this;
|
|
601
|
+
this.collect.set(name);
|
|
602
|
+
if (this.collect.hook._hooksCache.hasOwnProperty(name)) {
|
|
603
|
+
var emits = this.collect.hook._hooksCache[name];
|
|
604
|
+
if (!Object.keys(emits).length) return;
|
|
605
|
+
var _loop_1 = function _loop_1(key) {
|
|
606
|
+
if (emits[key].length) {
|
|
607
|
+
emits[key].forEach(function (item) {
|
|
608
|
+
_this.collect.hook.emit(key, item);
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
for (var key in emits) {
|
|
613
|
+
_loop_1(key);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
Ab.prototype.loadMode = function () {
|
|
618
|
+
// const name = getIframeUrl();
|
|
619
|
+
// let editMode = '';
|
|
620
|
+
// if (name) {
|
|
621
|
+
// const { scenario, href } = name;
|
|
622
|
+
// if (scenario) {
|
|
623
|
+
// this.editMode = true;
|
|
624
|
+
// editMode = scenario;
|
|
625
|
+
// } else if (
|
|
626
|
+
// href &&
|
|
627
|
+
// (href.indexOf('datatester') !== -1 ||
|
|
628
|
+
// href.indexOf('visual-editor') !== -1)
|
|
629
|
+
// ) {
|
|
630
|
+
// this.editMode = true;
|
|
631
|
+
// editMode = 'visual-editor';
|
|
632
|
+
// }
|
|
633
|
+
// }
|
|
634
|
+
// if (this.enable_ab_visual) {
|
|
635
|
+
// readyToLoadEditor(this.collect, this.config);
|
|
636
|
+
// if (editMode === 'visual-editor') {
|
|
637
|
+
// this.collect.destoryInstace();
|
|
638
|
+
// return;
|
|
639
|
+
// }
|
|
640
|
+
// }
|
|
641
|
+
// if (this.enable_multilink) {
|
|
642
|
+
// loadMuiltlink(this.collect, this.config);
|
|
643
|
+
// }
|
|
644
|
+
};
|
|
645
|
+
Ab.prototype.checkLocal = function () {
|
|
646
|
+
var _a = this.getABCache(),
|
|
647
|
+
ab_version = _a.ab_version,
|
|
648
|
+
ab_ext_version = _a.ab_ext_version,
|
|
649
|
+
ab_version_multilink = _a.ab_version_multilink,
|
|
650
|
+
data = _a.data;
|
|
651
|
+
var mulilinkUrlVid = this.checkFromUrl();
|
|
652
|
+
if (mulilinkUrlVid) {
|
|
653
|
+
this.mulilinkVersions.push(mulilinkUrlVid);
|
|
654
|
+
} else {
|
|
655
|
+
this.mulilinkVersions = ab_version_multilink || [];
|
|
656
|
+
}
|
|
657
|
+
this.extVersions = ab_ext_version || [];
|
|
658
|
+
this.versions = ab_version || [];
|
|
659
|
+
this.data = data;
|
|
660
|
+
var vids = this.versions.concat(this.extVersions);
|
|
661
|
+
if (this.enable_multilink) {
|
|
662
|
+
vids = vids.concat(this.mulilinkVersions);
|
|
663
|
+
}
|
|
664
|
+
this.configVersions(vids.join(','));
|
|
665
|
+
};
|
|
666
|
+
Ab.prototype.checkFromUrl = function () {
|
|
667
|
+
var urlQueryObj = parseUrlQuery(window.location.href);
|
|
668
|
+
if (urlQueryObj && urlQueryObj['vid']) {
|
|
669
|
+
return urlQueryObj['vid'];
|
|
670
|
+
}
|
|
671
|
+
return '';
|
|
672
|
+
};
|
|
673
|
+
Ab.prototype.updateVersions = function () {
|
|
674
|
+
var versions = this.extVersions.length ? this.versions.concat(this.extVersions) : this.versions;
|
|
675
|
+
if (this.enable_multilink) {
|
|
676
|
+
versions = versions.concat(this.mulilinkVersions);
|
|
677
|
+
}
|
|
678
|
+
this.configVersions(versions.join(','));
|
|
679
|
+
this.updateABCache();
|
|
680
|
+
this.changeListener.size > 0 && this.changeListener.forEach(function (listener) {
|
|
681
|
+
if (typeof listener === 'function') {
|
|
682
|
+
listener(versions);
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
};
|
|
686
|
+
Ab.prototype.configVersions = function (vids) {
|
|
687
|
+
this.collect.configManager.setAbVersion(vids);
|
|
688
|
+
};
|
|
689
|
+
Ab.prototype.getVar = function (name, defaultValue, callback) {
|
|
690
|
+
if (!name) {
|
|
691
|
+
throw new Error('variable must not be empty');
|
|
692
|
+
}
|
|
693
|
+
if (defaultValue === undefined) {
|
|
694
|
+
throw new Error('variable no default value');
|
|
695
|
+
}
|
|
696
|
+
if (typeof callback !== 'function') {
|
|
697
|
+
throw new Error('callback must be a function');
|
|
698
|
+
}
|
|
699
|
+
var callbackObj = {
|
|
700
|
+
name: name,
|
|
701
|
+
defaultValue: defaultValue,
|
|
702
|
+
callback: callback,
|
|
703
|
+
type: CallbackType.Var
|
|
704
|
+
};
|
|
705
|
+
if (this.fetchStatus === 'complete' && this.refreshFetchStatus === 'complete') {
|
|
706
|
+
this.getRealVar(callbackObj, name);
|
|
707
|
+
} else {
|
|
708
|
+
this.callbacks.push(callbackObj);
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
Ab.prototype.getRealVar = function (item, key) {
|
|
712
|
+
var name = item.name,
|
|
713
|
+
defaultValue = item.defaultValue,
|
|
714
|
+
callback = item.callback;
|
|
715
|
+
var data = this.data;
|
|
716
|
+
if (!data) {
|
|
717
|
+
callback(defaultValue);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
if (isObject(data[name])) {
|
|
721
|
+
var vid = data[name].vid;
|
|
722
|
+
if (key === '$ab_url') {
|
|
723
|
+
if (!this.mulilinkVersions.includes(vid)) {
|
|
724
|
+
this.mulilinkVersions.push(vid);
|
|
725
|
+
}
|
|
726
|
+
} else {
|
|
727
|
+
if (!this.versions.includes(vid)) {
|
|
728
|
+
this.versions.push(vid);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
this.updateVersions();
|
|
732
|
+
this.fechEvent(vid, key, defaultValue);
|
|
733
|
+
callback(data[name].val);
|
|
734
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
735
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
736
|
+
secType: 'AB',
|
|
737
|
+
info: "SDK \u66DD\u5149\u4E86\u5B9E\u9A8C" + name,
|
|
738
|
+
level: 'info',
|
|
739
|
+
time: Date.now(),
|
|
740
|
+
data: data[name]
|
|
741
|
+
});
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
745
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
746
|
+
secType: 'AB',
|
|
747
|
+
info: 'SDK 调用getVar',
|
|
748
|
+
level: 'info',
|
|
749
|
+
time: Date.now(),
|
|
750
|
+
data: defaultValue
|
|
751
|
+
});
|
|
752
|
+
callback(defaultValue);
|
|
753
|
+
};
|
|
754
|
+
Ab.prototype.getAllVars = function (callback) {
|
|
755
|
+
if (typeof callback !== 'function') {
|
|
756
|
+
throw new Error('callback must be a function');
|
|
757
|
+
}
|
|
758
|
+
var callbackObj = {
|
|
759
|
+
callback: callback,
|
|
760
|
+
type: CallbackType.All
|
|
761
|
+
};
|
|
762
|
+
if (this.fetchStatus === 'complete' && this.refreshFetchStatus === 'complete') {
|
|
763
|
+
this.getRealAllVars(callbackObj);
|
|
764
|
+
} else {
|
|
765
|
+
this.callbacks.push(callbackObj);
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
Ab.prototype.getRealAllVars = function (item) {
|
|
769
|
+
var callback = item.callback;
|
|
770
|
+
callback(this.data ? JSON.parse(JSON.stringify(this.data)) : {});
|
|
771
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
772
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
773
|
+
secType: 'AB',
|
|
774
|
+
info: 'SDK 调用getAllVars',
|
|
775
|
+
level: 'info',
|
|
776
|
+
time: Date.now(),
|
|
777
|
+
data: this.data
|
|
778
|
+
});
|
|
779
|
+
};
|
|
780
|
+
Ab.prototype.fechEvent = function (vid, key, ab_url) {
|
|
781
|
+
try {
|
|
782
|
+
if (this.config.disable_track_event) return;
|
|
783
|
+
if (!vid) return;
|
|
784
|
+
var _a = this.collect.configManager.get(),
|
|
785
|
+
header = _a.header,
|
|
786
|
+
user = _a.user;
|
|
787
|
+
var cache = this.getABCache();
|
|
788
|
+
if (cache && cache.uuid && cache.uuid !== user.user_unique_id) return;
|
|
789
|
+
var event_1 = {
|
|
790
|
+
event: 'abtest_exposure',
|
|
791
|
+
ab_sdk_version: "" + vid,
|
|
792
|
+
params: JSON.stringify({
|
|
793
|
+
app_id: this.config.appId,
|
|
794
|
+
ab_url: key === '$ab_url' ? ab_url : window.location.href
|
|
795
|
+
}),
|
|
796
|
+
local_time_ms: Date.now()
|
|
797
|
+
};
|
|
798
|
+
header['custom'] = JSON.stringify(header['custom']);
|
|
799
|
+
var abData = {
|
|
800
|
+
events: [event_1],
|
|
801
|
+
user: user,
|
|
802
|
+
header: header
|
|
803
|
+
};
|
|
804
|
+
if (key === '$ab_url') {
|
|
805
|
+
if (window.navigator.sendBeacon) {
|
|
806
|
+
window.navigator.sendBeacon(this.reportUrl, JSON.stringify([abData]));
|
|
807
|
+
} else {
|
|
808
|
+
this.reportExposure(abData);
|
|
809
|
+
}
|
|
810
|
+
} else {
|
|
811
|
+
this.reportExposure(abData);
|
|
812
|
+
}
|
|
813
|
+
} catch (e) {
|
|
814
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
815
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
816
|
+
info: '发生了异常',
|
|
817
|
+
level: 'error',
|
|
818
|
+
time: Date.now(),
|
|
819
|
+
data: e.message
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
Ab.prototype.reportExposure = function (abData) {
|
|
824
|
+
var _this = this;
|
|
825
|
+
this.exposureCache.push(abData);
|
|
826
|
+
if (this.reportTimeout) {
|
|
827
|
+
clearTimeout(this.reportTimeout);
|
|
828
|
+
}
|
|
829
|
+
if (this.exposureCache.length >= this.exposureLimit) {
|
|
830
|
+
this.report();
|
|
831
|
+
} else {
|
|
832
|
+
this.reportTimeout = setTimeout(function () {
|
|
833
|
+
_this.report();
|
|
834
|
+
clearTimeout(_this.reportTimeout);
|
|
835
|
+
}, this.ab_batch_time);
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
Ab.prototype.report = function () {
|
|
839
|
+
var _this = this;
|
|
840
|
+
var encodeData = this.collect.cryptoData(this.exposureCache);
|
|
841
|
+
this.collect.requestManager.useRequest({
|
|
842
|
+
url: this.reportUrl,
|
|
843
|
+
data: encodeData,
|
|
844
|
+
timeout: 100000,
|
|
845
|
+
useBeacon: false,
|
|
846
|
+
encryption: this.config.enable_encryption,
|
|
847
|
+
encryption_header: this.config.encryption_header,
|
|
848
|
+
zip: true,
|
|
849
|
+
type: 'event'
|
|
850
|
+
});
|
|
851
|
+
this.exposureCache.forEach(function (item) {
|
|
852
|
+
_this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
853
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_EVENT,
|
|
854
|
+
info: '埋点上报成功',
|
|
855
|
+
time: Date.now(),
|
|
856
|
+
data: [item],
|
|
857
|
+
code: 200,
|
|
858
|
+
status: 'success'
|
|
859
|
+
});
|
|
860
|
+
});
|
|
861
|
+
this.exposureCache = [];
|
|
862
|
+
};
|
|
863
|
+
Ab.prototype.setExternalAbVersion = function (vid) {
|
|
864
|
+
this.extVersions = [vid];
|
|
865
|
+
this.updateVersions();
|
|
866
|
+
};
|
|
867
|
+
Ab.prototype.getABconfig = function (params, callback) {
|
|
868
|
+
var keys = Object.keys(params);
|
|
869
|
+
if (keys && keys.length) {
|
|
870
|
+
this.collect.configManager.set(params);
|
|
871
|
+
}
|
|
872
|
+
this.fetchAB(callback);
|
|
873
|
+
};
|
|
874
|
+
Ab.prototype.get = function (key) {
|
|
875
|
+
if (this.ab_cross) {
|
|
876
|
+
var ab_cookie = this.cacheStorgae.getCookie(key, this.ab_cookie_domain);
|
|
877
|
+
return ab_cookie ? JSON.parse(ab_cookie) : null;
|
|
878
|
+
} else {
|
|
879
|
+
return this.cacheStorgae.getLocalItem(key);
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
Ab.prototype.set = function (key, data) {
|
|
883
|
+
if (this.ab_cross) {
|
|
884
|
+
this.cacheStorgae.setCookie(key, data, STORAGE_EXPRIRE, this.ab_cookie_domain);
|
|
885
|
+
} else {
|
|
886
|
+
this.cacheStorgae.setLocalItem(key, data);
|
|
887
|
+
}
|
|
888
|
+
this.collect.configManager.setAbCache(data);
|
|
889
|
+
};
|
|
890
|
+
Ab.prototype.getABCache = function (key) {
|
|
891
|
+
var data = {
|
|
892
|
+
ab_version: [],
|
|
893
|
+
ab_ext_version: [],
|
|
894
|
+
ab_version_multilink: [],
|
|
895
|
+
data: null,
|
|
896
|
+
timestamp: +new Date(),
|
|
897
|
+
uuid: ''
|
|
898
|
+
};
|
|
899
|
+
data = this.get(this.abKey) || data;
|
|
900
|
+
if (Date.now() - data.timestamp >= STORAGE_EXPRIRE) {
|
|
901
|
+
this.cacheStorgae.removeLocalItem(this.abKey);
|
|
902
|
+
return null;
|
|
903
|
+
}
|
|
904
|
+
if (key) {
|
|
905
|
+
return data[key];
|
|
906
|
+
}
|
|
907
|
+
return data;
|
|
908
|
+
};
|
|
909
|
+
Ab.prototype.updateABCache = function () {
|
|
910
|
+
var cache = this.getABCache();
|
|
911
|
+
cache.ab_version_multilink = this.mulilinkVersions;
|
|
912
|
+
cache.ab_ext_version = this.extVersions;
|
|
913
|
+
cache.ab_version = this.versions;
|
|
914
|
+
cache.timestamp = Date.now();
|
|
915
|
+
this.set(this.abKey, cache);
|
|
916
|
+
};
|
|
917
|
+
Ab.prototype.setAbCache = function (uuid) {
|
|
918
|
+
var cache = this.getABCache();
|
|
919
|
+
cache.data = this.data;
|
|
920
|
+
cache.uuid = uuid;
|
|
921
|
+
cache.timestamp = Date.now();
|
|
922
|
+
this.set(this.abKey, cache);
|
|
923
|
+
};
|
|
924
|
+
Ab.prototype.clearCache = function () {
|
|
925
|
+
this.refreshFetchStatus = 'ing';
|
|
926
|
+
this.data = {};
|
|
927
|
+
this.extVersions = [];
|
|
928
|
+
this.mulilinkVersions = [];
|
|
929
|
+
this.versions = [];
|
|
930
|
+
this.collect.configManager.clearAbCache();
|
|
931
|
+
};
|
|
932
|
+
Ab.prototype.openOverlayer = function (timeout) {
|
|
933
|
+
var _this = this;
|
|
934
|
+
openOverlayer();
|
|
935
|
+
if (timeout) {
|
|
936
|
+
var layer_1 = setTimeout(function () {
|
|
937
|
+
_this.closeOverlayer();
|
|
938
|
+
clearTimeout(layer_1);
|
|
939
|
+
}, timeout);
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
Ab.prototype.closeOverlayer = function () {
|
|
943
|
+
closeOverlayer();
|
|
944
|
+
};
|
|
945
|
+
Ab.prototype.fetchComplete = function (abData, uuid) {
|
|
946
|
+
var _this = this;
|
|
947
|
+
if (abData && Object.prototype.toString.call(abData) == '[object Object]') {
|
|
948
|
+
this.data = abData;
|
|
949
|
+
this.setAbCache(uuid);
|
|
950
|
+
var versions_1 = [];
|
|
951
|
+
Object.keys(abData).forEach(function (key) {
|
|
952
|
+
var vid = abData[key].vid;
|
|
953
|
+
if (vid) {
|
|
954
|
+
versions_1.push(vid);
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
this.versions = this.versions.filter(function (vid) {
|
|
958
|
+
return versions_1.includes(vid);
|
|
959
|
+
});
|
|
960
|
+
var $ab_url = abData.$ab_url,
|
|
961
|
+
$ab_modification = abData.$ab_modification;
|
|
962
|
+
if ($ab_modification && $ab_modification.val && this.enable_ab_visual) {
|
|
963
|
+
if (this.collect.destroy) return;
|
|
964
|
+
this.getVar('$ab_modification', window.location.href, function () {
|
|
965
|
+
// loadVisual($ab_modification.val);
|
|
966
|
+
_this.closeOverlayer();
|
|
967
|
+
});
|
|
968
|
+
} else if ($ab_url && this.enable_multilink) {
|
|
969
|
+
this.mulilinkVersions = this.mulilinkVersions.filter(function (vid) {
|
|
970
|
+
return versions_1.includes(vid);
|
|
971
|
+
});
|
|
972
|
+
var val_1 = $ab_url.val,
|
|
973
|
+
vid_1 = $ab_url.vid;
|
|
974
|
+
if (val_1 && vid_1) {
|
|
975
|
+
this.getVar('$ab_url', val_1, function () {
|
|
976
|
+
if (_this.editMode) return;
|
|
977
|
+
if (val_1 !== window.location.href) {
|
|
978
|
+
setTimeout(function () {
|
|
979
|
+
if (_this.collect.destroy) return;
|
|
980
|
+
var jump = "" + val_1;
|
|
981
|
+
jump = jump.indexOf('http') === -1 ? "https://" + jump : jump;
|
|
982
|
+
var newhost = parseURL(jump).host;
|
|
983
|
+
try {
|
|
984
|
+
var urlObj = new URL(jump);
|
|
985
|
+
if (newhost !== location.host) {
|
|
986
|
+
// 跳转的是一个新域名
|
|
987
|
+
urlObj.searchParams.append('vid', vid_1);
|
|
988
|
+
} else {
|
|
989
|
+
// 不同的域名不能replace
|
|
990
|
+
window.history.replaceState('', '', jump);
|
|
991
|
+
}
|
|
992
|
+
window.location.href = urlObj.href;
|
|
993
|
+
} catch (e) {
|
|
994
|
+
window.location.href = jump;
|
|
995
|
+
}
|
|
996
|
+
}, 100);
|
|
997
|
+
} else {
|
|
998
|
+
_this.closeOverlayer();
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
this.updateVersions();
|
|
1004
|
+
} else {
|
|
1005
|
+
this.closeOverlayer();
|
|
1006
|
+
}
|
|
1007
|
+
this.callbacks.forEach(function (item) {
|
|
1008
|
+
return _this[item.type === CallbackType.Var ? 'getRealVar' : 'getRealAllVars'](item, '');
|
|
1009
|
+
});
|
|
1010
|
+
this.callbacks = [];
|
|
1011
|
+
};
|
|
1012
|
+
Ab.prototype.fetchAB = function (callback) {
|
|
1013
|
+
var _this = this;
|
|
1014
|
+
var env = this.collect.configManager.get();
|
|
1015
|
+
var header = env.header,
|
|
1016
|
+
user = env.user;
|
|
1017
|
+
if (this.config.enable_anonymousid) {
|
|
1018
|
+
delete user.web_id;
|
|
1019
|
+
}
|
|
1020
|
+
var fetchUuid = user.user_unique_id;
|
|
1021
|
+
var requestBody = {
|
|
1022
|
+
header: __assign(__assign(__assign({
|
|
1023
|
+
aid: this.config.app_id
|
|
1024
|
+
}, user || {}), header || {}), {
|
|
1025
|
+
ab_sdk_version: this.collect.configManager.getAbVersion(),
|
|
1026
|
+
ab_url: window.location.href
|
|
1027
|
+
})
|
|
1028
|
+
};
|
|
1029
|
+
var cryptoData = this.collect.cryptoData(requestBody);
|
|
1030
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
1031
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
1032
|
+
info: 'SDK 发起AB实验请求',
|
|
1033
|
+
level: 'info',
|
|
1034
|
+
logType: 'fetch',
|
|
1035
|
+
time: Date.now(),
|
|
1036
|
+
data: requestBody,
|
|
1037
|
+
infoType: 'sdk'
|
|
1038
|
+
});
|
|
1039
|
+
this.collect.requestManager.useRequest({
|
|
1040
|
+
url: this.fetchUrl,
|
|
1041
|
+
data: cryptoData,
|
|
1042
|
+
success: function success(response) {
|
|
1043
|
+
_this.fetchStatus = 'complete';
|
|
1044
|
+
_this.refreshFetchStatus = 'complete';
|
|
1045
|
+
// let aa = {
|
|
1046
|
+
// message: "success",
|
|
1047
|
+
// data: {
|
|
1048
|
+
// abcdefg: { val: "gss", vid: "11407" },
|
|
1049
|
+
// erf: { val: 'name', vid: "22" },
|
|
1050
|
+
// hhhhh: { val: 'age', vid: "33" },
|
|
1051
|
+
// juuioh: { val: 'sex', vid: "44" },
|
|
1052
|
+
// $ab_url: { val: 'http://0.0.0.0:8899/index_cdn_5.html?off=true', vid: '0000' }
|
|
1053
|
+
// }
|
|
1054
|
+
// }
|
|
1055
|
+
// if (env.user.user_unique_id === 'ssss') {
|
|
1056
|
+
// aa.data.abcdefg.vid = '00000'
|
|
1057
|
+
// }
|
|
1058
|
+
var data = response.data,
|
|
1059
|
+
message = response.message; // 解析出code
|
|
1060
|
+
if (message === 'success') {
|
|
1061
|
+
_this.fetchComplete(data, fetchUuid);
|
|
1062
|
+
callback && callback(data);
|
|
1063
|
+
} else {
|
|
1064
|
+
_this.fetchComplete(null, fetchUuid);
|
|
1065
|
+
callback && callback(null);
|
|
1066
|
+
}
|
|
1067
|
+
_this.collect.emit(_this.types.AbComplete, data);
|
|
1068
|
+
_this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
1069
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
1070
|
+
secType: 'AB',
|
|
1071
|
+
info: 'AB实验请求成功',
|
|
1072
|
+
level: 'info',
|
|
1073
|
+
logType: 'fetch',
|
|
1074
|
+
time: Date.now(),
|
|
1075
|
+
data: data,
|
|
1076
|
+
infoType: 'sdk'
|
|
1077
|
+
});
|
|
1078
|
+
},
|
|
1079
|
+
fail: function fail() {
|
|
1080
|
+
_this.fetchStatus = 'complete';
|
|
1081
|
+
_this.refreshFetchStatus = 'complete';
|
|
1082
|
+
_this.fetchComplete(null, fetchUuid);
|
|
1083
|
+
callback && callback(null);
|
|
1084
|
+
_this.collect.emit(_this.types.AbTimeout);
|
|
1085
|
+
_this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
1086
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
1087
|
+
secType: 'AB',
|
|
1088
|
+
info: 'AB实验请求网络异常',
|
|
1089
|
+
level: 'error',
|
|
1090
|
+
logType: 'fetch',
|
|
1091
|
+
time: Date.now(),
|
|
1092
|
+
infoType: 'sdk'
|
|
1093
|
+
});
|
|
1094
|
+
},
|
|
1095
|
+
timeout: this.config.ab_timeout || 10000,
|
|
1096
|
+
encryption: this.config.enable_encryption,
|
|
1097
|
+
encryption_header: this.config.encryption_header
|
|
1098
|
+
});
|
|
1099
|
+
};
|
|
1100
|
+
Ab.prototype.filterUrl = function (url) {
|
|
1101
|
+
try {
|
|
1102
|
+
var _reg = '';
|
|
1103
|
+
if (url.indexOf('&multilink=true') !== -1) {
|
|
1104
|
+
_reg = '&multilink=true[\x00-\xff]*';
|
|
1105
|
+
} else if (url.indexOf('?multilink=true') !== -1) {
|
|
1106
|
+
_reg = '\\?multilink=true[\x00-\xff]*';
|
|
1107
|
+
}
|
|
1108
|
+
var reg = new RegExp(_reg, 'g');
|
|
1109
|
+
url = url.replace(reg, '');
|
|
1110
|
+
} catch (e) {}
|
|
1111
|
+
return url;
|
|
1112
|
+
};
|
|
1113
|
+
return Ab;
|
|
1114
|
+
}();
|
|
1115
|
+
|
|
1116
|
+
module.exports = Ab;
|