1 Star 0 Fork 0

Sensors Data/sa-sdk-alipaymini

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sensorsdata.custom.min.js 21.46 KB
一键复制 编辑 原始数据 按行查看 历史
shengyonggen 提交于 2022-04-22 18:11 +08:00 . Release 1.2.1
var sa={},_={};sa.para={name:"sensors",server_url:"",max_string_length:500,datasend_timeout:25e3,autoTrack:{appLaunch:!0,appShow:!0,appHide:!0,pageShow:!0,mpClick:!0,pageLeave:!1},show_log:!1,preset_properties:{},framework:{},batch_send:!0},sa.setPara=function(t){sa.para=_.extend2Lev(sa.para,t),_.isObject(sa.para.register)&&_.extend(_.info.properties,sa.para.register),sa.para.name||(sa.para.name="sensors");var e=sa.para.server_url;if(e){-1!==e.indexOf("/sa.gif")&&(sa.para.server_url=e.replace("/sa.gif","/sa")),sa.para.preset_properties=_.isObject(sa.para.preset_properties)?sa.para.preset_properties:{};var r={send_timeout:6e3,max_length:6};t&&t.datasend_timeout||sa.para.batch_send&&(sa.para.datasend_timeout=1e4),!0===sa.para.batch_send?sa.para.batch_send=_.extend({},r):_.isObject(sa.para.batch_send)?sa.para.batch_send=_.extend({},r,sa.para.batch_send):sa.para.batch_send=!1}else console.log("\u8bf7\u4f7f\u7528 setPara() \u65b9\u6cd5\u8bbe\u7f6e server_url \u6570\u636e\u63a5\u6536\u5730\u5740,\u8be6\u60c5\u53ef\u67e5\u770bhttps://www.sensorsdata.cn/manual/mp_sdk_new.html#112-%E5%BC%95%E5%85%A5%E5%B9%B6%E9%85%8D%E7%BD%AE%E5%8F%82%E6%95%B0")},sa.getServerUrl=function(){return sa.para.server_url},sa._queue=[],sa.getSystemInfoComplete=!1;var ArrayProto=Array.prototype,FuncProto=Function.prototype,ObjProto=Object.prototype,slice=ArrayProto.slice,toString=ObjProto.toString,hasOwnProperty=ObjProto.hasOwnProperty,LIB_VERSION="1.2.1",LIB_NAME="AlipayMini",source_channel_standard="utm_source utm_medium utm_campaign utm_content utm_term",latest_source_channel=["$latest_utm_source","$latest_utm_medium","$latest_utm_campaign","$latest_utm_content","$latest_utm_term","$latest_sa_utm"],page_show_time=Date.now(),sa_referrer="\u76f4\u63a5\u6253\u5f00";sa.lib_version=LIB_VERSION;var is_first_launch=!1,mpshow_time=null,first_show_page=!1,logger="object"==typeof logger?logger:{};function eventEmitter(){this.sub=[]}function eventSub(t){sa.events.add(this),this._events=[],this.handle=t,this.ready=!1}function usePlugin(t,e){"function"==typeof t.init&&t.init(sa,e)}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])}},function(){FuncProto.bind;var t=ArrayProto.forEach,e=ArrayProto.indexOf,r=Array.isArray,a={},s=_.each=function(e,r,s){if(null==e)return!1;if(t&&e.forEach===t)e.forEach(r,s);else if(e.length===+e.length){for(var n=0,i=e.length;n<i;n++)if(n in e&&r.call(s,e[n],n,e)===a)return!1}else for(var o in e)if(hasOwnProperty.call(e,o)&&r.call(s,e[o],o,e)===a)return!1};_.logger=logger,_.extend=function(t){return s(slice.call(arguments,1),function(e){for(var r in e)void 0!==e[r]&&(t[r]=e[r])}),t},_.extend2Lev=function(t){return s(slice.call(arguments,1),function(e){for(var r in e)void 0!==e[r]&&null!==e[r]&&(_.isObject(e[r])&&_.isObject(t[r])?_.extend(t[r],e[r]):t[r]=e[r])}),t},_.coverExtend=function(t){return s(slice.call(arguments,1),function(e){for(var r in e)void 0!==e[r]&&void 0===t[r]&&(t[r]=e[r])}),t},_.isArray=r||function(t){return"[object Array]"===toString.call(t)},_.isFunction=function(t){if(!t)return!1;var e=Object.prototype.toString.call(t);return"[object Function]"==e||"[object AsyncFunction]"==e},_.isArguments=function(t){return!(!t||!hasOwnProperty.call(t,"callee"))},_.toArray=function(t){return t?t.toArray?t.toArray():_.isArray(t)?slice.call(t):_.isArguments(t)?slice.call(t):_.values(t):[]},_.values=function(t){var e=[];return null==t?e:(s(t,function(t){e[e.length]=t}),e)},_.include=function(t,r){var n=!1;return null==t?n:e&&t.indexOf===e?-1!=t.indexOf(r):(s(t,function(t){if(n||(n=t===r))return a}),n)}}(),_.trim=function(t){return t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},_.isObject=function(t){return"[object Object]"==toString.call(t)&&null!=t},_.isEmptyObject=function(t){if(_.isObject(t)){for(var e in t)if(hasOwnProperty.call(t,e))return!1;return!0}return!1},_.isUndefined=function(t){return void 0===t},_.isString=function(t){return"[object String]"==toString.call(t)},_.isDate=function(t){return"[object Date]"==toString.call(t)},_.isBoolean=function(t){return"[object Boolean]"==toString.call(t)},_.isNumber=function(t){return"[object Number]"==toString.call(t)&&/[\d\.]+/.test(String(t))},_.isJSONString=function(t){try{JSON.parse(t)}catch(t){return!1}return!0},_.decodeURIComponent=function(t){var e="";try{e=decodeURIComponent(t)}catch(r){e=t}return e},_.encodeDates=function(t){return _.each(t,function(e,r){_.isDate(e)?t[r]=_.formatDate(e):_.isObject(e)&&(t[r]=_.encodeDates(e))}),t},_.formatDate=function(t){function e(t){return t<10?"0"+t:t}return t.getFullYear()+"-"+e(t.getMonth()+1)+"-"+e(t.getDate())+" "+e(t.getHours())+":"+e(t.getMinutes())+":"+e(t.getSeconds())+"."+e(t.getMilliseconds())},_.searchObjDate=function(t){_.isObject(t)&&_.each(t,function(e,r){_.isObject(e)?_.searchObjDate(t[r]):_.isDate(e)&&(t[r]=_.formatDate(e))})},_.formatString=function(t){return t.length>sa.para.max_string_length?(logger.info("\u5b57\u7b26\u4e32\u957f\u5ea6\u8d85\u8fc7\u9650\u5236\uff0c\u5df2\u7ecf\u505a\u622a\u53d6--"+t),t.slice(0,sa.para.max_string_length)):t},_.searchObjString=function(t){_.isObject(t)&&_.each(t,function(e,r){_.isObject(e)?_.searchObjString(t[r]):_.isString(e)&&(t[r]=_.formatString(e))})},_.parseSuperProperties=function(t){_.isObject(t)&&(_.each(t,function(e,r){if(_.isFunction(e))try{t[r]=e(),_.isFunction(t[r])&&(logger.info("\u60a8\u7684\u5c5e\u6027- "+r+" \u683c\u5f0f\u4e0d\u6ee1\u8db3\u8981\u6c42\uff0c\u6211\u4eec\u5df2\u7ecf\u5c06\u5176\u5220\u9664"),delete t[r])}catch(e){delete t[r],logger.info("\u60a8\u7684\u5c5e\u6027- "+r+" \u629b\u51fa\u4e86\u5f02\u5e38\uff0c\u6211\u4eec\u5df2\u7ecf\u5c06\u5176\u5220\u9664")}}),_.strip_sa_properties(t))},_.unique=function(t){for(var e,r=[],a={},s=0;s<t.length;s++)(e=t[s])in a||(a[e]=!0,r.push(e));return r},_.strip_sa_properties=function(t){return _.isObject(t)?(_.each(t,function(e,r){if(_.isArray(e)){var a=[];_.each(e,function(t){_.isString(t)?a.push(t):logger.info("\u60a8\u7684\u6570\u636e-",e,"\u7684\u6570\u7ec4\u91cc\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32,\u5df2\u7ecf\u5c06\u5176\u5220\u9664")}),0!==a.length?t[r]=a:(delete t[r],logger.info("\u5df2\u7ecf\u5220\u9664\u7a7a\u7684\u6570\u7ec4"))}_.isString(e)||_.isNumber(e)||_.isDate(e)||_.isBoolean(e)||_.isArray(e)||(logger.info("\u60a8\u7684\u6570\u636e-",e,"-\u683c\u5f0f\u4e0d\u6ee1\u8db3\u8981\u6c42\uff0c\u6211\u4eec\u5df2\u7ecf\u5c06\u5176\u5220\u9664"),delete t[r])}),t):t},_.strip_empty_properties=function(t){var e={};return _.each(t,function(t,r){null!=t&&(e[r]=t)}),e},_.utf8Encode=function(t){var e,r,a,s,n="";for(e=r=0,a=(t=(t+"").replace(/\r\n/g,"\n").replace(/\r/g,"\n")).length,s=0;s<a;s++){var i=t.charCodeAt(s),o=null;i<128?r++:o=i>127&&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=s+1)}return r>e&&(n+=t.substring(e,t.length)),n},_.base64Encode=function(t){var e,r,a,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,r=n>>12&63,a=n>>6&63,s=63&n,p[c++]=i.charAt(e)+i.charAt(r)+i.charAt(a)+i.charAt(s)}while(o<t.length);switch(u=p.join(""),t.length%3){case 1:u=u.slice(0,-2)+"==";break;case 2:u=u.slice(0,-1)+"="}return u},_.info={currentProps:{},properties:{$lib:LIB_NAME,$lib_version:String(LIB_VERSION)},getSystem:function(){var t=this.properties,e=!0;function r(){e&&(e=!1,my.getSystemInfo({success:function(e){var r,a;t.$model=e.model,t.$screen_width=Number(e.screenWidth),t.$screen_height=Number(e.screenHeight),t.$os=(r=e.platform,"ios"===(a=r.toLowerCase())?"iOS":"android"===a?"Android":r),t.$os_version=e.system.indexOf(" ")>-1?e.system.split(" ")[1]:e.system,t.$manufacturer=e.brand},complete:function(){var e,r=(new Date).getTimezoneOffset();my.getAppIdSync&&(e=my.getAppIdSync().appId),e&&(t.$app_id=e),_.isNumber(r)&&(t.$timezone_offset=r),sa.getSystemInfoComplete=!0,sa.checkIsComplete()}}))}my.getNetworkType({success:function(e){t.$network_type=e.networkType,r()},complete:function(){r()}})},setStatusComplete:function(){if(sa.getSystemInfoComplete)return!1;sa.getSystemInfoComplete=!0,sa._queue.length>0&&(_.each(sa._queue,function(t){sa.prepareData.apply(sa,slice.call(t))}),sa._queue=[])}},_.getIsFirstDay=function(){return"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()},_.request=function(t){var e,r;if(!t||_.isEmptyObject(t))return!1;t.complete=function(){r&&clearTimeout(r)},e=my.canIUse("request")?my.request(t):my.httpRequest(t),r=setTimeout(function(){_.isObject(e)&&_.isFunction(e.abort)&&e.abort()},sa.para.datasend_timeout)},_.sendPageLeave=function(){if(sa.para.autoTrack&&sa.para.autoTrack.pageLeave){var t={},e="";try{var r=getCurrentPages();e=(t=r[r.length-1])?t.route:""}catch(t){logger.info(t)}if(page_show_time>=0&&""!==e){var a={},s=(Date.now()-page_show_time)/1e3;(isNaN(s)||s<0)&&(s=0),a.$url_query=t.sensors_mp_url_query?t.sensors_mp_url_query:"",a.$url_path=e,a.event_duration=s,sa.track("$MPPageLeave",a),page_show_time=-1}}},sa._=_,sa.prepareData=function(t,e){if(!sa.isComplete)return sa._queue.push(arguments),!1;var r={distinct_id:this.store.getDistinctId(),lib:{$lib:LIB_NAME,$lib_method:"code",$lib_version:String(LIB_VERSION)},properties:{}};_.extend(r,t),_.isObject(t.properties)&&!_.isEmptyObject(t.properties)&&_.extend(r.properties,t.properties),t.type&&"profile"===t.type.slice(0,7)||(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),"track"===t.type&&(r.properties.$is_first_day=_.getIsFirstDay())),r.properties.$time&&_.isDate(r.properties.$time)?(r.time=1*r.properties.$time,delete r.properties.$time):r.time=1*new Date,_.parseSuperProperties(r.properties),_.searchObjDate(r),_.searchObjString(r),sa.para.batch_send?sa.sendStrategy.send(r):sa.send(r)},sa.checkIsComplete=function(){this.isComplete=!1,this.getSystemInfoComplete&&this.hasInit&&(this.isComplete=!0,sa._queue.length>0&&(_.each(sa._queue,function(t){sa.prepareData.apply(sa,slice.call(t))}),sa._queue=[]))},sa.store={getUUID:function(){return Date.now()+"-"+Math.floor(1e7*Math.random())+"-"+Math.random().toString(16).replace(".","")+"-"+String(31242*Math.random()).replace(".","").slice(0,8)},setStorage:function(){},getStorage:function(){return my.getStorageSync({key:"sensorsdata2015_zfb"})||{}},_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){"object"==typeof t&&t.distinct_id?this._state=t: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(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 a in"string"==typeof t?r[t]=e:"object"==typeof t&&(r=t),this._state=this._state||{},r)this._state[a]=r[a],"distinct_id"===a&&sa.events.emit("changeDistinctId");this.save()},change:function(t,e){this._state[t]=e},save:function(){my.setStorageSync({key:"sensorsdata2015_zfb",data:this._state})},init:function(){var t=this.getStorage().data;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.track=function(t,e,r){this.prepareData({type:"track",event:t,properties:e},r)},sa.identify=function(t,e){if("number"==typeof t)t=String(t);else if("string"!=typeof t)return!1;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,a){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:r},a)},sa.registerApp=function(t){_.isObject(t)&&!_.isEmptyObject(t)&&(_.info.currentProps=_.extend(_.info.currentProps,t))},sa.clearAppRegister=function(t){_.isArray(t)&&_.each(_.info.currentProps,function(e,r){_.include(t,r)&&delete _.info.currentProps[r]})},sa.clearAllRegister=function(){sa.store.setProps({},!0)},sa.login=function(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.logout=function(t){var e=sa.store.getFirstId();e?(sa.store.set("first_id",""),!0===t?sa.store.set("distinct_id",sa.store.getUUID()):sa.store.set("distinct_id",e)):logger.info("\u6ca1\u6709first_id\uff0clogout\u5931\u8d25")},sa.getAnonymousID=function(){if(!_.isEmptyObject(sa.store._state))return sa.store._state.first_id||sa.store._state.distinct_id;logger.info("\u8bf7\u5148\u521d\u59cb\u5316SDK")},sa.getLocation=function(){my.getSetting({success:function(t){if(!t.authSetting.location)return!1;my.getLocation({success:function(t){sa.registerApp({$latitude:t.latitude*Math.pow(10,6),$longitude:t.longitude*Math.pow(10,6)})},fail:function(t){console.log("\u83b7\u53d6\u4f4d\u7f6e\u5931\u8d25\uff1a",t)}})}})},sa.initial=function(){this._.info.getSystem(),this.store.init(),_.isObject(this.para.register)&&(_.info.properties=_.extend(_.info.properties,this.para.register))},sa.init=function(){if(!0===this.hasInit)return!1;this.hasInit=!0,sa.para.batch_send&&sa.sendStrategy.init(),sa.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(),$is_first_day:_.getIsFirstDay()},_.info.properties);return delete e.$lib,e}return{}},sa.send=function(t){var e="";t._nocache=(String(Math.random())+String(Math.random())+String(Math.random())).slice(2,15),logger.info(t),t._flush_time=Date.now(),t=JSON.stringify(t),e=-1!==sa.para.server_url.indexOf("?")?sa.para.server_url+"&data="+encodeURIComponent(_.base64Encode(t)):sa.para.server_url+"?data="+encodeURIComponent(_.base64Encode(t)),_.request({url:e,dataType:"text",method:"GET",headers:{"content-type":"application/x-www-form-urlencoded"}})},sa.sendStrategy={dataHasSend:!0,syncStorage:!1,is_first_batch_write:!0,failTime:0,init:function(){my.getStorage({key:"sensors_prepare_data",complete:function(t){var e=t.data&&_.isArray(t.data)?t.data:[];sa.store.mem.mdata=e.concat(sa.store.mem.mdata),sa.sendStrategy.syncStorage=!0}}),this.batchInterval()},onAppHide:function(){sa.para.batch_send&&this.batchSend()},send:function(t){if(!sa.para.server_url)return!1;this.dataHasChange=!0,sa.store.mem.getLength()>=500&&(logger.info("\u6570\u636e\u91cf\u5b58\u50a8\u8fc7\u5927\uff0c\u6709\u5f02\u5e38"),sa.store.mem.mdata.shift()),logger.info(t),sa.store.mem.add(t),sa.store.mem.getLength()>=sa.para.batch_send.max_length&&this.batchSend()},batchWrite:function(){var t=this;this.dataHasChange&&(this.is_first_batch_write&&(this.is_first_batch_write=!1,setTimeout(function(){t.batchSend()},1e3)),this.syncStorage&&(my.setStorageSync({key:"sensors_prepare_data",data:sa.store.mem.mdata}),this.dataHasChange=!1))},batchInterval(){var t=this;!function e(){setTimeout(function(){t.batchSend(),e()},sa.para.batch_send.send_timeout*Math.pow(2,t.failTime))}(),function e(){setTimeout(function(){t.batchWrite(),e()},500)}()},batchSend(){if(this.dataHasSend){var t,e,r=this,a=sa.store.mem.mdata;if(t=a.length>=100?a.slice(0,100):a,e=t.length,_.isArray(t)&&t.length>0){this.dataHasSend=!1;var s=Date.now();t.forEach(function(t){t._flush_time=s}),t=JSON.stringify(t),t="data_list="+encodeURIComponent(_.base64Encode(t)),_.request({url:sa.para.server_url,method:"POST",data:t,dataType:"text",success:function(t){r.batchRemove(e)},fail:function(){r.sendFail()}})}}},batchRemove(t){this.dataHasSend=!0,this.dataHasChange=!0,sa.store.mem.clear(t),this.batchWrite(),this.failTime=0},sendFail(){this.dataHasSend=!0,this.failTime++}},_.getPath=function(t){return t="string"==typeof t?t.replace(/^\//,""):"\u53d6\u503c\u5f02\u5e38"},_.getQueryParam=function(t,e){var r=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(t);return null===r||r&&"string"!=typeof r[1]&&r[1].length?"":_.decodeURIComponent(r[1])},_.getMPScene=function(t){return"number"==typeof t||"string"==typeof t&&""!==t?t="ali-"+String(t):"\u672a\u53d6\u5230\u503c"},_.getQuery=function(t){var e={};if(t&&_.isObject(t.query)&&(e=_.extend({},t.query),t.query.qrCode&&_.extend(e,_.getObjFromQuery(_.decodeURIComponent(t.query.qrCode)))),t&&_.isObject(t.referrerInfo)&&t.referrerInfo.extraData){var r={};_.isObject(t.referrerInfo.extraData)&&!_.isEmptyObject(t.referrerInfo.extraData)?r=t.referrerInfo.extraData:_.isJSONString(t.referrerInfo.extraData)&&(r=JSON.parse(t.referrerInfo.extraData)),_.extend(e,r)}return e},_.setUtm=function(t,e){var r=_.getQuery(t),a={},s=_.getCustomUtmFromQuery(r,"$","_","$"),n=_.getCustomUtmFromQuery(r,"$latest_","_latest_","$latest_");return a.pre1=s,a.pre2=n,_.extend(e,a.pre1),a},_.getObjFromQuery=function(t){var e=t.split("?"),r={};return e&&e[1]?(_.each(e[1].split("&"),function(t){var e=t.split("=");e[0]&&e[1]&&(r[e[0]]=e[1])}),r):{}},_.getCustomUtmFromQuery=function(t,e,r,a){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[r+n]=t[n]):s[a+n]=t[n];else for(var n in t)-1===(" "+source_channel_standard+" ").indexOf(" "+n+" ")?_.include(sa.para.source_channel,n)&&(s[r+n]=t[n]):s[e+n]=t[n];return s},_.existLatestUtm=function(){var t=!1;return _.each(latest_source_channel,function(e,r){_.info.currentProps[e]&&(t=!0)}),t},_.setQuery=function(t,e){if(t&&_.isObject(t)&&!_.isEmptyObject(t)){var r=[];return _.each(t,function(t,a){"q"===a&&_.isString(t)&&0===t.indexOf("http")||(e?r.push(a+"="+t):r.push(a+"="+_.decodeURIComponent(t)))}),r.join("&")}return""},_.setLatestChannel=function(t){_.isEmptyObject(t)||(function(t,e){var r=!1;for(var a in e)t[e[a]]&&(r=!0);return r}(t,latest_source_channel)&&sa.clearAppRegister(latest_source_channel),sa.registerApp(t))},_.getCurrentPath=function(){var t="\u672a\u53d6\u5230";try{var e=getCurrentPages();t=e[e.length-1].route}catch(t){logger.info(t)}return t},_.getIsFirstDay=function(){return"object"==typeof sa.store._state&&"number"==typeof sa.store._state.first_visit_day_time&&sa.store._state.first_visit_day_time>(new Date).getTime()},sa.appLaunch=function(t,e,r){e&&_.isObject(e)||(e={});var a={};t&&t.path&&(a.$url_path=_.getPath(t.path));var s=_.setUtm(t,a);is_first_launch?(a.$is_first_time=!0,_.isEmptyObject(s.pre1)||sa.setOnceProfile(s.pre1)):a.$is_first_time=!1,_.isEmptyObject(s.pre2)||_.setLatestChannel(s.pre2);var n=_.getMPScene(t.scene);n&&(a.$scene=n,sa.registerApp({$latest_scene:a.$scene})),a.$url_query=_.setQuery(t.query),_.extend(a,e),(!r||sa.para.autoTrack&&sa.para.autoTrack.appLaunch)&&sa.track("$MPLaunch",a)},sa.appShow=function(t,e,r){e&&_.isObject(e)||(e={});var a={};mpshow_time=(new Date).getTime(),first_show_page=!0,t&&t.path&&(a.$url_path=_.getPath(t.path));var s=_.setUtm(t,a);_.isEmptyObject(s.pre2)||_.setLatestChannel(s.pre2),!0===sa.para.preset_properties.location&&sa.getLocation();var n=_.getMPScene(t.scene);n&&(a.$scene=n,sa.registerApp({$latest_scene:a.$scene})),a.$url_query=_.setQuery(t.query),_.extend(a,e),(!r||sa.para.autoTrack&&sa.para.autoTrack.appShow)&&sa.track("$MPShow",a)},sa.appHide=function(t,e){t&&_.isObject(t)||(t={});var r=(new Date).getTime(),a={};a.$url_path=_.getCurrentPath(),mpshow_time&&r-mpshow_time>0&&(r-mpshow_time)/36e5<24&&(a.event_duration=(r-mpshow_time)/1e3),_.extend(a,t),(!e||sa.para.autoTrack&&sa.para.autoTrack.appHide)&&sa.track("$MPHide",a),sa.sendStrategy.onAppHide()},sa.pageShow=function(t,e){page_show_time=Date.now();var r={},a=_.getCurrentPath();r.$url_path=a;var s=getCurrentPages(),n=s[s.length-1];try{_.isObject(n)?(r.$url_query=n.sensors_mp_url_query?n.sensors_mp_url_query:"",first_show_page&&(first_show_page=!1,!_.existLatestUtm()&&n.utm&&_.isObject(n.utm.pre2)&&sa.registerApp(n.utm.pre2)),n.utm&&_.isObject(n.utm.pre1)&&_.extend(r,n.utm.pre1)):r.$url_query=""}catch(t){logger.info(t)}_.extend(r,t),(!e||sa.para.autoTrack&&sa.para.autoTrack.pageShow)&&sa.track("$MPViewScreen",r)},sa.pageLoad=function(t,e){if(e&&_.isObject(e)&&_.isObject(t))try{t.sensors_mp_url_query=_.setQuery(e);var r={};r.pre1=_.getCustomUtmFromQuery(e,"$","_","$"),r.pre2=_.getCustomUtmFromQuery(e,"$latest_","_latest_","$latest_"),t.utm=r}catch(t){logger.info(t)}},sa.quick=function(){var t=arguments[0],e=arguments[1],r=arguments[2],a=_.isObject(r)?r:{};"appLaunch"===t||"appShow"===t?e?sa[t](e,a):logger.info("App\u7684launch\u548cshow\uff0c\u5728sensors.quick\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f20\u5165App\u7684options\u53c2\u6570"):"appHide"===t&&(a=_.isObject(e)?e:{},sa[t](a))},eventEmitter.prototype={add:function(t){this.sub.push(t)},emit:function(t,e){this.sub.forEach(function(r){r.on(t,e)})}},eventSub.prototype={on:function(t,e){if(this.ready){if(_.isFunction(this.handle))try{this.handle(t,e)}catch(t){logger.info(t)}}else this._events.push({event:t,data:e})},isReady:function(){var t=this;t.ready=!0,t._events.forEach(function(e){if(_.isFunction(t.handle))try{t.handle(e.event,e.data)}catch(t){logger.info(t)}})}},sa.events=new eventEmitter,sa.eventSub=eventSub,sa.use=sa.usePlugin=usePlugin,sa.initial(),module.exports=sa;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/sensorsdata/sa-sdk-alipaymini.git
git@gitee.com:sensorsdata/sa-sdk-alipaymini.git
sensorsdata
sa-sdk-alipaymini
sa-sdk-alipaymini
master

搜索帮助