1 Star 0 Fork 0

Sensors Data/sa-sdk-wecode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sensorsdata.amd.min.js 12.74 KB
一键复制 编辑 原始数据 按行查看 历史
shengyonggen 提交于 2023-03-28 17:07 +08:00 . Release 0.1.3
!function(){'use strict';const t={lib_version:'0.1.3',lib_method:'code',lib_name:'WeCode',is_first_launch:!1,_queue:[],hasInit:!1,initUserComplete:!1,getSystemComplete:!1,mpshow_time:void 0,systemList:{deviceInfo:!1,weCodeInfo:!1,netWorkType:!1},para:{datasend_timeout:3e3,server_url:'',show_log:!0,appid:'',max_string_length:500,request_type:'fetch'},debug_appid:''},e=function(){var e=t.para.appid+'_sensorsdata2015_welink';return JSON.parse(localStorage.getItem(e))},r={};var n=Array.prototype,i=Object.prototype,o=n.slice,a=i.toString,s=i.hasOwnProperty,c=n.forEach,u=n.indexOf,p=Array.isArray,l={},f=r.each=function(t,e,r){if(null===t)return!1;if(c&&t.forEach===c)t.forEach(e,r);else if(t.length===+t.length){for(var n=0,i=t.length;n<i;n++)if(n in t&&e.call(r,t[n],n,t)===l)return!1}else for(var o in t)if(s.call(t,o)&&e.call(r,t[o],o,t)===l)return!1};r.extend=function(t){return f(o.call(arguments,1),function(e){for(var r in e)void 0!==e[r]&&(t[r]=e[r])}),t},r.extend2Lev=function(t){return f(o.call(arguments,1),function(e){for(var n in e)void 0!==e[n]&&(r.isObject(e[n])&&r.isObject(t[n])?r.extend(t[n],e[n]):t[n]=e[n])}),t},r.coverExtend=function(t){return f(o.call(arguments,1),function(e){for(var r in e)void 0!==e[r]&&void 0===t[r]&&(t[r]=e[r])}),t},r.isArray=p||function(t){return'[object Array]'===a.call(t)},r.isFunction=function(t){try{return/^\s*\bfunction\b/.test(t)}catch(t){return!1}},r.isArguments=function(t){return!(!t||!s.call(t,'callee'))},r.toArray=function(t){return t?t.toArray?t.toArray():r.isArray(t)?o.call(t):r.isArguments(t)?o.call(t):r.values(t):[]},r.values=function(t){var e=[];return null===t?e:(f(t,function(t){e[e.length]=t}),e)},r.include=function(t,e){var r=!1;return null===t?r:u&&t.indexOf===u?-1!==t.indexOf(e):(f(t,function(t){if(r||(r=t===e))return l}),r)},r.trim=function(t){return t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,'')},r.isObject=function(t){return'[object Object]'===a.call(t)&&null!==t},r.isEmptyObject=function(t){if(r.isObject(t)){for(var e in t)if(s.call(t,e))return!1;return!0}return!1},r.isUndefined=function(t){return void 0===t},r.isString=function(t){return'[object String]'===a.call(t)},r.isDate=function(t){return'[object Date]'===a.call(t)},r.isBoolean=function(t){return'[object Boolean]'===a.call(t)},r.isNumber=function(t){return'[object Number]'===a.call(t)&&/[\d\\.]+/.test(String(t))},r.isJSONString=function(t){try{JSON.parse(t)}catch(t){return!1}return!0},r.decodeURIComponent=function(t){var e='';try{e=decodeURIComponent(t)}catch(r){e=t}return e},r.encodeDates=function(t){return r.each(t,function(e,n){r.isDate(e)?t[n]=r.formatDate(e):r.isObject(e)&&(t[n]=r.encodeDates(e))}),t},r.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())},r.searchObjDate=function(t){r.isObject(t)&&r.each(t,function(e,n){r.isObject(e)?r.searchObjDate(t[n]):r.isDate(e)&&(t[n]=r.formatDate(e))})},r.searchObjString=function(t){r.isObject(t)&&r.each(t,function(e,n){r.isObject(e)?r.searchObjString(t[n]):r.isString(e)&&(t[n]=r.formatString(e))})},r.formatString=function(e){return e.length>t.para.max_string_length?(t.log('\u5b57\u7b26\u4e32\u957f\u5ea6\u8d85\u8fc7\u9650\u5236\uff0c\u5df2\u7ecf\u505a\u622a\u53d6--'+e),e.slice(0,t.para.max_string_length)):e},r.unique=function(t){for(var e,r=[],n={},i=0;i<t.length;i++)(e=t[i])in n||(n[e]=!0,r.push(e));return r},r.strip_sa_properties=function(e){return r.isObject(e)?(r.each(e,function(n,i){if(r.isArray(n)){var o=[];r.each(n,function(e){r.isString(e)?o.push(e):t.log('\u60a8\u7684\u6570\u636e-',n,'\u7684\u6570\u7ec4\u91cc\u7684\u503c\u5fc5\u987b\u662f\u5b57\u7b26\u4e32,\u5df2\u7ecf\u5c06\u5176\u5220\u9664')}),0!==o.length?e[i]=o:(delete e[i],t.log('\u5df2\u7ecf\u5220\u9664\u7a7a\u7684\u6570\u7ec4'))}r.isString(n)||r.isNumber(n)||r.isDate(n)||r.isBoolean(n)||r.isArray(n)||(t.log('\u60a8\u7684\u6570\u636e-',n,'-\u683c\u5f0f\u4e0d\u6ee1\u8db3\u8981\u6c42\uff0c\u6211\u4eec\u5df2\u7ecf\u5c06\u5176\u5220\u9664'),delete e[i])}),e):e},r.strip_empty_properties=function(t){var e={};return r.each(t,function(t,r){null!==t&&(e[r]=t)}),e},r.utf8Encode=function(t){var e,r,n,i,o='';for(e=r=0,n=(t=(t+'').replace(/\r\n/g,'\n').replace(/\r/g,'\n')).length,i=0;i<n;i++){var a=t.charCodeAt(i),s=null;a<128?r++:s=a>127&&a<2048?String.fromCharCode(a>>6|192,63&a|128):String.fromCharCode(a>>12|224,a>>6&63|128,63&a|128),null!==s&&(r>e&&(o+=t.substring(e,r)),o+=s,e=r=i+1)}return r>e&&(o+=t.substring(e,t.length)),o},r.base64Encode=function(t){var e,n,i,o,a,s='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',c=0,u=0,p='',l=[];if(!t)return t;t=r.utf8Encode(t);do{e=(a=t.charCodeAt(c++)<<16|t.charCodeAt(c++)<<8|t.charCodeAt(c++))>>18&63,n=a>>12&63,i=a>>6&63,o=63&a,l[u++]=s.charAt(e)+s.charAt(n)+s.charAt(i)+s.charAt(o)}while(c<t.length);switch(p=l.join(''),t.length%3){case 1:p=p.slice(0,-2)+'==';break;case 2:p=p.slice(0,-1)+'='}return p},r.checkInitComplete=function(){t.initUserComplete&&t.getSystemComplete&&(t.hasInit=!0,t._queue.length>0&&(r.each(t._queue,function(e){if('prepareData'===e.event){var n=Array.prototype.slice.apply(e.arg)[0];n.properties=r.stripUrl(n.properties),t.prepareData.call(t,n)}else t[e.event].apply(t,e.arg)}),this._queue=[]))},r.getUUID=function(){return Date.now()+'-'+Math.floor(1e7*Math.random())+'-'+Math.random().toString(16).replace('.','')+'-'+String(31242*Math.random()).replace('.','').slice(0,8)},r.request=function(e){HWH5[t.para.request_type](e,{method:'get',headers:{'Content-Type':'application/json'},timeout:t.para.datasend_timeout}).then(function(e){t.log('\u53d1\u9001\u8bf7\u6c42\u6210\u529f: ',e)}).catch(function(e){t.log('\u8bf7\u6c42\u5f02\u5e38',e)})},r.getPath=function(){var t=window.document.location.hash.split('#')[1];return t||t},r.getUrl=function(){var e=t.debug_appid,n=location.href||'';return e?r.matchUrl(n,e):n},r.matchUrl=function(t,e){return t.split(e)[1]||t},r.stripUrl=function(e){var n=t.debug_appid;return n&&e.$url&&(e.$url=r.matchUrl(e.$url,n)),e},r.formatSystem=function(t){var e=t.toLowerCase();return'ios'===e?'iOS':'android'===e?'Android':t},r.formatManufacturer=function(t){return t.split('-')[0]},r.getAppId=function(){var t=location.href.match(/\d{8,}/g),e='';return t&&t.length>0&&(e=r.resolveId(t)),e},r.resolveId=function(t){for(var e=t.length||0,n=0;n<e;n++){var i=t[n].slice(0,4),o=t[n].slice(4,6),a=t[n].slice(6,8);if(i&&o&&a){var s=new Date(i,o,a);if(r.isDate(s))return t[n]}}return''},r.stripAppId=function(t){var e=t.indexOf('.debug');return e>-1?t.slice(0,e):t},t._=r;var d={_state:{},toState:function(t){'object'==typeof t&&t.distinct_id?this._state=t:this.set('distinct_id',r.getUUID())},getFirstId:function(){return this._state.first_id},getIsFirstDay:function(){return'object'==typeof this._state&&'number'==typeof this._state.first_visit_day_time&&this._state.first_visit_day_time>(new Date).getTime()},getDistinctId:function(){return this._state.distinct_id},getProps:function(){return this._state.props||{}},setProps:function(t,e){var n=this._state.props||{};e?this.set('props',t):(r.extend(n,t),this.set('props',n))},set:function(t,e){var r={};for(var n in'string'==typeof t?r[t]=e:'object'==typeof t&&(r=t),this._state=this._state||{},r)this._state[n]=r[n];this.save()},save:function(){var e,r,n;e=this._state,r=JSON.stringify(e),n=t.para.appid+'_sensorsdata2015_welink',localStorage.setItem(n,r)}};t.store=d;var g={currentProps:{},properties:{$lib:t.lib_name,$lib_version:String(t.lib_version)}};function h(){t.systemList.deviceInfo&&t.systemList.weCodeInfo&&t.systemList.netWorkType&&(t.getSystemComplete=!0,r.checkInitComplete())}t.info=g;var _={};_.processData=function(t){return t},_.onceTrackData=function(t){return'data='+function(t){t=JSON.stringify(t);var e=r.base64Encode(t);return encodeURIComponent(e)}(t)},t.kit=_,t.modules={},t.usePlugin=function(e,n){r.isObject(e)&&r.isString(e.name)&&e.name&&(t.modules[e.name]?e=t.modules[e.name]:t.modules[e.name]=e),'function'==typeof e.init&&(e.init(t,n),t.log(e.name+' plugin is initialized'))},t.init=function(n){if(r.isObject(n)){if(t.para=r.extend2Lev(t.para,n),!t.para.server_url)return t.log('\u8bf7\u8c03\u7528 init \u65f6\u8bbe\u7f6e server_url \u6570\u636e\u63a5\u6536\u5730\u5740\uff01'),!1;t.para.appid||(t.para.appid=r.getAppId()),'fetchInternet'!==t.para.request_type&&'fetchVPN'!==t.para.request_type&&'fetch'!==t.para.request_type&&(t.para.request_type='fetch')}var i,o;!function(){var n=e();if(n)d.toState(n);else{t.is_first_launch=!0;var i=new Date,o=i.getTime();i.setHours(23),i.setMinutes(59),i.setSeconds(60),t.setOnceProfile({$first_visit_time:new Date}),d.set({distinct_id:r.getUUID(),first_visit_time:o,first_visit_day_time:i.getTime()})}t.initUserComplete=!0,r.checkInitComplete()}(),i=t.info.properties,o=(new Date).getTimezoneOffset(),r.isNumber(o)&&(i.$timezone_offset=o),HWH5.getDeviceInfo().then(function(e){i.$os=r.formatSystem(e.osType),'iOS'===i.$os?i.$manufacturer=r.formatManufacturer(e.deviceName):i.$manufacturer=e.deviceName,i.$os_version=e.osVersion,t.systemList.deviceInfo=!0,h()}).catch(function(e){t.log('\u83b7\u53d6\u8bbe\u5907\u4fe1\u606f\u5f02\u5e38',e)}),HWH5.getWecodeInfo().then(function(e){var n=r.stripAppId(e.appId);t.debug_appid=e.appId,n&&(t.para.appid=n),i.$app_id=t.para.appid,t.systemList.weCodeInfo=!0,h()}).catch(function(e){t.log('\u83b7\u53d6\u5c0f\u7a0b\u5e8f\u4fe1\u606f\u5f02\u5e38',e)}),HWH5.getNetworkType().then(function(e){i.$network_type=e.type,t.systemList.netWorkType=!0,h()}).catch(function(e){t.log('\u8fd4\u56de\u7f51\u7edc\u72b6\u6001\u5f02\u5e38',e)})},t.log=function(){if(t.para.show_log&&'object'==typeof console&&console.log)try{var e=Array.prototype.slice.call(arguments);return e.unshift('sensorsdata: '),console.log.apply(console,e)}catch(t){console.log('sensorsdata: ',arguments[0])}},t.prepareData=function(e){var n={distinct_id:d.getDistinctId(),lib:{$lib:t.lib_name,$lib_method:t.lib_method,$lib_version:String(t.lib_version)},properties:{}};r.extend(n,e),r.isObject(e.properties)&&!r.isEmptyObject(e.properties)&&r.extend(n.properties,e.properties),e.type&&'profile'===e.type.slice(0,7)||(n._track_id=Number(String(Math.random()).slice(2,5)+String(Math.random()).slice(2,4)+String(Date.now()).slice(-4)),n.properties=r.extend({},t.info.properties,t.store.getProps(),t.info.currentProps,n.properties),'track'===e.type&&(n.properties.$is_first_day=t.store.getIsFirstDay())),n.properties.$time&&r.isDate(n.properties.$time)?(n.time=1*n.properties.$time,delete n.properties.$time):n.time=1*new Date,r.searchObjDate(n),r.searchObjString(n),t.send(n)},t.setProfile=function(e){t.prepareData({type:'profile_set',properties:e})},t.setOnceProfile=function(e){t.prepareData({type:'profile_set_once',properties:e})},t.track=function(t,e){var n=r.extend({$url_path:r.getPath(),$url:r.getUrl()},e);this.prepareData({type:'track',event:t,properties:n})},t.identify=function(t){if('number'==typeof t)t=String(t);else if('string'!=typeof t)return!1;d.getFirstId()?d.set('first_id',t):d.set('distinct_id',t)},t.trackSignup=function(e,r,n){t.prepareData({original_id:t.store.getFirstId()||t.store.getDistinctId(),distinct_id:e,type:'track_signup',event:r,properties:n}),t.store.set('distinct_id',e)},t.registerApp=function(e){r.isObject(e)&&!r.isEmptyObject(e)&&(t.info.currentProps=r.extend(t.info.currentProps,e))},t.getServerUrl=function(){return t.para.server_url},t.clearAppRegister=function(e){r.isArray(e)&&r.each(t.info.currentProps,function(n,i){r.include(e,i)&&delete t.info.currentProps[i]})},t.appLaunch=function(e){e&&r.isObject(e)||(e={});var n={};t.is_first_launch?n.$is_first_time=!0:n.$is_first_time=!1,r.extend(n,e),t.track('$MPLaunch',n)},t.appShow=function(e){e&&r.isObject(e)||(e={});var n={};t.mpshow_time=(new Date).getTime(),r.extend(n,e),t.track('$MPShow',n)},t.appHide=function(e){e&&r.isObject(e)||(e={});var n=(new Date).getTime(),i={};t.mpshow_time&&n-t.mpshow_time>0&&(n-t.mpshow_time)/36e5<24&&(i.event_duration=(n-t.mpshow_time)/1e3),r.extend(i,e),t.track('$MPHide',i)},t.pageShow=function(e){var n={};n.$url_path=r.getPath(),r.extend(n,e),t.track('$MPViewScreen',n)},t.login=function(e){var r=d.getFirstId(),n=d.getDistinctId();e!==n&&(r?t.trackSignup(e,'$SignUp'):(d.set('first_id',n),t.trackSignup(e,'$SignUp')))},t.logout=function(e){var n=d.getFirstId();n?(d.set('first_id',''),!0===e?d.set('distinct_id',r.getUUID()):d.set('distinct_id',n)):t.log('\u6ca1\u6709first_id\uff0clogout\u5931\u8d25')},t.send=function(e){var n='';e._nocache=(String(Math.random())+String(Math.random())+String(Math.random())).slice(2,15),t.log(e),e._flush_time=Date.now();var i=_.onceTrackData(e);n=-1!==t.para.server_url.indexOf('?')?t.para.server_url+'&'+i:t.para.server_url+'?'+i,r.request(n)},r.each(['login','logout','identify','prepareData'],function(e){var r=t[e];t[e]=function(){t.hasInit?r.apply(t,arguments):t._queue.push({event:e,arg:arguments})}});try{window.sensorsDataWeCode2015=t}catch(t){console.error(t)}}();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sensorsdata/sa-sdk-wecode.git
git@gitee.com:sensorsdata/sa-sdk-wecode.git
sensorsdata
sa-sdk-wecode
sa-sdk-wecode
master

搜索帮助