-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathuma.min.js
1 lines (1 loc) · 33.2 KB
/
uma.min.js
1
"use strict";var t,e,n="[UMENG] -- ",a=(e=!1,function(){return t=null===t?new i:t});function i(){this.setDebug=function(t){e=t};this.d=function(){if(e)try{"string"==typeof arguments[0]&&(arguments[0]=n+arguments[0]);console.debug.apply(console,arguments)}catch(t){}};this.i=function(){try{if(e)try{"string"==typeof arguments[0]&&(arguments[0]=n+arguments[0]);console.info.apply(console,arguments)}catch(t){}}catch(t){}};this.e=function(){if(e)try{"string"==typeof arguments[0]&&(arguments[0]=n+arguments[0]);console.error.apply(console,arguments)}catch(t){}};this.w=function(){if(e)try{"string"==typeof arguments[0]&&(arguments[0]=n+arguments[0]);console.warn.apply(console,arguments)}catch(t){}};this.v=function(){if(e)try{"string"==typeof arguments[0]&&(arguments[0]=n+arguments[0]);console.log.apply(console,arguments)}catch(t){}};this.t=function(){if(e)try{console.table.apply(console,arguments)}catch(t){}};this.tip=function(){try{"string"==typeof arguments[0]&&(arguments[0]=n+arguments[0]);console.log.apply(console,arguments)}catch(t){}};this.tip_w=function(t){try{console.log("%c "+n+t,"background:red; padding: 4px; padding-right: 8px; border-radius: 4px; color: #fff;")}catch(t){}};this.err=function(){try{"string"==typeof arguments[0]&&(arguments[0]=n+arguments[0]);console.error.apply(console,arguments)}catch(t){}};this.repeat=function(t){for(var e=t;e.length<86;)e+=t;return e}}var r=t=null;function o(){if(r)return r;try{r=my.getSystemInfoSync()}catch(t){r=null}return r}function s(t){var e=o();return e&&e.app?new RegExp("^"+t+"$","i").test(e.app):0}function u(){return s("TB|taobao|com.taobao.taobao")}function c(){return s("LX")}function f(){return s("amap")}var p=new(function(){function t(){}t.prototype.setStorage=function(t,e,n){my.setStorage({key:t,data:e,success:function(t){"function"==typeof n&&n(!0)},fail:function(){"function"==typeof n&&n(!1)}})};t.prototype.getStorage=function(e,n){my.getStorage({key:e,success:function(t){"function"==typeof n&&n(t.data)},fail:function(t){a().w(e+": "+t.errMsg);"function"==typeof n&&n()}})};t.prototype.removeStorage=function(t,e){my.removeStorage({key:t,success:function(){"function"==typeof e&&e(!0)},fail:function(){"function"==typeof e&&e(!1)}})};t.prototype.getSystemInfo=function(t){var e,n,i,r=o();if(r){e={model:r.model,platform:r.platform,brand:r.brand,pixelRatio:r.pixelRatio,screenWidth:r.screenWidth,screenHeight:r.screenHeight,fontSizeSetting:r.fontSizeSetting,OSVersion:r.system,language:r.language,deviceName:r.model,platformVersion:r.version,platformSDKVersion:my.SDKVersion,resolution:"",statusBarHeight:r.statusBarHeight,storage:r.storage,host:r.app};if("android"===r.platform){n=Math.round(r.screenWidth);i=Math.round(r.screenHeight)}else{n=Math.round(r.screenWidth*r.pixelRatio);i=Math.round(r.screenHeight*r.pixelRatio)}e.resolution=i<n?n+"*"+i:i+"*"+n;"function"==typeof t&&t(e)}else"function"==typeof t&&t(e)};t.prototype.getDeviceInfo=function(e){try{var n=this;my.call("getDeviceInfo",{},function(t){t=(t||{}).data;if(t){n.setStorage("device_info",t);"function"==typeof e&&e(t)}else n.getStorage("device_info",function(t){"function"==typeof e&&e(t)})})}catch(t){a().w("支付宝获取设备info 失败",t);"function"==typeof e&&e()}};t.prototype.checkNetworkAvailable=function(e){my.getNetworkType({success:function(t){"function"==typeof e&&e(t.networkAvailable)},fail:function(){"function"==typeof e&&e()}})};t.prototype.getNetworkInfo=function(e){my.getNetworkType({success:function(t){"function"==typeof e&&e({networkAvailable:t.networkAvailable,networkType:t.networkType})},fail:function(){"function"==typeof e&&e()}})};t.prototype.getDeviceId=function(t){"function"==typeof t&&t("")};t.prototype.getAdvertisingId=function(t){"function"==typeof t&&t("")};t.prototype.getPageName=function(){return""};t.prototype.onNetworkStatusChange=function(e){my.onNetworkStatusChange(function(t){"function"==typeof e&&e(t.isConnected||!0)})};t.prototype.request=function(t){t.headers=t.header;try{delete t.header}catch(t){}return my.request?my.request(t):my.httpRequest(t)};t.prototype.getSdkType=function(){return this.getPlatform()+"mp"};t.prototype.getPlatform=function(){return u()?"taobao":f()?"gaode":c()?"fliggy":"alipay"};t.prototype.getUserInfo=function(n){var e={fail:function(){n&&n()},success:function(t){try{var e=JSON.parse(t.response).response;e&&n&&n({avatar:e.avatar,nickName:e.nickName,gender:e.gender,country:e.countryCode,province:e.province,city:e.city})}catch(t){n()}}};try{my.getSetting({success:function(t){console.log("setting: ",t);t&&t.authSetting&&t.authSetting.userInfo?my.getOpenUserInfo(e):n&&n()},fail:function(){n&&n()}})}catch(t){a.e("getUserInfo error",t)}};t.prototype.getAppInfoSync=function(){var t={};return{appId:(t=my.getAppIdSync?my.getAppIdSync()||{}:t).appId}};t.prototype.onShareAppMessage=function(){};t.prototype.shareAppMessage=function(){};return t}()),d={SESSION_INTERVAL:3e4,LOG_URL:"https://umini.shujupie.com/alipaym_logs",GET_OPENID_URL:"",USERINFO_URL:"https://umini.shujupie.com/uminiprogram_logs/comm/uif",DEVICE_INFO_KEY:"device_info",ADVERTISING_ID:"mobile_ad_id",ANDROID_ID:"android_id",CURRENT_SESSION:"current_session",SESSION_PAUSE_TIME:"session_pause_time",EVENT_SEND_DEFAULT_INTERVAL:15e3,EVENT_LAST_SEND_TIME:"last_send_time",MAX_EVENTID_LENGTH:128,MAX_PROPERTY_KEY_LENGTH:256,MAX_PROPERTY_KEYS_COUNT:100,REPORT_POLICY:"report_policy",REPORT_INTERVAL_TIME:"report_interval_time",REPORT_POLICY_START_SEND:"1",REPORT_POLICY_INTERVAL:"6",IMPRINT:"imprint",SEED_VERSION:"1.0.0",IMPL_VERSION:"2.6.1",ALIPAY_AVAILABLE_VERSION:"10.1.52",SHARE_PATH:"um_share_path",SHARES:"shares",REQUESTS:"requests",UUID:"um_uuid",UUID_SUFFIX:"ud",OPENID:"um_od",UNIONID:"um_unid",ALIPAYID:"um_alipayid",USERID:"um_userid",PROVIDER:"um_provider",SWANID:"um_swanid",ANONYMOUSID:"um_anonymousid",LAUNCH_OPTIONS:"LAUNCH_OPTIONS",UM_SSRC:"_um_ssrc",USER_INFO:"user_info",IS_ALIYUN:!1,ALIYUN_URL:"serverless.huoban.youmeng.network.forward"};var h,l={isNumber:function(t){return!Number.isNaN(parseInt(t,10))},compareVersion:function(t,e){for(var n=String(t).split("."),i=String(e).split("."),r=0;r<Math.max(n.length,i.length);r++){var o=parseInt(n[r]||0,10),s=parseInt(i[r]||0,10);if(s<o)return 1;if(o<s)return-1}return 0},getRandomStr:function(t){for(var e="",n=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],i=0;i<Number(t);i++)e+=n[Math.round(Math.random()*(n.length-1))];return e},clone:function(t){return JSON.parse(JSON.stringify(t))},startsWith:function(t,e){return!(!t||!e||0===e.length||e.length>t.length)&&t.substr(0,e.length)===e},endsWith:function(t,e){return!(!e||0===t.length||e.length>t.length)&&t.substring(t.length-e.length)===e},assign:function(t){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var i=arguments[n];if(i)for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e},deepEqual:function t(e,n){if(e===n)return!0;if(e&&"object"==typeof e&&n&&"object"==typeof n){if(Object.keys(e).length!==Object.keys(n).length)return!1;for(var i in e){if(Object.prototype.hasOwnProperty.call(n,i))return!1;if(!t(e[i],n[i]))return!1}return!0}return!1},trimStart:function(t,e){if(!t)return"";if("string"==typeof e&&e.length){e=new RegExp("^"+e+"*");t=t.replace(e,"")}else t=t.replace(/^s*/,"");return t},trimEnd:function(t,e){if(!t)return"";var n,i;if("string"==typeof e&&e.length){n=new RegExp(e);i=t.length;for(;n.test(t.charAt(i));)--i;return t.slice(0,i+1)}n=/s/;i=t.length-1;for(;n.test(t.charAt(i));)--i;return t.slice(0,i+1)},isFunction:function(t){return"function"==typeof t}},g=(h=null,function(){return h=h||new _});function _(){var n={};this.useOpenid=function(){return!!n.useOpenid};this.useSwanid=function(){return!!n.useSwanid};this.autoGetOpenid=function(){return!!n.autoGetOpenid};this.appKey=function(){return n.appKey};this.uploadUserInfo=function(){return n.uploadUserInfo};this.enableVerify=function(){return n.enableVerify};this.set=function(t){n=t};this.get=function(){return n};this.setItem=function(t,e){n[t]=e};this.getItem=function(t){return n[t]}}function y(){}y.prototype={on:function(t,e,n){var i=this.e||(this.e={});(i[t]||(i[t]=[])).push({fn:e,ctx:n});return this},once:function(t,e,n){var i=this;function r(){i.off(t,r);e.apply(n,arguments)}r._=e;return this.on(t,r,n)},emit:function(t){for(var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),i=0,r=n.length;i<r;i++)n[i].fn.apply(n[i].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),i=n[t],r=[];if(i&&e)for(var o=0,s=i.length;o<s;o++)i[o].fn!==e&&i[o].fn._!==e&&r.push(i[o]);r.length?n[t]=r:delete n[t];return this}};var v=new y;v.messageType={CONFIG_LOADED:0,UMA_LIB_INITED:1};var m=function(t,e){return(m=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function S(t,e){m(t,e);function n(){this.constructor=t}t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var I=function(){function t(){this._uuid="";this._userid="";this._provider="";this._idType=""}t.prototype.createUUID=function(){return l.getRandomStr(10)+Date.now()+l.getRandomStr(7)+d.UUID_SUFFIX};t.prototype.initUUID=function(e){var n=this;p.getStorage(d.UUID,function(t){if(t)n._uuid=t;else{n._uuid=n.createUUID();p.setStorage(d.UUID,n._uuid)}e&&e(t)})};t.prototype.initUserid=function(){var e=this;p.getStorage(d.USERID,function(t){if(!e._userid&&t){e._userid=t;a().v("userId is ",t)}});p.getStorage(d.PROVIDER,function(t){if(!e._provider&&t){e._provider=t;a().v("provider is ",t)}})};t.prototype.init=function(t){var e=this;e.initUUID(function(){e.initUserid();e.initID(t)})};t.prototype.setUserid=function(t,e){if(!this._userid&&t){this._userid=t;this._provider=e;p.setStorage(d.USERID,t);p.setStorage(d.PROVIDER,e)}};t.prototype.getUserId=function(){return this._userid};t.prototype.getProvider=function(){return this._provider};t.prototype.getIdType=function(){return this._idType};t.prototype.getIdTracking=function(){var t={};this._uuid&&(t.uuid=this._uuid);this._userid&&(t.userid=this._userid);return t};return t}();!function(e){S(t,e);function t(){var t=null!==e&&e.apply(this,arguments)||this;t._openid="";t._unionid="";t._useOpenid=!1;return t}t.prototype.initID=function(e){var n=this;n._idType=n._useOpenid?"openid":"uuid";a().v("id type: ",n._idType);p.getStorage(d.UNIONID,function(t){n._unionid=t});this._useOpenid?p.getStorage(d.OPENID,function(t){n._openid=t;e&&e()}):e&&e()};t.prototype.setUseOpenid=function(t){this._useOpenid=t};t.prototype.setOpenid=function(t){if(!this._openid&&t){this._openid=t;p.setStorage(d.OPENID,t)}};t.prototype.setUnionid=function(t){if(!this._unionid&&t){this._unionid=t;p.setStorage(d.UNIONID,t)}};t.prototype.getIdTracking=function(){var t=e.prototype.getIdTracking.call(this);this._openid&&(t.openid=this._openid);this._unionid&&(t.unionid=this._unionid);this._userid&&(t.userid=this._userid);return t};t.prototype.getId=function(){return this._useOpenid?this._openid:this._uuid}}(I);var A,E,O=function(e){S(t,e);function t(){var t=null!==e&&e.apply(this,arguments)||this;t._alipayid="";t._um_alipayid="";return t}t.prototype.getAlipayId=function(e){try{if(c()||u())return e(this._alipayid);f()?my.getAmapUserData({success:function(t){"function"==typeof e&&e(t.adiu)},fail:function(){a().err("no id");"function"==typeof e&&e("")}}):my.call("getOpenUserData",{},function(t){t=(t||{}).uid;t||a().err('请确保已经勾选支付宝功能包中的"友盟+数据服务"功能包!');"function"==typeof e&&e(t)})}catch(t){e("")}};t.prototype.initID=function(e){var n=this;u()||c()?n._idType="device_id":n._idType="alipay_id";p.getStorage(d.ALIPAYID,function(t){if(t){n._alipayid=t;e&&e()}else n.getAlipayId(function(t){a().v("获取到alipayid: %s",t);n._alipayid=t;p.setStorage(d.ALIPAYID,n._alipayid);e&&e()})})};t.prototype.getId=function(){return this._alipayid};t.prototype.getIdTracking=function(){var t=e.prototype.getIdTracking.call(this);if(u()||c()){this._alipayid&&(t.device_id=this._alipayid);return t}this._alipayid&&(t.alipay_id=this._alipayid);this._um_alipayid&&(t.um_alipayid=this._um_alipayid);return t};t.prototype.setAlipayUserid=function(t){this._um_alipayid=t};t.prototype.setDeviceId=function(t){t&&(this._alipayid=t)};return t}(I),T=function(){return A=A||new O},N=function(){return E=E||new R};function R(){var e=!1,n=null,i=[];this.addPageStart=function(t){if(t&&!e){n={ts:Date.now(),path:t,page_name:t};e=!0}};this.addPageEnd=function(t){if(e&&t&&n&&t===n.page_name){t=Date.now()-n.ts;n.duration=Math.abs(t);i.push(n);n=null;e=!1}};this.get=function(){return i};this.getCurrentPage=function(){return n};this.clear=function(){i.length=0}}var U={};function k(){return function(t){var e,n=[];for(e in t)"_um_ssrc"!==e&&"_um_sts"!==e&&n.push(e+"="+t[e]);return n.join("&")}(U)}var w,P,D,b=function(){return w=w||new L};function L(){return{add:function(t,e){a().v("share origin: %o",t);var n={title:t&&t.title,path:t&&t.path&&t.path.split("?")[0],_um_sts:Date.now()};n.path&&1<n.path.length&&l.startsWith(n.path,"/")&&(n.path=l.trimStart(n.path,"/"));var i=t.path||"",r=T().getId();if(r){var o=D.split(","),s=(o=o.filter(function(t){return 0<t.length})).indexOf(r);(o=0<=s?o.slice(0,s):o).length<3&&o.push(r);r=o.join(",");-1!==i.indexOf("?")?i+="&_um_ssrc="+r:i+="?_um_ssrc="+r;o=Date.now();i+="&_um_sts="+o;if(e){e=k(),e=e?e+"&_um_ssrc="+r+"&_um_sts="+o:"_um_ssrc="+r+"&_um_sts="+o;t.query=t.query?t.query+"&_um_ssrc="+r+"&_um_sts="+o:e}else t.path=i;n._um_ssrc=r;n._um_sts=o}P.push(n);a().v("share: %o",t);return t},setShareSource:function(t){D=t},clear:function(){P.length=0},get:function(){return P}}}var C,M,V,x,F={stringify:function(t){if(t)try{return JSON.stringify(t)}catch(t){}return""},parse:function(t){if(t)try{return JSON.parse(t)}catch(t){}return null},parseToArray:function(t){if(t)try{return JSON.parse(t)}catch(t){}return[]}},j=(x=!(P=[]),function(){return C=C||new q});function q(){this.load=function(e){if(V){p.removeStorage(M);e()}else{M="um_cache_"+g().appKey();p.getStorage(M,function(t){V=F.parse(t)||{};x=!0;p.removeStorage(M);e()})}};this.save=function(){V&&p.setStorage(M,F.stringify(V))};this.set=function(t,e){V&&(V[t]=e)};this.get=function(t){return(V||{})[t]};this.remove=function(t){V&&V[t]&&delete V[t]};this.getAll=function(){return V};this.clear=function(){V=null};this.has=function(t){return!!this.get(t)};this.isLoaded=function(){return x}}var H,G,Y,K,X="ekvs",B=1e4,W=(Y=[],K=[],function(){return H=H||{addEvent:function(t){if(G){Y.unshift(t);if(1<Y.length){z();Y.length=0}}else{a().w("session id is null: ",G);K.unshift(t)}},setSessionId:function(t){G=t;a().v("setSessionId: ",G);if(Array.isArray(K)&&K.length&&G){for(var e=0;e<K.length;e++)this.addEvent(K[e]);K.length=0}},getEkvs:function(){var t=j().get(X);return t=Y&&Y.length?J(t,Y):t},clear:function(){j().remove(X);Y.length=0}}});function z(){if(Y.length){var t=j().get(X);if(function(t){var e,n=0;for(e in t)Array.isArray(t[e])&&(n+=t[e].length);return n}(t)+Y.length<=B){t=J(t,Y);j().set(X,t)}}}function J(t,e){var n=(t=t||{})[G];Array.isArray(n)&&n.length?t[G]=n.concat(e):t[G]=[].concat(e);return t}var Q,Z="2g",$="3g",tt="4g",et={HALF_SESSION:"half_session",CLOSE_SESSION:"close_session",EKV:"ekv",ENTER_PAGE:"enter_page",LEAVE_PAGE:"leave_page"},nt=["access","access_subtype"],it={instance:function(){return Q=Q||rt()}};function rt(){var t=!1,i={};function e(n){var t=j().get(d.IMPRINT);t&&(i.imprint=t);i.device_type="Phone";i.sdk_version=d.IMPL_VERSION;i.appkey=g().appKey();p.getDeviceInfo(function(t){i.device_info=t||""});t=p.getAppInfoSync();i.appid=t.appId;i.app_env=t.appEnv;i.app_version=t.appVersion;p.getSystemInfo(function(e){p.getNetworkInfo(function(t){t=function(t,e){var n={};(t=t||{}).safeArea=t.safeArea||{};var i=(e=e||{}).networkType;"none"===i&&(i="unknown");var r=t.model||"",o=t.platform||"",s=t.brand||"",e=s.toLowerCase();n.sdk_type=p.getSdkType();n.platform=p.getPlatform();n.platform_sdk_version=t.platformSDKVersion;n.platform_version=t.platformVersion;n.resolution=t.resolution;n.pixel_ratio=t.pixelRatio;n.os=o;n.font_size_setting=t.fontSizeSetting;n.device_model=r;n.device_brand=s;n.device_manufacturer=e;n.device_manuid=r;n.device_name=r;n.os_version=t.OSVersion;n.language=t.language;n.theme=t.theme;n.benchmark_level=t.benchmarkLevel;n.status_bar_height=t.statusBarHeight;n.safe_area_top=t.safeArea.top;n.safe_area_left=t.safeArea.left;n.safe_area_right=t.safeArea.right;n.safe_area_bottom=t.safeArea.bottom;n.safe_area_height=t.safeArea.height;n.safe_area_width=t.safeArea.width;n.storage=t.storage;n.screen_width=t.screenWidth;n.screen_height=t.screenHeight;n.host=t.host;switch(i=i?i.toLowerCase():""){case tt:n.access_subtype="LTE";n.access="4G";break;case $:n.access_subtype="CDMA";n.access="3G";break;case Z:n.access_subtype="GRPS";n.access="2G";break;default:n.access=i;delete n.access_subtype}return n}(e,t);l.assign(i,t);n&&n()})})}return{init:function(){e(function(){t=!0})},isLoaded:function(){return t},get:function(){return i},getRealtimeFields:function(){var e={};nt.forEach(function(t){e[t]=i[t]});return e},setIdTracking:function(t){this.setItem("id_tracking",t)},setIdType:function(t){this.setItem("id_type",t)},setAppVersion:function(t){this.setItem("app_version",t)},setSuperProperty:function(t){i.sp||(i.sp={});i.sp.isv=t},getSuperProperty:function(){return i&&i.sp?i.sp.isv:""},setItem:function(t,e){i[t]=e},getItem:function(t){return i[t]}}}var ot,st,at,ut=(at=st=ot=Q=V=C=w=E=A=null,function(){return ot=ot||ct()});function ct(){return{resume:function(t){var e=!1;at=at||j().get(d.CURRENT_SESSION);var n=new Date;st=n.getTime();if(!at||!at.end_time||st-at.end_time>d.SESSION_INTERVAL){e=!0;!function(t){try{var e=(at||{}).options||{},n=l.assign({},function(t){var e,n={};for(e in t)0===e.indexOf("_um_")&&(n[e]=t[e]);a().v("query: ",t);a().v("_um_params: ",n);return n}(t.query));n.path=t.path||e.path;n.scene=t.scene?p.getPlatform()+"_"+t.scene:e.scene;e=t.referrerInfo;e&&(n.referrerAppId=e.appId);a().v("session options: ",n);e=n[d.UM_SSRC];e&&b().setShareSource(e);e=Date.now();at={id:l.getRandomStr(10)+e,start_time:e,options:n}}catch(t){a().e("生成新session失败: ",t)}}(t);a().v("开始新的session(%s): ",at.id,at)}else a().v("延续上一次session(%s): %s ",at.id,n.toLocaleTimeString(),at);return e},pause:function(){!function(){if(at){var t=new Date;at.end_time=t.getTime();"number"!=typeof at.duration&&(at.duration=0);at.duration=at.end_time-st;j().set(d.CURRENT_SESSION,at);a().v("退出会话(%s): %s ",at.id,t.toLocaleTimeString(),at)}}()},getCurrentSessionId:function(){return(at||{}).id},getCurrentSession:function(){return at},cloneCurrentSession:function(){return l.clone(at)}}}function ft(t){var e=null;switch(t){case et.HALF_SESSION:e=function(){var t=null,e=ut().cloneCurrentSession();e&&(t={header:{st:"1"},analytics:{sessions:[e]}});return t}();break;case et.CLOSE_SESSION:e=function(){var t=null,e={},n=ut().cloneCurrentSession();if(n){var i=N().get(),r=b().get();Array.isArray(i)&&i.length&&(n.pages=l.clone(i));Array.isArray(r)&&r.length&&(n.shares=l.clone(r));N().clear();b().clear();e.sessions=[n]}n=W().getEkvs();if(n){e.ekvs=l.clone(n);W().clear()}(e.sessions||e.ekvs)&&(t={analytics:e});return t}();break;case et.EKV:e=function(){var t=null,e=W().getEkvs();if(e){t={analytics:{ekvs:l.clone(e)}};W().clear()}return t}()}return e}var pt={sessions:"sn",ekvs:"e",active_user:"active_user"},dt={sdk_type:"sdt",access:"ac",access_subtype:"acs",device_model:"dm",language:"lang",device_type:"dt",device_manufacturer:"dmf",device_name:"dn",platform_version:"pv",id_type:"it",font_size_setting:"fss",os_version:"ov",device_manuid:"did",platform_sdk_version:"psv",device_brand:"db",appkey:"ak",_id:"id",id_tracking:"itr",imprint:"imp",sdk_version:"sv",resolution:"rl",testToken:"ttn",theme:"t5",benchmark_level:"bml",screen_width:"sw",screen_height:"sh",status_bar_height:"sbh",safe_area_top:"sat",safe_area_left:"sal",safe_area_right:"sar",safe_area_bottom:"sab",safe_area_height:"sah",safe_area_width:"saw",pixel_ratio:"pr",storage:"s7",host:"hs"},ht={uuid:"ud",unionid:"und",openid:"od",anonymousid:"nd",alipay_id:"ad",device_id:"dd",userid:"puid"};function lt(t){return{h:function(t,e){var n=gt(t,e);t&&t.id_tracking&&(n[e.id_tracking||"id_tracking"]=gt(t.id_tracking,ht));return n}(t.header,dt),a:function(t,e){var n={};if(t)for(var i in t)t[i]&&(n[e[i]]=t[i]);return n}(t.analytics,pt)}}function gt(t,e){var n,i={};for(n in t)e[n]?i[e[n]]=t[n]:i[n]=t[n];return i}var _t=M=D="";function yt(t){if(t.length<2)return(e=t.charCodeAt(0))<128?t:e<2048?Tt(192|e>>>6)+Tt(128|63&e):Tt(224|e>>>12&15)+Tt(128|e>>>6&63)+Tt(128|63&e);var e=65536+1024*(t.charCodeAt(0)-55296)+(t.charCodeAt(1)-56320);return Tt(240|e>>>18&7)+Tt(128|e>>>12&63)+Tt(128|e>>>6&63)+Tt(128|63&e)}function vt(t){var e=[0,2,1][t.length%3],t=t.charCodeAt(0)<<16|(1<t.length?t.charCodeAt(1):0)<<8|(2<t.length?t.charCodeAt(2):0);return[Et.charAt(t>>>18),Et.charAt(t>>>12&63),2<=e?"=":Et.charAt(t>>>6&63),1<=e?"=":Et.charAt(63&t)].join("")}function mt(t){return t.replace(Nt,yt).replace(/[\s\S]{1,3}/g,vt)}function St(t){switch(t.length){case 4:var e=((7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3))-65536;return Tt(55296+(e>>>10))+Tt(56320+(1023&e));case 3:return Tt((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return Tt((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}}function It(t){var e=t.length,n=e%4,t=(0<e?Ot[t.charAt(0)]<<18:0)|(1<e?Ot[t.charAt(1)]<<12:0)|(2<e?Ot[t.charAt(2)]<<6:0)|(3<e?Ot[t.charAt(3)]:0);(t=[Tt(t>>>16),Tt(t>>>8&255),Tt(255&t)]).length-=[0,0,2,1][n];return t.join("")}function At(t){return t.replace(/[\s\S]{1,4}/g,It).replace(Rt,St)}var Et="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ot=function(t){for(var e={},n=0,i=t.length;n<i;n++)e[t.charAt(n)]=n;return e}(Et),Tt=String.fromCharCode,Nt=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,Rt=new RegExp(["[À-ß][-¿]","[à-ï][-¿]{2}","[ð-÷][-¿]{3}"].join("|"),"g"),Ut={encode:function(t,e){return e?mt(String(t)).replace(/[+\/]/g,function(t){return"+"==t?"-":"_"}).replace(/=/g,""):mt(String(t))},decode:function(t){return At(String(t).replace(/[-_]/g,function(t){return"-"==t?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,""))}};var kt=new function(){var e="",n=this;this.set=function(t){e=t};this.get=function(){return e};this.getImpObj=function(){return F.parse(Ut.decode(e))};this.getItem=function(t){var e=n.getImpObj();return e&&e[t]||""};this.load=function(){e=j().get(d.IMPRINT)};this.save=function(){e&&j().set(d.IMPRINT,e)}};function wt(n,i,r,t){it.instance().setIdType(T().getIdType());it.instance().setIdTracking(T().getIdTracking());var e=T().getUserId();e&&n.analytics&&(n.analytics.active_user={puid:e,provider:T().getProvider()});e=l.clone(it.instance().get());n.header=l.assign(e,n.header,{ts:Date.now(),testToken:_t,traceId:l.getRandomStr(10)+Date.now()+l.getRandomStr(9)});var e=lt(n),o=F.stringify(e),e={url:d.LOG_URL,method:"POST",data:Ut.encode(o),success:function(t){var e=t.code||t.status||t.statusCode;if(200===e||413===e){a().i("数据发送成功: ",n,o);!function(t){if(t){it.instance().setItem(d.IMPRINT,t);kt.set(t);kt.save();a().v("imprint: ",kt.getImpObj());kt.getItem("ttn_invalid")&&(_t="")}}((t.data||{}).imprint);"function"==typeof i&&i(t)}else{a().w("数据发送失败: ",o);"function"==typeof r&&r()}},fail:function(t){a().w("超时: ",o);"function"==typeof r&&r()},complete:function(){"function"==typeof t&&t()}};p.request(l.assign(e,{header:{"Content-Type":e=p.getSdkType()+"/json","Msg-Type":e}}))}function Pt(t){var e=t,n=[];this.enqueue=function(t){"number"==typeof e&&this.size()>=e&&this.dequeue();n.push(t)};this.dequeue=function(){return n.shift()};this.front=function(){return n[0]};this.isEmpty=function(){return 0===n.length};this.clear=function(){n.length=0};this.size=function(){return n.length};this.items=function(){return n};this.print=function(){console.log(n.toString())}}var Dt,bt,Lt,Ct,Mt=(Dt=null,bt=!1,Lt=[],Ct=new Pt(50),function(){return Dt=Dt||new Ft});function Vt(e){var t=Ct.front();if(t)wt(t,function(){Ct.dequeue();Vt(e)},function(){var t=Ct.dequeue();t&&!t.noCache&&Lt.push(t);Vt(e)});else{!function(){Lt.forEach(function(t){Ct.enqueue(t)});Lt.length=0}();e()}}function xt(t){if(T().getId())if(bt)a().i("队列正在发送中");else{bt=!0;Vt(function(){bt=!1;"function"==typeof t&&t()})}else{a().i("获取id标识失败,暂缓发送");"function"==typeof t&&t()}}function Ft(){this.send=function(t,e,n){t?this.add(t,e,function(){xt(n)}):xt(n)};this.add=function(t,e,n){!function t(e,n,i){if(it.instance().isLoaded()){n=n||{};var r=ft(e);if(r){var o=it.instance().getRealtimeFields();r.header=l.assign({},r.header,o);r.noCache=n.noCache;Ct.enqueue(r)}"function"==typeof i&&i()}else setTimeout(function(){t(e,n,i)},100)}(t,e,n)};this.load=function(){var t=j().get(d.REQUESTS);t&&t.length&&t.forEach(function(t){Ct.enqueue(t)});j().remove(d.REQUESTS)};this.save=function(){j().set(d.REQUESTS,l.clone(Ct.items()));Ct.clear()}}var jt,qt=(jt=null,function(){return jt=jt||new Ht});function Ht(){this.update=function(){p.getUserInfo(function(e){if(e){var t=j().get(d.USER_INFO);t&&l.deepEqual(e,t)||function(e,n){var t=g().appKey(),i=p.getSdkType(),r=T().getId(),o=T().getIdType();if(!(t&&i&&r&&o))return;o={ak:g().appKey(),sdt:p.getSdkType(),uin:e.nickName,uia:e.avatar,uig:e.gender,uit:e.country,uip:e.province,uic:e.city,uil:e.language,id:T().getId(),it:T().getIdType()},o=JSON.stringify(o);o=Ut.encode(o);p.request({url:d.USERINFO_URL,method:"POST",header:{"content-type":"application/x-www-form-urlencoded"},data:"ui="+o,success:function(t){a().v("用户信息上传成功: ",e);n&&n(t&&t.data&&200===t.data.code)},fail:function(){a().e("用户信息上传失败: ",e);n&&n(!1)}})}(e,function(t){t&&j().set(d.USER_INFO,e)})}})}}function Gt(t,e){this.id=t;this.ts=Date.now();var n=typeof e;if("string"==n&&e)this[t]=e;else if("object"==n)for(var i in e)!{}.hasOwnProperty.call(e,i)||(this[i]=e[i])}function Yt(){var r=!1,n=!1,o=0;this.init=function(t){a().v("sdk version: "+d.IMPL_VERSION);r?a().v("Lib重复实例化"):j().load(function(){a().v("cache初始化成功: ",j().getAll());!function(){T().setUseOpenid&&T().setUseOpenid(g().useOpenid());T().init(function(){it.instance().init();a().v("Header初始化成功")})}();r=!0;"function"==typeof t&&t();a().tip("SDK集成成功")})};this.resume=function(t){if(r&&!n){a().v("showOptions: ",t);var e;n=!0;g().enableVerify()&&t&&t.query&&(e=t.query._ttn,_t=e||_t);this._resume(t)}};this._resume=function(t){Mt().load();var e=ut().resume(t),t=ut().getCurrentSessionId();W().setSessionId(t);e&&Mt().add(et.HALF_SESSION,{},function(){T().setUseOpenid&&T().setUseOpenid(g().useOpenid());if(g().useOpenid()&&g().autoGetOpenid()&&!T().getId()){a().v("get id async");!function e(n,i){if(T().getId()||n<=0)return;T().getOpenIdAsync(g().appKey(),function(t){if(t){a().v("获取id成功");Mt().send()}else{a().v("获取openid失败,启动重试,剩余可用次数",n-1);setTimeout(function(){e(n-1,i)},i)}})}(10,3e3)}else{a().v("session auto send");Mt().send()}})};this.pause=function(t){if(r){n=!1;o=0;ut().pause();g().uploadUserInfo()&&qt().update();Mt().send(et.CLOSE_SESSION,{},function(){Mt().save();j().save();a().v("cache save success");"function"==typeof t&&t()})}};this.setOpenid=function(t){a().v("setOpenId: %s",t);T().setOpenid(t);Mt().send()};this.setUnionid=function(t){a().v("setUnionid: %s",t);T().setUnionid(t)};this.setUserid=function(t,e){a().v("setUserid: %s",t,e);T().setUserid(t,e)};this.setAnonymousid=function(t){a().v("setAnonymousId: %s",t);T().setAnonymousid(t);Mt().send()};this.setAppVersion=function(t){t&&"string"!=typeof t?a().w("setAppVersion方法只接受字符串类型参数"):it.instance().setAppVersion(t)};this.setAlipayUserid=function(t){if(t&&"string"!=typeof t)a().w("setAlipayUserid方法只接受字符串类型参数");else{a().v("setAlipayUserid: %s",t);T().setAlipayUserid(t)}};this.setDeviceId=function(t){if("string"==typeof t){T().setDeviceId(t);return t}};this.setSuperProperty=function(t){if(t&&"string"!=typeof t)a().w("超级属性只支持字符串类型");else{var e=this;if(it.instance().getSuperProperty()!==t){it.instance().setSuperProperty(t);e.pause(function(){e.resume()})}}};this.trackEvent=function(t,e){if(r){a().v("event: ",t,e);if(function(t,e){if(t&&"string"==typeof t){var n=["id","ts","du"],i={};n.forEach(function(t){i[t]=1});if(i[t])a().e("eventId不能与以下保留字冲突: "+n.join(","));else if(t.length>d.MAX_EVENTID_LENGTH)a().e("The maximum length of event id shall not exceed "+d.MAX_EVENTID_LENGTH);else{if(!e||"object"==typeof e&&!Array.isArray(e)||"string"==typeof e){if("object"==typeof e){var r,o=0;for(r in e)if({}.hasOwnProperty.call(e,r)){if(r.length>d.MAX_PROPERTY_KEY_LENGTH){a().e("The maximum length of property key shall not exceed "+d.MAX_PROPERTY_KEY_LENGTH);return}if(o>=d.MAX_PROPERTY_KEYS_COUNT){a().e("The maximum count of properties shall not exceed "+d.MAX_PROPERTY_KEYS_COUNT);return}if(i[r]){a().e("属性中的key不能与以下保留字冲突: "+n.join(","));return}o+=1}}return 1}a().e("please check trackEvent properties. properties should be string or object(not include Array)")}}else a().e('please check trackEvent id. id should be "string" and not null')}(t,e)){var n=new Gt(t,e);W().addEvent(n);var i=!!_t,t=i?0:d.EVENT_SEND_DEFAULT_INTERVAL,e=Date.now();if(n=e,t=t,"number"!=typeof o||"number"!=typeof t||(o<=0||t<n-o)){o=e;Mt().send(et.EKV,{noCache:i},function(){})}}}};this.trackShare=function(t){if(r){try{if(-1<p.getSdkType().indexOf("game")){t=b().add(t,!0);a().v("shareQuery: ",t)}else{t=b().add(t,!1);a().v("sharePath: ",t.path)}}catch(t){a().v("shareAppMessage: ",t)}return t}};this.trackPageStart=function(t){r&&N().addPageStart(t)};this.trackPageEnd=function(t){r&&N().addPageEnd(t)};this.onShareAppMessage=function(t){var e=this;p.onShareAppMessage(function(){return e.trackShare(t())})};this.shareAppMessage=function(t){this.trackShare(t);p.shareAppMessage(t)}}var Kt=[];function Xt(){}Xt.prototype={createMethod:function(t,e,n){try{t[e]=n&&n[e]?function(){return n[e].apply(n,arguments)}:function(){Kt.push([e,[].slice.call(arguments)])}}catch(t){a().v("create method errror: ",t)}},installApi:function(t,e){try{for(var n="resume,pause,trackEvent,trackPageStart,trackPageEnd,trackShare,setUserid,setAppVersion,setAlipayUserid,setSuperProperty,setDeviceId".split(","),i=0,r=n.length;i<r;i++)this.createMethod(t,n[i],e);if(e)for(i=0,r=Kt.length;i<r;i++){var o=Kt[i];try{e[o[0]].apply(e,o[1])}catch(t){a().v("impl[v[0]].apply error: ",o[0],t)}}}catch(t){a().v("install api errror: ",t)}}};var Bt=["https://umini.shujupie.com","https://ulogs.umeng.com"],Wt=0;function zt(e,t){if(e>=Bt.length||t){t&&function(){var t="https://umini.shujupie.com";d.LOG_URL=d.LOG_URL.replace(t,Bt[Wt]);d.GET_OPENID_URL=d.GET_OPENID_URL.replace(t,Bt[Wt]);d.USERINFO_URL=d.USERINFO_URL.replace(t,Bt[Wt])}();t&&a().v("命中可用服务",Bt[Wt]);t||a().tip_w("未命中可用服务")}else p.request({url:Bt[e]+"/uminiprogram_logs/ckdh",success:function(t){200===(t.code||t.status||t.statusCode)&&t.data&&200===t.data.code?zt((Wt=e)+1,!0):zt(e+1,!1)},fail:function(){zt(e+1,!1)}})}({init:function(t){setTimeout(function(){zt(0,!1)},t)}}).init(3e3);var Jt=new Xt,Qt={_inited:!1,_log:a(),use:function(t,e){t&&l.isFunction(t.install)?t.install(Qt,e):l.isFunction(t)&&t(Qt,e);return Qt},messager:v,init:function(t){if(this._inited)a().v("已经实例过,请避免重复初始化");else if(t)if(t.appKey){"boolean"!=typeof t.useOpenid&&(t.useOpenid=!0);g().set(t);a().setDebug(t.debug);this._inited=!0;var e=this;v.emit(v.messageType.CONFIG_LOADED,t);try{var n=new Yt;a().v("成功创建Lib对象");n.init(function(){a().v("Lib对象初始化成功");Jt.installApi(e,n);a().v("安装Lib接口成功");v.emit(v.messageType.UMA_LIB_INITED,t)})}catch(t){a().w("创建Lib对象异常: "+t)}}else a().err("请确保传入正确的appkey");else a().err("请正确设置相关信息!")}};try{Jt.installApi(Qt,null)}catch(t){a().w("uma赋值异常: ",t)}var Zt="",$t={};function te(t){t&&(Zt=t)}function ee(){return function(t,e){if(!t)return"";var n,i=[];for(n in e)"_um_ssrc"!==n&&"_um_sts"!==n&&i.push(n+"="+e[n]);var r=i.join("&");return r?t+"?"+r:t}(Zt,$t[Zt])}function ne(t,n){if(t.onShareAppMessage){var i=t.onShareAppMessage;t.onShareAppMessage=function(t){var e=i.call(this,t)||{},t=ee();!e.path&&t&&(e.path=t);return n.trackShare.call(this,e)}}}var ie={};function re(t,e,n){var i=t[e];t[e]=function(t){n.call(this,t);i&&i.call(this,t)}}function oe(t){try{ie=t?l.clone(t):{};a().v("App onShow: ",t,ie)}catch(t){a().v("onAppShow: ",t)}}function se(){try{Qt.pause()}catch(t){a().v("onAppHide: ",t)}}function ae(t){try{te(this.route);t&&(e=this.route,n=t,e&&($t[e]=n));if(t){ie.query=ie.query||{};l.assign(ie.query,t)}a().v("Page onLoad: ",t,ie)}catch(t){a().v("onPageLoad: ",t)}var e,n}function ue(){try{te(this.route);Qt.resume(ie);Qt.trackPageStart(this.route)}catch(t){a().v("onPageShow: ",t)}}function ce(){try{Qt.trackPageEnd(this.route)}catch(t){a().v("onPageHide: ",t)}}try{var fe=App;App=function(t){re(t,"onLaunch",function(){!function(e){try{p.getSystemInfo(function(t){t&&t.version&&"alipay"===t.app&&l.compareVersion(t.version,d.ALIPAY_AVAILABLE_VERSION)<0?a().err("只支持版本号大于等于10.1.52的支付宝客户端!"):Qt.init(e)})}catch(t){a().v("onAppLaunch: ",t)}}(t.umengConfig)});re(t,"onShow",oe);re(t,"onHide",se);ne(t,Qt);fe(t)}}catch(t){a().w("App重写异常")}try{var pe=Page;Page=function(t){re(t,"onShow",ue);re(t,"onHide",ce);re(t,"onUnload",ce);re(t,"onLoad",ae);ne(t,Qt);pe(t)}}catch(t){a().w("Page重写异常")}my.uma=Qt;module.exports=Qt;