diff --git a/CHANGELOG.md b/CHANGELOG.md index e875300..92ed4a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.13.16(2019-12-25) +* 更新:更新场景值描述 + ## 1.13.15(2019-12-24) * 修复:修复使用批量发送方式发送数据时,网络从无网切换到有网时,数据无法发送的问题 * 优化:onLaunch onShow 生命周期函数中,参数对象中获取不到scene值时的处理逻辑 diff --git a/package.json b/package.json index 521ebe9..cd179b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sa-sdk-miniprogram", - "version": "1.13.15", + "version": "1.13.16", "description": "sensorsdata miniprogram sdk", "main": "sensorsdata.min.js", "scripts": { diff --git a/sensorsdata.custom.es6.min.js b/sensorsdata.custom.es6.min.js index dcc5d4b..570f0ae 100755 --- a/sensorsdata.custom.es6.min.js +++ b/sensorsdata.custom.es6.min.js @@ -1 +1 @@ -var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var r=sa.para.source_channel.length,s=0;ssa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,r){_.isObject(e)?_.searchObjString(t[r]):_.isString(e)&&(t[r]=_.formatString(e))})},_.unique=function(t){for(var e,r=[],s={},a=0;a127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(r>e&&(n+=t.substring(e,r)),n+=o,e=r=a+1)}return r>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,r,s,a,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,r=n>>12&63,s=n>>6&63,a=63&n,p[c++]=i.charAt(e)+i.charAt(r)+i.charAt(s)+i.charAt(a)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,r,s){if(!_.isObject(t))return{};var a={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(a[r+n]=t[n]):a[s+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(a[r+n]=t[n]):a[e+n]=t[n];return a},_.getObjFromQuery=function(t){var e=t.split("?"),r=[],s={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(r=t.split("="))[0]&&r[1]&&(s[r[0]]=r[1])}),s):{}},_.setStorageSync=function(t,e){var r=function(){wx.setStorageSync(t,e)};try{r()}catch(t){logger.info("set Storage fail --",t);try{r()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(r){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var r={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(r=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(r))return{};var s=(r=JSON.parse(r)).d,a=r.p,n=r.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof s?(e.$share_depth=s,share_depth=s):e.$share_depth="-1",e.$share_url_path="string"==typeof a?a:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,r,s,a,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,r=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),s=new RegExp("("+r.join("|")+")%3D","i"),1===(a=Object.keys(e)).length&&"scene"===a[0]&&s.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),r=e.scene,s=e.q,a=e.query;for(var n in a)a[n]=_.decodeURIComponent(a[n]);return r&&(r=-1!==(r=_.decodeURIComponent(r)).indexOf("?")?"?"+r.replace(/\?/g,""):"?"+r,_.extend(a,_.getObjFromQuery(r))),s&&_.extend(a,_.getObjFromQuery(_.decodeURIComponent(s))),a},_.setUtm=function(t,e){var r={},s=_.getMixedQuery(t),a=_.getCustomUtmFromQuery(s,"$","_","$"),n=_.getCustomUtmFromQuery(s,"$latest_","_latest_","$latest_");return r.pre1=a,r.pre2=n,_.extend(e,a),r},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var r,s;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(r=e.platform,"ios"===(s=r.toLowerCase())?"iOS":"android"===s?"Android":r),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var r={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(r,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(r.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(r._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),r.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,r.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?r.properties.$is_first_day=!0:r.properties.$is_first_day=!1),r.properties.$time&&_.isDate(r.properties.$time)?(r.time=1*r.properties.$time,delete r.properties.$time):sa.para.use_client_time&&(r.time=1*new Date),_.searchObjDate(r),_.searchObjString(r),logger.info(r),sa.sendStrategy.send(r)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var r=this._state.props||{};e?this.set("props",t):(_.extend(r,t),this.set("props",r))},set:function(t,e){var r={};for(var s in"string"==typeof t?r[t]=e:"object"==typeof t&&(r=t),this._state=this._state||{},r)this._state[s]=r[s];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,r=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:r,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,r){_.isString(e)?t[r]=[e]:_.isArray(e)||(delete t[r],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var r=t;_.isString(t)&&((t={})[r]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,r){this.prepareData({type:"track",event:t,properties:e},r)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var r=sa.store.getFirstId();!0===e?r?sa.store.set("first_id",t):sa.store.set("distinct_id",t):r?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,r,s){var a=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:a,distinct_id:t,type:"track_signup",event:e,properties:r},s)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),r={};_.isArray(t)&&(_.each(e,function(e,s){_.include(t,s)||(r[s]=e)}),sa.store.setProps(r,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,r){_.include(t,r)&&delete _.info.currentProps[r]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var r=!1;for(var s in e)t[e[s]]&&(r=!0);return r}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),r=sa.store.getDistinctId();t!==r&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",r),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,r){0===r.indexOf("$")&&(t[r]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(r){r&&sa.setOpenid(r,t.isCoverLogin),e&&_.isFunction(e)&&e(r),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var r=[];return _.each(t,function(t,s){"q"===s&&_.isString(t)&&0===t.indexOf("http")||"scene"===s||(e?r.push(s+"="+t):r.push(s+"="+_.decodeURIComponent(t)))}),r.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),r=e[e.length-1].options;t=_.getCustomUtmFromQuery(r,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,r){var s=sa.para.autoTrack[t],a="";sa.para.autoTrack&&s&&("function"==typeof s?(a=s(),_.isObject(a)&&_.extend(e,a)):_.isObject(s)&&(_.extend(e,s),sa.para.autoTrack[t]=!0),sa.track(r,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var r={};t&&t.path&&(r.$url_path=_.getPath(t.path)),_.setShareInfo(t,r);var s=_.setUtm(t,r);is_first_launch?(r.$is_first_time=!0,_.isEmptyObject(s.pre1)||sa.setOnceProfile(s.pre1)):r.$is_first_time=!1,sa.setLatestChannel(s.pre2),r.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:r.$scene}),r.$url_query=_.setQuery(t.query),e?(r=_.extend(r,e),sa.track("$MPLaunch",r)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",r,"$MPLaunch")},appShow:function(t,e){var r={};mpshow_time=(new Date).getTime(),t&&t.path&&(r.$url_path=_.getPath(t.path)),_.setShareInfo(t,r);var s=_.setUtm(t,r);sa.setLatestChannel(s.pre2),r.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:r.$scene}),r.$url_query=_.setQuery(t.query),e?(r=_.extend(r,e),sa.track("$MPShow",r)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",r,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),r={};r.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(r.event_duration=(e-mpshow_time)/1e3),t?(r=_.extend(r,t),sa.track("$MPHide",r)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",r,"$MPHide"),sa.sendStrategy.onAppHide()}},sa.quick=function(){var t=arguments[0],e=arguments[1],r=arguments[2],s=_.isObject(r)?r:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,s):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(s=_.isObject(e)?e:{},sa.autoTrackCustom[t](s))},sa.initial();export default sa; \ No newline at end of file +var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var r=sa.para.source_channel.length,s=0;ssa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,r){_.isObject(e)?_.searchObjString(t[r]):_.isString(e)&&(t[r]=_.formatString(e))})},_.unique=function(t){for(var e,r=[],s={},a=0;a127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(r>e&&(n+=t.substring(e,r)),n+=o,e=r=a+1)}return r>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,r,s,a,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,r=n>>12&63,s=n>>6&63,a=63&n,p[c++]=i.charAt(e)+i.charAt(r)+i.charAt(s)+i.charAt(a)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,r,s){if(!_.isObject(t))return{};var a={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(a[r+n]=t[n]):a[s+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(a[r+n]=t[n]):a[e+n]=t[n];return a},_.getObjFromQuery=function(t){var e=t.split("?"),r=[],s={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(r=t.split("="))[0]&&r[1]&&(s[r[0]]=r[1])}),s):{}},_.setStorageSync=function(t,e){var r=function(){wx.setStorageSync(t,e)};try{r()}catch(t){logger.info("set Storage fail --",t);try{r()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(r){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var r={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(r=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(r))return{};var s=(r=JSON.parse(r)).d,a=r.p,n=r.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof s?(e.$share_depth=s,share_depth=s):e.$share_depth="-1",e.$share_url_path="string"==typeof a?a:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,r,s,a,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,r=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),s=new RegExp("("+r.join("|")+")%3D","i"),1===(a=Object.keys(e)).length&&"scene"===a[0]&&s.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),r=e.scene,s=e.q,a=e.query;for(var n in a)a[n]=_.decodeURIComponent(a[n]);return r&&(r=-1!==(r=_.decodeURIComponent(r)).indexOf("?")?"?"+r.replace(/\?/g,""):"?"+r,_.extend(a,_.getObjFromQuery(r))),s&&_.extend(a,_.getObjFromQuery(_.decodeURIComponent(s))),a},_.setUtm=function(t,e){var r={},s=_.getMixedQuery(t),a=_.getCustomUtmFromQuery(s,"$","_","$"),n=_.getCustomUtmFromQuery(s,"$latest_","_latest_","$latest_");return r.pre1=a,r.pre2=n,_.extend(e,a),r},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var r,s;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(r=e.platform,"ios"===(s=r.toLowerCase())?"iOS":"android"===s?"Android":r),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var r={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(r,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(r.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(r._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),r.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,r.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?r.properties.$is_first_day=!0:r.properties.$is_first_day=!1),r.properties.$time&&_.isDate(r.properties.$time)?(r.time=1*r.properties.$time,delete r.properties.$time):sa.para.use_client_time&&(r.time=1*new Date),_.searchObjDate(r),_.searchObjString(r),logger.info(r),sa.sendStrategy.send(r)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var r=this._state.props||{};e?this.set("props",t):(_.extend(r,t),this.set("props",r))},set:function(t,e){var r={};for(var s in"string"==typeof t?r[t]=e:"object"==typeof t&&(r=t),this._state=this._state||{},r)this._state[s]=r[s];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,r=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:r,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,r){_.isString(e)?t[r]=[e]:_.isArray(e)||(delete t[r],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var r=t;_.isString(t)&&((t={})[r]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,r){this.prepareData({type:"track",event:t,properties:e},r)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var r=sa.store.getFirstId();!0===e?r?sa.store.set("first_id",t):sa.store.set("distinct_id",t):r?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,r,s){var a=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:a,distinct_id:t,type:"track_signup",event:e,properties:r},s)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),r={};_.isArray(t)&&(_.each(e,function(e,s){_.include(t,s)||(r[s]=e)}),sa.store.setProps(r,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,r){_.include(t,r)&&delete _.info.currentProps[r]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var r=!1;for(var s in e)t[e[s]]&&(r=!0);return r}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),r=sa.store.getDistinctId();t!==r&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",r),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,r){0===r.indexOf("$")&&(t[r]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(r){r&&sa.setOpenid(r,t.isCoverLogin),e&&_.isFunction(e)&&e(r),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var r=[];return _.each(t,function(t,s){"q"===s&&_.isString(t)&&0===t.indexOf("http")||"scene"===s||(e?r.push(s+"="+t):r.push(s+"="+_.decodeURIComponent(t)))}),r.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),r=e[e.length-1].options;t=_.getCustomUtmFromQuery(r,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,r){var s=sa.para.autoTrack[t],a="";sa.para.autoTrack&&s&&("function"==typeof s?(a=s(),_.isObject(a)&&_.extend(e,a)):_.isObject(s)&&(_.extend(e,s),sa.para.autoTrack[t]=!0),sa.track(r,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var r={};t&&t.path&&(r.$url_path=_.getPath(t.path)),_.setShareInfo(t,r);var s=_.setUtm(t,r);is_first_launch?(r.$is_first_time=!0,_.isEmptyObject(s.pre1)||sa.setOnceProfile(s.pre1)):r.$is_first_time=!1,sa.setLatestChannel(s.pre2),r.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:r.$scene}),r.$url_query=_.setQuery(t.query),e?(r=_.extend(r,e),sa.track("$MPLaunch",r)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",r,"$MPLaunch")},appShow:function(t,e){var r={};mpshow_time=(new Date).getTime(),t&&t.path&&(r.$url_path=_.getPath(t.path)),_.setShareInfo(t,r);var s=_.setUtm(t,r);sa.setLatestChannel(s.pre2),r.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:r.$scene}),r.$url_query=_.setQuery(t.query),e?(r=_.extend(r,e),sa.track("$MPShow",r)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",r,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),r={};r.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(r.event_duration=(e-mpshow_time)/1e3),t?(r=_.extend(r,t),sa.track("$MPHide",r)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",r,"$MPHide"),sa.sendStrategy.onAppHide()}},sa.quick=function(){var t=arguments[0],e=arguments[1],r=arguments[2],s=_.isObject(r)?r:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,s):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(s=_.isObject(e)?e:{},sa.autoTrackCustom[t](s))},sa.initial();export default sa; \ No newline at end of file diff --git a/sensorsdata.custom.min.js b/sensorsdata.custom.min.js index 6ec481d..6506c55 100755 --- a/sensorsdata.custom.min.js +++ b/sensorsdata.custom.min.js @@ -1 +1 @@ -var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var r=sa.para.source_channel.length,s=0;ssa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,r){_.isObject(e)?_.searchObjString(t[r]):_.isString(e)&&(t[r]=_.formatString(e))})},_.unique=function(t){for(var e,r=[],s={},a=0;a127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(r>e&&(n+=t.substring(e,r)),n+=o,e=r=a+1)}return r>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,r,s,a,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,r=n>>12&63,s=n>>6&63,a=63&n,p[c++]=i.charAt(e)+i.charAt(r)+i.charAt(s)+i.charAt(a)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,r,s){if(!_.isObject(t))return{};var a={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(a[r+n]=t[n]):a[s+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(a[r+n]=t[n]):a[e+n]=t[n];return a},_.getObjFromQuery=function(t){var e=t.split("?"),r=[],s={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(r=t.split("="))[0]&&r[1]&&(s[r[0]]=r[1])}),s):{}},_.setStorageSync=function(t,e){var r=function(){wx.setStorageSync(t,e)};try{r()}catch(t){logger.info("set Storage fail --",t);try{r()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(r){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var r={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(r=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(r))return{};var s=(r=JSON.parse(r)).d,a=r.p,n=r.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof s?(e.$share_depth=s,share_depth=s):e.$share_depth="-1",e.$share_url_path="string"==typeof a?a:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,r,s,a,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,r=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),s=new RegExp("("+r.join("|")+")%3D","i"),1===(a=Object.keys(e)).length&&"scene"===a[0]&&s.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),r=e.scene,s=e.q,a=e.query;for(var n in a)a[n]=_.decodeURIComponent(a[n]);return r&&(r=-1!==(r=_.decodeURIComponent(r)).indexOf("?")?"?"+r.replace(/\?/g,""):"?"+r,_.extend(a,_.getObjFromQuery(r))),s&&_.extend(a,_.getObjFromQuery(_.decodeURIComponent(s))),a},_.setUtm=function(t,e){var r={},s=_.getMixedQuery(t),a=_.getCustomUtmFromQuery(s,"$","_","$"),n=_.getCustomUtmFromQuery(s,"$latest_","_latest_","$latest_");return r.pre1=a,r.pre2=n,_.extend(e,a),r},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var r,s;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(r=e.platform,"ios"===(s=r.toLowerCase())?"iOS":"android"===s?"Android":r),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var r={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(r,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(r.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(r._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),r.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,r.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?r.properties.$is_first_day=!0:r.properties.$is_first_day=!1),r.properties.$time&&_.isDate(r.properties.$time)?(r.time=1*r.properties.$time,delete r.properties.$time):sa.para.use_client_time&&(r.time=1*new Date),_.searchObjDate(r),_.searchObjString(r),logger.info(r),sa.sendStrategy.send(r)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var r=this._state.props||{};e?this.set("props",t):(_.extend(r,t),this.set("props",r))},set:function(t,e){var r={};for(var s in"string"==typeof t?r[t]=e:"object"==typeof t&&(r=t),this._state=this._state||{},r)this._state[s]=r[s];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,r=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:r,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,r){_.isString(e)?t[r]=[e]:_.isArray(e)||(delete t[r],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var r=t;_.isString(t)&&((t={})[r]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,r){this.prepareData({type:"track",event:t,properties:e},r)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var r=sa.store.getFirstId();!0===e?r?sa.store.set("first_id",t):sa.store.set("distinct_id",t):r?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,r,s){var a=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:a,distinct_id:t,type:"track_signup",event:e,properties:r},s)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),r={};_.isArray(t)&&(_.each(e,function(e,s){_.include(t,s)||(r[s]=e)}),sa.store.setProps(r,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,r){_.include(t,r)&&delete _.info.currentProps[r]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var r=!1;for(var s in e)t[e[s]]&&(r=!0);return r}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),r=sa.store.getDistinctId();t!==r&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",r),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,r){0===r.indexOf("$")&&(t[r]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(r){r&&sa.setOpenid(r,t.isCoverLogin),e&&_.isFunction(e)&&e(r),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var r=[];return _.each(t,function(t,s){"q"===s&&_.isString(t)&&0===t.indexOf("http")||"scene"===s||(e?r.push(s+"="+t):r.push(s+"="+_.decodeURIComponent(t)))}),r.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),r=e[e.length-1].options;t=_.getCustomUtmFromQuery(r,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,r){var s=sa.para.autoTrack[t],a="";sa.para.autoTrack&&s&&("function"==typeof s?(a=s(),_.isObject(a)&&_.extend(e,a)):_.isObject(s)&&(_.extend(e,s),sa.para.autoTrack[t]=!0),sa.track(r,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var r={};t&&t.path&&(r.$url_path=_.getPath(t.path)),_.setShareInfo(t,r);var s=_.setUtm(t,r);is_first_launch?(r.$is_first_time=!0,_.isEmptyObject(s.pre1)||sa.setOnceProfile(s.pre1)):r.$is_first_time=!1,sa.setLatestChannel(s.pre2),r.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:r.$scene}),r.$url_query=_.setQuery(t.query),e?(r=_.extend(r,e),sa.track("$MPLaunch",r)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",r,"$MPLaunch")},appShow:function(t,e){var r={};mpshow_time=(new Date).getTime(),t&&t.path&&(r.$url_path=_.getPath(t.path)),_.setShareInfo(t,r);var s=_.setUtm(t,r);sa.setLatestChannel(s.pre2),r.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:r.$scene}),r.$url_query=_.setQuery(t.query),e?(r=_.extend(r,e),sa.track("$MPShow",r)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",r,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),r={};r.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(r.event_duration=(e-mpshow_time)/1e3),t?(r=_.extend(r,t),sa.track("$MPHide",r)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",r,"$MPHide"),sa.sendStrategy.onAppHide()}},sa.quick=function(){var t=arguments[0],e=arguments[1],r=arguments[2],s=_.isObject(r)?r:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,s):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(s=_.isObject(e)?e:{},sa.autoTrackCustom[t](s))},sa.initial(),module.exports=sa; \ No newline at end of file +var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var r=sa.para.source_channel.length,s=0;ssa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,r){_.isObject(e)?_.searchObjString(t[r]):_.isString(e)&&(t[r]=_.formatString(e))})},_.unique=function(t){for(var e,r=[],s={},a=0;a127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(r>e&&(n+=t.substring(e,r)),n+=o,e=r=a+1)}return r>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,r,s,a,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,r=n>>12&63,s=n>>6&63,a=63&n,p[c++]=i.charAt(e)+i.charAt(r)+i.charAt(s)+i.charAt(a)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,r,s){if(!_.isObject(t))return{};var a={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(a[r+n]=t[n]):a[s+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(a[r+n]=t[n]):a[e+n]=t[n];return a},_.getObjFromQuery=function(t){var e=t.split("?"),r=[],s={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(r=t.split("="))[0]&&r[1]&&(s[r[0]]=r[1])}),s):{}},_.setStorageSync=function(t,e){var r=function(){wx.setStorageSync(t,e)};try{r()}catch(t){logger.info("set Storage fail --",t);try{r()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(r){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var r={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(r=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(r))return{};var s=(r=JSON.parse(r)).d,a=r.p,n=r.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof s?(e.$share_depth=s,share_depth=s):e.$share_depth="-1",e.$share_url_path="string"==typeof a?a:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,r,s,a,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,r=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),s=new RegExp("("+r.join("|")+")%3D","i"),1===(a=Object.keys(e)).length&&"scene"===a[0]&&s.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),r=e.scene,s=e.q,a=e.query;for(var n in a)a[n]=_.decodeURIComponent(a[n]);return r&&(r=-1!==(r=_.decodeURIComponent(r)).indexOf("?")?"?"+r.replace(/\?/g,""):"?"+r,_.extend(a,_.getObjFromQuery(r))),s&&_.extend(a,_.getObjFromQuery(_.decodeURIComponent(s))),a},_.setUtm=function(t,e){var r={},s=_.getMixedQuery(t),a=_.getCustomUtmFromQuery(s,"$","_","$"),n=_.getCustomUtmFromQuery(s,"$latest_","_latest_","$latest_");return r.pre1=a,r.pre2=n,_.extend(e,a),r},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var r,s;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(r=e.platform,"ios"===(s=r.toLowerCase())?"iOS":"android"===s?"Android":r),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var r={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(r,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(r.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(r._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),r.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,r.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?r.properties.$is_first_day=!0:r.properties.$is_first_day=!1),r.properties.$time&&_.isDate(r.properties.$time)?(r.time=1*r.properties.$time,delete r.properties.$time):sa.para.use_client_time&&(r.time=1*new Date),_.searchObjDate(r),_.searchObjString(r),logger.info(r),sa.sendStrategy.send(r)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var r=this._state.props||{};e?this.set("props",t):(_.extend(r,t),this.set("props",r))},set:function(t,e){var r={};for(var s in"string"==typeof t?r[t]=e:"object"==typeof t&&(r=t),this._state=this._state||{},r)this._state[s]=r[s];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,r=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:r,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,r){_.isString(e)?t[r]=[e]:_.isArray(e)||(delete t[r],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var r=t;_.isString(t)&&((t={})[r]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,r){this.prepareData({type:"track",event:t,properties:e},r)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var r=sa.store.getFirstId();!0===e?r?sa.store.set("first_id",t):sa.store.set("distinct_id",t):r?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,r,s){var a=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:a,distinct_id:t,type:"track_signup",event:e,properties:r},s)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),r={};_.isArray(t)&&(_.each(e,function(e,s){_.include(t,s)||(r[s]=e)}),sa.store.setProps(r,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,r){_.include(t,r)&&delete _.info.currentProps[r]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var r=!1;for(var s in e)t[e[s]]&&(r=!0);return r}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),r=sa.store.getDistinctId();t!==r&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",r),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,r){0===r.indexOf("$")&&(t[r]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(r){r&&sa.setOpenid(r,t.isCoverLogin),e&&_.isFunction(e)&&e(r),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var r=[];return _.each(t,function(t,s){"q"===s&&_.isString(t)&&0===t.indexOf("http")||"scene"===s||(e?r.push(s+"="+t):r.push(s+"="+_.decodeURIComponent(t)))}),r.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),r=e[e.length-1].options;t=_.getCustomUtmFromQuery(r,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,r){var s=sa.para.autoTrack[t],a="";sa.para.autoTrack&&s&&("function"==typeof s?(a=s(),_.isObject(a)&&_.extend(e,a)):_.isObject(s)&&(_.extend(e,s),sa.para.autoTrack[t]=!0),sa.track(r,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var r={};t&&t.path&&(r.$url_path=_.getPath(t.path)),_.setShareInfo(t,r);var s=_.setUtm(t,r);is_first_launch?(r.$is_first_time=!0,_.isEmptyObject(s.pre1)||sa.setOnceProfile(s.pre1)):r.$is_first_time=!1,sa.setLatestChannel(s.pre2),r.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:r.$scene}),r.$url_query=_.setQuery(t.query),e?(r=_.extend(r,e),sa.track("$MPLaunch",r)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",r,"$MPLaunch")},appShow:function(t,e){var r={};mpshow_time=(new Date).getTime(),t&&t.path&&(r.$url_path=_.getPath(t.path)),_.setShareInfo(t,r);var s=_.setUtm(t,r);sa.setLatestChannel(s.pre2),r.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:r.$scene}),r.$url_query=_.setQuery(t.query),e?(r=_.extend(r,e),sa.track("$MPShow",r)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",r,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),r={};r.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(r.event_duration=(e-mpshow_time)/1e3),t?(r=_.extend(r,t),sa.track("$MPHide",r)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",r,"$MPHide"),sa.sendStrategy.onAppHide()}},sa.quick=function(){var t=arguments[0],e=arguments[1],r=arguments[2],s=_.isObject(r)?r:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,s):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(s=_.isObject(e)?e:{},sa.autoTrackCustom[t](s))},sa.initial(),module.exports=sa; \ No newline at end of file diff --git a/sensorsdata.full.es6.js b/sensorsdata.full.es6.js index 92fdf2d..ac908c2 100755 --- a/sensorsdata.full.es6.js +++ b/sensorsdata.full.es6.js @@ -94,7 +94,7 @@ var ArrayProto = Array.prototype, slice = ArrayProto.slice, toString = ObjProto.toString, hasOwnProperty = ObjProto.hasOwnProperty, - LIB_VERSION = '1.13.15', + LIB_VERSION = '1.13.16', LIB_NAME = 'MiniProgram'; var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term'; @@ -174,8 +174,8 @@ var mp_scene = { 1104: '微信聊天主界面下拉,“我的小程序”栏', 1106: '聊天主界面下拉,从顶部搜索结果页,打开小程序', 1107: '订阅消息,打开小程序', - 1113: '安卓手机负一屏,打开小程序(三星', - 1114: '安卓手机侧边栏,打开小程序(三星)', + 1113: '安卓手机负一屏,打开小程序(三星)', + 1114: '安卓手机侧边栏,打开小程序(三星)', 1124: '扫“一物一码”打开小程序', 1125: '长按图片识别“一物一码”', 1126: '扫描手机相册中选取的“一物一码”', diff --git a/sensorsdata.full.js b/sensorsdata.full.js index 765857c..54554be 100755 --- a/sensorsdata.full.js +++ b/sensorsdata.full.js @@ -94,7 +94,7 @@ var ArrayProto = Array.prototype, slice = ArrayProto.slice, toString = ObjProto.toString, hasOwnProperty = ObjProto.hasOwnProperty, - LIB_VERSION = '1.13.15', + LIB_VERSION = '1.13.16', LIB_NAME = 'MiniProgram'; var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term'; @@ -174,8 +174,8 @@ var mp_scene = { 1104: '微信聊天主界面下拉,“我的小程序”栏', 1106: '聊天主界面下拉,从顶部搜索结果页,打开小程序', 1107: '订阅消息,打开小程序', - 1113: '安卓手机负一屏,打开小程序(三星', - 1114: '安卓手机侧边栏,打开小程序(三星)', + 1113: '安卓手机负一屏,打开小程序(三星)', + 1114: '安卓手机侧边栏,打开小程序(三星)', 1124: '扫“一物一码”打开小程序', 1125: '长按图片识别“一物一码”', 1126: '扫描手机相册中选取的“一物一码”', diff --git a/sensorsdata.min.es6.js b/sensorsdata.min.es6.js index 0362af4..fccdefe 100755 --- a/sensorsdata.min.es6.js +++ b/sensorsdata.min.es6.js @@ -1 +1 @@ -var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var a=sa.para.source_channel.length,r=0;rsa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,a){_.isObject(e)?_.searchObjString(t[a]):_.isString(e)&&(t[a]=_.formatString(e))})},_.unique=function(t){for(var e,a=[],r={},s=0;s127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(a>e&&(n+=t.substring(e,a)),n+=o,e=a=s+1)}return a>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,a,r,s,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,a=n>>12&63,r=n>>6&63,s=63&n,p[c++]=i.charAt(e)+i.charAt(a)+i.charAt(r)+i.charAt(s)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,a,r){if(!_.isObject(t))return{};var s={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[r+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[e+n]=t[n];return s},_.getObjFromQuery=function(t){var e=t.split("?"),a=[],r={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(a=t.split("="))[0]&&a[1]&&(r[a[0]]=a[1])}),r):{}},_.setStorageSync=function(t,e){var a=function(){wx.setStorageSync(t,e)};try{a()}catch(t){logger.info("set Storage fail --",t);try{a()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(a){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var a={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(a=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(a))return{};var r=(a=JSON.parse(a)).d,s=a.p,n=a.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof r?(e.$share_depth=r,share_depth=r):e.$share_depth="-1",e.$share_url_path="string"==typeof s?s:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,a,r,s,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,a=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),r=new RegExp("("+a.join("|")+")%3D","i"),1===(s=Object.keys(e)).length&&"scene"===s[0]&&r.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),a=e.scene,r=e.q,s=e.query;for(var n in s)s[n]=_.decodeURIComponent(s[n]);return a&&(a=-1!==(a=_.decodeURIComponent(a)).indexOf("?")?"?"+a.replace(/\?/g,""):"?"+a,_.extend(s,_.getObjFromQuery(a))),r&&_.extend(s,_.getObjFromQuery(_.decodeURIComponent(r))),s},_.setUtm=function(t,e){var a={},r=_.getMixedQuery(t),s=_.getCustomUtmFromQuery(r,"$","_","$"),n=_.getCustomUtmFromQuery(r,"$latest_","_latest_","$latest_");return a.pre1=s,a.pre2=n,_.extend(e,s),a},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var a,r;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(a=e.platform,"ios"===(r=a.toLowerCase())?"iOS":"android"===r?"Android":a),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var a={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(a,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(a.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(a._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),a.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,a.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?a.properties.$is_first_day=!0:a.properties.$is_first_day=!1),a.properties.$time&&_.isDate(a.properties.$time)?(a.time=1*a.properties.$time,delete a.properties.$time):sa.para.use_client_time&&(a.time=1*new Date),_.searchObjDate(a),_.searchObjString(a),logger.info(a),sa.sendStrategy.send(a)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var a=this._state.props||{};e?this.set("props",t):(_.extend(a,t),this.set("props",a))},set:function(t,e){var a={};for(var r in"string"==typeof t?a[t]=e:"object"==typeof t&&(a=t),this._state=this._state||{},a)this._state[r]=a[r];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,a=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:a,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,a){_.isString(e)?t[a]=[e]:_.isArray(e)||(delete t[a],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var a=t;_.isString(t)&&((t={})[a]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,a){this.prepareData({type:"track",event:t,properties:e},a)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var a=sa.store.getFirstId();!0===e?a?sa.store.set("first_id",t):sa.store.set("distinct_id",t):a?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,a,r){var s=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:s,distinct_id:t,type:"track_signup",event:e,properties:a},r)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),a={};_.isArray(t)&&(_.each(e,function(e,r){_.include(t,r)||(a[r]=e)}),sa.store.setProps(a,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,a){_.include(t,a)&&delete _.info.currentProps[a]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var a=!1;for(var r in e)t[e[r]]&&(a=!0);return a}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),a=sa.store.getDistinctId();t!==a&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",a),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,a){0===a.indexOf("$")&&(t[a]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(a){a&&sa.setOpenid(a,t.isCoverLogin),e&&_.isFunction(e)&&e(a),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var a=[];return _.each(t,function(t,r){"q"===r&&_.isString(t)&&0===t.indexOf("http")||"scene"===r||(e?a.push(r+"="+t):a.push(r+"="+_.decodeURIComponent(t)))}),a.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),a=e[e.length-1].options;t=_.getCustomUtmFromQuery(a,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,a){var r=sa.para.autoTrack[t],s="";sa.para.autoTrack&&r&&("function"==typeof r?(s=r(),_.isObject(s)&&_.extend(e,s)):_.isObject(r)&&(_.extend(e,r),sa.para.autoTrack[t]=!0),sa.track(a,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var a={};t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);is_first_launch?(a.$is_first_time=!0,_.isEmptyObject(r.pre1)||sa.setOnceProfile(r.pre1)):a.$is_first_time=!1,sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPLaunch",a)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",a,"$MPLaunch")},appShow:function(t,e){var a={};mpshow_time=(new Date).getTime(),t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPShow",a)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",a,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),a={};a.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(a.event_duration=(e-mpshow_time)/1e3),t?(a=_.extend(a,t),sa.track("$MPHide",a)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",a,"$MPHide"),sa.sendStrategy.onAppHide()},pageLoad:function(t){t&&_.isObject(t)&&(this.sensors_mp_url_query=_.setQuery(t),this.sensors_mp_encode_url_query=_.setQuery(t,!0))},pageShow:function(){var t={},e=_.getCurrentPath();t.$referrer=sa_referrer,t.$url_path=e,sa.status.last_referrer=sa_referrer,t.$url_query=this.sensors_mp_url_query?this.sensors_mp_url_query:"",t=_.extend(t,_.getUtmFromPage()),sa.para.onshow?sa.para.onshow(sa,e,this):sa.para.autoTrack&&sa.para.autoTrack.pageShow&&sa.autoTrackCustom.trackCustom("pageShow",t,"$MPViewScreen"),sa_referrer=e,sa.status.referrer=e},pageShare:function(t,e){var a=t.onShareAppMessage;t.onShareAppMessage=function(){var t=a.apply(this,arguments);return sa.para.autoTrack&&sa.para.autoTrack.pageShare&&sa.autoTrackCustom.trackCustom("pageShare",{$url_path:_.getCurrentPath(),$share_depth:_.getShareDepth()},"$MPShare"),sa.para.allow_amend_share_path&&("object"!=typeof t&&((t={}).path=_.getCurrentUrl(this)),"object"!=typeof t||void 0!==t.path&&""!==t.path||(t.path=_.getCurrentUrl(this)),"object"==typeof t&&"string"==typeof t.path&&(-1===t.path.indexOf("?")?t.path=t.path+"?":"&"!==t.path.slice(-1)&&(t.path=t.path+"&")),t.path=t.path+"sampshare="+encodeURIComponent(_.getShareInfo())),t}}},sa.quick=function(){var t=arguments[0],e=arguments[1],a=arguments[2],r=_.isObject(a)?a:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,r):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(r=_.isObject(e)?e:{},sa.autoTrackCustom[t](r))};var oldApp=App;App=function(t){mp_proxy(t,"onLaunch","appLaunch"),mp_proxy(t,"onShow","appShow"),mp_proxy(t,"onHide","appHide"),oldApp.apply(this,arguments)};var oldPage=Page;Page=function(t){mp_proxy(t,"onLoad","pageLoad"),mp_proxy(t,"onShow","pageShow"),"function"==typeof t.onShareAppMessage&&sa.autoTrackCustom.pageShare(t),oldPage.apply(this,arguments)};var oldComponent=Component;Component=function(t){try{t.methods=t.methods||{},mp_proxy(t.methods,"onLoad","pageLoad"),mp_proxy(t.methods,"onShow","pageShow"),"function"==typeof t.methods.onShareAppMessage&&sa.autoTrackCustom.pageShare(t.methods),oldComponent.apply(this,arguments)}catch(t){oldComponent.apply(this,arguments)}},sa.initial();export default sa; \ No newline at end of file +var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var a=sa.para.source_channel.length,r=0;rsa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,a){_.isObject(e)?_.searchObjString(t[a]):_.isString(e)&&(t[a]=_.formatString(e))})},_.unique=function(t){for(var e,a=[],r={},s=0;s127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(a>e&&(n+=t.substring(e,a)),n+=o,e=a=s+1)}return a>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,a,r,s,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,a=n>>12&63,r=n>>6&63,s=63&n,p[c++]=i.charAt(e)+i.charAt(a)+i.charAt(r)+i.charAt(s)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,a,r){if(!_.isObject(t))return{};var s={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[r+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[e+n]=t[n];return s},_.getObjFromQuery=function(t){var e=t.split("?"),a=[],r={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(a=t.split("="))[0]&&a[1]&&(r[a[0]]=a[1])}),r):{}},_.setStorageSync=function(t,e){var a=function(){wx.setStorageSync(t,e)};try{a()}catch(t){logger.info("set Storage fail --",t);try{a()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(a){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var a={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(a=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(a))return{};var r=(a=JSON.parse(a)).d,s=a.p,n=a.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof r?(e.$share_depth=r,share_depth=r):e.$share_depth="-1",e.$share_url_path="string"==typeof s?s:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,a,r,s,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,a=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),r=new RegExp("("+a.join("|")+")%3D","i"),1===(s=Object.keys(e)).length&&"scene"===s[0]&&r.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),a=e.scene,r=e.q,s=e.query;for(var n in s)s[n]=_.decodeURIComponent(s[n]);return a&&(a=-1!==(a=_.decodeURIComponent(a)).indexOf("?")?"?"+a.replace(/\?/g,""):"?"+a,_.extend(s,_.getObjFromQuery(a))),r&&_.extend(s,_.getObjFromQuery(_.decodeURIComponent(r))),s},_.setUtm=function(t,e){var a={},r=_.getMixedQuery(t),s=_.getCustomUtmFromQuery(r,"$","_","$"),n=_.getCustomUtmFromQuery(r,"$latest_","_latest_","$latest_");return a.pre1=s,a.pre2=n,_.extend(e,s),a},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var a,r;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(a=e.platform,"ios"===(r=a.toLowerCase())?"iOS":"android"===r?"Android":a),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var a={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(a,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(a.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(a._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),a.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,a.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?a.properties.$is_first_day=!0:a.properties.$is_first_day=!1),a.properties.$time&&_.isDate(a.properties.$time)?(a.time=1*a.properties.$time,delete a.properties.$time):sa.para.use_client_time&&(a.time=1*new Date),_.searchObjDate(a),_.searchObjString(a),logger.info(a),sa.sendStrategy.send(a)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var a=this._state.props||{};e?this.set("props",t):(_.extend(a,t),this.set("props",a))},set:function(t,e){var a={};for(var r in"string"==typeof t?a[t]=e:"object"==typeof t&&(a=t),this._state=this._state||{},a)this._state[r]=a[r];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,a=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:a,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,a){_.isString(e)?t[a]=[e]:_.isArray(e)||(delete t[a],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var a=t;_.isString(t)&&((t={})[a]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,a){this.prepareData({type:"track",event:t,properties:e},a)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var a=sa.store.getFirstId();!0===e?a?sa.store.set("first_id",t):sa.store.set("distinct_id",t):a?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,a,r){var s=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:s,distinct_id:t,type:"track_signup",event:e,properties:a},r)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),a={};_.isArray(t)&&(_.each(e,function(e,r){_.include(t,r)||(a[r]=e)}),sa.store.setProps(a,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,a){_.include(t,a)&&delete _.info.currentProps[a]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var a=!1;for(var r in e)t[e[r]]&&(a=!0);return a}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),a=sa.store.getDistinctId();t!==a&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",a),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,a){0===a.indexOf("$")&&(t[a]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(a){a&&sa.setOpenid(a,t.isCoverLogin),e&&_.isFunction(e)&&e(a),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var a=[];return _.each(t,function(t,r){"q"===r&&_.isString(t)&&0===t.indexOf("http")||"scene"===r||(e?a.push(r+"="+t):a.push(r+"="+_.decodeURIComponent(t)))}),a.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),a=e[e.length-1].options;t=_.getCustomUtmFromQuery(a,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,a){var r=sa.para.autoTrack[t],s="";sa.para.autoTrack&&r&&("function"==typeof r?(s=r(),_.isObject(s)&&_.extend(e,s)):_.isObject(r)&&(_.extend(e,r),sa.para.autoTrack[t]=!0),sa.track(a,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var a={};t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);is_first_launch?(a.$is_first_time=!0,_.isEmptyObject(r.pre1)||sa.setOnceProfile(r.pre1)):a.$is_first_time=!1,sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPLaunch",a)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",a,"$MPLaunch")},appShow:function(t,e){var a={};mpshow_time=(new Date).getTime(),t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPShow",a)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",a,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),a={};a.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(a.event_duration=(e-mpshow_time)/1e3),t?(a=_.extend(a,t),sa.track("$MPHide",a)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",a,"$MPHide"),sa.sendStrategy.onAppHide()},pageLoad:function(t){t&&_.isObject(t)&&(this.sensors_mp_url_query=_.setQuery(t),this.sensors_mp_encode_url_query=_.setQuery(t,!0))},pageShow:function(){var t={},e=_.getCurrentPath();t.$referrer=sa_referrer,t.$url_path=e,sa.status.last_referrer=sa_referrer,t.$url_query=this.sensors_mp_url_query?this.sensors_mp_url_query:"",t=_.extend(t,_.getUtmFromPage()),sa.para.onshow?sa.para.onshow(sa,e,this):sa.para.autoTrack&&sa.para.autoTrack.pageShow&&sa.autoTrackCustom.trackCustom("pageShow",t,"$MPViewScreen"),sa_referrer=e,sa.status.referrer=e},pageShare:function(t,e){var a=t.onShareAppMessage;t.onShareAppMessage=function(){var t=a.apply(this,arguments);return sa.para.autoTrack&&sa.para.autoTrack.pageShare&&sa.autoTrackCustom.trackCustom("pageShare",{$url_path:_.getCurrentPath(),$share_depth:_.getShareDepth()},"$MPShare"),sa.para.allow_amend_share_path&&("object"!=typeof t&&((t={}).path=_.getCurrentUrl(this)),"object"!=typeof t||void 0!==t.path&&""!==t.path||(t.path=_.getCurrentUrl(this)),"object"==typeof t&&"string"==typeof t.path&&(-1===t.path.indexOf("?")?t.path=t.path+"?":"&"!==t.path.slice(-1)&&(t.path=t.path+"&")),t.path=t.path+"sampshare="+encodeURIComponent(_.getShareInfo())),t}}},sa.quick=function(){var t=arguments[0],e=arguments[1],a=arguments[2],r=_.isObject(a)?a:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,r):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(r=_.isObject(e)?e:{},sa.autoTrackCustom[t](r))};var oldApp=App;App=function(t){mp_proxy(t,"onLaunch","appLaunch"),mp_proxy(t,"onShow","appShow"),mp_proxy(t,"onHide","appHide"),oldApp.apply(this,arguments)};var oldPage=Page;Page=function(t){mp_proxy(t,"onLoad","pageLoad"),mp_proxy(t,"onShow","pageShow"),"function"==typeof t.onShareAppMessage&&sa.autoTrackCustom.pageShare(t),oldPage.apply(this,arguments)};var oldComponent=Component;Component=function(t){try{t.methods=t.methods||{},mp_proxy(t.methods,"onLoad","pageLoad"),mp_proxy(t.methods,"onShow","pageShow"),"function"==typeof t.methods.onShareAppMessage&&sa.autoTrackCustom.pageShare(t.methods),oldComponent.apply(this,arguments)}catch(t){oldComponent.apply(this,arguments)}},sa.initial();export default sa; \ No newline at end of file diff --git a/sensorsdata.min.js b/sensorsdata.min.js index a1dc908..b96bb98 100755 --- a/sensorsdata.min.js +++ b/sensorsdata.min.js @@ -1 +1 @@ -var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var a=sa.para.source_channel.length,r=0;rsa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,a){_.isObject(e)?_.searchObjString(t[a]):_.isString(e)&&(t[a]=_.formatString(e))})},_.unique=function(t){for(var e,a=[],r={},s=0;s127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(a>e&&(n+=t.substring(e,a)),n+=o,e=a=s+1)}return a>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,a,r,s,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,a=n>>12&63,r=n>>6&63,s=63&n,p[c++]=i.charAt(e)+i.charAt(a)+i.charAt(r)+i.charAt(s)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,a,r){if(!_.isObject(t))return{};var s={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[r+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[e+n]=t[n];return s},_.getObjFromQuery=function(t){var e=t.split("?"),a=[],r={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(a=t.split("="))[0]&&a[1]&&(r[a[0]]=a[1])}),r):{}},_.setStorageSync=function(t,e){var a=function(){wx.setStorageSync(t,e)};try{a()}catch(t){logger.info("set Storage fail --",t);try{a()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(a){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var a={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(a=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(a))return{};var r=(a=JSON.parse(a)).d,s=a.p,n=a.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof r?(e.$share_depth=r,share_depth=r):e.$share_depth="-1",e.$share_url_path="string"==typeof s?s:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,a,r,s,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,a=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),r=new RegExp("("+a.join("|")+")%3D","i"),1===(s=Object.keys(e)).length&&"scene"===s[0]&&r.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),a=e.scene,r=e.q,s=e.query;for(var n in s)s[n]=_.decodeURIComponent(s[n]);return a&&(a=-1!==(a=_.decodeURIComponent(a)).indexOf("?")?"?"+a.replace(/\?/g,""):"?"+a,_.extend(s,_.getObjFromQuery(a))),r&&_.extend(s,_.getObjFromQuery(_.decodeURIComponent(r))),s},_.setUtm=function(t,e){var a={},r=_.getMixedQuery(t),s=_.getCustomUtmFromQuery(r,"$","_","$"),n=_.getCustomUtmFromQuery(r,"$latest_","_latest_","$latest_");return a.pre1=s,a.pre2=n,_.extend(e,s),a},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var a,r;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(a=e.platform,"ios"===(r=a.toLowerCase())?"iOS":"android"===r?"Android":a),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var a={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(a,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(a.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(a._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),a.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,a.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?a.properties.$is_first_day=!0:a.properties.$is_first_day=!1),a.properties.$time&&_.isDate(a.properties.$time)?(a.time=1*a.properties.$time,delete a.properties.$time):sa.para.use_client_time&&(a.time=1*new Date),_.searchObjDate(a),_.searchObjString(a),logger.info(a),sa.sendStrategy.send(a)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var a=this._state.props||{};e?this.set("props",t):(_.extend(a,t),this.set("props",a))},set:function(t,e){var a={};for(var r in"string"==typeof t?a[t]=e:"object"==typeof t&&(a=t),this._state=this._state||{},a)this._state[r]=a[r];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,a=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:a,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,a){_.isString(e)?t[a]=[e]:_.isArray(e)||(delete t[a],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var a=t;_.isString(t)&&((t={})[a]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,a){this.prepareData({type:"track",event:t,properties:e},a)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var a=sa.store.getFirstId();!0===e?a?sa.store.set("first_id",t):sa.store.set("distinct_id",t):a?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,a,r){var s=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:s,distinct_id:t,type:"track_signup",event:e,properties:a},r)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),a={};_.isArray(t)&&(_.each(e,function(e,r){_.include(t,r)||(a[r]=e)}),sa.store.setProps(a,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,a){_.include(t,a)&&delete _.info.currentProps[a]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var a=!1;for(var r in e)t[e[r]]&&(a=!0);return a}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),a=sa.store.getDistinctId();t!==a&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",a),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,a){0===a.indexOf("$")&&(t[a]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(a){a&&sa.setOpenid(a,t.isCoverLogin),e&&_.isFunction(e)&&e(a),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var a=[];return _.each(t,function(t,r){"q"===r&&_.isString(t)&&0===t.indexOf("http")||"scene"===r||(e?a.push(r+"="+t):a.push(r+"="+_.decodeURIComponent(t)))}),a.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),a=e[e.length-1].options;t=_.getCustomUtmFromQuery(a,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,a){var r=sa.para.autoTrack[t],s="";sa.para.autoTrack&&r&&("function"==typeof r?(s=r(),_.isObject(s)&&_.extend(e,s)):_.isObject(r)&&(_.extend(e,r),sa.para.autoTrack[t]=!0),sa.track(a,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var a={};t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);is_first_launch?(a.$is_first_time=!0,_.isEmptyObject(r.pre1)||sa.setOnceProfile(r.pre1)):a.$is_first_time=!1,sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPLaunch",a)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",a,"$MPLaunch")},appShow:function(t,e){var a={};mpshow_time=(new Date).getTime(),t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPShow",a)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",a,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),a={};a.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(a.event_duration=(e-mpshow_time)/1e3),t?(a=_.extend(a,t),sa.track("$MPHide",a)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",a,"$MPHide"),sa.sendStrategy.onAppHide()},pageLoad:function(t){t&&_.isObject(t)&&(this.sensors_mp_url_query=_.setQuery(t),this.sensors_mp_encode_url_query=_.setQuery(t,!0))},pageShow:function(){var t={},e=_.getCurrentPath();t.$referrer=sa_referrer,t.$url_path=e,sa.status.last_referrer=sa_referrer,t.$url_query=this.sensors_mp_url_query?this.sensors_mp_url_query:"",t=_.extend(t,_.getUtmFromPage()),sa.para.onshow?sa.para.onshow(sa,e,this):sa.para.autoTrack&&sa.para.autoTrack.pageShow&&sa.autoTrackCustom.trackCustom("pageShow",t,"$MPViewScreen"),sa_referrer=e,sa.status.referrer=e},pageShare:function(t,e){var a=t.onShareAppMessage;t.onShareAppMessage=function(){var t=a.apply(this,arguments);return sa.para.autoTrack&&sa.para.autoTrack.pageShare&&sa.autoTrackCustom.trackCustom("pageShare",{$url_path:_.getCurrentPath(),$share_depth:_.getShareDepth()},"$MPShare"),sa.para.allow_amend_share_path&&("object"!=typeof t&&((t={}).path=_.getCurrentUrl(this)),"object"!=typeof t||void 0!==t.path&&""!==t.path||(t.path=_.getCurrentUrl(this)),"object"==typeof t&&"string"==typeof t.path&&(-1===t.path.indexOf("?")?t.path=t.path+"?":"&"!==t.path.slice(-1)&&(t.path=t.path+"&")),t.path=t.path+"sampshare="+encodeURIComponent(_.getShareInfo())),t}}},sa.quick=function(){var t=arguments[0],e=arguments[1],a=arguments[2],r=_.isObject(a)?a:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,r):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(r=_.isObject(e)?e:{},sa.autoTrackCustom[t](r))};var oldApp=App;App=function(t){mp_proxy(t,"onLaunch","appLaunch"),mp_proxy(t,"onShow","appShow"),mp_proxy(t,"onHide","appHide"),oldApp.apply(this,arguments)};var oldPage=Page;Page=function(t){mp_proxy(t,"onLoad","pageLoad"),mp_proxy(t,"onShow","pageShow"),"function"==typeof t.onShareAppMessage&&sa.autoTrackCustom.pageShare(t),oldPage.apply(this,arguments)};var oldComponent=Component;Component=function(t){try{t.methods=t.methods||{},mp_proxy(t.methods,"onLoad","pageLoad"),mp_proxy(t.methods,"onShow","pageShow"),"function"==typeof t.methods.onShareAppMessage&&sa.autoTrackCustom.pageShare(t.methods),oldComponent.apply(this,arguments)}catch(t){oldComponent.apply(this,arguments)}},sa.initial(),module.exports=sa; \ No newline at end of file +var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var a=sa.para.source_channel.length,r=0;rsa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,a){_.isObject(e)?_.searchObjString(t[a]):_.isString(e)&&(t[a]=_.formatString(e))})},_.unique=function(t){for(var e,a=[],r={},s=0;s127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(a>e&&(n+=t.substring(e,a)),n+=o,e=a=s+1)}return a>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,a,r,s,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,a=n>>12&63,r=n>>6&63,s=63&n,p[c++]=i.charAt(e)+i.charAt(a)+i.charAt(r)+i.charAt(s)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,a,r){if(!_.isObject(t))return{};var s={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[r+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[e+n]=t[n];return s},_.getObjFromQuery=function(t){var e=t.split("?"),a=[],r={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(a=t.split("="))[0]&&a[1]&&(r[a[0]]=a[1])}),r):{}},_.setStorageSync=function(t,e){var a=function(){wx.setStorageSync(t,e)};try{a()}catch(t){logger.info("set Storage fail --",t);try{a()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(a){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var a={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(a=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(a))return{};var r=(a=JSON.parse(a)).d,s=a.p,n=a.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof r?(e.$share_depth=r,share_depth=r):e.$share_depth="-1",e.$share_url_path="string"==typeof s?s:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,a,r,s,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,a=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),r=new RegExp("("+a.join("|")+")%3D","i"),1===(s=Object.keys(e)).length&&"scene"===s[0]&&r.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),a=e.scene,r=e.q,s=e.query;for(var n in s)s[n]=_.decodeURIComponent(s[n]);return a&&(a=-1!==(a=_.decodeURIComponent(a)).indexOf("?")?"?"+a.replace(/\?/g,""):"?"+a,_.extend(s,_.getObjFromQuery(a))),r&&_.extend(s,_.getObjFromQuery(_.decodeURIComponent(r))),s},_.setUtm=function(t,e){var a={},r=_.getMixedQuery(t),s=_.getCustomUtmFromQuery(r,"$","_","$"),n=_.getCustomUtmFromQuery(r,"$latest_","_latest_","$latest_");return a.pre1=s,a.pre2=n,_.extend(e,s),a},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var a,r;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(a=e.platform,"ios"===(r=a.toLowerCase())?"iOS":"android"===r?"Android":a),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var a={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(a,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(a.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(a._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),a.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,a.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?a.properties.$is_first_day=!0:a.properties.$is_first_day=!1),a.properties.$time&&_.isDate(a.properties.$time)?(a.time=1*a.properties.$time,delete a.properties.$time):sa.para.use_client_time&&(a.time=1*new Date),_.searchObjDate(a),_.searchObjString(a),logger.info(a),sa.sendStrategy.send(a)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var a=this._state.props||{};e?this.set("props",t):(_.extend(a,t),this.set("props",a))},set:function(t,e){var a={};for(var r in"string"==typeof t?a[t]=e:"object"==typeof t&&(a=t),this._state=this._state||{},a)this._state[r]=a[r];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,a=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:a,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,a){_.isString(e)?t[a]=[e]:_.isArray(e)||(delete t[a],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var a=t;_.isString(t)&&((t={})[a]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,a){this.prepareData({type:"track",event:t,properties:e},a)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var a=sa.store.getFirstId();!0===e?a?sa.store.set("first_id",t):sa.store.set("distinct_id",t):a?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,a,r){var s=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:s,distinct_id:t,type:"track_signup",event:e,properties:a},r)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),a={};_.isArray(t)&&(_.each(e,function(e,r){_.include(t,r)||(a[r]=e)}),sa.store.setProps(a,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,a){_.include(t,a)&&delete _.info.currentProps[a]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var a=!1;for(var r in e)t[e[r]]&&(a=!0);return a}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),a=sa.store.getDistinctId();t!==a&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",a),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,a){0===a.indexOf("$")&&(t[a]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(a){a&&sa.setOpenid(a,t.isCoverLogin),e&&_.isFunction(e)&&e(a),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var a=[];return _.each(t,function(t,r){"q"===r&&_.isString(t)&&0===t.indexOf("http")||"scene"===r||(e?a.push(r+"="+t):a.push(r+"="+_.decodeURIComponent(t)))}),a.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),a=e[e.length-1].options;t=_.getCustomUtmFromQuery(a,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,a){var r=sa.para.autoTrack[t],s="";sa.para.autoTrack&&r&&("function"==typeof r?(s=r(),_.isObject(s)&&_.extend(e,s)):_.isObject(r)&&(_.extend(e,r),sa.para.autoTrack[t]=!0),sa.track(a,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var a={};t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);is_first_launch?(a.$is_first_time=!0,_.isEmptyObject(r.pre1)||sa.setOnceProfile(r.pre1)):a.$is_first_time=!1,sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPLaunch",a)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",a,"$MPLaunch")},appShow:function(t,e){var a={};mpshow_time=(new Date).getTime(),t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPShow",a)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",a,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),a={};a.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(a.event_duration=(e-mpshow_time)/1e3),t?(a=_.extend(a,t),sa.track("$MPHide",a)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",a,"$MPHide"),sa.sendStrategy.onAppHide()},pageLoad:function(t){t&&_.isObject(t)&&(this.sensors_mp_url_query=_.setQuery(t),this.sensors_mp_encode_url_query=_.setQuery(t,!0))},pageShow:function(){var t={},e=_.getCurrentPath();t.$referrer=sa_referrer,t.$url_path=e,sa.status.last_referrer=sa_referrer,t.$url_query=this.sensors_mp_url_query?this.sensors_mp_url_query:"",t=_.extend(t,_.getUtmFromPage()),sa.para.onshow?sa.para.onshow(sa,e,this):sa.para.autoTrack&&sa.para.autoTrack.pageShow&&sa.autoTrackCustom.trackCustom("pageShow",t,"$MPViewScreen"),sa_referrer=e,sa.status.referrer=e},pageShare:function(t,e){var a=t.onShareAppMessage;t.onShareAppMessage=function(){var t=a.apply(this,arguments);return sa.para.autoTrack&&sa.para.autoTrack.pageShare&&sa.autoTrackCustom.trackCustom("pageShare",{$url_path:_.getCurrentPath(),$share_depth:_.getShareDepth()},"$MPShare"),sa.para.allow_amend_share_path&&("object"!=typeof t&&((t={}).path=_.getCurrentUrl(this)),"object"!=typeof t||void 0!==t.path&&""!==t.path||(t.path=_.getCurrentUrl(this)),"object"==typeof t&&"string"==typeof t.path&&(-1===t.path.indexOf("?")?t.path=t.path+"?":"&"!==t.path.slice(-1)&&(t.path=t.path+"&")),t.path=t.path+"sampshare="+encodeURIComponent(_.getShareInfo())),t}}},sa.quick=function(){var t=arguments[0],e=arguments[1],a=arguments[2],r=_.isObject(a)?a:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,r):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(r=_.isObject(e)?e:{},sa.autoTrackCustom[t](r))};var oldApp=App;App=function(t){mp_proxy(t,"onLaunch","appLaunch"),mp_proxy(t,"onShow","appShow"),mp_proxy(t,"onHide","appHide"),oldApp.apply(this,arguments)};var oldPage=Page;Page=function(t){mp_proxy(t,"onLoad","pageLoad"),mp_proxy(t,"onShow","pageShow"),"function"==typeof t.onShareAppMessage&&sa.autoTrackCustom.pageShare(t),oldPage.apply(this,arguments)};var oldComponent=Component;Component=function(t){try{t.methods=t.methods||{},mp_proxy(t.methods,"onLoad","pageLoad"),mp_proxy(t.methods,"onShow","pageShow"),"function"==typeof t.methods.onShareAppMessage&&sa.autoTrackCustom.pageShare(t.methods),oldComponent.apply(this,arguments)}catch(t){oldComponent.apply(this,arguments)}},sa.initial(),module.exports=sa; \ No newline at end of file diff --git a/sensorsdata.plugin.es6.min.js b/sensorsdata.plugin.es6.min.js index da4355e..f520a81 100755 --- a/sensorsdata.plugin.es6.min.js +++ b/sensorsdata.plugin.es6.min.js @@ -1 +1 @@ -var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var a=sa.para.source_channel.length,r=0;rsa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,a){_.isObject(e)?_.searchObjString(t[a]):_.isString(e)&&(t[a]=_.formatString(e))})},_.unique=function(t){for(var e,a=[],r={},s=0;s127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(a>e&&(n+=t.substring(e,a)),n+=o,e=a=s+1)}return a>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,a,r,s,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,a=n>>12&63,r=n>>6&63,s=63&n,p[c++]=i.charAt(e)+i.charAt(a)+i.charAt(r)+i.charAt(s)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,a,r){if(!_.isObject(t))return{};var s={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[r+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[e+n]=t[n];return s},_.getObjFromQuery=function(t){var e=t.split("?"),a=[],r={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(a=t.split("="))[0]&&a[1]&&(r[a[0]]=a[1])}),r):{}},_.setStorageSync=function(t,e){var a=function(){wx.setStorageSync(t,e)};try{a()}catch(t){logger.info("set Storage fail --",t);try{a()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(a){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var a={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(a=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(a))return{};var r=(a=JSON.parse(a)).d,s=a.p,n=a.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof r?(e.$share_depth=r,share_depth=r):e.$share_depth="-1",e.$share_url_path="string"==typeof s?s:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,a,r,s,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,a=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),r=new RegExp("("+a.join("|")+")%3D","i"),1===(s=Object.keys(e)).length&&"scene"===s[0]&&r.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),a=e.scene,r=e.q,s=e.query;for(var n in s)s[n]=_.decodeURIComponent(s[n]);return a&&(a=-1!==(a=_.decodeURIComponent(a)).indexOf("?")?"?"+a.replace(/\?/g,""):"?"+a,_.extend(s,_.getObjFromQuery(a))),r&&_.extend(s,_.getObjFromQuery(_.decodeURIComponent(r))),s},_.setUtm=function(t,e){var a={},r=_.getMixedQuery(t),s=_.getCustomUtmFromQuery(r,"$","_","$"),n=_.getCustomUtmFromQuery(r,"$latest_","_latest_","$latest_");return a.pre1=s,a.pre2=n,_.extend(e,s),a},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var a,r;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(a=e.platform,"ios"===(r=a.toLowerCase())?"iOS":"android"===r?"Android":a),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var a={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(a,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(a.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(a._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),a.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,a.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?a.properties.$is_first_day=!0:a.properties.$is_first_day=!1),a.properties.$time&&_.isDate(a.properties.$time)?(a.time=1*a.properties.$time,delete a.properties.$time):sa.para.use_client_time&&(a.time=1*new Date),_.searchObjDate(a),_.searchObjString(a),logger.info(a),sa.sendStrategy.send(a)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var a=this._state.props||{};e?this.set("props",t):(_.extend(a,t),this.set("props",a))},set:function(t,e){var a={};for(var r in"string"==typeof t?a[t]=e:"object"==typeof t&&(a=t),this._state=this._state||{},a)this._state[r]=a[r];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,a=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:a,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,a){_.isString(e)?t[a]=[e]:_.isArray(e)||(delete t[a],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var a=t;_.isString(t)&&((t={})[a]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,a){this.prepareData({type:"track",event:t,properties:e},a)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var a=sa.store.getFirstId();!0===e?a?sa.store.set("first_id",t):sa.store.set("distinct_id",t):a?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,a,r){var s=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:s,distinct_id:t,type:"track_signup",event:e,properties:a},r)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),a={};_.isArray(t)&&(_.each(e,function(e,r){_.include(t,r)||(a[r]=e)}),sa.store.setProps(a,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,a){_.include(t,a)&&delete _.info.currentProps[a]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var a=!1;for(var r in e)t[e[r]]&&(a=!0);return a}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),a=sa.store.getDistinctId();t!==a&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",a),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,a){0===a.indexOf("$")&&(t[a]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(a){a&&sa.setOpenid(a,t.isCoverLogin),e&&_.isFunction(e)&&e(a),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var a=[];return _.each(t,function(t,r){"q"===r&&_.isString(t)&&0===t.indexOf("http")||"scene"===r||(e?a.push(r+"="+t):a.push(r+"="+_.decodeURIComponent(t)))}),a.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),a=e[e.length-1].options;t=_.getCustomUtmFromQuery(a,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,a){var r=sa.para.autoTrack[t],s="";sa.para.autoTrack&&r&&("function"==typeof r?(s=r(),_.isObject(s)&&_.extend(e,s)):_.isObject(r)&&(_.extend(e,r),sa.para.autoTrack[t]=!0),sa.track(a,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var a={};t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);is_first_launch?(a.$is_first_time=!0,_.isEmptyObject(r.pre1)||sa.setOnceProfile(r.pre1)):a.$is_first_time=!1,sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPLaunch",a)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",a,"$MPLaunch")},appShow:function(t,e){var a={};mpshow_time=(new Date).getTime(),t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPShow",a)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",a,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),a={};a.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(a.event_duration=(e-mpshow_time)/1e3),t?(a=_.extend(a,t),sa.track("$MPHide",a)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",a,"$MPHide"),sa.sendStrategy.onAppHide()},pageLoad:function(t){t&&_.isObject(t)&&(this.sensors_mp_url_query=_.setQuery(t),this.sensors_mp_encode_url_query=_.setQuery(t,!0))},pageShow:function(){var t={},e=_.getCurrentPath();t.$referrer=sa_referrer,t.$url_path=e,sa.status.last_referrer=sa_referrer,t.$url_query=this.sensors_mp_url_query?this.sensors_mp_url_query:"",t=_.extend(t,_.getUtmFromPage()),sa.para.onshow?sa.para.onshow(sa,e,this):sa.para.autoTrack&&sa.para.autoTrack.pageShow&&sa.autoTrackCustom.trackCustom("pageShow",t,"$MPViewScreen"),sa_referrer=e,sa.status.referrer=e},pageShare:function(t,e){var a=t.onShareAppMessage;t.onShareAppMessage=function(){var t=a.apply(this,arguments);return sa.para.autoTrack&&sa.para.autoTrack.pageShare&&sa.autoTrackCustom.trackCustom("pageShare",{$url_path:_.getCurrentPath(),$share_depth:_.getShareDepth()},"$MPShare"),sa.para.allow_amend_share_path&&("object"!=typeof t&&((t={}).path=_.getCurrentUrl(this)),"object"!=typeof t||void 0!==t.path&&""!==t.path||(t.path=_.getCurrentUrl(this)),"object"==typeof t&&"string"==typeof t.path&&(-1===t.path.indexOf("?")?t.path=t.path+"?":"&"!==t.path.slice(-1)&&(t.path=t.path+"&")),t.path=t.path+"sampshare="+encodeURIComponent(_.getShareInfo())),t}}},sa.quick=function(){var t=arguments[0],e=arguments[1],a=arguments[2],r=_.isObject(a)?a:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,r):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(r=_.isObject(e)?e:{},sa.autoTrackCustom[t](r))},sa.App=function(t){mp_proxy(t=t||{},"onLaunch","appLaunch"),mp_proxy(t,"onShow","appShow"),mp_proxy(t,"onHide","appHide"),App.apply(this,arguments)},sa.Page=function(t){mp_proxy(t,"onLoad","pageLoad"),mp_proxy(t,"onShow","pageShow"),"function"==typeof t.onShareAppMessage&&sa.autoTrackCustom.pageShare(t),Page.apply(this,arguments)},sa.initial();export default sa; \ No newline at end of file +var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var a=sa.para.source_channel.length,r=0;rsa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,a){_.isObject(e)?_.searchObjString(t[a]):_.isString(e)&&(t[a]=_.formatString(e))})},_.unique=function(t){for(var e,a=[],r={},s=0;s127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(a>e&&(n+=t.substring(e,a)),n+=o,e=a=s+1)}return a>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,a,r,s,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,a=n>>12&63,r=n>>6&63,s=63&n,p[c++]=i.charAt(e)+i.charAt(a)+i.charAt(r)+i.charAt(s)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,a,r){if(!_.isObject(t))return{};var s={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[r+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[e+n]=t[n];return s},_.getObjFromQuery=function(t){var e=t.split("?"),a=[],r={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(a=t.split("="))[0]&&a[1]&&(r[a[0]]=a[1])}),r):{}},_.setStorageSync=function(t,e){var a=function(){wx.setStorageSync(t,e)};try{a()}catch(t){logger.info("set Storage fail --",t);try{a()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(a){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var a={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(a=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(a))return{};var r=(a=JSON.parse(a)).d,s=a.p,n=a.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof r?(e.$share_depth=r,share_depth=r):e.$share_depth="-1",e.$share_url_path="string"==typeof s?s:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,a,r,s,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,a=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),r=new RegExp("("+a.join("|")+")%3D","i"),1===(s=Object.keys(e)).length&&"scene"===s[0]&&r.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),a=e.scene,r=e.q,s=e.query;for(var n in s)s[n]=_.decodeURIComponent(s[n]);return a&&(a=-1!==(a=_.decodeURIComponent(a)).indexOf("?")?"?"+a.replace(/\?/g,""):"?"+a,_.extend(s,_.getObjFromQuery(a))),r&&_.extend(s,_.getObjFromQuery(_.decodeURIComponent(r))),s},_.setUtm=function(t,e){var a={},r=_.getMixedQuery(t),s=_.getCustomUtmFromQuery(r,"$","_","$"),n=_.getCustomUtmFromQuery(r,"$latest_","_latest_","$latest_");return a.pre1=s,a.pre2=n,_.extend(e,s),a},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var a,r;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(a=e.platform,"ios"===(r=a.toLowerCase())?"iOS":"android"===r?"Android":a),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var a={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(a,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(a.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(a._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),a.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,a.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?a.properties.$is_first_day=!0:a.properties.$is_first_day=!1),a.properties.$time&&_.isDate(a.properties.$time)?(a.time=1*a.properties.$time,delete a.properties.$time):sa.para.use_client_time&&(a.time=1*new Date),_.searchObjDate(a),_.searchObjString(a),logger.info(a),sa.sendStrategy.send(a)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var a=this._state.props||{};e?this.set("props",t):(_.extend(a,t),this.set("props",a))},set:function(t,e){var a={};for(var r in"string"==typeof t?a[t]=e:"object"==typeof t&&(a=t),this._state=this._state||{},a)this._state[r]=a[r];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,a=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:a,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,a){_.isString(e)?t[a]=[e]:_.isArray(e)||(delete t[a],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var a=t;_.isString(t)&&((t={})[a]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,a){this.prepareData({type:"track",event:t,properties:e},a)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var a=sa.store.getFirstId();!0===e?a?sa.store.set("first_id",t):sa.store.set("distinct_id",t):a?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,a,r){var s=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:s,distinct_id:t,type:"track_signup",event:e,properties:a},r)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),a={};_.isArray(t)&&(_.each(e,function(e,r){_.include(t,r)||(a[r]=e)}),sa.store.setProps(a,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,a){_.include(t,a)&&delete _.info.currentProps[a]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var a=!1;for(var r in e)t[e[r]]&&(a=!0);return a}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),a=sa.store.getDistinctId();t!==a&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",a),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,a){0===a.indexOf("$")&&(t[a]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(a){a&&sa.setOpenid(a,t.isCoverLogin),e&&_.isFunction(e)&&e(a),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var a=[];return _.each(t,function(t,r){"q"===r&&_.isString(t)&&0===t.indexOf("http")||"scene"===r||(e?a.push(r+"="+t):a.push(r+"="+_.decodeURIComponent(t)))}),a.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),a=e[e.length-1].options;t=_.getCustomUtmFromQuery(a,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,a){var r=sa.para.autoTrack[t],s="";sa.para.autoTrack&&r&&("function"==typeof r?(s=r(),_.isObject(s)&&_.extend(e,s)):_.isObject(r)&&(_.extend(e,r),sa.para.autoTrack[t]=!0),sa.track(a,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var a={};t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);is_first_launch?(a.$is_first_time=!0,_.isEmptyObject(r.pre1)||sa.setOnceProfile(r.pre1)):a.$is_first_time=!1,sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPLaunch",a)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",a,"$MPLaunch")},appShow:function(t,e){var a={};mpshow_time=(new Date).getTime(),t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPShow",a)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",a,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),a={};a.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(a.event_duration=(e-mpshow_time)/1e3),t?(a=_.extend(a,t),sa.track("$MPHide",a)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",a,"$MPHide"),sa.sendStrategy.onAppHide()},pageLoad:function(t){t&&_.isObject(t)&&(this.sensors_mp_url_query=_.setQuery(t),this.sensors_mp_encode_url_query=_.setQuery(t,!0))},pageShow:function(){var t={},e=_.getCurrentPath();t.$referrer=sa_referrer,t.$url_path=e,sa.status.last_referrer=sa_referrer,t.$url_query=this.sensors_mp_url_query?this.sensors_mp_url_query:"",t=_.extend(t,_.getUtmFromPage()),sa.para.onshow?sa.para.onshow(sa,e,this):sa.para.autoTrack&&sa.para.autoTrack.pageShow&&sa.autoTrackCustom.trackCustom("pageShow",t,"$MPViewScreen"),sa_referrer=e,sa.status.referrer=e},pageShare:function(t,e){var a=t.onShareAppMessage;t.onShareAppMessage=function(){var t=a.apply(this,arguments);return sa.para.autoTrack&&sa.para.autoTrack.pageShare&&sa.autoTrackCustom.trackCustom("pageShare",{$url_path:_.getCurrentPath(),$share_depth:_.getShareDepth()},"$MPShare"),sa.para.allow_amend_share_path&&("object"!=typeof t&&((t={}).path=_.getCurrentUrl(this)),"object"!=typeof t||void 0!==t.path&&""!==t.path||(t.path=_.getCurrentUrl(this)),"object"==typeof t&&"string"==typeof t.path&&(-1===t.path.indexOf("?")?t.path=t.path+"?":"&"!==t.path.slice(-1)&&(t.path=t.path+"&")),t.path=t.path+"sampshare="+encodeURIComponent(_.getShareInfo())),t}}},sa.quick=function(){var t=arguments[0],e=arguments[1],a=arguments[2],r=_.isObject(a)?a:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,r):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(r=_.isObject(e)?e:{},sa.autoTrackCustom[t](r))},sa.App=function(t){mp_proxy(t=t||{},"onLaunch","appLaunch"),mp_proxy(t,"onShow","appShow"),mp_proxy(t,"onHide","appHide"),App.apply(this,arguments)},sa.Page=function(t){mp_proxy(t,"onLoad","pageLoad"),mp_proxy(t,"onShow","pageShow"),"function"==typeof t.onShareAppMessage&&sa.autoTrackCustom.pageShare(t),Page.apply(this,arguments)},sa.initial();export default sa; \ No newline at end of file diff --git a/sensorsdata.plugin.min.js b/sensorsdata.plugin.min.js index 8ffbea6..091e295 100755 --- a/sensorsdata.plugin.min.js +++ b/sensorsdata.plugin.min.js @@ -1 +1 @@ -var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var a=sa.para.source_channel.length,r=0;rsa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,a){_.isObject(e)?_.searchObjString(t[a]):_.isString(e)&&(t[a]=_.formatString(e))})},_.unique=function(t){for(var e,a=[],r={},s=0;s127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(a>e&&(n+=t.substring(e,a)),n+=o,e=a=s+1)}return a>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,a,r,s,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,a=n>>12&63,r=n>>6&63,s=63&n,p[c++]=i.charAt(e)+i.charAt(a)+i.charAt(r)+i.charAt(s)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,a,r){if(!_.isObject(t))return{};var s={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[r+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[e+n]=t[n];return s},_.getObjFromQuery=function(t){var e=t.split("?"),a=[],r={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(a=t.split("="))[0]&&a[1]&&(r[a[0]]=a[1])}),r):{}},_.setStorageSync=function(t,e){var a=function(){wx.setStorageSync(t,e)};try{a()}catch(t){logger.info("set Storage fail --",t);try{a()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(a){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var a={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(a=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(a))return{};var r=(a=JSON.parse(a)).d,s=a.p,n=a.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof r?(e.$share_depth=r,share_depth=r):e.$share_depth="-1",e.$share_url_path="string"==typeof s?s:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,a,r,s,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,a=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),r=new RegExp("("+a.join("|")+")%3D","i"),1===(s=Object.keys(e)).length&&"scene"===s[0]&&r.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),a=e.scene,r=e.q,s=e.query;for(var n in s)s[n]=_.decodeURIComponent(s[n]);return a&&(a=-1!==(a=_.decodeURIComponent(a)).indexOf("?")?"?"+a.replace(/\?/g,""):"?"+a,_.extend(s,_.getObjFromQuery(a))),r&&_.extend(s,_.getObjFromQuery(_.decodeURIComponent(r))),s},_.setUtm=function(t,e){var a={},r=_.getMixedQuery(t),s=_.getCustomUtmFromQuery(r,"$","_","$"),n=_.getCustomUtmFromQuery(r,"$latest_","_latest_","$latest_");return a.pre1=s,a.pre2=n,_.extend(e,s),a},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var a,r;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(a=e.platform,"ios"===(r=a.toLowerCase())?"iOS":"android"===r?"Android":a),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var a={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(a,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(a.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(a._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),a.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,a.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?a.properties.$is_first_day=!0:a.properties.$is_first_day=!1),a.properties.$time&&_.isDate(a.properties.$time)?(a.time=1*a.properties.$time,delete a.properties.$time):sa.para.use_client_time&&(a.time=1*new Date),_.searchObjDate(a),_.searchObjString(a),logger.info(a),sa.sendStrategy.send(a)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var a=this._state.props||{};e?this.set("props",t):(_.extend(a,t),this.set("props",a))},set:function(t,e){var a={};for(var r in"string"==typeof t?a[t]=e:"object"==typeof t&&(a=t),this._state=this._state||{},a)this._state[r]=a[r];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,a=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:a,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,a){_.isString(e)?t[a]=[e]:_.isArray(e)||(delete t[a],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var a=t;_.isString(t)&&((t={})[a]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,a){this.prepareData({type:"track",event:t,properties:e},a)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var a=sa.store.getFirstId();!0===e?a?sa.store.set("first_id",t):sa.store.set("distinct_id",t):a?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,a,r){var s=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:s,distinct_id:t,type:"track_signup",event:e,properties:a},r)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),a={};_.isArray(t)&&(_.each(e,function(e,r){_.include(t,r)||(a[r]=e)}),sa.store.setProps(a,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,a){_.include(t,a)&&delete _.info.currentProps[a]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var a=!1;for(var r in e)t[e[r]]&&(a=!0);return a}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),a=sa.store.getDistinctId();t!==a&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",a),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,a){0===a.indexOf("$")&&(t[a]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(a){a&&sa.setOpenid(a,t.isCoverLogin),e&&_.isFunction(e)&&e(a),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var a=[];return _.each(t,function(t,r){"q"===r&&_.isString(t)&&0===t.indexOf("http")||"scene"===r||(e?a.push(r+"="+t):a.push(r+"="+_.decodeURIComponent(t)))}),a.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),a=e[e.length-1].options;t=_.getCustomUtmFromQuery(a,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,a){var r=sa.para.autoTrack[t],s="";sa.para.autoTrack&&r&&("function"==typeof r?(s=r(),_.isObject(s)&&_.extend(e,s)):_.isObject(r)&&(_.extend(e,r),sa.para.autoTrack[t]=!0),sa.track(a,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var a={};t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);is_first_launch?(a.$is_first_time=!0,_.isEmptyObject(r.pre1)||sa.setOnceProfile(r.pre1)):a.$is_first_time=!1,sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPLaunch",a)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",a,"$MPLaunch")},appShow:function(t,e){var a={};mpshow_time=(new Date).getTime(),t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPShow",a)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",a,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),a={};a.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(a.event_duration=(e-mpshow_time)/1e3),t?(a=_.extend(a,t),sa.track("$MPHide",a)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",a,"$MPHide"),sa.sendStrategy.onAppHide()},pageLoad:function(t){t&&_.isObject(t)&&(this.sensors_mp_url_query=_.setQuery(t),this.sensors_mp_encode_url_query=_.setQuery(t,!0))},pageShow:function(){var t={},e=_.getCurrentPath();t.$referrer=sa_referrer,t.$url_path=e,sa.status.last_referrer=sa_referrer,t.$url_query=this.sensors_mp_url_query?this.sensors_mp_url_query:"",t=_.extend(t,_.getUtmFromPage()),sa.para.onshow?sa.para.onshow(sa,e,this):sa.para.autoTrack&&sa.para.autoTrack.pageShow&&sa.autoTrackCustom.trackCustom("pageShow",t,"$MPViewScreen"),sa_referrer=e,sa.status.referrer=e},pageShare:function(t,e){var a=t.onShareAppMessage;t.onShareAppMessage=function(){var t=a.apply(this,arguments);return sa.para.autoTrack&&sa.para.autoTrack.pageShare&&sa.autoTrackCustom.trackCustom("pageShare",{$url_path:_.getCurrentPath(),$share_depth:_.getShareDepth()},"$MPShare"),sa.para.allow_amend_share_path&&("object"!=typeof t&&((t={}).path=_.getCurrentUrl(this)),"object"!=typeof t||void 0!==t.path&&""!==t.path||(t.path=_.getCurrentUrl(this)),"object"==typeof t&&"string"==typeof t.path&&(-1===t.path.indexOf("?")?t.path=t.path+"?":"&"!==t.path.slice(-1)&&(t.path=t.path+"&")),t.path=t.path+"sampshare="+encodeURIComponent(_.getShareInfo())),t}}},sa.quick=function(){var t=arguments[0],e=arguments[1],a=arguments[2],r=_.isObject(a)?a:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,r):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(r=_.isObject(e)?e:{},sa.autoTrackCustom[t](r))},sa.App=function(t){mp_proxy(t=t||{},"onLaunch","appLaunch"),mp_proxy(t,"onShow","appShow"),mp_proxy(t,"onHide","appHide"),App.apply(this,arguments)},sa.Page=function(t){mp_proxy(t,"onLoad","pageLoad"),mp_proxy(t,"onShow","pageShow"),"function"==typeof t.onShareAppMessage&&sa.autoTrackCustom.pageShare(t),Page.apply(this,arguments)},sa.initial(),module.exports=sa; \ No newline at end of file +var _={},sa={para:{name:"sensors",server_url:"",send_timeout:1e3,use_client_time:!1,show_log:!0,allow_amend_share_path:!0,max_string_length:300,datasend_timeout:3e3,source_channel:[],autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,pageShare:!0},is_persistent_save:!1}},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){console.log(arguments[0])}},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t);var e=[];if(_.isArray(sa.para.source_channel))for(var a=sa.para.source_channel.length,r=0;rsa.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},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,a){_.isObject(e)?_.searchObjString(t[a]):_.isString(e)&&(t[a]=_.formatString(e))})},_.unique=function(t){for(var e,a=[],r={},s=0;s127&&i<2048?String.fromCharCode(i>>6|192,63&i|128):String.fromCharCode(i>>12|224,i>>6&63|128,63&i|128),null!==o&&(a>e&&(n+=t.substring(e,a)),n+=o,e=a=s+1)}return a>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,a,r,s,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,c=0,u="",p=[];if(!t)return t;t=_.utf8Encode(t);do{e=(n=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,a=n>>12&63,r=n>>6&63,s=63&n,p[c++]=i.charAt(e)+i.charAt(a)+i.charAt(r)+i.charAt(s)}while(o0&&(_.each(this.queue,function(t){sa[t[0]].apply(sa,slice.call(t[1]))}),this.queue=[]))}},_.getCustomUtmFromQuery=function(t,e,a,r){if(!_.isObject(t))return{};var s={};if(t.sa_utm)for(var n in t)"sa_utm"!==n?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[r+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(s[a+n]=t[n]):s[e+n]=t[n];return s},_.getObjFromQuery=function(t){var e=t.split("?"),a=[],r={};return e&&e[1]?(_.each(e[1].split("&"),function(t){(a=t.split("="))[0]&&a[1]&&(r[a[0]]=a[1])}),r):{}},_.setStorageSync=function(t,e){var a=function(){wx.setStorageSync(t,e)};try{a()}catch(t){logger.info("set Storage fail --",t);try{a()}catch(t){logger.info("set Storage fail again --",t)}}},_.getStorageSync=function(t){var e="";try{e=wx.getStorageSync(t)}catch(a){try{e=wx.getStorageSync(t)}catch(t){logger.info("getStorage fail")}}return e},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?(t=String(t),mp_scene[t]||t):"\u672a\u53d6\u5230\u503c"},_.getShareDepth=function(){if("number"==typeof share_depth&&0!==share_depth){var t=sa.store.getDistinctId(),e=sa.store.getFirstId();return!share_distinct_id||share_distinct_id!==t&&share_distinct_id!==e?share_depth+1:share_depth}return 1},_.setShareInfo=function(t,e){var a={};if(!(t&&_.isObject(t.query)&&t.query.sampshare))return{};if(a=_.decodeURIComponent(t.query.sampshare),!_.isJSONString(a))return{};var r=(a=JSON.parse(a)).d,s=a.p,n=a.i;"string"==typeof n?(e.$share_distinct_id=n,share_distinct_id=n):e.$share_distinct_id="\u53d6\u503c\u5f02\u5e38","number"==typeof r?(e.$share_depth=r,share_depth=r):e.$share_depth="-1",e.$share_url_path="string"==typeof s?s:"\u53d6\u503c\u5f02\u5e38"},_.getShareInfo=function(){return JSON.stringify({i:sa.store.getDistinctId()||"\u53d6\u503c\u5f02\u5e38",p:_.getCurrentPath(),d:_.getShareDepth()})},_.detectOptionQuery=function(t){if(!t||!_.isObject(t.query))return{};var e,a,r,s,n={};return n.query=_.extend({},t.query),"string"==typeof n.query.scene&&(e=n.query,a=["utm_source","utm_content","utm_medium","utm_campaign","utm_term","sa_utm"].concat(sa.para.source_channel),r=new RegExp("("+a.join("|")+")%3D","i"),1===(s=Object.keys(e)).length&&"scene"===s[0]&&r.test(e.scene))&&(n.scene=n.query.scene,delete n.query.scene),t.query.q&&t.query.scancode_time&&"101"===String(t.scene).slice(0,3)&&(n.q=String(n.query.q),delete n.query.q,delete n.query.scancode_time),n},_.getMixedQuery=function(t){var e=_.detectOptionQuery(t),a=e.scene,r=e.q,s=e.query;for(var n in s)s[n]=_.decodeURIComponent(s[n]);return a&&(a=-1!==(a=_.decodeURIComponent(a)).indexOf("?")?"?"+a.replace(/\?/g,""):"?"+a,_.extend(s,_.getObjFromQuery(a))),r&&_.extend(s,_.getObjFromQuery(_.decodeURIComponent(r))),s},_.setUtm=function(t,e){var a={},r=_.getMixedQuery(t),s=_.getCustomUtmFromQuery(r,"$","_","$"),n=_.getCustomUtmFromQuery(r,"$latest_","_latest_","$latest_");return a.pre1=s,a.pre2=n,_.extend(e,s),a},_.wxrequest=function(t){var e=wx.request(t);setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties;function e(){wx.getSystemInfo({success:function(e){var a,r;t.$manufacturer=e.brand,t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(a=e.platform,"ios"===(r=a.toLowerCase())?"iOS":"android"===r?"Android":a),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system},complete:function(){sa.initialState.systemIsComplete=!0,sa.initialState.checkIsComplete()}})}wx.getNetworkType({success:function(e){t.$network_type=e.networkType},complete:e})}},sa._=_,sa.prepareData=function(t,e){var a={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(a,this.store.getUnionId(),t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(a.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(sa.para.batch_send&&(a._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4))),a.properties=_.extend({},_.info.properties,sa.store.getProps(),_.info.currentProps,a.properties),"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()?a.properties.$is_first_day=!0:a.properties.$is_first_day=!1),a.properties.$time&&_.isDate(a.properties.$time)?(a.time=1*a.properties.$time,delete a.properties.$time):sa.para.use_client_time&&(a.time=1*new Date),_.searchObjDate(a),_.searchObjString(a),logger.info(a),sa.sendStrategy.send(a)},sa.store={verifyDistinctId:function(t){return"number"==typeof t&&(t=String(t),/^\d+$/.test(t)||(t="unexpected_id")),"string"==typeof t&&""!==t||(t="unexpected_id"),t},storageInfo:null,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(){return this.storageInfo?this.storageInfo:(this.storageInfo=sa._.getStorageSync("sensorsdata2015_wechat")||"",this.storageInfo)},_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;_.isJSONString(t)?(e=JSON.parse(t)).distinct_id?this._state=e:this.set("distinct_id",this.getUUID()):_.isObject(t)&&(e=t).distinct_id?this._state=e:this.set("distinct_id",this.getUUID())},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getUnionId:function(){var t={};return this._state.first_id&&this._state.distinct_id?(t.login_id=this._state.distinct_id,t.anonymous_id=this._state.first_id):t.anonymous_id=this._state.distinct_id,t},getProps:function(){return this._state.props||{}},setProps:function(t,e){var a=this._state.props||{};e?this.set("props",t):(_.extend(a,t),this.set("props",a))},set:function(t,e){var a={};for(var r in"string"==typeof t?a[t]=e:"object"==typeof t&&(a=t),this._state=this._state||{},a)this._state[r]=a[r];this.save()},change:function(t,e){this._state[t]=e},save:function(){sa._.setStorageSync("sensorsdata2015_wechat",this._state)},init:function(){var t=this.getStorage();if(t)this.toState(t);else{is_first_launch=!0;var e=new Date,a=e.getTime();e.setHours(23),e.setMinutes(59),e.setSeconds(60),sa.setOnceProfile({$first_visit_time:new Date}),this.set({distinct_id:this.getUUID(),first_visit_time:a,first_visit_day_time:e.getTime()})}}},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.appendProfile=function(t,e){if(!_.isObject(t))return!1;_.each(t,function(e,a){_.isString(e)?t[a]=[e]:_.isArray(e)||(delete t[a],logger.info("appendProfile\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4"))}),sa.prepareData({type:"profile_append",properties:t},e)},sa.incrementProfile=function(t,e){if(!_.isObject(t))return!1;var a=t;_.isString(t)&&((t={})[a]=1),sa.prepareData({type:"profile_increment",properties:t},e)},sa.track=function(t,e,a){this.prepareData({type:"track",event:t,properties:e},a)},sa.identify=function(t,e){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var a=sa.store.getFirstId();!0===e?a?sa.store.set("first_id",t):sa.store.set("distinct_id",t):a?sa.store.change("first_id",t):sa.store.change("distinct_id",t)},sa.trackSignup=function(t,e,a,r){var s=sa.store.getFirstId()||sa.store.getDistinctId();sa.store.set("distinct_id",t),sa.prepareData({original_id:s,distinct_id:t,type:"track_signup",event:e,properties:a},r)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.register=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&sa.store.setProps(t)},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.clearAllProps=function(t){var e=sa.store.getProps(),a={};_.isArray(t)&&(_.each(e,function(e,r){_.include(t,r)||(a[r]=e)}),sa.store.setProps(a,!0))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,a){_.include(t,a)&&delete _.info.currentProps[a]})},sa.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var a=!1;for(var r in e)t[e[r]]&&(a=!0);return a}(t,latest_source_channel)&&(sa.clearAppRegister(latest_source_channel),sa.clearAllProps(latest_source_channel)),sa.para.is_persistent_save?sa.register(t):sa.registerApp(t))},sa.login=function(t){if("string"!=typeof t&&"number"!=typeof t)return!1;t=sa.store.verifyDistinctId(t);var e=sa.store.getFirstId(),a=sa.store.getDistinctId();t!==a&&(e?sa.trackSignup(t,"$SignUp"):(sa.store.set("first_id",a),sa.trackSignup(t,"$SignUp")))},sa.openid={getRequest:function(t){wx.login({success:function(e){e.code&&sa.para.appid&&sa.para.openid_url?_.wxrequest({url:sa.para.openid_url+"&code="+e.code+"&appid="+sa.para.appid,method:"GET",complete:function(e){_.isObject(e)&&_.isObject(e.data)&&e.data.openid?t(e.data.openid):t()}}):t()}})},getWXStorage:function(){var t=sa.store.getStorage();if(t&&_.isObject(t))return t.openid},getOpenid:function(t){if(!sa.para.appid)return t(),!1;var e=this.getWXStorage();e?t(e):this.getRequest(t)}},sa.initial=function(){this._.info.getSystem(),this.store.init()},sa.init=function(t){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.setPara(t),sa.para.batch_send&&(wx.getStorage({key:"sensors_mp_prepare_data",complete(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),sa.sendStrategy.batchInterval()),sa.initialState.storeIsComplete=!0,sa.initialState.checkIsComplete()},sa.getPresetProperties=function(){if(_.info&&_.info.properties&&_.info.properties.$lib){var t={};_.each(_.info.currentProps,function(e,a){0===a.indexOf("$")&&(t[a]=e)});var e=_.extend(t,{$url_path:_.getCurrentPath()},_.info.properties,sa.store.getProps());return delete e.$lib,e}return{}},_.autoExeQueue=function(){return{items:[],enqueue:function(t){this.items.push(t),this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:!1,start:function(){this.items.length>0&&!this.isRun&&(this.isRun=!0,this.getCurrentItem().start())},close:function(){this.dequeue(),this.isRun=!1,this.start()}}},sa.requestQueue=function(t){this.url=t.url},sa.requestQueue.prototype.isEnd=function(){this.received||(this.received=!0,this.close())},sa.requestQueue.prototype.start=function(){var t=this;setTimeout(function(){t.isEnd()},sa.para.send_timeout),_.wxrequest({url:this.url,method:"GET",complete:function(){t.isEnd()}})},sa.dataQueue=_.autoExeQueue(),sa.sendStrategy={dataHasSend:!0,dataHasChange:!1,syncStorage:!1,onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;if(sa.para.batch_send){if(this.dataHasChange=!0,sa.store.mem.getLength()>=300)return logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),!1;sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()}else this.queueSend(t)},queueSend:function(t){t=JSON.stringify(t),t=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t));var e=new sa.requestQueue({url:t});e.close=function(){sa.dataQueue.close()},sa.dataQueue.enqueue(e)},wxrequest:function(t){if(_.isArray(t.data)&&t.data.length>0){var e=Date.now();t.data.forEach(function(t){t._flush_time=e}),t.data=JSON.stringify(t.data),_.wxrequest({url:sa.para.server_url,method:"POST",dataType:"text",data:"data_list="+encodeURIComponent(_.base64Encode(t.data)),success:function(){t.success(t.len)},fail:function(){t.fail()}})}else t.success(t.len)},batchSend:function(){if(this.dataHasSend){var t=sa.store.mem.mdata,e=t.length;e>0&&(this.dataHasSend=!1,this.wxrequest({data:t,len:e,success:this.batchRemove.bind(this),fail:this.sendFail.bind(this)}))}},sendFail:function(){this.dataHasSend=!0},batchRemove:function(t){sa.store.mem.clear(t),this.dataHasSend=!0,this.dataHasChange=!0,this.batchWrite()},is_first_batch_write:!0,batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.dataHasChange=!1,this.syncStorage&&sa._.setStorageSync("sensors_mp_prepare_data",sa.store.mem.mdata))},batchInterval:function(){var t=this;!function e(){setTimeout(function(){t.batchWrite(),e()},500)}(),function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout)}()}},sa.setOpenid=function(t,e){sa.store.set("openid",t),e?sa.store.set("distinct_id",t):sa.identify(t,!0)},sa.initWithOpenid=function(t,e){(t=t||{}).appid&&(sa.para.appid=t.appid),sa.openid.getOpenid(function(a){a&&sa.setOpenid(a,t.isCoverLogin),e&&_.isFunction(e)&&e(a),sa.init(t)})},_.each(["setProfile","setOnceProfile","track","quick","incrementProfile","appendProfile"],function(t){var e=sa[t];sa[t]=function(){sa.initialState.isComplete?e.apply(sa,arguments):sa.initialState.queue.push([t,arguments])}}),_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var a=[];return _.each(t,function(t,r){"q"===r&&_.isString(t)&&0===t.indexOf("http")||"scene"===r||(e?a.push(r+"="+t):a.push(r+"="+_.decodeURIComponent(t)))}),a.join("&")}return""},_.getUtmFromPage=function(){var t={};try{var e=getCurrentPages(),a=e[e.length-1].options;t=_.getCustomUtmFromQuery(a,"$","_","$")}catch(t){logger.info(t)}return t},sa.autoTrackCustom={trackCustom:function(t,e,a){var r=sa.para.autoTrack[t],s="";sa.para.autoTrack&&r&&("function"==typeof r?(s=r(),_.isObject(s)&&_.extend(e,s)):_.isObject(r)&&(_.extend(e,r),sa.para.autoTrack[t]=!0),sa.track(a,e))},appLaunch:function(t,e){"object"!=typeof this||this.trackCustom||(this[sa.para.name]=sa);var a={};t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);is_first_launch?(a.$is_first_time=!0,_.isEmptyObject(r.pre1)||sa.setOnceProfile(r.pre1)):a.$is_first_time=!1,sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPLaunch",a)):sa.para.autoTrack&&sa.para.autoTrack.appLaunch&&sa.autoTrackCustom.trackCustom("appLaunch",a,"$MPLaunch")},appShow:function(t,e){var a={};mpshow_time=(new Date).getTime(),t&&t.path&&(a.$url_path=_.getPath(t.path)),_.setShareInfo(t,a);var r=_.setUtm(t,a);sa.setLatestChannel(r.pre2),a.$scene=_.getMPScene(t.scene),sa.registerApp({$latest_scene:a.$scene}),a.$url_query=_.setQuery(t.query),e?(a=_.extend(a,e),sa.track("$MPShow",a)):sa.para.autoTrack&&sa.para.autoTrack.appShow&&sa.autoTrackCustom.trackCustom("appShow",a,"$MPShow")},appHide:function(t){var e=(new Date).getTime(),a={};a.$url_path=_.getCurrentPath(),mpshow_time&&e-mpshow_time>0&&(e-mpshow_time)/36e5<24&&(a.event_duration=(e-mpshow_time)/1e3),t?(a=_.extend(a,t),sa.track("$MPHide",a)):sa.para.autoTrack&&sa.para.autoTrack.appHide&&sa.autoTrackCustom.trackCustom("appHide",a,"$MPHide"),sa.sendStrategy.onAppHide()},pageLoad:function(t){t&&_.isObject(t)&&(this.sensors_mp_url_query=_.setQuery(t),this.sensors_mp_encode_url_query=_.setQuery(t,!0))},pageShow:function(){var t={},e=_.getCurrentPath();t.$referrer=sa_referrer,t.$url_path=e,sa.status.last_referrer=sa_referrer,t.$url_query=this.sensors_mp_url_query?this.sensors_mp_url_query:"",t=_.extend(t,_.getUtmFromPage()),sa.para.onshow?sa.para.onshow(sa,e,this):sa.para.autoTrack&&sa.para.autoTrack.pageShow&&sa.autoTrackCustom.trackCustom("pageShow",t,"$MPViewScreen"),sa_referrer=e,sa.status.referrer=e},pageShare:function(t,e){var a=t.onShareAppMessage;t.onShareAppMessage=function(){var t=a.apply(this,arguments);return sa.para.autoTrack&&sa.para.autoTrack.pageShare&&sa.autoTrackCustom.trackCustom("pageShare",{$url_path:_.getCurrentPath(),$share_depth:_.getShareDepth()},"$MPShare"),sa.para.allow_amend_share_path&&("object"!=typeof t&&((t={}).path=_.getCurrentUrl(this)),"object"!=typeof t||void 0!==t.path&&""!==t.path||(t.path=_.getCurrentUrl(this)),"object"==typeof t&&"string"==typeof t.path&&(-1===t.path.indexOf("?")?t.path=t.path+"?":"&"!==t.path.slice(-1)&&(t.path=t.path+"&")),t.path=t.path+"sampshare="+encodeURIComponent(_.getShareInfo())),t}}},sa.quick=function(){var t=arguments[0],e=arguments[1],a=arguments[2],r=_.isObject(a)?a:{};if("getAnonymousID"===t){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id?sa.store._state.first_id:sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")}else"appLaunch"===t||"appShow"===t?e?sa.autoTrackCustom[t](e,r):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(r=_.isObject(e)?e:{},sa.autoTrackCustom[t](r))},sa.App=function(t){mp_proxy(t=t||{},"onLaunch","appLaunch"),mp_proxy(t,"onShow","appShow"),mp_proxy(t,"onHide","appHide"),App.apply(this,arguments)},sa.Page=function(t){mp_proxy(t,"onLoad","pageLoad"),mp_proxy(t,"onShow","pageShow"),"function"==typeof t.onShareAppMessage&&sa.autoTrackCustom.pageShare(t),Page.apply(this,arguments)},sa.initial(),module.exports=sa; \ No newline at end of file