@anka-dev/tracker
Advanced tools
Comparing version 0.3.0 to 0.3.1
/** | ||
* @anka-dev/tracker. | ||
* V0.2.0 | ||
* Fri Sep 28 2018 16:58:51 GMT+0800 (CST) | ||
* V0.3.1 | ||
* Tue Oct 09 2018 15:27:35 GMT+0800 (CST) | ||
* https://github.com/iException/anka-tracker#readme | ||
@@ -9,3 +9,3 @@ * MIT License | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Tracker={})}(this,function(t){"use strict";function e(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function n(t,e,n,r){var o,i=arguments.length,a=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(i<3?o(a):i>3?o(e,n,a):o(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}function r(t){return new Promise(function(e,n){wx.request(l({},t,{success:function(t){t.statusCode>=200&&t.statusCode<300?e&&e(t.data):n&&n(t.data)},fail:function(t){n&&n(t)}}))})}function o(t){return new Promise(function(e,n){wx.setStorage(l({},t,{success:function(t){e(t)},fail:function(t){n(t)}}))})}function i(t){return new Promise(function(e,n){wx.getStorage({key:t,success:function(t){e(t.data)},fail:function(t){n(t)}})})}function a(){return new Promise(function(t,e){wx.getSystemInfo({success:function(e){t(e)},fail:function(t){e(t)}})})}function c(){return new Promise(function(t,e){wx.getNetworkType({success:function(e){t(e.networkType)},fail:function(t){e(t)}})})}function s(t){wx.onNetworkStatusChange(function(e){t(e.networkType)})}function u(t,e,n){var r=t[e];t[e]=function(t){return n.call(this,t),r&&r.call(this,t)}}function p(){return function(t,e,n){return n.writable=!1,n}}const l=Object.assign||function(t){for(var e,n=1;n<arguments.length;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t};var f,h=function(){function t(t){this.data=[],this.config=t}return t.prototype.get=function(){return i("tracker_tasks").then(function(t){return Promise.resolve(t)}).catch(function(t){return Promise.resolve([])})},t.prototype.update=function(t){return this.data=t,o({key:"tracker_tasks",data:t})},t}(),d={DEBUG:!0,log:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.DEBUG&&console.log.apply(console,["%c[🔍 tracker]","color:rgba(118,147,92,1);"].concat(t))}},y=Object.prototype.hasOwnProperty,g=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}(),m=function(t){for(var e;t.length;){var n=t.pop();if(e=n.obj[n.prop],Array.isArray(e)){for(var r=[],o=0;o<e.length;++o)void 0!==e[o]&&r.push(e[o]);n.obj[n.prop]=r}}return e},v=function(t,e){for(var n=e&&e.plainObjects?Object.create(null):{},r=0;r<t.length;++r)void 0!==t[r]&&(n[r]=t[r]);return n},w={arrayToObject:v,assign:function(t,e){return Object.keys(e).reduce(function(t,n){return t[n]=e[n],t},t)},compact:function(t){for(var e=[{obj:{o:t},prop:"o"}],n=[],r=0;r<e.length;++r)for(var o=e[r],i=o.obj[o.prop],a=Object.keys(i),c=0;c<a.length;++c){var s=a[c],u=i[s];"object"==typeof u&&null!==u&&-1===n.indexOf(u)&&(e.push({obj:i,prop:s}),n.push(u))}return m(e)},decode:function(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(e){return t}},encode:function(t){if(0===t.length)return t;for(var e="string"==typeof t?t:String(t),n="",r=0;r<e.length;++r){var o=e.charCodeAt(r);45===o||46===o||95===o||126===o||o>=48&&o<=57||o>=65&&o<=90||o>=97&&o<=122?n+=e.charAt(r):o<128?n+=g[o]:o<2048?n+=g[192|o>>6]+g[128|63&o]:o<55296||o>=57344?n+=g[224|o>>12]+g[128|o>>6&63]+g[128|63&o]:(r+=1,o=65536+((1023&o)<<10|1023&e.charCodeAt(r)),n+=g[240|o>>18]+g[128|o>>12&63]+g[128|o>>6&63]+g[128|63&o])}return n},isBuffer:function(t){return null!==t&&void 0!==t&&!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},merge:function t(e,n,r){if(!n)return e;if("object"!=typeof n){if(Array.isArray(e))e.push(n);else{if("object"!=typeof e)return[e,n];(r.plainObjects||r.allowPrototypes||!y.call(Object.prototype,n))&&(e[n]=!0)}return e}if("object"!=typeof e)return[e].concat(n);var o=e;return Array.isArray(e)&&!Array.isArray(n)&&(o=v(e,r)),Array.isArray(e)&&Array.isArray(n)?(n.forEach(function(n,o){y.call(e,o)?e[o]&&"object"==typeof e[o]?e[o]=t(e[o],n,r):e.push(n):e[o]=n}),e):Object.keys(n).reduce(function(e,o){var i=n[o];return y.call(e,o)?e[o]=t(e[o],i,r):e[o]=i,e},o)}},b=String.prototype.replace,k={default:"RFC3986",formatters:{RFC1738:function(t){return b.call(t,/%20/g,"+")},RFC3986:function(t){return t}},RFC1738:"RFC1738",RFC3986:"RFC3986"},O={brackets:function(t){return t+"[]"},indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},P=Date.prototype.toISOString,S={delimiter:"&",encode:!0,encoder:w.encode,encodeValuesOnly:!1,serializeDate:function(t){return P.call(t)},skipNulls:!1,strictNullHandling:!1},_=function t(e,n,r,o,i,a,c,s,u,p,l,f){var h=e;if("function"==typeof c)h=c(n,h);else if(h instanceof Date)h=p(h);else if(null===h){if(o)return a&&!f?a(n,S.encoder):n;h=""}if("string"==typeof h||"number"==typeof h||"boolean"==typeof h||w.isBuffer(h))return a?[l(f?n:a(n,S.encoder))+"="+l(a(h,S.encoder))]:[l(n)+"="+l(String(h))];var d=[];if(void 0===h)return d;var y;if(Array.isArray(c))y=c;else{var g=Object.keys(h);y=s?g.sort(s):g}for(var m=0;m<y.length;++m){var v=y[m];i&&null===h[v]||(d=Array.isArray(h)?d.concat(t(h[v],r(n,v),r,o,i,a,c,s,u,p,l,f)):d.concat(t(h[v],n+(u?"."+v:"["+v+"]"),r,o,i,a,c,s,u,p,l,f)))}return d},j=function(t,e){var n=t,r=e?w.assign({},e):{};if(null!==r.encoder&&void 0!==r.encoder&&"function"!=typeof r.encoder)throw new TypeError("Encoder has to be a function.");var o=void 0===r.delimiter?S.delimiter:r.delimiter,i="boolean"==typeof r.strictNullHandling?r.strictNullHandling:S.strictNullHandling,a="boolean"==typeof r.skipNulls?r.skipNulls:S.skipNulls,c="boolean"==typeof r.encode?r.encode:S.encode,s="function"==typeof r.encoder?r.encoder:S.encoder,u="function"==typeof r.sort?r.sort:null,p=void 0!==r.allowDots&&r.allowDots,l="function"==typeof r.serializeDate?r.serializeDate:S.serializeDate,f="boolean"==typeof r.encodeValuesOnly?r.encodeValuesOnly:S.encodeValuesOnly;if(void 0===r.format)r.format=k.default;else if(!Object.prototype.hasOwnProperty.call(k.formatters,r.format))throw new TypeError("Unknown format option provided.");var h,d,y=k.formatters[r.format];"function"==typeof r.filter?n=(d=r.filter)("",n):Array.isArray(r.filter)&&(h=d=r.filter);var g=[];if("object"!=typeof n||null===n)return"";var m;m=r.arrayFormat in O?r.arrayFormat:"indices"in r?r.indices?"indices":"repeat":"indices";var v=O[m];h||(h=Object.keys(n)),u&&h.sort(u);for(var b=0;b<h.length;++b){var P=h[b];a&&null===n[P]||(g=g.concat(_(n[P],P,v,i,a,c?s:null,d,u,p,l,y,f)))}var j=g.join(o),D=!0===r.addQueryPrefix?"?":"";return j.length>0?D+j:""},D=Object.prototype.hasOwnProperty,N={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:w.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},C=function(t,e){for(var n={},r=e.ignoreQueryPrefix?t.replace(/^\?/,""):t,o=e.parameterLimit===1/0?void 0:e.parameterLimit,i=r.split(e.delimiter,o),a=0;a<i.length;++a){var c,s,u=i[a],p=u.indexOf("]="),l=-1===p?u.indexOf("="):p+1;-1===l?(c=e.decoder(u,N.decoder),s=e.strictNullHandling?null:""):(c=e.decoder(u.slice(0,l),N.decoder),s=e.decoder(u.slice(l+1),N.decoder)),D.call(n,c)?n[c]=[].concat(n[c]).concat(s):n[c]=s}return n},A=function(t,e,n){for(var r=e,o=t.length-1;o>=0;--o){var i,a=t[o];if("[]"===a)i=(i=[]).concat(r);else{i=n.plainObjects?Object.create(null):{};var c="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,s=parseInt(c,10);!isNaN(s)&&a!==c&&String(s)===c&&s>=0&&n.parseArrays&&s<=n.arrayLimit?(i=[])[s]=r:i[c]=r}r=i}return r},I=function(t,e,n){if(t){var r=n.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,i=/(\[[^[\]]*])/.exec(r),a=i?r.slice(0,i.index):r,c=[];if(a){if(!n.plainObjects&&D.call(Object.prototype,a)&&!n.allowPrototypes)return;c.push(a)}for(var s=0;null!==(i=o.exec(r))&&s<n.depth;){if(s+=1,!n.plainObjects&&D.call(Object.prototype,i[1].slice(1,-1))&&!n.allowPrototypes)return;c.push(i[1])}return i&&c.push("["+r.slice(i.index)+"]"),A(c,e,n)}},x={formats:k,parse:function(t,e){var n=e?w.assign({},e):{};if(null!==n.decoder&&void 0!==n.decoder&&"function"!=typeof n.decoder)throw new TypeError("Decoder has to be a function.");if(n.ignoreQueryPrefix=!0===n.ignoreQueryPrefix,n.delimiter="string"==typeof n.delimiter||w.isRegExp(n.delimiter)?n.delimiter:N.delimiter,n.depth="number"==typeof n.depth?n.depth:N.depth,n.arrayLimit="number"==typeof n.arrayLimit?n.arrayLimit:N.arrayLimit,n.parseArrays=!1!==n.parseArrays,n.decoder="function"==typeof n.decoder?n.decoder:N.decoder,n.allowDots="boolean"==typeof n.allowDots?n.allowDots:N.allowDots,n.plainObjects="boolean"==typeof n.plainObjects?n.plainObjects:N.plainObjects,n.allowPrototypes="boolean"==typeof n.allowPrototypes?n.allowPrototypes:N.allowPrototypes,n.parameterLimit="number"==typeof n.parameterLimit?n.parameterLimit:N.parameterLimit,n.strictNullHandling="boolean"==typeof n.strictNullHandling?n.strictNullHandling:N.strictNullHandling,""===t||null===t||void 0===t)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof t?C(t,n):t,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),a=0;a<i.length;++a){var c=i[a],s=I(c,r[c],n);o=w.merge(o,s,n)}return w.compact(o)},stringify:j},E=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getCommonData=function(t){var e=this,n=t.onLaunchOption,r=void 0===n?{}:n;return Promise.all([this.getTrackId(),a(),c()]).then(function(t){var n=t[0],o=t[1],i=t[2],a=o.system.split(/\s+/),c=x.stringify(r.query),s={__debug:1,sdk_version:"0.2.0",model:o.model,os:a[0],os_version:a[1],network_type:i,env_version:o.version,ip:"",app_type:"wx",app_id:"",app_name:"",template_version:"",app_category:"",source:r.scene,source_path:r.path,source_app_id:r.referrerInfo?r.referrerInfo.appId||"":"",source_params:c,source_src_key:r.query?r.query[e.config.sourceSrcKey]||"":"",track_id:n};return Promise.resolve(s)})},n.prototype.getTrackId=function(){var t=this;return i(this.config.trackIdKey).then(function(t){return Promise.resolve(t)}).catch(function(e){return t.setTrackId()})},n.prototype.setTrackId=function(){var t=this,e=this.genUUId();return o({key:this.config.trackIdKey,data:e}).then(function(){return Promise.resolve(e)},function(){return o({key:t.config.trackIdKey,data:e}),Promise.resolve(e)})},n.prototype.genUUId=function(){return Date.now()+"-"+Math.floor(1e7*Math.random())+"-"+Math.random().toString(16).replace(".","")+"-"+String(31242*Math.random()).replace(".","").slice(0,8)},n}(function(){function t(t){this.config=t}return t.validate=function(t,e){var n={required:[],optional:[]};for(var r in e)e.hasOwnProperty(r)&&!t[r]&&n[1===e[r]?"required":"optional"].push(r);return n},t}()),L=function(){function t(t,e){this.url=t.trackerHost,this.config=t,this.commonData=e}return t.prototype.send=function(t){var e=this.url,n=l({},this.commonData,t.data);if(this.config.attachActionToUrl){var o=n.action||"";e=/\/$/.test(this.url)?""+this.url+o:this.url+"/"+o}return"function"==typeof this.config.beforeSend&&(n=this.config.beforeSend(n)),d.log("打点数据校验结果:",t,E.validate(n,this.config.dataScheme)),r({url:e,method:this.config.httpMethod,data:n}).then(function(){return t.isSucceed(),Promise.resolve(t)}).catch(function(){return t.isFailed(),Promise.resolve(t)})},t}(),U=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getNetworkStatus=function(){return c().then(function(t){return Promise.resolve(t)},function(t){return console.error("[tracker] 获取网络状态失败",t),Promise.resolve("none")})},n.prototype.watchNetworkStatusChange=function(t){s(t)},n}(function(){function t(t){this.config=t}return t}());!function(t){t[t.SUCCESS=-1]="SUCCESS",t[t.PENDING=0]="PENDING",t[t.FAILED=1]="FAILED"}(f||(f={}));var q,M=function(){function t(t){var e=Date.now();this._id=Math.random().toString(16).replace(".",""),this.status=f.PENDING,this.data=t,this.timestamp=e}return t.prototype.isSucceed=function(){this.status=f.SUCCESS},t.prototype.isFailed=function(){this.status++},t}();!function(t){t[t.IDLE=0]="IDLE",t[t.PAUSE=1]="PAUSE",t[t.RUNNING=2]="RUNNING"}(q||(q={}));var T=function(){function t(t){this.queue=[],this.failedQueue=[],this.config=t,this.lastStoreUpdate=0,this.executor=new R}return t.prototype.init=function(t){var e=this;this.sender||(this.store=t.store,this.sender=t.sender,this.executor.init(this.sender,this),this.store.get().then(function(t){var n;(n=e.queue).push.apply(n,t.map(function(t){return new M(t.data)})),e.run()}))},t.prototype.push=function(t){t.status===f.PENDING&&this.queue.length<this.config.queueMaxLength?(this.queue.push(t),this.updateStore(),this.run()):t.status>=f.FAILED&&t.status<=this.config.retry&&(this.failedQueue.push(t),this.updateStore(),this.run())},t.prototype.pop=function(){var t=this.failedQueue.length,e=this.config.groupMaxLength,n=t-e>=0?this.failedQueue.splice(0,e):this.failedQueue.splice(0,t).concat(this.queue.splice(0,e-t));return this.updateStore(),n},t.prototype.updateStore=function(t){var e=Date.now();(this.store&&e-this.lastStoreUpdate>=500||t&&this.store)&&(this.store.update(this.queue.concat(this.failedQueue)),this.lastStoreUpdate=e)},t.prototype.run=function(){setTimeout(this.executor.run.bind(this.executor),0)},t.prototype.suspend=function(t){this.updateStore(!0),this.executor.suspend(t)},t}(),R=function(){function t(){this.status=q.IDLE}return Object.defineProperty(t.prototype,"isIdle",{get:function(){return this.sender&&this.queueManager&&this.status===q.IDLE},enumerable:!0,configurable:!0}),t.prototype.init=function(t,e){this.sender=t,this.queueManager=e},t.prototype.run=function(){this.isIdle&&this.exec()},t.prototype.exec=function(){var t=this,e=this.queueManager.pop();if(!e.length)return void(this.status=q.IDLE);this.status=q.RUNNING,Promise.all(e.map(function(e){return t.sender.send(e)})).then(function(e){e.forEach(function(e){e.status!==f.SUCCESS&&t.queueManager.push(e)})}).then(function(){t.timer=setTimeout(function(){t.exec()},t.queueManager.config.interval)})},t.prototype.suspend=function(t){t?(this.status=q.PAUSE,clearTimeout(this.timer)):this.status===q.PAUSE?(this.status=q.IDLE,this.run()):this.status===q.IDLE&&this.run()},t}(),F=function(){function t(t){this.config=t,this.queueManager=new T(this.config)}return t.prototype.init=function(t){this.queueManager.init(l({},t))},t.prototype.log=function(t){this.queueManager.push(t)},t}(),H={debug:!0,httpMethod:"POST",retry:2,interval:1e3,groupMaxLength:5,timestampKey:"timestamp_ms",trackIdKey:"__track_id",queueMaxLength:500,commonData:{},dataScheme:{},sourceSrcKey:"src",detectChanel:!0,detectAppStart:!0,attachActionToUrl:!1},G=function(){function t(t){void 0===t&&(t={}),Object.assign(this,H,t)}return t}(),Q=function(){function t(t){void 0===t&&(t={}),this.config=new G(t),this.core=new F(this.config),d.DEBUG=this.config.debug,this.core.queueManager.suspend(!0),this.networkDetector=new U(this.config),this.commonDataVendor=new E(this.config)}return t.prototype.init=function(t){if(!this.sender){var e=this.handleNetworkStatusChange.bind(this);this.sender=new L(this.config,t),this.store=new h(this.config),this.core.init({sender:this.sender,store:this.store}),this.networkDetector.getNetworkStatus().then(e,e),this.networkDetector.watchNetworkStatusChange(e),d.log("初始化完成")}},t.prototype.handleNetworkStatusChange=function(t){var e="none"===t||t instanceof Error;this.core.queueManager.suspend(e)},t.prototype.log=function(t){var e=Date.now();t[this.config.timestampKey]=e,this.core.log(new M(t))},n([p()],t.prototype,"init",null),n([p()],t.prototype,"handleNetworkStatusChange",null),n([p()],t.prototype,"log",null),t}(),K=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return e(r,t),r.generateTrackerInstance=function(){var t={};try{t=require("./anka-tracker.config.js")}catch(t){console.log("anka-tracker 缺少配置文件",t)}var e=new r(t);if(void 0===typeof App||void 0===typeof Page){var n=App,o=Page;App=function(t){return u(t,"onLaunch",function(t){e.onLaunchOption=t,e.config.detectChanel&&e.detectChanel(t.query[e.config.sourceSrcKey])}),e.config.detectAppStart&&u(t,"onShow",function(t){e.evt("app_start",{})}),n(t)},Page=function(t){return u(t,"onLoad",function(t){this.__page_params__=t}),"function"==typeof e.config.autoPageView&&u(t,"onShow",function(){var t=getCurrentPages().slice().pop();e.config.autoPageView(t,function(n){e.pv(n.action,n,{page_id:t.route,page_url:t.route,page_params:x.stringify(t.__page_params__)})})}),o(t)}}return e},r.prototype.asyncInitWithCommonData=function(t){var e=this;return void 0===t&&(t={}),this.commonDataVendor.getCommonData({onLaunchOption:this.onLaunchOption}).then(function(n){e.init(Object.assign(n,e.config.commonData,t))}).catch(function(t){d.log("初始化失败"),console.log(t)})},r.prototype.detectChanel=function(t){if(t){var e={};t.split(/_+/).forEach(function(t,n){e["source_src_key_"+(n+1)]=t}),this.evt("channel",e)}},r.prototype.composeCommonData=function(t){var e=[];return t.map(function(t){"function"==typeof t?e.push(new Promise(function(e){t(e)})):e.push(Promise.resolve(t))}),Promise.all(e).then(function(t){return Promise.resolve(Object.assign.apply(Object,[{}].concat(t)))})},r.prototype.track=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];this.composeCommonData(e).then(function(e){return t.log(e)})},r.prototype.evt=function(t){void 0===t&&(t="");for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(!t)throw new Error("缺少 action 参数");this.track.apply(this,e.concat([{action:t,tracktype:"event"}]))},r.prototype.pv=function(t){var e=this;void 0===t&&(t="");for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];this.composeCommonData(n).then(function(n){e.log(Object.assign(n,e.genLastPageUrl(n),{action:t,tracktype:"pageview"}))})},r.prototype.genLastPageUrl=function(t){var e=this,n=e.last_page_id,r=void 0===n?"":n,o=e.last_page_url,i=void 0===o?"":o;return this.last_page_url=t.page_url||"",this.last_page_id=t.page_id||"",{last_page_id:r,last_page_url:i}},n([p()],r.prototype,"asyncInitWithCommonData",null),n([p()],r.prototype,"detectChanel",null),n([p()],r.prototype,"composeCommonData",null),n([p()],r.prototype,"track",null),n([p()],r.prototype,"evt",null),n([p()],r.prototype,"pv",null),n([p()],r.prototype,"genLastPageUrl",null),r}(Q),B=K.generateTrackerInstance();t.Tracker=Q,t.BxTracker=K,t.tracker=B,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Tracker={})}(this,function(t){"use strict";function e(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function n(t,e,n,r){var o,i=arguments.length,a=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(i<3?o(a):i>3?o(e,n,a):o(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}function r(t){return new Promise(function(e,n){wx.request(l({},t,{success:function(t){t.statusCode>=200&&t.statusCode<300?e&&e(t.data):n&&n(t.data)},fail:function(t){n&&n(t)}}))})}function o(t){return new Promise(function(e,n){wx.setStorage(l({},t,{success:function(t){e(t)},fail:function(t){n(t)}}))})}function i(t){return new Promise(function(e,n){wx.getStorage({key:t,success:function(t){e(t.data)},fail:function(t){n(t)}})})}function a(){return new Promise(function(t,e){wx.getSystemInfo({success:function(e){t(e)},fail:function(t){e(t)}})})}function c(){return new Promise(function(t,e){wx.getNetworkType({success:function(e){t(e.networkType)},fail:function(t){e(t)}})})}function s(t){wx.onNetworkStatusChange(function(e){t(e.networkType)})}function u(t,e,n){var r=t[e];t[e]=function(t){return n.call(this,t),r&&r.call(this,t)}}function p(){return function(t,e,n){return n.writable=!1,n}}const l=Object.assign||function(t){for(var e,n=1;n<arguments.length;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t};var f,h=function(){function t(t){this.data=[],this.config=t}return t.prototype.get=function(){return i("tracker_tasks").then(function(t){return Promise.resolve(t)}).catch(function(t){return Promise.resolve([])})},t.prototype.update=function(t){return this.data=t,o({key:"tracker_tasks",data:t})},t}(),d={DEBUG:!0,log:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.DEBUG&&console.log.apply(console,["%c[🔍 tracker]","color:rgba(118,147,92,1);"].concat(t))}},y=Object.prototype.hasOwnProperty,g=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}(),m=function(t){for(var e;t.length;){var n=t.pop();if(e=n.obj[n.prop],Array.isArray(e)){for(var r=[],o=0;o<e.length;++o)void 0!==e[o]&&r.push(e[o]);n.obj[n.prop]=r}}return e},v=function(t,e){for(var n=e&&e.plainObjects?Object.create(null):{},r=0;r<t.length;++r)void 0!==t[r]&&(n[r]=t[r]);return n},b={arrayToObject:v,assign:function(t,e){return Object.keys(e).reduce(function(t,n){return t[n]=e[n],t},t)},compact:function(t){for(var e=[{obj:{o:t},prop:"o"}],n=[],r=0;r<e.length;++r)for(var o=e[r],i=o.obj[o.prop],a=Object.keys(i),c=0;c<a.length;++c){var s=a[c],u=i[s];"object"==typeof u&&null!==u&&-1===n.indexOf(u)&&(e.push({obj:i,prop:s}),n.push(u))}return m(e)},decode:function(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(e){return t}},encode:function(t){if(0===t.length)return t;for(var e="string"==typeof t?t:String(t),n="",r=0;r<e.length;++r){var o=e.charCodeAt(r);45===o||46===o||95===o||126===o||o>=48&&o<=57||o>=65&&o<=90||o>=97&&o<=122?n+=e.charAt(r):o<128?n+=g[o]:o<2048?n+=g[192|o>>6]+g[128|63&o]:o<55296||o>=57344?n+=g[224|o>>12]+g[128|o>>6&63]+g[128|63&o]:(r+=1,o=65536+((1023&o)<<10|1023&e.charCodeAt(r)),n+=g[240|o>>18]+g[128|o>>12&63]+g[128|o>>6&63]+g[128|63&o])}return n},isBuffer:function(t){return null!==t&&void 0!==t&&!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},merge:function t(e,n,r){if(!n)return e;if("object"!=typeof n){if(Array.isArray(e))e.push(n);else{if("object"!=typeof e)return[e,n];(r.plainObjects||r.allowPrototypes||!y.call(Object.prototype,n))&&(e[n]=!0)}return e}if("object"!=typeof e)return[e].concat(n);var o=e;return Array.isArray(e)&&!Array.isArray(n)&&(o=v(e,r)),Array.isArray(e)&&Array.isArray(n)?(n.forEach(function(n,o){y.call(e,o)?e[o]&&"object"==typeof e[o]?e[o]=t(e[o],n,r):e.push(n):e[o]=n}),e):Object.keys(n).reduce(function(e,o){var i=n[o];return y.call(e,o)?e[o]=t(e[o],i,r):e[o]=i,e},o)}},w=String.prototype.replace,k={default:"RFC3986",formatters:{RFC1738:function(t){return w.call(t,/%20/g,"+")},RFC3986:function(t){return t}},RFC1738:"RFC1738",RFC3986:"RFC3986"},O={brackets:function(t){return t+"[]"},indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},j=Date.prototype.toISOString,P={delimiter:"&",encode:!0,encoder:b.encode,encodeValuesOnly:!1,serializeDate:function(t){return j.call(t)},skipNulls:!1,strictNullHandling:!1},S=function t(e,n,r,o,i,a,c,s,u,p,l,f){var h=e;if("function"==typeof c)h=c(n,h);else if(h instanceof Date)h=p(h);else if(null===h){if(o)return a&&!f?a(n,P.encoder):n;h=""}if("string"==typeof h||"number"==typeof h||"boolean"==typeof h||b.isBuffer(h))return a?[l(f?n:a(n,P.encoder))+"="+l(a(h,P.encoder))]:[l(n)+"="+l(String(h))];var d=[];if(void 0===h)return d;var y;if(Array.isArray(c))y=c;else{var g=Object.keys(h);y=s?g.sort(s):g}for(var m=0;m<y.length;++m){var v=y[m];i&&null===h[v]||(d=Array.isArray(h)?d.concat(t(h[v],r(n,v),r,o,i,a,c,s,u,p,l,f)):d.concat(t(h[v],n+(u?"."+v:"["+v+"]"),r,o,i,a,c,s,u,p,l,f)))}return d},_=function(t,e){var n=t,r=e?b.assign({},e):{};if(null!==r.encoder&&void 0!==r.encoder&&"function"!=typeof r.encoder)throw new TypeError("Encoder has to be a function.");var o=void 0===r.delimiter?P.delimiter:r.delimiter,i="boolean"==typeof r.strictNullHandling?r.strictNullHandling:P.strictNullHandling,a="boolean"==typeof r.skipNulls?r.skipNulls:P.skipNulls,c="boolean"==typeof r.encode?r.encode:P.encode,s="function"==typeof r.encoder?r.encoder:P.encoder,u="function"==typeof r.sort?r.sort:null,p=void 0!==r.allowDots&&r.allowDots,l="function"==typeof r.serializeDate?r.serializeDate:P.serializeDate,f="boolean"==typeof r.encodeValuesOnly?r.encodeValuesOnly:P.encodeValuesOnly;if(void 0===r.format)r.format=k.default;else if(!Object.prototype.hasOwnProperty.call(k.formatters,r.format))throw new TypeError("Unknown format option provided.");var h,d,y=k.formatters[r.format];"function"==typeof r.filter?n=(d=r.filter)("",n):Array.isArray(r.filter)&&(h=d=r.filter);var g=[];if("object"!=typeof n||null===n)return"";var m;m=r.arrayFormat in O?r.arrayFormat:"indices"in r?r.indices?"indices":"repeat":"indices";var v=O[m];h||(h=Object.keys(n)),u&&h.sort(u);for(var w=0;w<h.length;++w){var j=h[w];a&&null===n[j]||(g=g.concat(S(n[j],j,v,i,a,c?s:null,d,u,p,l,y,f)))}var _=g.join(o),D=!0===r.addQueryPrefix?"?":"";return _.length>0?D+_:""},D=Object.prototype.hasOwnProperty,N={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:b.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},C=function(t,e){for(var n={},r=e.ignoreQueryPrefix?t.replace(/^\?/,""):t,o=e.parameterLimit===1/0?void 0:e.parameterLimit,i=r.split(e.delimiter,o),a=0;a<i.length;++a){var c,s,u=i[a],p=u.indexOf("]="),l=-1===p?u.indexOf("="):p+1;-1===l?(c=e.decoder(u,N.decoder),s=e.strictNullHandling?null:""):(c=e.decoder(u.slice(0,l),N.decoder),s=e.decoder(u.slice(l+1),N.decoder)),D.call(n,c)?n[c]=[].concat(n[c]).concat(s):n[c]=s}return n},A=function(t,e,n){for(var r=e,o=t.length-1;o>=0;--o){var i,a=t[o];if("[]"===a)i=(i=[]).concat(r);else{i=n.plainObjects?Object.create(null):{};var c="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,s=parseInt(c,10);!isNaN(s)&&a!==c&&String(s)===c&&s>=0&&n.parseArrays&&s<=n.arrayLimit?(i=[])[s]=r:i[c]=r}r=i}return r},I=function(t,e,n){if(t){var r=n.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,i=/(\[[^[\]]*])/.exec(r),a=i?r.slice(0,i.index):r,c=[];if(a){if(!n.plainObjects&&D.call(Object.prototype,a)&&!n.allowPrototypes)return;c.push(a)}for(var s=0;null!==(i=o.exec(r))&&s<n.depth;){if(s+=1,!n.plainObjects&&D.call(Object.prototype,i[1].slice(1,-1))&&!n.allowPrototypes)return;c.push(i[1])}return i&&c.push("["+r.slice(i.index)+"]"),A(c,e,n)}},x={formats:k,parse:function(t,e){var n=e?b.assign({},e):{};if(null!==n.decoder&&void 0!==n.decoder&&"function"!=typeof n.decoder)throw new TypeError("Decoder has to be a function.");if(n.ignoreQueryPrefix=!0===n.ignoreQueryPrefix,n.delimiter="string"==typeof n.delimiter||b.isRegExp(n.delimiter)?n.delimiter:N.delimiter,n.depth="number"==typeof n.depth?n.depth:N.depth,n.arrayLimit="number"==typeof n.arrayLimit?n.arrayLimit:N.arrayLimit,n.parseArrays=!1!==n.parseArrays,n.decoder="function"==typeof n.decoder?n.decoder:N.decoder,n.allowDots="boolean"==typeof n.allowDots?n.allowDots:N.allowDots,n.plainObjects="boolean"==typeof n.plainObjects?n.plainObjects:N.plainObjects,n.allowPrototypes="boolean"==typeof n.allowPrototypes?n.allowPrototypes:N.allowPrototypes,n.parameterLimit="number"==typeof n.parameterLimit?n.parameterLimit:N.parameterLimit,n.strictNullHandling="boolean"==typeof n.strictNullHandling?n.strictNullHandling:N.strictNullHandling,""===t||null===t||void 0===t)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof t?C(t,n):t,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),a=0;a<i.length;++a){var c=i[a],s=I(c,r[c],n);o=b.merge(o,s,n)}return b.compact(o)},stringify:_},E=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getCommonData=function(t){var e=this,n=t.onLaunchOption,r=void 0===n?{}:n;return Promise.all([this.getTrackId(),a(),c()]).then(function(t){var n=t[0],o=t[1],i=t[2],a=o.system.split(/\s+/),c=x.stringify(r.query),s={__debug:1,sdk_version:"0.3.1",model:o.model,os:a[0],os_version:a[1],network_type:i,env_version:o.version,ip:"",app_type:"wx",app_id:"",app_name:"",template_version:"",app_category:"",source:r.scene,source_path:r.path,source_app_id:r.referrerInfo?r.referrerInfo.appId||"":"",source_params:c,source_src_key:r.query?r.query[e.config.sourceSrcKey]||"":"",track_id:n};return Promise.resolve(s)})},n.prototype.getTrackId=function(){var t=this;return i(this.config.trackIdKey).then(function(t){return Promise.resolve(t)}).catch(function(e){return t.setTrackId()})},n.prototype.setTrackId=function(){var t=this,e=this.genUUId();return o({key:this.config.trackIdKey,data:e}).then(function(){return Promise.resolve(e)},function(){return o({key:t.config.trackIdKey,data:e}),Promise.resolve(e)})},n.prototype.genUUId=function(){return Date.now()+"-"+Math.floor(1e7*Math.random())+"-"+Math.random().toString(16).replace(".","")+"-"+String(31242*Math.random()).replace(".","").slice(0,8)},n}(function(){function t(t){this.config=t}return t.validate=function(t,e){var n={required:[],optional:[]};for(var r in e)e.hasOwnProperty(r)&&!t[r]&&n[1===e[r]?"required":"optional"].push(r);return n},t}()),L=function(){function t(t,e){this.url=t.trackerHost,this.config=t,this.commonData=e}return t.prototype.send=function(t){var e=this.url,n=l({},this.commonData,t.data);if(this.config.attachActionToUrl){var o=n.action||"";e=/\/$/.test(this.url)?""+this.url+o:this.url+"/"+o}return"function"==typeof this.config.beforeSend&&(n=this.config.beforeSend(n)),d.log("打点数据校验结果:",t,E.validate(n,this.config.dataScheme)),r({url:e,method:this.config.httpMethod,data:n}).then(function(){return t.isSucceed(),Promise.resolve(t)}).catch(function(){return t.isFailed(),Promise.resolve(t)})},t}(),U=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getNetworkStatus=function(){return c().then(function(t){return Promise.resolve(t)},function(t){return console.error("[tracker] 获取网络状态失败",t),Promise.resolve("none")})},n.prototype.watchNetworkStatusChange=function(t){s(t)},n}(function(){function t(t){this.config=t}return t}());!function(t){t[t.SUCCESS=-1]="SUCCESS",t[t.PENDING=0]="PENDING",t[t.FAILED=1]="FAILED"}(f||(f={}));var q,M=function(){function t(t){var e=Date.now();this._id=Math.random().toString(16).replace(".",""),this.status=f.PENDING,this.data=t,this.timestamp=e}return t.prototype.isSucceed=function(){this.status=f.SUCCESS},t.prototype.isFailed=function(){this.status++},t}();!function(t){t[t.IDLE=0]="IDLE",t[t.PAUSE=1]="PAUSE",t[t.RUNNING=2]="RUNNING"}(q||(q={}));var T=function(){function t(t){this.queue=[],this.failedQueue=[],this.config=t,this.lastStoreUpdate=0,this.executor=new R}return t.prototype.init=function(t){var e=this;this.sender||(this.store=t.store,this.sender=t.sender,this.executor.init(this.sender,this),this.store.get().then(function(t){var n;(n=e.queue).push.apply(n,t.map(function(t){return new M(t.data)})),e.run()}))},t.prototype.push=function(t){t.status===f.PENDING&&this.queue.length<this.config.queueMaxLength?(this.queue.push(t),this.updateStore(),this.run()):t.status>=f.FAILED&&t.status<=this.config.retry&&(this.failedQueue.push(t),this.updateStore(),this.run())},t.prototype.pop=function(){var t=this.failedQueue.length,e=this.config.groupMaxLength,n=t-e>=0?this.failedQueue.splice(0,e):this.failedQueue.splice(0,t).concat(this.queue.splice(0,e-t));return this.updateStore(),n},t.prototype.updateStore=function(t){var e=Date.now();(this.store&&e-this.lastStoreUpdate>=500||t&&this.store)&&(this.store.update(this.queue.concat(this.failedQueue)),this.lastStoreUpdate=e)},t.prototype.run=function(){setTimeout(this.executor.run.bind(this.executor),0)},t.prototype.suspend=function(t){this.updateStore(!0),this.executor.suspend(t)},t}(),R=function(){function t(){this.status=q.IDLE}return Object.defineProperty(t.prototype,"isIdle",{get:function(){return this.sender&&this.queueManager&&this.status===q.IDLE},enumerable:!0,configurable:!0}),t.prototype.init=function(t,e){this.sender=t,this.queueManager=e},t.prototype.run=function(){this.isIdle&&this.exec()},t.prototype.exec=function(){var t=this,e=this.queueManager.pop();if(!e.length)return void(this.status=q.IDLE);this.status=q.RUNNING,Promise.all(e.map(function(e){return t.sender.send(e)})).then(function(e){e.forEach(function(e){e.status!==f.SUCCESS&&t.queueManager.push(e)})}).then(function(){t.timer=setTimeout(function(){t.exec()},t.queueManager.config.interval)})},t.prototype.suspend=function(t){t?(this.status=q.PAUSE,clearTimeout(this.timer)):this.status===q.PAUSE?(this.status=q.IDLE,this.run()):this.status===q.IDLE&&this.run()},t}(),F=function(){function t(t){this.config=t,this.queueManager=new T(this.config)}return t.prototype.init=function(t){this.queueManager.init(l({},t))},t.prototype.log=function(t){this.queueManager.push(t)},t}(),H={debug:!0,httpMethod:"POST",retry:2,interval:1e3,groupMaxLength:5,timestampKey:"timestamp_ms",trackIdKey:"__track_id",queueMaxLength:500,commonData:{},dataScheme:{},sourceSrcKey:"src",detectChanel:!0,detectAppStart:!0,attachActionToUrl:!1},G=function(){function t(t){void 0===t&&(t={}),Object.assign(this,H,t)}return t}(),Q=function(){function t(t){void 0===t&&(t={}),this.config=new G(t),this.core=new F(this.config),d.DEBUG=this.config.debug,this.core.queueManager.suspend(!0),this.networkDetector=new U(this.config),this.commonDataVendor=new E(this.config)}return t.prototype.init=function(t){if(!this.sender){var e=this.handleNetworkStatusChange.bind(this);this.sender=new L(this.config,t),this.store=new h(this.config),this.core.init({sender:this.sender,store:this.store}),this.networkDetector.getNetworkStatus().then(e,e),this.networkDetector.watchNetworkStatusChange(e),d.log("初始化完成")}},t.prototype.handleNetworkStatusChange=function(t){var e="none"===t||t instanceof Error;this.core.queueManager.suspend(e)},t.prototype.log=function(t){var e=Date.now();t[this.config.timestampKey]=e,this.core.log(new M(t))},n([p()],t.prototype,"init",null),n([p()],t.prototype,"handleNetworkStatusChange",null),n([p()],t.prototype,"log",null),t}(),K=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return e(r,t),r.generateTrackerInstance=function(t){var e={};try{var n=require("./anka-tracker.config.js");Object.assign(e,n)}catch(e){!t&&console.log("缺少配置文件 anka-tracker.config.js",e)}t&&Object.assign(e,t);var o=new r(e);if(void 0!==typeof App&&void 0!==typeof Page){var i=App,a=Page;App=function(t){return u(t,"onLaunch",function(t){o.onLaunchOption=t,o.config.detectChanel&&o.detectChanel(t.query[o.config.sourceSrcKey])}),o.config.detectAppStart&&u(t,"onShow",function(t){o.evt("app_start",{})}),i(t)},Page=function(t){return u(t,"onLoad",function(t){this.__page_params__=t}),"function"==typeof o.config.autoPageView&&u(t,"onShow",function(){var t=getCurrentPages().slice().pop();o.config.autoPageView(t,function(e){o.pv(e.action,e,{page_id:t.route,page_url:t.route,page_params:x.stringify(t.__page_params__)})})}),a(t)}}else console.log("当前未处于小程序环境!");return o},r.prototype.asyncInitWithCommonData=function(t){var e=this;return void 0===t&&(t={}),this.commonDataVendor.getCommonData({onLaunchOption:this.onLaunchOption}).then(function(n){e.init(Object.assign(n,e.config.commonData,t))}).catch(function(t){d.log("初始化失败"),console.log(t)})},r.prototype.detectChanel=function(t){if(t){var e={};t.split(/_+/).forEach(function(t,n){e["source_src_key_"+(n+1)]=t}),this.evt("channel",e)}},r.prototype.composeCommonData=function(t){var e=[];return t.map(function(t){"function"==typeof t?e.push(new Promise(function(e){t(e)})):e.push(Promise.resolve(t))}),Promise.all(e).then(function(t){return Promise.resolve(Object.assign.apply(Object,[{}].concat(t)))})},r.prototype.track=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];this.composeCommonData(e).then(function(e){return t.log(e)})},r.prototype.evt=function(t){void 0===t&&(t="");for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(!t)throw new Error("缺少 action 参数");this.track.apply(this,e.concat([{action:t,tracktype:"event"}]))},r.prototype.pv=function(t){var e=this;void 0===t&&(t="");for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];this.composeCommonData(n).then(function(n){e.log(Object.assign(n,e.genLastPageUrl(n),{action:t,tracktype:"pageview"}))})},r.prototype.genLastPageUrl=function(t){var e=this,n=e.last_page_id,r=void 0===n?"":n,o=e.last_page_url,i=void 0===o?"":o;return this.last_page_url=t.page_url||"",this.last_page_id=t.page_id||"",{last_page_id:r,last_page_url:i}},n([p()],r.prototype,"asyncInitWithCommonData",null),n([p()],r.prototype,"detectChanel",null),n([p()],r.prototype,"composeCommonData",null),n([p()],r.prototype,"track",null),n([p()],r.prototype,"evt",null),n([p()],r.prototype,"pv",null),n([p()],r.prototype,"genLastPageUrl",null),r}(Q),B=K.generateTrackerInstance();t.Tracker=Q,t.BxTracker=K,t.tracker=B,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=anka-tracker.min.js.map |
{ | ||
"name": "@anka-dev/tracker", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "", | ||
@@ -9,5 +9,7 @@ "main": "dist/anka-tracker.min.js", | ||
"dev:game": "rollup -c build/rollup.config.game.dev.js -w", | ||
"build": "rollup -c build/rollup.config.prod.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "rollup -c build/rollup.config.prod.js" | ||
}, | ||
"anka": { | ||
"type": "lib" | ||
}, | ||
"repository": { | ||
@@ -14,0 +16,0 @@ "type": "git", |
@@ -10,12 +10,18 @@ import qs from 'qs' | ||
static generateTrackerInstance (): Tracker { | ||
let config = <InilialzeConfig>{} | ||
static generateTrackerInstance (customConfig?: InilialzeConfig): Tracker { | ||
let defaultConfig = <InilialzeConfig>{} | ||
try { | ||
config = require('./anka-tracker.config.js') | ||
const config = require('./anka-tracker.config.js') | ||
Object.assign(defaultConfig, config) | ||
} catch (err) { | ||
console.log('anka-tracker 缺少配置文件', err) | ||
!customConfig && console.log('缺少配置文件 anka-tracker.config.js', err) | ||
} | ||
const tracker = new BxTracker(config) | ||
if (typeof App === void (0) || typeof Page === void (0)) { | ||
customConfig && Object.assign(defaultConfig, customConfig) | ||
const tracker = new BxTracker(defaultConfig) | ||
if (typeof App !== void (0) && typeof Page !== void (0)) { | ||
const AppConstructor = App | ||
@@ -59,2 +65,4 @@ const PageConstructor = Page | ||
} | ||
} else { | ||
console.log('当前未处于小程序环境!') | ||
} | ||
@@ -61,0 +69,0 @@ |
@@ -774,3 +774,3 @@ (function (global, factory) { | ||
var version = "0.2.0"; | ||
var version = "0.3.0"; | ||
@@ -1148,12 +1148,14 @@ var WeChatCommonDataVender = (function (_super) { | ||
} | ||
BxTracker.generateTrackerInstance = function () { | ||
var config = {}; | ||
BxTracker.generateTrackerInstance = function (customConfig) { | ||
var defaultConfig = {}; | ||
try { | ||
config = require('./anka-tracker.config.js'); | ||
var config = require('./anka-tracker.config.js'); | ||
Object.assign(defaultConfig, config); | ||
} | ||
catch (err) { | ||
console.log('anka-tracker 缺少配置文件', err); | ||
!customConfig && console.log('缺少配置文件 anka-tracker.config.js', err); | ||
} | ||
var tracker = new BxTracker(config); | ||
if (typeof App === void (0) || typeof Page === void (0)) { | ||
customConfig && Object.assign(defaultConfig, customConfig); | ||
var tracker = new BxTracker(defaultConfig); | ||
if (typeof App !== void (0) && typeof Page !== void (0)) { | ||
var AppConstructor_1 = App; | ||
@@ -1194,2 +1196,5 @@ var PageConstructor_1 = Page; | ||
} | ||
else { | ||
console.log('当前未处于小程序环境!'); | ||
} | ||
return tracker; | ||
@@ -1196,0 +1201,0 @@ }; |
@@ -1,2 +0,6 @@ | ||
const { tracker } = require('./anka-tracker.js') | ||
const { BxTracker } = require('./anka-tracker.js') | ||
const tracker = BxTracker.generateTrackerInstance({ | ||
detectChanel: false, | ||
detectAppStart: true | ||
}) | ||
@@ -3,0 +7,0 @@ //app.js |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
1519789
8411
2