diff --git a/sensorsdata.js b/sensorsdata.js index 134ee8e..e7d57df 100644 --- a/sensorsdata.js +++ b/sensorsdata.js @@ -24,6 +24,63 @@ var ArrayProto = Array.prototype, var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term'; +var mp_scene = { + 1001: '发现栏小程序主入口', + 1005: '顶部搜索框的搜索结果页', + 1006: '发现栏小程序主入口搜索框的搜索结果页', + 1007: '单人聊天会话中的小程序消息卡片', + 1008: '群聊会话中的小程序消息卡片', + 1011: '扫描二维码', + 1012: '长按图片识别二维码', + 1013: '手机相册选取二维码', + 1014: '小程序模版消息', + 1017: '前往体验版的入口页', + 1019: '微信钱包', + 1020: '公众号 profile 页相关小程序列表', + 1022: '聊天顶部置顶小程序入口', + 1023: '安卓系统桌面图标', + 1024: '小程序 profile 页', + 1025: '扫描一维码', + 1026: '附近小程序列表', + 1027: '顶部搜索框搜索结果页“使用过的小程序”列表', + 1028: '我的卡包', + 1029: '卡券详情页', + 1030: '自动化测试下打开小程序', + 1031: '长按图片识别一维码', + 1032: '手机相册选取一维码', + 1034: '微信支付完成页', + 1035: '公众号自定义菜单', + 1036: 'App 分享消息卡片', + 1037: '小程序打开小程序', + 1038: '从另一个小程序返回', + 1039: '摇电视', + 1042: '添加好友搜索框的搜索结果页', + 1043: '公众号模板消息', + 1044: '带 shareTicket 的小程序消息卡片(详情)', + 1047: '扫描小程序码', + 1048: '长按图片识别小程序码', + 1049: '手机相册选取小程序码', + 1052: '卡券的适用门店列表', + 1053: '搜一搜的结果页', + 1054: '顶部搜索框小程序快捷入口', + 1056: '音乐播放器菜单', + 1057: '钱包中的银行卡详情页', + 1058: '公众号文章', + 1059: '体验版小程序绑定邀请页', + 1064: '微信连Wi-Fi状态栏', + 1067: '公众号文章广告', + 1068: '附近小程序列表广告', + 1071: '钱包中的银行卡列表页', + 1072: '二维码收款页面', + 1073: '客服消息列表下发的小程序消息卡片', + 1074: '公众号会话下发的小程序消息卡片', + 1078: '连Wi-Fi成功页', + 1089: '微信聊天主界面下拉', + 1090: '长按小程序右上角菜单唤出最近使用历史', + 1092: '城市服务入口' +}; + + var sa_referrer = '直接打开'; sa.lib_version = LIB_VERSION; @@ -480,6 +537,11 @@ _.getUtm = function (url) { return params; }; +_.getMPScene = function(key){ + key = String(key); + return mp_scene[key] || key; +}; + _.info = { properties: { $lib: LIB_NAME, @@ -870,6 +932,7 @@ function appLaunch(para) { if (para && _.isObject(para.query) && para.query.q) { _.extend(prop, _.getUtm(para.query.q)); } + prop.$scene = _.getMPScene(para.scene); // console.log('app_launch', JSON.stringify(arguments)); if (sa.para.autoTrack && sa.para.autoTrack.appLaunch === true) { sa.autoTrackCustom('appLaunch', prop, '$MPLaunch'); @@ -888,6 +951,7 @@ function appShow(para) { if (para && _.isObject(para.query) && para.query.q) { _.extend(prop, _.getUtm(para.query.q)); } + prop.$scene = _.getMPScene(para.scene); if (sa.para.autoTrack && sa.para.autoTrack.appShow === true) { sa.autoTrackCustom('appShow',prop,'$MPShow'); } diff --git a/sensorsdata.min.js b/sensorsdata.min.js index afd9a52..f9a41a6 100644 --- a/sensorsdata.min.js +++ b/sensorsdata.min.js @@ -1 +1 @@ -var _={};var sa={};sa.para=require("sensorsdata_conf.js");sa._queue=[];sa.getSystemInfoComplete=false;var ArrayProto=Array.prototype,FuncProto=Function.prototype,ObjProto=Object.prototype,slice=ArrayProto.slice,toString=ObjProto.toString,hasOwnProperty=ObjProto.hasOwnProperty,LIB_VERSION="1.0",LIB_NAME="MiniProgram";var source_channel_standard="utm_source utm_medium utm_campaign utm_content utm_term";var sa_referrer="直接打开";sa.lib_version=LIB_VERSION;var logger=typeof logger==="object"?logger:{};logger.info=function(){if(typeof console==="object"&&console.log){try{return console.log.apply(console,arguments)}catch(e){console.log(arguments[0])}}};(function(){var nativeBind=FuncProto.bind,nativeForEach=ArrayProto.forEach,nativeIndexOf=ArrayProto.indexOf,nativeIsArray=Array.isArray,breaker={};var each=_.each=function(obj,iterator,context){if(obj==null){return false}if(nativeForEach&&obj.forEach===nativeForEach){obj.forEach(iterator,context)}else if(obj.length===+obj.length){for(var i=0,l=obj.length;isa.para.max_string_length){logger.info("字符串长度超过限制,已经做截取--"+str);return str.slice(0,sa.para.max_string_length)}else{return str}};_.searchObjString=function(o){if(_.isObject(o)){_.each(o,function(a,b){if(_.isObject(a)){_.searchObjString(o[b])}else{if(_.isString(a)){o[b]=_.formatString(a)}}})}};_.unique=function(ar){var temp,n=[],o={};for(var i=0;i127&&c1<2048){enc=String.fromCharCode(c1>>6|192,c1&63|128)}else{enc=String.fromCharCode(c1>>12|224,c1>>6&63|128,c1&63|128)}if(enc!==null){if(end>start){utftext+=string.substring(start,end)}utftext+=enc;start=end=n+1}}if(end>start){utftext+=string.substring(start,string.length)}return utftext};_.base64Encode=function(data){var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,enc="",tmp_arr=[];if(!data){return data}data=_.utf8Encode(data);do{o1=data.charCodeAt(i++);o2=data.charCodeAt(i++);o3=data.charCodeAt(i++);bits=o1<<16|o2<<8|o3;h1=bits>>18&63;h2=bits>>12&63;h3=bits>>6&63;h4=bits&63;tmp_arr[ac++]=b64.charAt(h1)+b64.charAt(h2)+b64.charAt(h3)+b64.charAt(h4)}while(i0){campaign_keywords=campaign_keywords.concat(sa.para.source_channel);campaign_keywords=_.unique(campaign_keywords)}_.each(campaign_keywords,function(kwkey){kw=_.getQueryParam(url,kwkey);if(kw.length){if(_.include(campagin_w,kwkey)){params["$"+kwkey]=kw}else{params[kwkey]=kw}}});return params};_.info={properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION),$user_agent:"SensorsAnalytics MP SDK"},getSystem:function(){var e=this.properties;var that=this;function getNetwork(){wx.getNetworkType({success:function(t){e.$network_type=t["networkType"]},complete:getSystemInfo})}function getSystemInfo(){wx.getSystemInfo({success:function(t){e.$model=t["model"];e.$screen_width=Number(t["windowWidth"]);e.$screen_height=Number(t["windowHeight"]);e.$os=t["system"].split(" ")[0];e.$os_version=t["system"].split(" ")[1]},complete:that.setStatusComplete})}getNetwork()},setStatusComplete:function(){sa.getSystemInfoComplete=true;if(sa._queue.length>0){_.each(sa._queue,function(content){sa.prepareData.apply(sa,slice.call(content))});sa._queue=[]}}};sa._=_;sa.prepareData=function(p,callback){if(!sa.getSystemInfoComplete){sa._queue.push(arguments);return false}var data={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(data,p);if(_.isObject(p.properties)&&!_.isEmptyObject(p.properties)){_.extend(data.properties,p.properties)}if(!p.type||p.type.slice(0,7)!=="profile"){data.properties=_.extend({},_.info.properties,sa.store.getProps(),data.properties);if(typeof sa.store._state==="object"&&typeof sa.store._state.first_visit_day_time==="number"&&sa.store._state.first_visit_day_time>(new Date).getTime()){data.properties.$is_first_day=true}else{data.properties.$is_first_day=false}}if(data.properties.$time&&_.isDate(data.properties.$time)){data.time=data.properties.$time*1;delete data.properties.$time}else{if(sa.para.use_client_time){data.time=new Date*1}}_.searchObjDate(data);_.searchObjString(data);sa.send(data,callback)};sa.store={getUUID:function(){return""+Date.now()+"-"+Math.floor(1e7*Math.random())+"-"+Math.random().toString(16).replace(".","")+"-"+String(Math.random()*31242).replace(".","").slice(0,8)},setStorage:function(){},getStorage:function(){return wx.getStorageSync("sensorsdata2015_wechat")||""},_state:{},toState:function(ds){var state=null;if(_.isJSONString(ds)){state=JSON.parse(ds);if(state.distinct_id){this._state=state}else{this.set("distinct_id",this.getUUID())}}else{this.set("distinct_id",this.getUUID())}},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getProps:function(){return this._state.props||{}},setProps:function(newp,isCover){var props=this._state.props||{};if(!isCover){_.extend(props,newp);this.set("props",props)}else{this.set("props",newp)}},set:function(name,value){var obj={};if(typeof name==="string"){obj[name]=value}else if(typeof name==="object"){obj=name}this._state=this._state||{};for(var i in obj){this._state[i]=obj[i]}this.save()},change:function(name,value){this._state[name]=value},save:function(){wx.setStorageSync("sensorsdata2015_wechat",JSON.stringify(this._state))},init:function(){var info=this.getStorage();if(info){this.toState(info)}else{var time=new Date;var visit_time=time.getTime();time.setHours(23);time.setMinutes(59);time.setSeconds(60);this.set({distinct_id:this.getUUID(),first_visit_time:visit_time,first_visit_day_time:time.getTime()})}}};sa.setProfile=function(p,c){sa.prepareData({type:"profile_set",properties:p},c)};sa.setOnceProfile=function(p,c){sa.prepareData({type:"profile_set_once",properties:p},c)};sa.track=function(e,p,c){this.prepareData({type:"track",event:e,properties:p},c)};sa.identify=function(id,isSave){if(typeof id==="number"){id=String(id)}else if(typeof id!=="string"){return false}var firstId=sa.store.getFirstId();if(isSave===true){if(firstId){sa.store.set("first_id",id)}else{sa.store.set("distinct_id",id)}}else{if(firstId){sa.store.change("first_id",id)}else{sa.store.change("distinct_id",id)}}};sa.trackSignup=function(id,e,p,c){sa.prepareData({original_id:sa.store.getFirstId()||sa.store.getDistinctId(),distinct_id:id,type:"track_signup",event:e,properties:p},c);sa.store.set("distinct_id",id)};sa.register=function(obj){if(_.isObject(obj)&&!_.isEmptyObject(obj)){sa.store.setProps(obj)}};sa.clearAllRegister=function(){sa.store.setProps({},true)};sa.login=function(id){var firstId=sa.store.getFirstId();var distinctId=sa.store.getDistinctId();if(id!==distinctId){if(firstId){sa.trackSignup(id,"$SignUp")}else{sa.store.set("first_id",distinctId);sa.trackSignup(id,"$SignUp")}}};sa.init=function(){this._.info.getSystem();this.store.init();if(_.isObject(this.para.register)){_.info.properties=_.extend(_.info.properties,this.para.register)}};_.autoExeQueue=function(){var queue={items:[],enqueue:function(val){this.items.push(val);this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:false,start:function(){if(this.items.length>0&&!this.isRun){this.isRun=true;this.getCurrentItem().start()}},close:function(){this.dequeue();this.isRun=false;this.start()}};return queue};sa.requestQueue=function(para){this.url=para.url};sa.requestQueue.prototype.isEnd=function(){if(!this.received){this.received=true;this.close()}};sa.requestQueue.prototype.start=function(){var me=this;setTimeout(function(){me.isEnd()},300);wx.request({url:this.url,method:"GET",complete:function(){me.isEnd()}})};sa.dataQueue=_.autoExeQueue();sa.send=function(t){var url="";t._nocache=(String(Math.random())+String(Math.random())+String(Math.random())).slice(2,15);logger.info(t);t=JSON.stringify(t);if(sa.para.server_url.indexOf("?")!==-1){url=sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t))}else{url=sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t))}var instance=new sa.requestQueue({url:url});instance.close=function(){sa.dataQueue.close()};sa.dataQueue.enqueue(instance)};sa.autoTrackCustom=function(api,prop,event){var temp=sa.para.autoTrack[api];var tempFunc="";if(sa.para.autoTrack&&temp){if(typeof temp==="function"){tempFunc=temp();if(_.isObject(tempFunc)){_.extend(prop,tempFunc)}}else if(_.isObject(temp)){_.extend(prop,temp)}sa.track(event,prop)}};function e(t,n,o){if(t[n]){var e=t[n];t[n]=function(t){o.call(this,t,n);e.call(this,t)}}else t[n]=function(t){o.call(this,t,n)}}function appLaunch(para){this[sa.para.name]=sa;sa.init();var prop={};if(para&¶.path){prop.$url_path=para.path}if(para&&_.isObject(para.query)&¶.query.q){_.extend(prop,_.getUtm(para.query.q))}if(sa.para.autoTrack&&sa.para.autoTrack.appLaunch===true){sa.autoTrackCustom("appLaunch",prop,"$MPLaunch")}}function appShow(para){var prop={};if(para&¶.path){prop.$url_path=para.path}if(para&&_.isObject(para.query)&¶.query.q){_.extend(prop,_.getUtm(para.query.q))}if(sa.para.autoTrack&&sa.para.autoTrack.appShow===true){sa.autoTrackCustom("appShow",prop,"$MPShow")}}function appHide(){if(sa.para.autoTrack&&sa.para.autoTrack.appHide===true){sa.autoTrackCustom("appHide",{},"$MPHide")}}function appError(){}function appUnLaunch(){}var p=App;App=function(t){e(t,"onLaunch",appLaunch);e(t,"onShow",appShow);e(t,"onHide",appHide);p(t)};function pageOnunload(n,e){}function pageOnHide(){}function pageOnReady(){}function pageOnPullDownRefresh(){}function pageOnReachBottom(){}function pageOnShareAppMessage(n,e){}var v=Page;Page=function(t){e(t,"onLoad",function(para){if(para&&_.isObject(para)&¶.q){this.sensors_mp_load_utm=_.getUtm(para.q)}});e(t,"onShow",function(){var router="系统没有取到值";if(typeof this==="object"){if(typeof this.route==="string"){router=this.route}else if(typeof this.__route__==="string"){router=this.__route__}}var prop={};prop.$referrer=sa_referrer;prop.$url_path=router;if(this.sensors_mp_load_utm){_.extend(prop,this.sensors_mp_load_utm);this.sensors_mp_load_utm=null}if(sa.para.onshow){sa.para.onshow(sa,router,this)}else{sa.autoTrackCustom("pageShow",prop,"$MPViewScreen")}sa_referrer=router});v(t)};module.exports=sa; \ No newline at end of file +var _={};var sa={};sa.para=require("sensorsdata_conf.js");sa._queue=[];sa.getSystemInfoComplete=false;var ArrayProto=Array.prototype,FuncProto=Function.prototype,ObjProto=Object.prototype,slice=ArrayProto.slice,toString=ObjProto.toString,hasOwnProperty=ObjProto.hasOwnProperty,LIB_VERSION="1.0",LIB_NAME="MiniProgram";var source_channel_standard="utm_source utm_medium utm_campaign utm_content utm_term";var mp_scene={1001:"发现栏小程序主入口",1005:"顶部搜索框的搜索结果页",1006:"发现栏小程序主入口搜索框的搜索结果页",1007:"单人聊天会话中的小程序消息卡片",1008:"群聊会话中的小程序消息卡片",1011:"扫描二维码",1012:"长按图片识别二维码",1013:"手机相册选取二维码",1014:"小程序模版消息",1017:"前往体验版的入口页",1019:"微信钱包",1020:"公众号 profile 页相关小程序列表",1022:"聊天顶部置顶小程序入口",1023:"安卓系统桌面图标",1024:"小程序 profile 页",1025:"扫描一维码",1026:"附近小程序列表",1027:"顶部搜索框搜索结果页“使用过的小程序”列表",1028:"我的卡包",1029:"卡券详情页",1030:"自动化测试下打开小程序",1031:"长按图片识别一维码",1032:"手机相册选取一维码",1034:"微信支付完成页",1035:"公众号自定义菜单",1036:"App 分享消息卡片",1037:"小程序打开小程序",1038:"从另一个小程序返回",1039:"摇电视",1042:"添加好友搜索框的搜索结果页",1043:"公众号模板消息",1044:"带 shareTicket 的小程序消息卡片(详情)",1047:"扫描小程序码",1048:"长按图片识别小程序码",1049:"手机相册选取小程序码",1052:"卡券的适用门店列表",1053:"搜一搜的结果页",1054:"顶部搜索框小程序快捷入口",1056:"音乐播放器菜单",1057:"钱包中的银行卡详情页",1058:"公众号文章",1059:"体验版小程序绑定邀请页",1064:"微信连Wi-Fi状态栏",1067:"公众号文章广告",1068:"附近小程序列表广告",1071:"钱包中的银行卡列表页",1072:"二维码收款页面",1073:"客服消息列表下发的小程序消息卡片",1074:"公众号会话下发的小程序消息卡片",1078:"连Wi-Fi成功页",1089:"微信聊天主界面下拉",1090:"长按小程序右上角菜单唤出最近使用历史",1092:"城市服务入口"};var sa_referrer="直接打开";sa.lib_version=LIB_VERSION;var logger=typeof logger==="object"?logger:{};logger.info=function(){if(typeof console==="object"&&console.log){try{return console.log.apply(console,arguments)}catch(e){console.log(arguments[0])}}};(function(){var nativeBind=FuncProto.bind,nativeForEach=ArrayProto.forEach,nativeIndexOf=ArrayProto.indexOf,nativeIsArray=Array.isArray,breaker={};var each=_.each=function(obj,iterator,context){if(obj==null){return false}if(nativeForEach&&obj.forEach===nativeForEach){obj.forEach(iterator,context)}else if(obj.length===+obj.length){for(var i=0,l=obj.length;isa.para.max_string_length){logger.info("字符串长度超过限制,已经做截取--"+str);return str.slice(0,sa.para.max_string_length)}else{return str}};_.searchObjString=function(o){if(_.isObject(o)){_.each(o,function(a,b){if(_.isObject(a)){_.searchObjString(o[b])}else{if(_.isString(a)){o[b]=_.formatString(a)}}})}};_.unique=function(ar){var temp,n=[],o={};for(var i=0;i127&&c1<2048){enc=String.fromCharCode(c1>>6|192,c1&63|128)}else{enc=String.fromCharCode(c1>>12|224,c1>>6&63|128,c1&63|128)}if(enc!==null){if(end>start){utftext+=string.substring(start,end)}utftext+=enc;start=end=n+1}}if(end>start){utftext+=string.substring(start,string.length)}return utftext};_.base64Encode=function(data){var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,enc="",tmp_arr=[];if(!data){return data}data=_.utf8Encode(data);do{o1=data.charCodeAt(i++);o2=data.charCodeAt(i++);o3=data.charCodeAt(i++);bits=o1<<16|o2<<8|o3;h1=bits>>18&63;h2=bits>>12&63;h3=bits>>6&63;h4=bits&63;tmp_arr[ac++]=b64.charAt(h1)+b64.charAt(h2)+b64.charAt(h3)+b64.charAt(h4)}while(i0){campaign_keywords=campaign_keywords.concat(sa.para.source_channel);campaign_keywords=_.unique(campaign_keywords)}_.each(campaign_keywords,function(kwkey){kw=_.getQueryParam(url,kwkey);if(kw.length){if(_.include(campagin_w,kwkey)){params["$"+kwkey]=kw}else{params[kwkey]=kw}}});return params};_.getMPScene=function(key){key=String(key);return mp_scene[key]||key};_.info={properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION),$user_agent:"SensorsAnalytics MP SDK"},getSystem:function(){var e=this.properties;var that=this;function getNetwork(){wx.getNetworkType({success:function(t){e.$network_type=t["networkType"]},complete:getSystemInfo})}function getSystemInfo(){wx.getSystemInfo({success:function(t){e.$model=t["model"];e.$screen_width=Number(t["windowWidth"]);e.$screen_height=Number(t["windowHeight"]);e.$os=t["system"].split(" ")[0];e.$os_version=t["system"].split(" ")[1]},complete:that.setStatusComplete})}getNetwork()},setStatusComplete:function(){sa.getSystemInfoComplete=true;if(sa._queue.length>0){_.each(sa._queue,function(content){sa.prepareData.apply(sa,slice.call(content))});sa._queue=[]}}};sa._=_;sa.prepareData=function(p,callback){if(!sa.getSystemInfoComplete){sa._queue.push(arguments);return false}var data={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(data,p);if(_.isObject(p.properties)&&!_.isEmptyObject(p.properties)){_.extend(data.properties,p.properties)}if(!p.type||p.type.slice(0,7)!=="profile"){data.properties=_.extend({},_.info.properties,sa.store.getProps(),data.properties);if(typeof sa.store._state==="object"&&typeof sa.store._state.first_visit_day_time==="number"&&sa.store._state.first_visit_day_time>(new Date).getTime()){data.properties.$is_first_day=true}else{data.properties.$is_first_day=false}}if(data.properties.$time&&_.isDate(data.properties.$time)){data.time=data.properties.$time*1;delete data.properties.$time}else{if(sa.para.use_client_time){data.time=new Date*1}}_.searchObjDate(data);_.searchObjString(data);sa.send(data,callback)};sa.store={getUUID:function(){return""+Date.now()+"-"+Math.floor(1e7*Math.random())+"-"+Math.random().toString(16).replace(".","")+"-"+String(Math.random()*31242).replace(".","").slice(0,8)},setStorage:function(){},getStorage:function(){return wx.getStorageSync("sensorsdata2015_wechat")||""},_state:{},toState:function(ds){var state=null;if(_.isJSONString(ds)){state=JSON.parse(ds);if(state.distinct_id){this._state=state}else{this.set("distinct_id",this.getUUID())}}else{this.set("distinct_id",this.getUUID())}},getFirstId:function(){return this._state.first_id},getDistinctId:function(){return this._state.distinct_id},getProps:function(){return this._state.props||{}},setProps:function(newp,isCover){var props=this._state.props||{};if(!isCover){_.extend(props,newp);this.set("props",props)}else{this.set("props",newp)}},set:function(name,value){var obj={};if(typeof name==="string"){obj[name]=value}else if(typeof name==="object"){obj=name}this._state=this._state||{};for(var i in obj){this._state[i]=obj[i]}this.save()},change:function(name,value){this._state[name]=value},save:function(){wx.setStorageSync("sensorsdata2015_wechat",JSON.stringify(this._state))},init:function(){var info=this.getStorage();if(info){this.toState(info)}else{var time=new Date;var visit_time=time.getTime();time.setHours(23);time.setMinutes(59);time.setSeconds(60);this.set({distinct_id:this.getUUID(),first_visit_time:visit_time,first_visit_day_time:time.getTime()})}}};sa.setProfile=function(p,c){sa.prepareData({type:"profile_set",properties:p},c)};sa.setOnceProfile=function(p,c){sa.prepareData({type:"profile_set_once",properties:p},c)};sa.track=function(e,p,c){this.prepareData({type:"track",event:e,properties:p},c)};sa.identify=function(id,isSave){if(typeof id==="number"){id=String(id)}else if(typeof id!=="string"){return false}var firstId=sa.store.getFirstId();if(isSave===true){if(firstId){sa.store.set("first_id",id)}else{sa.store.set("distinct_id",id)}}else{if(firstId){sa.store.change("first_id",id)}else{sa.store.change("distinct_id",id)}}};sa.trackSignup=function(id,e,p,c){sa.prepareData({original_id:sa.store.getFirstId()||sa.store.getDistinctId(),distinct_id:id,type:"track_signup",event:e,properties:p},c);sa.store.set("distinct_id",id)};sa.register=function(obj){if(_.isObject(obj)&&!_.isEmptyObject(obj)){sa.store.setProps(obj)}};sa.clearAllRegister=function(){sa.store.setProps({},true)};sa.login=function(id){var firstId=sa.store.getFirstId();var distinctId=sa.store.getDistinctId();if(id!==distinctId){if(firstId){sa.trackSignup(id,"$SignUp")}else{sa.store.set("first_id",distinctId);sa.trackSignup(id,"$SignUp")}}};sa.init=function(){this._.info.getSystem();this.store.init();if(_.isObject(this.para.register)){_.info.properties=_.extend(_.info.properties,this.para.register)}};_.autoExeQueue=function(){var queue={items:[],enqueue:function(val){this.items.push(val);this.start()},dequeue:function(){return this.items.shift()},getCurrentItem:function(){return this.items[0]},isRun:false,start:function(){if(this.items.length>0&&!this.isRun){this.isRun=true;this.getCurrentItem().start()}},close:function(){this.dequeue();this.isRun=false;this.start()}};return queue};sa.requestQueue=function(para){this.url=para.url};sa.requestQueue.prototype.isEnd=function(){if(!this.received){this.received=true;this.close()}};sa.requestQueue.prototype.start=function(){var me=this;setTimeout(function(){me.isEnd()},300);wx.request({url:this.url,method:"GET",complete:function(){me.isEnd()}})};sa.dataQueue=_.autoExeQueue();sa.send=function(t){var url="";t._nocache=(String(Math.random())+String(Math.random())+String(Math.random())).slice(2,15);logger.info(t);t=JSON.stringify(t);if(sa.para.server_url.indexOf("?")!==-1){url=sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t))}else{url=sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t))}var instance=new sa.requestQueue({url:url});instance.close=function(){sa.dataQueue.close()};sa.dataQueue.enqueue(instance)};sa.autoTrackCustom=function(api,prop,event){var temp=sa.para.autoTrack[api];var tempFunc="";if(sa.para.autoTrack&&temp){if(typeof temp==="function"){tempFunc=temp();if(_.isObject(tempFunc)){_.extend(prop,tempFunc)}}else if(_.isObject(temp)){_.extend(prop,temp)}sa.track(event,prop)}};function e(t,n,o){if(t[n]){var e=t[n];t[n]=function(t){o.call(this,t,n);e.call(this,t)}}else t[n]=function(t){o.call(this,t,n)}}function appLaunch(para){this[sa.para.name]=sa;sa.init();var prop={};if(para&¶.path){prop.$url_path=para.path}if(para&&_.isObject(para.query)&¶.query.q){_.extend(prop,_.getUtm(para.query.q))}prop.$scene=_.getMPScene(para.scene);if(sa.para.autoTrack&&sa.para.autoTrack.appLaunch===true){sa.autoTrackCustom("appLaunch",prop,"$MPLaunch")}}function appShow(para){var prop={};if(para&¶.path){prop.$url_path=para.path}if(para&&_.isObject(para.query)&¶.query.q){_.extend(prop,_.getUtm(para.query.q))}prop.$scene=_.getMPScene(para.scene);if(sa.para.autoTrack&&sa.para.autoTrack.appShow===true){sa.autoTrackCustom("appShow",prop,"$MPShow")}}function appHide(){if(sa.para.autoTrack&&sa.para.autoTrack.appHide===true){sa.autoTrackCustom("appHide",{},"$MPHide")}}function appError(){}function appUnLaunch(){}var p=App;App=function(t){e(t,"onLaunch",appLaunch);e(t,"onShow",appShow);e(t,"onHide",appHide);p(t)};function pageOnunload(n,e){}function pageOnHide(){}function pageOnReady(){}function pageOnPullDownRefresh(){}function pageOnReachBottom(){}function pageOnShareAppMessage(n,e){}var v=Page;Page=function(t){e(t,"onLoad",function(para){if(para&&_.isObject(para)&¶.q){this.sensors_mp_load_utm=_.getUtm(para.q)}});e(t,"onShow",function(){var router="系统没有取到值";if(typeof this==="object"){if(typeof this.route==="string"){router=this.route}else if(typeof this.__route__==="string"){router=this.__route__}}var prop={};prop.$referrer=sa_referrer;prop.$url_path=router;if(this.sensors_mp_load_utm){_.extend(prop,this.sensors_mp_load_utm);this.sensors_mp_load_utm=null}if(sa.para.onshow){sa.para.onshow(sa,router,this)}else{sa.autoTrackCustom("pageShow",prop,"$MPViewScreen")}sa_referrer=router});v(t)};module.exports=sa; \ No newline at end of file