-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsensorsdata.min.js
1 lines (1 loc) · 24.3 KB
/
sensorsdata.min.js
1
import storage from"@system.storage";import nativeFetch from"@system.fetch";import device from"@system.device";import network from"@system.network";import router from"@system.router";import app from"@system.app";var sa={},nativeIsArray=Array.isArray,ObjProto=Object.prototype,ArrayProto=Array.prototype,nativeForEach=ArrayProto.forEach,nativeIndexOf=ArrayProto.indexOf,toString=ObjProto.toString,hasOwnProperty=ObjProto.hasOwnProperty,slice=ArrayProto.slice;function each(t,e,i){if(null==t)return!1;var n={};if(nativeForEach&&t.forEach===nativeForEach)t.forEach(e,i);else if(t.length===+t.length){for(var r=0,s=t.length;r<s;r++)if(r in t&&e.call(i,t[r],r,t)===n)return!1}else for(var a in t)if(hasOwnProperty.call(t,a)&&e.call(i,t[a],a,t)===n)return!1}function isObject(t){return null!=t&&"[object Object]"==toString.call(t)}var getRandomBasic=function(){var t=(new Date).getTime();return function(e){return Math.ceil((t=(9301*t+49297)%233280)/233280*e)}}();function getRandom(){if("function"==typeof Uint32Array){var t="";if("undefined"!=typeof crypto?t=crypto:"undefined"!=typeof msCrypto&&(t=msCrypto),isObject(t)&&t.getRandomValues){var e=new Uint32Array(1);return t.getRandomValues(e)[0]/Math.pow(2,32)}}return getRandomBasic(1e19)/1e19}function extend(t){return each(slice.call(arguments,1),function(e){for(var i in e)void 0!==e[i]&&(t[i]=e[i])}),t}function extend2Lev(t){return each(slice.call(arguments,1),function(e){for(var i in e)void 0!==e[i]&&null!==e[i]&&(isObject(e[i])&&isObject(t[i])?extend(t[i],e[i]):t[i]=e[i])}),t}function coverExtend(t){return each(slice.call(arguments,1),function(e){for(var i in e)void 0!==e[i]&&void 0===t[i]&&(t[i]=e[i])}),t}var isArray=nativeIsArray||function(t){return"[object Array]"===toString.call(t)};function isFunction(t){if(!t)return!1;var e=Object.prototype.toString.call(t);return"[object Function]"==e||"[object AsyncFunction]"==e}function isArguments(t){return!(!t||!hasOwnProperty.call(t,"callee"))}function toArray(t){return t?t.toArray?t.toArray():isArray(t)?slice.call(t):isArguments(t)?slice.call(t):values(t):[]}function values(t){var e=[];return null==t?e:(each(t,function(t){e[e.length]=t}),e)}function include(t,e){var i=!1;return null==t?i:nativeIndexOf&&t.indexOf===nativeIndexOf?-1!=t.indexOf(e):(each(t,function(t){if(i||(i=t===e))return{}}),i)}function trim(t){return t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}function isEmptyObject(t){if(isObject(t)){for(var e in t)if(hasOwnProperty.call(t,e))return!1;return!0}return!1}function deepCopy(t){var e={};return function t(e,i){for(var n in i){var r=i[n];isArray(r)?(e[n]=[],t(e[n],r)):isObject(r)?(e[n]={},t(e[n],r)):e[n]=r}}(e,t),e}function isUndefined(t){return void 0===t}function isString(t){return"[object String]"==toString.call(t)}function isDate(t){return"[object Date]"==toString.call(t)}function isBoolean(t){return"[object Boolean]"==toString.call(t)}function isNumber(t){return"[object Number]"==toString.call(t)&&/[\d\\.]+/.test(String(t))}function isJSONString(t){try{JSON.parse(t)}catch(t){return!1}return!0}var isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},isSafeInteger=Number.isSafeInteger||function(t){return isInteger(t)&&Math.abs(t)<=Math.pow(2,53)-1},urlSafeBase64={ENC:{"+":"-","/":"_","=":"."},DEC:{"-":"+",_:"/",".":"="},encode:function(t){return t.replace(/[+\/=]/g,function(t){return urlSafeBase64.ENC[t]})},decode:function(t){return t.replace(/[-_.]/g,function(t){return urlSafeBase64.DEC[t]})},trim:function(t){return t.replace(/[.=]{1,2}$/,"")},isBase64:function(t){return/^[A-Za-z0-9+\/]*[=]{0,2}$/.test(t)},isUrlSafeBase64:function(t){return/^[A-Za-z0-9_-]*[.]{0,2}$/.test(t)}},logger="object"==typeof logger?logger:{};logger.info=function(){if(sa.para.show_log&&"object"==typeof console&&console.log)try{return console.log.apply(console,arguments)}catch(t){}};var check={checkKeyword:function(t){return/^((?!^distinct_id$|^original_id$|^device_id$|^time$|^properties$|^id$|^first_id$|^second_id$|^users$|^events$|^event$|^user_id$|^date$|^datetime$|^user_group|^user_tag)[a-zA-Z_$][a-zA-Z\d_$]{0,99})$/i.test(t)},checkIdLength:function(t){return!(String(t).length>255)||(logger.info("id \u957f\u5ea6\u8d85\u8fc7 255 \u4e2a\u5b57\u7b26\uff01"),!1)}};function isNewLoginId(t,e){return t!==sa.store._state.history_login_id.name||sa.store._state.history_login_id.value!==e}function validId(t){return!isString(t)&&!isNumber(t)||""===t?(logger.info("\u8f93\u5165 ID \u7c7b\u578b\u9519\u8bef"),!1):isNumber(t)&&(t=String(t),!/^\d+$/.test(t))?(logger.info("\u8f93\u5165 ID \u7c7b\u578b\u9519\u8bef"),!1):!!check.checkIdLength(t)&&t}function encodeDates(t){return each(t,function(e,i){isDate(e)?t[i]=formatDate(e):isObject(e)&&(t[i]=encodeDates(e))}),t}function formatDate(t){function e(t){return t<10?"0"+t:t}return t.getFullYear()+"-"+e(t.getMonth()+1)+"-"+e(t.getDate())+" "+e(t.getHours())+":"+e(t.getMinutes())+":"+e(t.getSeconds())+"."+e(t.getMilliseconds())}function searchObjDate(t){isObject(t)&&each(t,function(e,i){isObject(e)?searchObjDate(t[i]):isDate(e)&&(t[i]=formatDate(e))})}function formatString(t){return t.length>sa.para.max_string_length?(logger.info("\u5b57\u7b26\u4e32\u957f\u5ea6\u8d85\u8fc7\u9650\u5236\uff0c\u5df2\u7ecf\u505a\u622a\u53d6--"+t),t.slice(0,sa.para.max_string_length)):t}function searchObjString(t){isObject(t)&&each(t,function(e,i){isObject(e)?searchObjString(t[i]):isString(e)&&(t[i]=formatString(e))})}function unique(t){for(var e,i=[],n={},r=0;r<t.length;r++)(e=t[r])in n||(n[e]=!0,i.push(e));return i}function strip_sa_properties(t){return isObject(t)?(each(t,function(e,i){if(isArray(e)){var n=[];each(e,function(t){isString(t)?n.push(t):logger.info("\u60a8\u7684\u6570\u636e-",e,"\u7684\u6570\u7ec4\u91cc\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32,\u5df2\u7ecf\u5c06\u5176\u5220\u9664")}),0!==n.length?t[i]=n:(delete t[i],logger.info("\u5df2\u7ecf\u5220\u9664\u7a7a\u7684\u6570\u7ec4"))}isString(e)||isNumber(e)||isDate(e)||isBoolean(e)||isArray(e)||(logger.info("\u60a8\u7684\u6570\u636e-",e,"-\u683c\u5f0f\u4e0d\u6ee1\u8db3\u8981\u6c42\uff0c\u6211\u4eec\u5df2\u7ecf\u5c06\u5176\u5220\u9664"),delete t[i])}),t):t}function strip_empty_properties(t){var e={};return each(t,function(t,i){null!=t&&(e[i]=t)}),e}function isPresetIdKeys(t,e){var i=["$identity_anonymous_id"];for(var n of(isArray(e)&&(i=i.concat(e)),i))if(n===t)return!0;return!1}function utf8Encode(t){var e,i,n,r,s="";for(e=i=0,n=(t=(t+"").replace(/\r\n/g,"\n").replace(/\r/g,"\n")).length,r=0;r<n;r++){var a=t.charCodeAt(r),o=null;a<128?i++:o=a>127&&a<2048?String.fromCharCode(a>>6|192,63&a|128):String.fromCharCode(a>>12|224,a>>6&63|128,63&a|128),null!==o&&(i>e&&(s+=t.substring(e,i)),s+=o,e=i=r+1)}return i>e&&(s+=t.substring(e,t.length)),s}function base64Encode(t){var e,i,n,r,s,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",d=[];if(!t)return t;t=utf8Encode(t);do{e=(s=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,i=s>>12&63,n=s>>6&63,r=63&s,d[c++]=a.charAt(e)+a.charAt(i)+a.charAt(n)+a.charAt(r)}while(o<t.length);switch(u=d.join(""),t.length%3){case 1:u=u.slice(0,-2)+"==";break;case 2:u=u.slice(0,-1)+"="}return u}function formatPath(t){return t="string"==typeof t?t.replace(/^\//,""):"\u53d6\u503c\u5f02\u5e38"}function getCurrentPath(){var t=router.getState();return"object"==typeof t?t.path:""}function getCurrentTitle(){var t=router.getState();return"object"==typeof t?t.name:""}function getCurrentSource(){var t=app.getInfo(),e={$source_package_name:"",$scene:""};return"object"==typeof t&&"object"==typeof t.source&&(e.$source_package_name=t.source.packageName||"",e.$scene=t.source.type||""),e}function setUpperCase(t){return isString(t)?t.toLocaleUpperCase():t}function getIsFirstDay(){return"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()}function isSameAndAnonymousID(t){var e=sa.store.getFirstId(),i=sa.store.getDistinctId();return e?t===e:t===i}var info={currentProps:{},properties:{},getSystem:function(){var t=this.properties;function e(){device.getInfo({success:function(e){t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=e.osType,t.$model=e.model,t.$os_version=e.osVersionName,t.$brand=setUpperCase(e.brand),t.$manufacturer=e.manufacturer,"Apple"!==e.manufacturer&&(t.$manufacturer=setUpperCase(e.manufacturer))},complete:function(){var e=(new Date).getTimezoneOffset(),i=app.getInfo().packageName;i&&(t.$app_id=i),isNumber(e)&&(t.$timezone_offset=e),sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}network.getType({success:function(e){t.$network_type=setUpperCase(e.type)},complete:e})}};function rot13defs(t){return rot13obfs(t=String(t),113)}function rot13obfs(t,e){e="number"==typeof e?e:13;for(var i=(t=String(t)).split(""),n=0,r=i.length;n<r;n++){i[n].charCodeAt(0)<126&&(i[n]=String.fromCharCode((i[n].charCodeAt(0)+e)%126))}return i.join("")}var _=Object.freeze({__proto__:null,check:check,validId:validId,encodeDates:encodeDates,isNewLoginId:isNewLoginId,formatDate:formatDate,searchObjDate:searchObjDate,formatString:formatString,searchObjString:searchObjString,unique:unique,strip_sa_properties:strip_sa_properties,strip_empty_properties:strip_empty_properties,utf8Encode:utf8Encode,base64Encode:base64Encode,formatPath:formatPath,getCurrentPath:getCurrentPath,getCurrentTitle:getCurrentTitle,getCurrentSource:getCurrentSource,isPresetIdKeys:isPresetIdKeys,getIsFirstDay:getIsFirstDay,isSameAndAnonymousID:isSameAndAnonymousID,info:info,rot13defs:rot13defs,rot13obfs:rot13obfs,logger:logger,each:each,isObject:isObject,getRandom:getRandom,extend:extend,extend2Lev:extend2Lev,coverExtend:coverExtend,isArray:isArray,isFunction:isFunction,isArguments:isArguments,toArray:toArray,values:values,include:include,trim:trim,isEmptyObject:isEmptyObject,deepCopy:deepCopy,isUndefined:isUndefined,isString:isString,isDate:isDate,isBoolean:isBoolean,isNumber:isNumber,isJSONString:isJSONString,isInteger:isInteger,isSafeInteger:isSafeInteger,slice:slice,urlSafeBase64:urlSafeBase64}),IDENTITY_KEY={EMAIL:"$identity_email",MOBILE:"$identity_mobile",LOGIN:"$identity_login_id"},identityId="$identity_quick_app_id",IDENTITIES={identity_unionid:"",identity_id:identityId,openid_name:"",bind_preset_id:[identityId],unbind_without_check:[identityId],login_preset_id:[identityId]},eventEmitter=function(){this.sub=[]};eventEmitter.prototype={add:function(t){this.sub.push(t)},emit:function(t,e){this.sub.forEach(function(i){i.on(t,e)})}};var eventSub=function(t){sa.events.add(this),this._events=[],this.handle=t,this.ready=!1};eventSub.prototype={on:function(t,e){if(this.ready){if(isFunction(this.handle))try{this.handle(t,e)}catch(t){logger.info(t)}}else this._events.push({event:t,data:e})},isReady:function(){var t=this;t.ready=!0,t._events.forEach(function(e){if(isFunction(t.handle))try{t.handle(e.event,e.data)}catch(t){logger.info(t)}})}},sa._=_,sa.eventSub=eventSub,sa.events=new eventEmitter,sa.para={name:"sensors",server_url:"",max_string_length:500,batch_send:!0,show_log:!1};var is_first_launch=!1;sa._queue=[],sa.setPara=function(t){sa.para=extend2Lev(sa.para,t);var e={send_timeout:6e3,max_length:6};!0===sa.para.batch_send?sa.para.batch_send=extend({},e):isObject(sa.para.batch_send)?sa.para.batch_send=extend({},e,sa.para.batch_send):sa.para.batch_send=!1,sa.para.server_url||logger.info("\u8bf7\u4f7f\u7528 setPara() \u65b9\u6cd5\u8bbe\u7f6e server_url \u6570\u636e\u63a5\u6536\u5730\u5740")},sa.getServerUrl=function(){return sa.para.server_url};var ArrayProto$1=Array.prototype,ObjProto$1=Object.prototype,slice$1=ArrayProto$1.slice,hasOwnProperty$1=ObjProto$1.hasOwnProperty,LIB_VERSION="0.10.1",LIB_NAME="QuickApp";function bindWithoutCheck(t,e){sa.store._state.identities[t]=e,sa.store.save(),sa.prepareData({type:"track_id_bind",event:"$BindID"})}function unbindWithoutCheck(t,e){hasOwnProperty$1.call(sa.store._state.identities,t)&&e===sa.store._state.identities[t]&&(IDENTITIES.unbind_without_check&&IDENTITIES.unbind_without_check.indexOf(t)<0&&delete sa.store._state.identities[t],sa.store.save());var i=sa.store.getDistinctId(),n=sa.store.getFirstId();i===t+"+"+e&&(sa.store.set("first_id",""),sa.store.set("distinct_id",n),sa.store.set("history_login_id",{name:"",value:""}));var r={};r[t]=e,sa.prepareData({type:"track_id_unbind",event:"$UnbindID",unbind_value:r})}sa.store={storageInfo:null,store_queue:[],getUUID:function(){return Date.now()+"-"+Math.floor(1e7*Math.random())+"-"+Math.random().toString(16).replace(".","")+"-"+String(31242*Math.random()).replace(".","").slice(0,8)},getStorage:function(t){storage.get({key:"sensorsdata2015_quickapp",success:function(e){t(e)},fail:function(t,e){logger.info("\u83b7\u53d6storage\u5931\u8d25-\u4f1a\u5bfc\u81f4\u89e3\u6790distinct_id\u5f02\u5e38",t,e)}})},_state:{},mem:{mdata:[],getLength:function(){return this.mdata.length},add:function(t){this.mdata.push(t)},clear:function(t){this.mdata.splice(0,t)}},toState:function(t){var e=null,i=this;function n(){e.distinct_id?i._state=e:i.set("distinct_id",i.getUUID())}isJSONString(t)?(e=JSON.parse(t),n()):isObject(t)?(e=t,n()):this.set("distinct_id",i.getUUID());var r=this._state._first_id||this._state.first_id,s=this._state._distinct_id||this._state.distinct_id,a=(this._state.history_login_id?this._state.history_login_id:{}).name;if(this._state.identities&&isString(this._state.identities)){var o=JSON.parse(rot13defs(this._state.identities));this._state.identities=o}function c(t){for(var e in sa.store._state.identities)hasOwnProperty$1.call(sa.store._state.identities,e)&&e!==IDENTITIES.identity_id&&e!==t&&delete sa.store._state.identities[e]}this._state.identities&&isObject(this._state.identities)&&!isEmptyObject(this._state.identities)||(this._state.identities={},this._state.identities[IDENTITIES.identity_id]=i.getUUID()),r?a&&hasOwnProperty$1.call(this._state.identities,a)?this._state.identities[a]!==s&&(this._state.identities[a]=s,c(a),this._state.history_login_id.value=s):(this._state.identities[IDENTITY_KEY.LOGIN]=s,c(IDENTITY_KEY.LOGIN),this._state.history_login_id={name:IDENTITY_KEY.LOGIN,value:s}):this._state.history_login_id={name:"",value:""},this.save()},getFirstId:function(){return this._state._first_id||this._state.first_id},getDistinctId:function(){var t=this.getLoginDistinctId();return t||(this._state._distinct_id||this._state.distinct_id)},getHistoryLoginId:function(){return isObject(this._state.history_login_id)?this._state.history_login_id:null},getLoginDistinctId:function(){var t=this.getHistoryLoginId();return isObject(t)&&t.value?t.name!==IDENTITY_KEY.LOGIN?t.name+"+"+t.value:t.value:null},getProps:function(){return this._state.props||{}},getUnionId:function(){var t={},e=this._state.first_id,i=this._state.distinct_id;return e&&i?(t.login_id=i,t.anonymous_id=e):t.anonymous_id=i,t},setProps:function(t,e){var i=this._state.props||{};e?this.set("props",t):(extend(i,t),this.set("props",i))},set:function(t,e){var i={};for(var n in"string"==typeof t?i[t]=e:"object"==typeof t&&(i=t),this._state=this._state||{},i)this._state[n]=i[n],"first_id"===n?delete this._state._first_id:"distinct_id"===n&&(delete this._state._distinct_id,sa.events.emit("changeDistinctId"));this.save()},identitiesSet:function(t){var e={};switch(t.type){case"login":e[IDENTITIES.identity_id]=this._state.identities[IDENTITIES.identity_id],e[t.id_name]=t.id;break;case"logout":e[IDENTITIES.identity_id]=this._state.identities[IDENTITIES.identity_id]}this.set("identities",e)},change:function(t,e){this._state["_"+t]=e},save:function(){var t=deepCopy(this._state),e=rot13obfs(JSON.stringify(t.identities));if(t.identities=e,delete t._first_id,delete t._distinct_id,sa.para.encrypt_storage){t="data:enc;"+rot13obfs(JSON.stringify(t))}storage.set({key:"sensorsdata2015_quickapp",value:t,fail:function(t,e){logger.info("\u5b58\u50a8storage\u6570\u636e\u5931\u8d25",t,e)}})},init:function(){var t=this,e=t.getUUID();this.getStorage(function(i){var n=i;if(n){if(isString(n)&&-1!==n.indexOf("data:enc;")){n=n.substring("data:enc;".length);try{n=JSON.parse(rot13defs(n))}catch(t){}}t.toState(n)}else{is_first_launch=!0;var r=new Date,s=r.getTime();r.setHours(23),r.setMinutes(59),r.setSeconds(60),t.set({distinct_id:e,first_visit_time:s,first_visit_day_time:r.getTime(),identities:{[IDENTITIES.identity_id]:e},history_login_id:{name:"",value:""}})}sa.initialState.storeIsComplete=!0,sa.events.emit("initStore"),sa.initialState.checkIsComplete()})}},sa.initialState={queue:[],isComplete:!1,systemIsComplete:!1,storeIsComplete:!1,checkIsComplete:function(){this.systemIsComplete&&this.storeIsComplete&&(this.isComplete=!0,this.queue.length>0&&(each(this.queue,function(t){sa[t[0]].apply(sa,slice$1.call(t[1]))}),sa.queue=[]))}},sa.prepareData=function(t){var e={distinct_id:this.store.getDistinctId(),identities:sa.store._state.identities,lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};if("track_id_unbind"===t.type&&"$UnbindID"===t.event&&(e.identities=deepCopy(t.unbind_value),delete t.unbind_value),extend(e,t),isObject(t.properties)&&!isEmptyObject(t.properties)&&extend(e.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(e._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4)),e.properties=extend({$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},info.properties,sa.store.getProps(),info.currentProps,e.properties),"$AppStart"===e.event&&(e.properties.$is_first_time=!!is_first_launch),"track"===t.type&&(e.properties.$is_first_day=getIsFirstDay())),e.properties.$time&&isDate(e.properties.$time)?(e.time=1*e.properties.$time,delete e.properties.$time):e.time=1*new Date,searchObjDate(e),searchObjString(e),!sa.para.server_url)return!1;sa.para.batch_send?sa.sendStrategy.send(e):sa.send(e)},sa.track=function(t,e,i){this.prepareData({type:"track",event:t,properties:e},i)},sa.identify=function(t,e){if(t=validId(t)){var i=sa.store.getFirstId();!0===e?i?sa.store.set("first_id",t):sa.store.set("distinct_id",t):i?sa.store.change("first_id",t):sa.store.change("distinct_id",t)}},sa.bind=function(t,e){var i="";if(isNumber(e)){if(isInteger(e)&&!1===isSafeInteger(e))return logger.info("Value must be String"),!1;e=String(e)}if(!isString(t))return logger.info("Key must be String"),!1;var n=sa.store.getHistoryLoginId(),r=n?n.name:"",s=[IDENTITY_KEY.LOGIN,r];return isArray(IDENTITIES.bind_preset_id)&&(s=[IDENTITY_KEY.LOGIN,r].concat(IDENTITIES.bind_preset_id)),!check.checkKeyword(t)||isPresetIdKeys(t,s)?(i="Key ["+t+"] is invalid",logger.info(i),!1):e&&""!==e?isString(e)?!!check.checkIdLength(e)&&void bindWithoutCheck(t,e):(logger.info("Value must be String"),!1):(logger.info("Value is empty or null"),!1)},sa.unbind=function(t,e){var i="";if(isNumber(e)){if(isInteger(e)&&!1===isSafeInteger(e))return logger.info("Value must be String"),!1;e=String(e)}return isString(t)?!check.checkKeyword(t)||isPresetIdKeys(t,[IDENTITY_KEY.LOGIN])?(i="Key ["+t+"] is invalid",logger.info(i),!1):e&&""!==e?isString(e)?!!check.checkIdLength(e)&&void unbindWithoutCheck(t,e):(logger.info("Value must be String"),!1):(logger.info("Value is empty or null"),!1):(logger.info("Key must be String"),!1)},sa.loginWithKey=function(t,e){if(!isString(t))return logger.info("Key must be String"),!1;var i="";if(!check.checkKeyword(t)||t.length>100)return i="Key ["+t+"] is invalid",logger.info(i),!1;if(isPresetIdKeys(t,IDENTITIES.login_preset_id))return i="Key ["+t+"] is invalid",logger.info(i),!1;if(!(e=validId(e)))return!1;if(isSameAndAnonymousID(e))return!1;var n=sa.store.getFirstId(),r=sa.store.getDistinctId();isNewLoginId(t,e)&&(sa.store._state.identities[t]=e,sa.store.set("history_login_id",{name:t,value:e}),n||sa.store.set("first_id",r),sa.trackSignup({id:e,event_name:"$SignUp",id_name:t}),sa.store.identitiesSet({type:"login",id:e,id_name:t}))},sa.trackSignup=function(t,e,i){var n,r,s,a;isObject(t)?(n=t.id,r=t.event_name,s=t.id_name):(n=t,r=e),sa.store.set("distinct_id",n),a=s&&s!==IDENTITY_KEY.LOGIN?s+"+"+n:n;var o=sa.store.getFirstId()||sa.store.getDistinctId();sa.prepareData({original_id:o,distinct_id:a,type:"track_signup",event:r,properties:i})},sa.registerApp=function(t){isObject(t)&&!isEmptyObject(t)&&(info.currentProps=extend(info.currentProps,t))},sa.clearAppRegister=function(t){isArray(t)&&each(info.currentProps,function(e,i){include(t,i)&&delete info.currentProps[i]})},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.login=function(t){if(!(t=validId(t)))return!1;if(isSameAndAnonymousID(t))return!1;var e=sa.store.getFirstId(),i=sa.store.getDistinctId(),n=IDENTITY_KEY.LOGIN;isNewLoginId(n,t)&&(sa.store._state.identities&&(sa.store._state.identities[n]=t),sa.store.set("history_login_id",{name:n,value:t}),e||sa.store.set("first_id",i),sa.trackSignup({id:t,event_name:"$SignUp"}),sa.store.identitiesSet({type:"login",id:t,id_name:n}))},sa.getAnonymousID=function(){if(!isEmptyObject(sa.store._state))return sa.store._state.first_id||sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")},sa.logout=function(t){var e=sa.store.getFirstId();sa.store.identitiesSet({type:"logout"}),sa.store.set("history_login_id",{name:"",value:""}),e?(sa.store.set("first_id",""),!0===t?sa.store.set("distinct_id",sa.store.getUUID()):sa.store.set("distinct_id",e)):logger.info("\u6ca1\u6709first_id\uff0clogout\u5931\u8d25")},sa.setProfile=function(t,e){sa.prepareData({type:"profile_set",properties:t},e)},sa.setOnceProfile=function(t,e){sa.prepareData({type:"profile_set_once",properties:t},e)},sa.init=function(t){this._.info.getSystem(),this.store.init(),"object"==typeof t&&(t[sa.para.name]=sa),sa.para.batch_send&&sa.sendStrategy.init()},sa.send=function(t){var e="";t._nocache=(String(Math.random())+String(Math.random())+String(Math.random())).slice(2,15),logger.info(t),t._flush_time=Date.now(),t=JSON.stringify(t),e=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(base64Encode(t));nativeFetch.fetch({data:"String",responseType:"text",method:"GET",url:e})},sa.usePlugin=function(t,e){"function"==typeof t.init&&t.init(sa,e)},sa.use=function(t,e){"function"==typeof t.init&&t.init(sa,e)},sa.sendStrategy={dataHasSend:!0,syncStorage:!1,is_first_batch_write:!0,failTime:0,init:function(){storage.get({key:"sensors_prepare_data",complete:function(t){var e=t.data&&isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),this.batchInterval()},onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;this.dataHasChange=!0,sa.store.mem.getLength()>=500&&(logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),sa.store.mem.mdata.shift()),logger.info(t),sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()},batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.syncStorage&&storage.set({key:"sensors_prepare_data",value:sa.store.mem.mdata,success:function(){t.dataHasChange=!1}}))},batchInterval(){var t=this;!function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout*Math.pow(2,t.failTime))}(),function e(){setTimeout(function(){t.batchWrite(),e()},500)}()},batchSend(){if(this.dataHasSend){var t,e,i=this,n=sa.store.mem.mdata;if(t=n.length>=100?n.slice(0,100):n,e=t.length,isArray(t)&&t.length>0){this.dataHasSend=!1;var r=Date.now();t.forEach(function(t){t._flush_time=r}),t=JSON.stringify(t),t="data_list="+encodeURIComponent(base64Encode(t)),nativeFetch.fetch({url:sa.para.server_url,method:"POST",data:t,responseType:"text",success:function(){i.batchRemove(e)},fail:function(){i.sendFail()}})}}},batchRemove(t){this.dataHasSend=!0,this.dataHasChange=!0,sa.store.mem.clear(t),this.batchWrite(),this.failTime=0},sendFail(){this.dataHasSend=!0,this.failTime++}},sa.appLaunch=function(t){t&&isObject(t)||(t={});var e={};extend(e,t),extend(e,getCurrentSource()),sa.track("$AppStart",e)},sa.pageShow=function(t){t&&isObject(t)||(t={});var e={};e.$url_path=getCurrentPath(),e.$title=getCurrentTitle(),extend(e,getCurrentSource()),extend(e,t),sa.track("$AppViewScreen",e)},sa.appHide=function(t){t&&isObject(t)||(t={});var e={};e.$url_path=getCurrentPath(),e.$title=getCurrentTitle(),extend(e,t),sa.track("$AppEnd",e)},each(["setProfile","pageShow","appHide","login","logout","identify","appLaunch","setOnceProfile","track","clearAllRegister","quick","incrementProfile","appendProfile","bind","unbind","loginWithKey"],function(t){var e=sa[t];sa[t]&&(sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])})});export default sa;