@fle-sdk/event-tracking-web 1.2.0-beta.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +340 -115
- package/lib/index.esm.js +1979 -16
- package/lib/index.esm.min.js +1 -0
- package/lib/index.js +1987 -16
- package/lib/index.min.js +1 -0
- package/lib/types/index.d.ts +132 -87
- package/lib/types/tools.d.ts +209 -113
- package/lib/types/type.d.ts +466 -243
- package/package.json +9 -6
- package/lib/index.ems.js +0 -16
- package/lib/index.ems.js.map +0 -1
- package/lib/index.esm.js.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/index.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).WebTracking=t()}(this,(function(){"use strict";var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)};var t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}return new(function(n){function r(){var e=n.call(this)||this;return e.batchQueue=[],e.batchTimer=null,e.BATCH_QUEUE_STORAGE_KEY="web_tracking_batch_queue",e.userInfo=null,e.currentUrl="",e.pageKey="",e.deviceId="",e.eventDescMap={PageView:"Web 浏览页面",WebClick:"Web 元素点击",PageRetained:"Web 页面浏览时长",CustomTrack:"Web 自定义代码上报"},e.init=function(t){e.preset(t);var n=window.location.pathname;e.currentUrl=window.location.href,e.pageKey=n.replace(/\//g,"_").substring(1),e.systemsInfo=e.getSystemsInfo(t.platform),e.deviceId=e.getDeviceId(),e.setCookie("retainedStartTime",e.getTimeStamp()),e.initConfig.batchSend&&(e.restoreBatchQueueFromStorage(),e.setupBeforeUnloadListener())},e.preset=function(t){t instanceof Object&&e.each(t,(function(t,n){e.initConfig.hasOwnProperty(n)&&(e.initConfig[n]=t)})),/^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-\(\)]*[\w@?^=%&/~+#-\(\)])?$/.test(e.initConfig.serverUrl)||(e.printLog("当前 server_url 为空或不正确,只在控制台打印日志,network 中不会发数据,请配置正确的 server_url!"),e.initConfig.showLog=!0),e.initConfig.autoTrack?e.listener():e.unlistener()},e.login=function(t){e.isObject(t)&&(e.userInfo=t)},e.getDeviceId=function(){if(e.deviceId)return e.deviceId;var t=e.getCookie("device_id")||e.getLocalStorage("device_id");if(t)return e.deviceId=t,e.deviceId;var n=e.collectFingerprint(),r=e.hashFingerprint(n);return e.setCookie("device_id",r,730),e.setLocalStorage("device_id",r),e.deviceId=r,e.deviceId},e.resetDeviceId=function(){return document.cookie="device_id=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",localStorage.removeItem("device_id"),e.deviceId="",e.getDeviceId()},e.track=function(t){var n=t.desc,r=t.partkey,i=t.business,o=t.header,a=e.getParams({desc:n,event:"CustomTrack",itemKey:e.getItemKey(r),privateParamMap:{business:i}});return e.sendData(a,o)},e.listener=function(){e.initConfig.isTrackSinglePage&&(e.rewriteHistory(),e.addSinglePageEvent(e.onPageViewCallback)),e.each(["load","beforeunload"],(function(t){e.addEventListener(window,t,e.onPageViewCallback)})),e.addEventListener(window,"click",e.onClickCallback)},e.unlistener=function(){if(e.initConfig.isTrackSinglePage){var t=window.history.pushState?"popstate":"hashchange";e.each(["pushState","replaceState",t],(function(t){e.removeEventListener(window,t,e.onPageViewCallback)}))}e.each(["load","beforeunload"],(function(t){e.removeEventListener(window,t,e.onPageViewCallback)})),e.removeEventListener(window,"click",e.onClickCallback),e.clearBatchTimer()},e.clearBatchTimer=function(){null!==e.batchTimer&&(clearTimeout(e.batchTimer),e.batchTimer=null)},e.clearBatchQueue=function(){e.batchQueue=[],e.setLocalStorage(e.BATCH_QUEUE_STORAGE_KEY,"[]"),e.initConfig.showLog&&e.printLog("批量队列已清空")},e.onClickCallback=function(t){var n,r=t.target;if(null===(n=null==r?void 0:r.dataset)||void 0===n?void 0:n.partKey){var i=[t.pageX,t.pageY],o=r.id,a=r.className,c={id:o,nodeName:r.nodeName,className:a,position:i},s=e.getParams({event:"WebClick",desc:e.eventDescMap.WebClick,itemKey:e.getItemKey(r.dataset.partKey),privateParamMap:{targetEle:c,pointerType:t.pointerType,currentUrl:e.currentUrl,elementSelector:e.getDomSelector(r)||""}});return e.sendData(s)}},e.onPageViewCallback=function(t){var n,r,i=window.location.origin,o=e.getParams({event:"PageView",desc:e.eventDescMap.PageView,privateParamMap:{currentUrl:e.currentUrl,targetUrl:(null===(n=t.arguments)||void 0===n?void 0:n[2])?i+(null===(r=t.arguments)||void 0===r?void 0:r[2]):null}});e.currentUrl=window.location.href,e.pageKey=window.location.pathname.replace(/\//g,"_").substring(1),e.sendRetained(t.type),e.sendData(o)},e.getParams=function(t){var n=t.event,r=t.desc,i=t.privateParamMap,o=void 0===i?{}:i,a=t.itemKey,c=e.initConfig.business,s=window.innerWidth,u=window.innerHeight,l=window.screen.width,g=window.screen.height,d=e.filterSensitiveData(c||{}),h=e.filterSensitiveData(e.userInfo||{}),p=e.filterSensitiveData(o||{}),f=e.filterSensitiveData(e.getQueryValue()||{}),v={currentUrl:p.currentUrl||e.currentUrl,business:Object.assign({},d,p.business||{}),pageWidth:s,pageHeight:u,screenWidth:l,screenHeight:g,sdkVersion:e.sdkVersion,systemsInfo:e.systemsInfo,urlParams:f,userInfo:h,deviceId:e.deviceId};return p.targetEle&&(v.targetEle=p.targetEle),p.targetUrl&&(v.targetUrl=p.targetUrl),p.pointerType&&(v.pointerType=p.pointerType),p.elementSelector&&(v.elementSelector=p.elementSelector),p.retainedDuration&&(v.retainedDuration=p.retainedDuration),{event:n,desc:r,itemKey:a||e.getItemKey(),requestTime:e.getTimeStamp(),privateParamMap:v}},e.shouldSample=function(){var t=e.initConfig.sampleRate;return t>=1||!(t<=0)&&Math.random()<t},e.flushBatchQueue=function(){if(0!==e.batchQueue.length){var t=function(e,t){for(var n=0,r=t.length,i=e.length;n<r;n++,i++)e[i]=t[n];return e}([],e.batchQueue);e.batchQueue=[],e.saveBatchQueueToStorage(),e.sendBatchData(t)}},e.sendBatchData=function(t){var n=e.initConfig,r=n.serverUrl,i=n.contentType;n.showLog&&(e.printLog("批量发送 "+t.length+" 条数据"),t.forEach((function(t){return e.printLog(t)}))),e.ajax({url:r,type:"POST",data:JSON.stringify({events:t}),contentType:i,credentials:!1,timeout:e.initConfig.sendTimeout,cors:!0,success:function(){e.initConfig.showLog&&e.printLog("批量发送成功: "+t.length+" 条数据")},error:function(n){var r;e.printLog("批量发送失败: "+n+",数据已重新加入队列"),(r=e.batchQueue).unshift.apply(r,t),e.batchQueue.length>2*e.initConfig.batchMaxSize&&(e.batchQueue=e.batchQueue.slice(0,e.initConfig.batchMaxSize)),e.saveBatchQueueToStorage()}})},e.addToBatchQueue=function(t){var n=e.initConfig,r=n.batchInterval,i=n.batchMaxSize;e.batchQueue.push(t),e.saveBatchQueueToStorage(),e.batchQueue.length>=i?e.flushBatchQueue():e.batchTimer||(e.batchTimer=window.setTimeout((function(){e.flushBatchQueue(),e.batchTimer=null}),r))},e.restoreBatchQueueFromStorage=function(){try{var t=e.getLocalStorage(e.BATCH_QUEUE_STORAGE_KEY);if(t){var n=JSON.parse(t);if(Array.isArray(n)&&n.length>0){e.batchQueue=n,e.initConfig.showLog&&e.printLog("从 LocalStorage 恢复 "+n.length+" 条待发送数据");var r=e.initConfig.batchMaxSize;if(e.batchQueue.length>=r)e.flushBatchQueue();else{var i=e.initConfig.batchInterval;e.batchTimer||(e.batchTimer=window.setTimeout((function(){e.flushBatchQueue(),e.batchTimer=null}),i))}}}}catch(t){e.printLog("恢复批量队列失败: "+t),e.setLocalStorage(e.BATCH_QUEUE_STORAGE_KEY,"[]")}},e.saveBatchQueueToStorage=function(){try{if(JSON.stringify(e.batchQueue).length>4194304){var t=Math.floor(.8*e.batchQueue.length);e.batchQueue=e.batchQueue.slice(-t),e.printLog("队列过大,已截断保留最新 "+t+" 条数据")}e.setLocalStorage(e.BATCH_QUEUE_STORAGE_KEY,JSON.stringify(e.batchQueue))}catch(t){e.printLog("保存批量队列到 LocalStorage 失败: "+t)}},e.setupBeforeUnloadListener=function(){document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState&&e.batchQueue.length>0&&e.saveBatchQueueToStorage()})),window.addEventListener("beforeunload",(function(){if(e.batchQueue.length>0)if(navigator.sendBeacon&&e.initConfig.serverUrl)try{var t=JSON.stringify({events:e.batchQueue}),n=new Blob([t],{type:"application/json"});navigator.sendBeacon(e.initConfig.serverUrl,n),e.batchQueue=[],e.setLocalStorage(e.BATCH_QUEUE_STORAGE_KEY,"[]")}catch(t){e.saveBatchQueueToStorage()}else e.saveBatchQueueToStorage()}))},e.sendData=function(t,n){if(!e.shouldSample())return Promise.resolve({success:!0,message:"数据已采样跳过"});var r=e.initConfig,i=r.serverUrl,o=r.sendTimeout,a=r.contentType,c=r.showLog,s=r.header,u=r.batchSend;return c&&e.printLog(t),u?(e.addToBatchQueue(t),Promise.resolve({success:!0,message:"已添加到批量队列"})):!0!==e.isSupportBeaconSend()||n||s?new Promise((function(r,c){e.ajax({header:n||s,url:i,type:"POST",data:JSON.stringify(t),contentType:a,credentials:!1,timeout:o,cors:!0,success:function(e){return r({success:!0,data:e})},error:function(e,t){return c({success:!1,message:String(e),code:t})}})})):e.sendBeacon({contentType:a,url:i,data:t})},e.sendRetained=function(n){var r=e.getParams({event:"PageRetained",desc:e.eventDescMap.PageRetained});if(["beforeunload","pushState","replaceState","hashchange","popstate"].indexOf(n)>=0){var i=e.getCookie("retainedStartTime"),o=i?+i:e.getTimeStamp(),a=t(t({},r),{privateParamMap:t(t({},r.privateParamMap),{retainedDuration:Math.max(r.requestTime-o,0)})});e.sendData(a),e.setCookie("retainedStartTime",e.getTimeStamp())}},e.getItemKey=function(t){return[e.initConfig.appKey,e.pageKey,t?t.toString():void 0].filter((function(e){return!!e})).reduce((function(e,t){return e+(e.length?".":"")+t}),"")},e.sdkVersion="1.2.0",e.initConfig={appKey:"",platform:void 0,showLog:!1,serverUrl:"",autoTrack:!1,sendTimeout:3e3,isTrackSinglePage:!1,contentType:"application/json",business:{},header:void 0,sampleRate:1,batchSend:!1,batchInterval:5e3,batchMaxSize:10},e.systemsInfo={},e}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}(r,n),r.prototype.addSinglePageEvent=function(e){var t=this,n=window.history.pushState?"popstate":"hashchange";this.each(["pushState","replaceState",n],(function(n){t.addEventListener(window,n,e)}))},r}(function(){function e(){var e=this;this.getSystemsInfo=function(e){var t=navigator.userAgent,n="other",r=[],i={language:navigator.language},o=t.match(/MicroMessenger\/([\d\.]+)/i),a=o&&o[1]?o[1]:null,c=t.match(/(ipod).*\s([\d_]+)/i),s=t.match(/(ipad).*\s([\d_]+)/i),u=t.match(/(iphone)\sos\s([\d_]+)/i),l=t.match(/(android)\s([\d\.]+)/i),g=t.match(/(Windows NT)\s([\d\.]+)/i),d=t.match(/(Mac OS X)\s([\d_]+)/i);r=[],l?(r.push("Android "+l[2]),n="h5"):u?(r.push("iPhone, iOS "+u[2].replace(/_/g,".")),n="h5"):s?(r.push("iPad, iOS "+s[2].replace(/_/g,".")),n="ipad"):c?(r.push("iPod, iOS "+c[2].replace(/_/g,".")),n="h5"):g?(r.push("Windows "+g[2].replace(/_/g,".")),n="pc"):d&&(r.push("Mac, MacOS "+d[2].replace(/_/g,".")),n="pc"),a&&r.push("WeChat "+a),i.client=r.length?r.join(", "):"Unknown",i.platform=e||n;var h=t.toLowerCase().match(/ nettype\/([^ ]+)/g);return h&&h[0]&&(r=[(h=h[0].split("/"))[1]],i.network=r.length?r.join(", "):"Unknown"),i.ua=t,i},this.addEventListener=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,(function(t){return n.call(e,t)}),!1)},this.removeEventListener=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n):e.detachEvent&&e.detachEvent("on"+t,(function(t){return n.call(e,t)}),!0)},this.rewriteHistory=function(){var e=window.history,t=function(e){var t=window.history,n=t[e],r=new Event(e);return function(){var e=n.apply(t,arguments);return r.arguments=arguments,window.dispatchEvent(r),e}};window.history.pushState&&(e.pushState=t("pushState"),e.replaceState=t("replaceState"))},this.isArray=Array.isArray||function(e){return"[object Array]"===toString.call(e)},this.formatJsonString=function(e){try{return JSON.stringify(e,null," ")}catch(t){return JSON.stringify(e)}},this.nativeForEach=Array.prototype.forEach,this.slice=Array.prototype.slice,this.hasOwnProperty=Object.prototype.hasOwnProperty,this.breaker={},this.each=function(t,n,r){if(null==t)return!1;if(e.nativeForEach&&t.forEach===e.nativeForEach)t.forEach(n,r);else if(e.isArray(t)&&t.length===+t.length){for(var i=0,o=t.length;i<o;i++)if(i in t&&n.call(r,t[i],i,t)===e.breaker)return!1}else for(var a in t)if(e.hasOwnProperty.call(t,a)&&n.call(r,t[a],a,t)===e.breaker)return!1;return!0},this.getDomIndex=function(e){if(!e.parentNode)return-1;for(var t=0,n=e.tagName,r=e.parentNode.children,i=0;i<r.length;i++)if(r[i].tagName===n){if(e===r[i])return t;t++}return-1},this.selector=function(t){var n=t.parentNode&&9==t.parentNode.nodeType?-1:e.getDomIndex(t);return t.getAttribute&&t.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.getAttribute("id"))?"#"+t.getAttribute("id"):t.tagName.toLowerCase()+(~n?":nth-of-type("+(n+1)+")":"")},this.getDomSelector=function(t,n){if(!t||!t.parentNode||!t.parentNode.children)return!1;n=n&&n.join?n:[];var r=t.nodeName.toLowerCase();return t&&"body"!==r&&1==t.nodeType?(n.unshift(e.selector(t)),t.getAttribute&&t.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.getAttribute("id"))?n.join(" > "):e.getDomSelector(t.parentNode,n)):(n.unshift("body"),n.join(" > "))},this.getCookie=function(e){for(var t=e+"=",n=document.cookie.split(";"),r=0;r<n.length;r++){for(var i=n[r];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(t))return this._decodeURIComponent(i.substring(t.length,i.length))}return null},this.setCookie=function(e,t,n){var r,i="";n=null==n?73e3:n;var o=this.getMainHost();if(r=o?"; domain="+o:"",0!==n){var a=new Date;"s"===String(n).slice(-1)?a.setTime(a.getTime()+1e3*Number(String(n).slice(0,-1))):a.setTime(a.getTime()+24*n*60*60*1e3),i="; expires="+a.toUTCString()}function c(e){return e||!1}var s="",u="",l="";e&&(s=c(e)),t&&(u=c(t)),r&&(l=c(r)),s&&u&&(document.cookie=s+"="+encodeURIComponent(u)+i+"; path=/"+l)},this.getLocalStorage=function(e){try{return localStorage.getItem(e)}catch(e){return null}},this.setLocalStorage=function(e,t){try{localStorage.setItem(e,t)}catch(e){}},this.removeCookie=function(t){e.setCookie(t,"",-1)},this.getTimeStamp=function(){return(new Date).getTime()},this.uuid=function(){return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},this.getDistinctId=function(){var t=e.getCookie("distinctId");return t||(t=e.uuid(),e.setCookie("distinctId",t),t)},this.filterSensitiveData=function(t,n){if(void 0===n&&(n=["password","token","secret","key"]),!e.isObject(t))return t;var r={};return e.each(t,(function(t,i){n.some((function(e){return"string"==typeof i&&i.toLowerCase().includes(e.toLowerCase())}))?r[i]="***":e.isObject(t)?r[i]=e.filterSensitiveData(t,n):r[i]=t})),r},this.xssFilter=function(e){return e?"string"!=typeof e?e.toString():e.replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/"):""},this.getQueryValue=function(){for(var e=decodeURI(window.location.href).match(new RegExp("[?&][^?&]+=[^?&]+","g"))||[],t={},n=0;n<e.length;n++){var r=e[n].replace(/\?|\&/,"").split("=");t[r[0]]=r[1]}return Object.keys(t).length>0?t:null},this.ajax=function(t){function r(e){if(!e)return{};if("string"==typeof e)try{return JSON.parse(e)}catch(e){return{}}return"object"===n(e)?e:{}}t.timeout=t.timeout||3e4,t.credentials=void 0===t.credentials||t.credentials;var i=e.xhr(t.cors);if(!i)return!1;t.type||(t.type=t.data?"POST":"GET");var o,a=t.success,c=t.error;t.success=function(e){a&&a(e),o&&(clearTimeout(o),o=null)},t.error=function(e,t){c&&c(e,t),o&&(clearTimeout(o),o=null)},o=window.setTimeout((function(){!function(){try{e.isObject(i)&&i.abort&&i.abort()}catch(t){e.printLog(t)}o&&(clearTimeout(o),o=null,t.error&&t.error(),i.onreadystatechange=null,i.onload=null,i.onerror=null)}()}),t.timeout),i.onreadystatechange=function(){try{4==i.readyState&&(i.status>=200&&i.status<300||304==i.status?t.success&&t.success(r(i.responseText)):t.error&&t.error(r(i.responseText),i.status),i.onreadystatechange=null,i.onload=null)}catch(e){i.onreadystatechange=null,i.onload=null}},i.open(t.type||"GET",t.url,!0);try{t.credentials&&(i.withCredentials=!0),e.isObject(t.header)&&e.each(t.header,(function(e,t){i.setRequestHeader&&i.setRequestHeader(t,e)})),t.data&&(t.cors||i.setRequestHeader&&i.setRequestHeader("X-Requested-With","XMLHttpRequest"),"application/json"===t.contentType?i.setRequestHeader&&i.setRequestHeader("Content-type","application/json; charset=UTF-8"):i.setRequestHeader&&i.setRequestHeader("Content-type","application/x-www-form-urlencoded"))}catch(t){e.printLog(t)}i.send(t.data||null)},this.xhr=function(e){return e?void 0!==window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?new XMLHttpRequest:null:void 0!==window.XMLHttpRequest?new XMLHttpRequest:null},this.getUA=function(){var e,t={},n=navigator.userAgent.toLowerCase();return(e=n.match(/opera.([\d.]+)/))?t.opera=Number(e[1].split(".")[0]):(e=n.match(/msie ([\d.]+)/))?t.ie=Number(e[1].split(".")[0]):(e=n.match(/edge.([\d.]+)/))?t.edge=Number(e[1].split(".")[0]):(e=n.match(/firefox\/([\d.]+)/))?t.firefox=Number(e[1].split(".")[0]):(e=n.match(/chrome\/([\d.]+)/))?t.chrome=Number(e[1].split(".")[0]):(e=n.match(/version\/([\d.]+).*safari/))?t.safari=Number(e[1].match(/^\d*.\d*/)):(e=n.match(/trident\/([\d.]+)/))&&(t.ie=11),t},this.isSupportBeaconSend=function(){var t=!1;if("object"!==("undefined"==typeof navigator?"undefined":n(navigator))||"function"!=typeof navigator.sendBeacon)return t;var r=e.getUA(),i=navigator.userAgent.toLowerCase();if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)){var o=(i.match(/os [\d._]*/gi)+"").replace(/[^0-9|_.]/gi,"").replace(/_/gi,".").split(".");void 0===r.safari&&(r.safari=Number(o[0])),o[0]&&+o[0]<13?(r.chrome>41||r.firefox>30||r.opera>25||r.safari>12)&&(t=!0):(r.chrome>41||r.firefox>30||r.opera>25||r.safari>11.3)&&(t=!0)}else(r.chrome>38||r.edge>13||r.firefox>30||r.opera>25||r.safari>11)&&(t=!0);return t},this.throttle=function(e,t){var n=null,r=0;return function(){for(var i=[],o=0;o<arguments.length;o++)i[o]=arguments[o];var a=Date.now(),c=t-(a-r);c<=0||c>t?(n&&(clearTimeout(n),n=null),r=a,e.apply(void 0,i)):n||(n=window.setTimeout((function(){r=Date.now(),n=null,e.apply(void 0,i)}),c))}},this.debounce=function(e,t){var n=null;return function(){for(var r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];n&&clearTimeout(n),n=window.setTimeout((function(){e.apply(void 0,r)}),t)}},this.sendBeacon=function(t){if(!0===e.isSupportBeaconSend()){var n={type:t.contentType},r=new Blob([JSON.stringify(t.data)],n);return navigator.sendBeacon(t.url,r)?Promise.resolve({success:!0,message:"发送成功"}):Promise.reject({success:!1,message:"sendBeacon返回false"})}return Promise.reject({success:!1,message:"不支持sendBeacon,发送失败!"})},this.getDeviceId=function(){var t=e.getCookie("device_id")||e.getLocalStorage("device_id");if(t)return t;var n=e.collectFingerprint(),r=e.hashFingerprint(n);return e.setCookie("device_id",r,730),e.setLocalStorage("device_id",r),r},this.collectFingerprint=function(){var t={};return t.userAgent=navigator.userAgent,t.screenWidth=screen.width,t.screenHeight=screen.height,t.colorDepth=screen.colorDepth,t.pixelDepth=screen.pixelDepth,t.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,t.timezoneOffset=(new Date).getTimezoneOffset(),t.language=navigator.language,t.languages=Array.from(navigator.languages),t.platform=navigator.platform,t.webgl=e.getWebGLFingerprint(),t.canvas=e.getCanvasFingerprint(),t.audio=e.getAudioFingerprint(),t.fonts=e.getFontFingerprint(),t.plugins=e.getPluginsFingerprint(),t.localStorage=e.hasLocalStorage(),t.sessionStorage=e.hasSessionStorage(),t.indexedDB=e.hasIndexedDB(),t.hardwareConcurrency=navigator.hardwareConcurrency,t.deviceMemory=navigator.deviceMemory,t.maxTouchPoints=navigator.maxTouchPoints,t.connection=e.getConnectionFingerprint(),t},this.getWebGLFingerprint=function(){try{var e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");if(!t)return"not-supported";var n=t.getExtension("WEBGL_debug_renderer_info");return(n?t.getParameter(n.UNMASKED_VENDOR_WEBGL):"unknown")+"|"+(n?t.getParameter(n.UNMASKED_RENDERER_WEBGL):"unknown")}catch(e){return"error"}},this.getCanvasFingerprint=function(){try{var e=document.createElement("canvas"),t=e.getContext("2d");return t?(t.textBaseline="top",t.font="14px Arial",t.fillStyle="#f60",t.fillRect(125,1,62,20),t.fillStyle="#069",t.fillText("Canvas fingerprint",2,15),t.fillStyle="rgba(102, 204, 0, 0.7)",t.fillText("Canvas fingerprint",4,17),e.toDataURL().slice(-50)):"not-supported"}catch(e){return"error"}},this.getAudioFingerprint=function(){try{var e=window.AudioContext||window.webkitAudioContext;if(!e)return"not-supported";var t=new e,n=t.createOscillator(),r=t.createAnalyser(),i=t.createGain(),o=t.createScriptProcessor(4096,1,1);n.type="triangle",n.frequency.value=1e4,i.gain.value=0,n.connect(r),r.connect(o),o.connect(i),i.connect(t.destination),n.start(0);var a=t.sampleRate+"|"+t.currentTime;return n.stop(),t.close(),a}catch(e){return"error"}},this.getFontFingerprint=function(){try{var e=["monospace","sans-serif","serif"],t="mmmmmmmmmmlli",n=document.createElement("canvas").getContext("2d");if(!n)return"not-supported";var r=[],i={};return e.forEach((function(e){n.font="72px "+e,i[e]=n.measureText(t).width})),["Arial","Arial Black","Comic Sans MS","Courier New","Georgia","Helvetica","Impact","Times New Roman","Trebuchet MS","Verdana"].forEach((function(o){var a=!1;e.forEach((function(e){n.font="72px '"+o+"', "+e,n.measureText(t).width!==i[e]&&(a=!0)})),a&&r.push(o)})),r.join(",")}catch(e){return"error"}},this.getPluginsFingerprint=function(){try{var e=[];if(navigator.plugins)for(var t=0;t<navigator.plugins.length;t++){var n=navigator.plugins[t];n&&e.push(n.name+"|"+n.description+"|"+n.filename)}return e.join(";")}catch(e){return"error"}},this.hasLocalStorage=function(){try{var e="__test__";return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(e){return!1}},this.hasSessionStorage=function(){try{var e="__test__";return sessionStorage.setItem(e,e),sessionStorage.removeItem(e),!0}catch(e){return!1}},this.hasIndexedDB=function(){return"indexedDB"in window&&null!==indexedDB},this.getConnectionFingerprint=function(){try{var e=navigator.connection||navigator.mozConnection||navigator.webkitConnection;return e?e.effectiveType+"|"+e.downlink+"|"+e.rtt:"not-supported"}catch(e){return"error"}},this.hashFingerprint=function(e){for(var t=JSON.stringify(e,Object.keys(e).sort()),n=5381,r=52711,i=0;i<t.length;i++){var o=t.charCodeAt(i);n=(n<<5)+n+o,r=(r<<5)+r+o}return"fp_"+(4096*(n>>>0)+(r>>>0)).toString(36)}}return e.prototype.printLog=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(this.isObject(e[0])&&(e[0]=this.formatJsonString(e[0])),"object"===("undefined"==typeof console?"undefined":n(console))&&console.log)try{return console.log.apply(console,e)}catch(t){console.log(e[0])}},e.prototype.isObject=function(e){return null!=e&&"[object Object]"==toString.call(e)},e.prototype.isUndefined=function(e){return void 0===e},e.prototype.isString=function(e){return"[object String]"==toString.call(e)},e.prototype.isDate=function(e){return"[object Date]"==toString.call(e)},e.prototype.isBoolean=function(e){return"[object Boolean]"==toString.call(e)},e.prototype.isNumber=function(e){return"[object Number]"==toString.call(e)&&/[\d\.]+/.test(String(e))},e.prototype.isElement=function(e){return!(!e||1!==e.nodeType)},e.prototype.isFunction=function(e){if(!e)return!1;var t=toString.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t},e.prototype.isJSONString=function(e){if(!this.isString(e))return!1;try{JSON.parse(e)}catch(e){return!1}return!0},e.prototype._decodeURIComponent=function(e){var t=e;try{t=decodeURIComponent(e)}catch(n){t=e}return t},e.prototype.getMainHost=function(){var e="mh_"+Math.random(),t=new RegExp("(^|;)\\s*"+e+"=12345"),n=new Date(0),r=document.domain,i=r.split("."),o=[];for(o.unshift(i.pop());i.length;){o.unshift(i.pop());var a=o.join("."),c=e+"=12345;domain=."+a;if(document.cookie=c,t.test(document.cookie))return document.cookie=c+";expires="+n,a}return r},e}()))}));
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,87 +1,132 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* web 数据埋点 SDK
|
|
3
|
-
* @class WebTracking
|
|
4
|
-
* @version 1.
|
|
5
|
-
* key由这几部分组成:appkey.pagekey.partkey 通过“.”来分割
|
|
6
|
-
* appkey:应用唯一标识
|
|
7
|
-
* pagekey:页面唯一标识,取当前路由 window.location.pathname.replace(/\//g, '_').substr(1)
|
|
8
|
-
* partkey:控件/自定义事件唯一标识,可通过接口获取或自定义
|
|
9
|
-
*/
|
|
10
|
-
import Tools from "./tools";
|
|
11
|
-
import { EventParams, InitParams, SystemsInfoTypes, TrackParams, PresetParams, TrackingPostParams, JsonProps, EventTypes,
|
|
12
|
-
declare class WebTracking extends Tools {
|
|
13
|
-
initConfig: InitParams;
|
|
14
|
-
sdkVersion: string;
|
|
15
|
-
systemsInfo: SystemsInfoTypes;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
protected
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* @
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @description
|
|
76
|
-
* @param
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @description
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
/**
|
|
2
|
+
* web 数据埋点 SDK
|
|
3
|
+
* @class WebTracking
|
|
4
|
+
* @version 1.2.0
|
|
5
|
+
* key由这几部分组成:appkey.pagekey.partkey 通过“.”来分割
|
|
6
|
+
* appkey:应用唯一标识
|
|
7
|
+
* pagekey:页面唯一标识,取当前路由 window.location.pathname.replace(/\//g, '_').substr(1)
|
|
8
|
+
* partkey:控件/自定义事件唯一标识,可通过接口获取或自定义
|
|
9
|
+
*/
|
|
10
|
+
import Tools from "./tools";
|
|
11
|
+
import { EventParams, InitParams, SystemsInfoTypes, TrackParams, PresetParams, TrackingPostParams, JsonProps, EventTypes, GetParamsOptions, TrackingResponse } from "./type";
|
|
12
|
+
declare class WebTracking extends Tools {
|
|
13
|
+
initConfig: InitParams;
|
|
14
|
+
sdkVersion: string;
|
|
15
|
+
systemsInfo: SystemsInfoTypes;
|
|
16
|
+
private batchQueue;
|
|
17
|
+
private batchTimer;
|
|
18
|
+
private readonly BATCH_QUEUE_STORAGE_KEY;
|
|
19
|
+
constructor();
|
|
20
|
+
protected userInfo?: JsonProps;
|
|
21
|
+
protected currentUrl: string;
|
|
22
|
+
protected pageKey: string;
|
|
23
|
+
protected deviceId: string;
|
|
24
|
+
protected eventDescMap: Record<EventTypes, string>;
|
|
25
|
+
/**
|
|
26
|
+
* @description 初始化函数
|
|
27
|
+
* @param {object} InitParams [初始化参数]
|
|
28
|
+
*/
|
|
29
|
+
init: (initParams: InitParams) => void;
|
|
30
|
+
/**
|
|
31
|
+
* TODO: 需要判断有哪些不能被预制的参数
|
|
32
|
+
* @description 预置参数
|
|
33
|
+
* @param {object} PresetParams [预置参数]
|
|
34
|
+
*/
|
|
35
|
+
preset: (presetParams: PresetParams) => void;
|
|
36
|
+
/**
|
|
37
|
+
* 用户登录
|
|
38
|
+
*/
|
|
39
|
+
login: (userInfo: JsonProps) => void;
|
|
40
|
+
/**
|
|
41
|
+
* 获取设备唯一标识
|
|
42
|
+
* @returns 设备唯一标识
|
|
43
|
+
*/
|
|
44
|
+
getDeviceId: () => string;
|
|
45
|
+
/**
|
|
46
|
+
* 重置设备ID
|
|
47
|
+
* 清除存储的设备ID并重新生成
|
|
48
|
+
* @returns 新的设备ID
|
|
49
|
+
*/
|
|
50
|
+
resetDeviceId: () => string;
|
|
51
|
+
/**
|
|
52
|
+
* 自定义代码埋点上报
|
|
53
|
+
* @param {object} TrackParams [自定义上报参数]
|
|
54
|
+
* @return {Promise<TrackingResponse>} [回调]
|
|
55
|
+
*/
|
|
56
|
+
track: ({ desc, partkey, business, header }: TrackParams) => Promise<TrackingResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* @description 监听全埋点事件
|
|
59
|
+
*/
|
|
60
|
+
protected listener: () => void;
|
|
61
|
+
/**
|
|
62
|
+
* @description 取消全埋点事件
|
|
63
|
+
*/
|
|
64
|
+
protected unlistener: () => void;
|
|
65
|
+
/**
|
|
66
|
+
* @description 清理批量发送定时器
|
|
67
|
+
*/
|
|
68
|
+
clearBatchTimer: () => void;
|
|
69
|
+
/**
|
|
70
|
+
* @description 清空批量队列(包括 LocalStorage 中的数据)
|
|
71
|
+
*/
|
|
72
|
+
clearBatchQueue: () => void;
|
|
73
|
+
protected onClickCallback: (e: MouseEvent) => Promise<TrackingResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* @description 添加单页面监听事件
|
|
76
|
+
* @param callback
|
|
77
|
+
*/
|
|
78
|
+
addSinglePageEvent(callback: (e: EventParams) => void): void;
|
|
79
|
+
/**
|
|
80
|
+
* @description 路由触发事件
|
|
81
|
+
*/
|
|
82
|
+
protected onPageViewCallback: (e: EventParams) => void;
|
|
83
|
+
getParams: ({ event, desc, privateParamMap, itemKey, }: GetParamsOptions) => TrackingPostParams;
|
|
84
|
+
/**
|
|
85
|
+
* 数据采样判断
|
|
86
|
+
* @returns 是否应该采样
|
|
87
|
+
*/
|
|
88
|
+
private shouldSample;
|
|
89
|
+
/**
|
|
90
|
+
* 批量发送数据
|
|
91
|
+
*/
|
|
92
|
+
private flushBatchQueue;
|
|
93
|
+
/**
|
|
94
|
+
* 发送批量数据
|
|
95
|
+
* @param data 批量数据
|
|
96
|
+
*/
|
|
97
|
+
private sendBatchData;
|
|
98
|
+
/**
|
|
99
|
+
* 添加到批量队列
|
|
100
|
+
* @param params 数据参数
|
|
101
|
+
*/
|
|
102
|
+
private addToBatchQueue;
|
|
103
|
+
/**
|
|
104
|
+
* 从 LocalStorage 恢复批量队列
|
|
105
|
+
*/
|
|
106
|
+
private restoreBatchQueueFromStorage;
|
|
107
|
+
/**
|
|
108
|
+
* 保存批量队列到 LocalStorage
|
|
109
|
+
*/
|
|
110
|
+
private saveBatchQueueToStorage;
|
|
111
|
+
/**
|
|
112
|
+
* 设置页面卸载监听器,保存队列
|
|
113
|
+
*/
|
|
114
|
+
private setupBeforeUnloadListener;
|
|
115
|
+
/**
|
|
116
|
+
* 发送数据通用函数
|
|
117
|
+
*/
|
|
118
|
+
sendData: (params: TrackingPostParams, header?: JsonProps) => Promise<TrackingResponse>;
|
|
119
|
+
/**
|
|
120
|
+
* @description 留存时长上报
|
|
121
|
+
* @param type
|
|
122
|
+
*/
|
|
123
|
+
sendRetained: (type: string) => void;
|
|
124
|
+
/**
|
|
125
|
+
* @description 获取 itemKey
|
|
126
|
+
* @param {[string]} partkey [控件/自定义事件的唯一标识]
|
|
127
|
+
* @return {[string]}
|
|
128
|
+
*/
|
|
129
|
+
protected getItemKey: (partkey?: string | number) => string;
|
|
130
|
+
}
|
|
131
|
+
declare const _default: WebTracking;
|
|
132
|
+
export default _default;
|
package/lib/types/tools.d.ts
CHANGED
|
@@ -1,113 +1,209 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 埋点工具函数
|
|
3
|
-
*/
|
|
4
|
-
import type { Target, SystemsInfoTypes, JsonProps, PlatformType,
|
|
5
|
-
export default class WebTrackingTools {
|
|
6
|
-
constructor();
|
|
7
|
-
/**
|
|
8
|
-
* 打印log
|
|
9
|
-
*/
|
|
10
|
-
printLog(...rest:
|
|
11
|
-
/**
|
|
12
|
-
* 系统信息
|
|
13
|
-
*/
|
|
14
|
-
getSystemsInfo: (platform: PlatformType | string) => SystemsInfoTypes;
|
|
15
|
-
/**
|
|
16
|
-
* 监听事件
|
|
17
|
-
* @param {Window | Element} target
|
|
18
|
-
* @param {String} type
|
|
19
|
-
* @param {Function} handler
|
|
20
|
-
*/
|
|
21
|
-
protected addEventListener: (target: Target, type: string, handler: (e: Event) => void) => void;
|
|
22
|
-
/**
|
|
23
|
-
* 移除监听事件
|
|
24
|
-
* @param {Element} target
|
|
25
|
-
* @param {String} type
|
|
26
|
-
* @param {Funtion} handler
|
|
27
|
-
*/
|
|
28
|
-
protected removeEventListener: (target: Target, type: string, handler: (e: Event) => void) => void;
|
|
29
|
-
/**
|
|
30
|
-
* 重写history[pushState][replaceState]方法
|
|
31
|
-
*/
|
|
32
|
-
rewriteHistory: () => void;
|
|
33
|
-
/**
|
|
34
|
-
* @description 检验是否是对象
|
|
35
|
-
*/
|
|
36
|
-
isObject(obj:
|
|
37
|
-
isUndefined(obj:
|
|
38
|
-
isArray: (obj:
|
|
39
|
-
isString(obj:
|
|
40
|
-
isDate(obj:
|
|
41
|
-
isBoolean(obj:
|
|
42
|
-
isNumber(obj:
|
|
43
|
-
isElement(obj:
|
|
44
|
-
isFunction(f:
|
|
45
|
-
isJSONString(str:
|
|
46
|
-
/**
|
|
47
|
-
* 将json序列化成json字符串
|
|
48
|
-
* @param obj
|
|
49
|
-
* @returns {[JsonString]} [json字符串]
|
|
50
|
-
*/
|
|
51
|
-
protected formatJsonString: (obj:
|
|
52
|
-
nativeForEach: (callbackfn: (value: any, index: number, array: any[]) => void, thisArg?: any) => void;
|
|
53
|
-
slice: (start?: number, end?: number) => any[];
|
|
54
|
-
hasOwnProperty: (v: PropertyKey) => boolean;
|
|
55
|
-
breaker: {};
|
|
56
|
-
/**
|
|
57
|
-
* @description 循环遍历
|
|
58
|
-
*/
|
|
59
|
-
each: (obj:
|
|
60
|
-
_decodeURIComponent(val:
|
|
61
|
-
getMainHost(): string;
|
|
62
|
-
protected getDomIndex: (el: Element) => number;
|
|
63
|
-
protected selector: (el: Element) => string;
|
|
64
|
-
getDomSelector: (el:
|
|
65
|
-
/**
|
|
66
|
-
* @description 增强cookie操作
|
|
67
|
-
*/
|
|
68
|
-
getCookie: (name:
|
|
69
|
-
setCookie: (name: string, value: string | number, days?: number) => void;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
*
|
|
78
|
-
* @
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
* @
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 埋点工具函数
|
|
3
|
+
*/
|
|
4
|
+
import type { Target, SystemsInfoTypes, JsonProps, PlatformType, PrivateParamProps, DeviceFingerprint, AjaxParams, SendBeaconParams, TrackingResponse } from "./type";
|
|
5
|
+
export default class WebTrackingTools {
|
|
6
|
+
constructor();
|
|
7
|
+
/**
|
|
8
|
+
* 打印log
|
|
9
|
+
*/
|
|
10
|
+
printLog(...rest: unknown[]): void;
|
|
11
|
+
/**
|
|
12
|
+
* 系统信息
|
|
13
|
+
*/
|
|
14
|
+
getSystemsInfo: (platform: PlatformType | string) => SystemsInfoTypes;
|
|
15
|
+
/**
|
|
16
|
+
* 监听事件
|
|
17
|
+
* @param {Window | Element} target
|
|
18
|
+
* @param {String} type
|
|
19
|
+
* @param {Function} handler
|
|
20
|
+
*/
|
|
21
|
+
protected addEventListener: (target: Target, type: string, handler: (e: Event) => void) => void;
|
|
22
|
+
/**
|
|
23
|
+
* 移除监听事件
|
|
24
|
+
* @param {Element} target
|
|
25
|
+
* @param {String} type
|
|
26
|
+
* @param {Funtion} handler
|
|
27
|
+
*/
|
|
28
|
+
protected removeEventListener: (target: Target, type: string, handler: (e: Event) => void) => void;
|
|
29
|
+
/**
|
|
30
|
+
* 重写history[pushState][replaceState]方法
|
|
31
|
+
*/
|
|
32
|
+
rewriteHistory: () => void;
|
|
33
|
+
/**
|
|
34
|
+
* @description 检验是否是对象
|
|
35
|
+
*/
|
|
36
|
+
isObject(obj: unknown): boolean;
|
|
37
|
+
isUndefined(obj: unknown): boolean;
|
|
38
|
+
isArray: (obj: unknown) => boolean;
|
|
39
|
+
isString(obj: unknown): boolean;
|
|
40
|
+
isDate(obj: unknown): boolean;
|
|
41
|
+
isBoolean(obj: unknown): boolean;
|
|
42
|
+
isNumber(obj: unknown): boolean;
|
|
43
|
+
isElement(obj: unknown): boolean;
|
|
44
|
+
isFunction(f: unknown): boolean;
|
|
45
|
+
isJSONString(str: unknown): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 将json序列化成json字符串
|
|
48
|
+
* @param obj
|
|
49
|
+
* @returns {[JsonString]} [json字符串]
|
|
50
|
+
*/
|
|
51
|
+
protected formatJsonString: (obj: unknown) => string;
|
|
52
|
+
nativeForEach: (callbackfn: (value: any, index: number, array: any[]) => void, thisArg?: any) => void;
|
|
53
|
+
slice: (start?: number, end?: number) => any[];
|
|
54
|
+
hasOwnProperty: (v: PropertyKey) => boolean;
|
|
55
|
+
breaker: {};
|
|
56
|
+
/**
|
|
57
|
+
* @description 循环遍历
|
|
58
|
+
*/
|
|
59
|
+
each: (obj: unknown, iterator: (value: unknown, key: string | number, obj: unknown) => void, context?: unknown) => boolean;
|
|
60
|
+
_decodeURIComponent(val: string): string;
|
|
61
|
+
getMainHost(): string;
|
|
62
|
+
protected getDomIndex: (el: Element) => number;
|
|
63
|
+
protected selector: (el: Element) => string;
|
|
64
|
+
getDomSelector: (el: HTMLElement, arr?: string[]) => string | false;
|
|
65
|
+
/**
|
|
66
|
+
* @description 增强cookie操作
|
|
67
|
+
*/
|
|
68
|
+
getCookie: (name: string) => string | null;
|
|
69
|
+
setCookie: (name: string, value: string | number, days?: number) => void;
|
|
70
|
+
/**
|
|
71
|
+
* 获取localStorage值
|
|
72
|
+
* @param key 存储键名
|
|
73
|
+
* @returns 存储值
|
|
74
|
+
*/
|
|
75
|
+
getLocalStorage: (key: string) => string | null;
|
|
76
|
+
/**
|
|
77
|
+
* 设置localStorage值
|
|
78
|
+
* @param key 存储键名
|
|
79
|
+
* @param value 存储值
|
|
80
|
+
*/
|
|
81
|
+
setLocalStorage: (key: string, value: string) => void;
|
|
82
|
+
removeCookie: (name: string) => void;
|
|
83
|
+
/**
|
|
84
|
+
* 获取当前时间戳
|
|
85
|
+
* @return {number} [当前时间戳]
|
|
86
|
+
*/
|
|
87
|
+
getTimeStamp: () => number;
|
|
88
|
+
/**
|
|
89
|
+
* 获取 UUID
|
|
90
|
+
* @return {string} [UUID唯一值]
|
|
91
|
+
*/
|
|
92
|
+
uuid: () => string;
|
|
93
|
+
/**
|
|
94
|
+
* 获取设备Id
|
|
95
|
+
* @return {number} [设备Id]
|
|
96
|
+
*/
|
|
97
|
+
getDistinctId: () => string;
|
|
98
|
+
/**
|
|
99
|
+
* 敏感字段过滤
|
|
100
|
+
* @param obj 需要过滤的对象
|
|
101
|
+
* @param sensitiveKeys 敏感字段列表
|
|
102
|
+
* @returns 过滤后的对象
|
|
103
|
+
*/
|
|
104
|
+
filterSensitiveData: (obj: JsonProps | PrivateParamProps, sensitiveKeys?: string[]) => JsonProps | PrivateParamProps;
|
|
105
|
+
/**
|
|
106
|
+
* XSS过滤
|
|
107
|
+
* @param str 需要过滤的字符串
|
|
108
|
+
* @returns 过滤后的字符串
|
|
109
|
+
*/
|
|
110
|
+
xssFilter: (str: string | number | undefined | null) => string;
|
|
111
|
+
/**
|
|
112
|
+
* 获取url中的参数
|
|
113
|
+
* @param {[string]} name [参数名]
|
|
114
|
+
*/
|
|
115
|
+
getQueryValue: () => JsonProps | null;
|
|
116
|
+
/**
|
|
117
|
+
* Ajax请求方法
|
|
118
|
+
* @param para Ajax请求参数
|
|
119
|
+
* @returns 是否成功发起请求
|
|
120
|
+
*/
|
|
121
|
+
ajax: (para: AjaxParams) => boolean;
|
|
122
|
+
xhr: (cors?: boolean) => XMLHttpRequest | null;
|
|
123
|
+
getUA: () => {
|
|
124
|
+
[key: string]: number;
|
|
125
|
+
};
|
|
126
|
+
isSupportBeaconSend: () => Boolean;
|
|
127
|
+
/**
|
|
128
|
+
* 节流函数
|
|
129
|
+
* @param func 需要节流的函数
|
|
130
|
+
* @param wait 等待时间
|
|
131
|
+
* @returns 节流后的函数
|
|
132
|
+
*/
|
|
133
|
+
throttle: <T extends (...args: unknown[]) => void>(func: T, wait: number) => (...args: Parameters<T>) => void;
|
|
134
|
+
/**
|
|
135
|
+
* 防抖函数
|
|
136
|
+
* @param func 需要防抖的函数
|
|
137
|
+
* @param wait 等待时间
|
|
138
|
+
* @returns 防抖后的函数
|
|
139
|
+
*/
|
|
140
|
+
debounce: <T extends (...args: unknown[]) => void>(func: T, wait: number) => (...args: Parameters<T>) => void;
|
|
141
|
+
/**
|
|
142
|
+
* beacon请求
|
|
143
|
+
* @param para SendBeacon参数
|
|
144
|
+
* @returns Promise<TrackingResponse>
|
|
145
|
+
*/
|
|
146
|
+
sendBeacon: (para: SendBeaconParams) => Promise<TrackingResponse>;
|
|
147
|
+
/**
|
|
148
|
+
* 获取设备唯一标识
|
|
149
|
+
* 基于浏览器指纹技术,通过收集浏览器特征生成唯一ID
|
|
150
|
+
* @returns 返回设备唯一标识字符串
|
|
151
|
+
*/
|
|
152
|
+
getDeviceId: () => string;
|
|
153
|
+
/**
|
|
154
|
+
* 收集浏览器指纹信息
|
|
155
|
+
* @returns 返回浏览器指纹对象
|
|
156
|
+
*/
|
|
157
|
+
protected collectFingerprint: () => DeviceFingerprint;
|
|
158
|
+
/**
|
|
159
|
+
* 获取WebGL指纹
|
|
160
|
+
* @returns WebGL指纹字符串
|
|
161
|
+
*/
|
|
162
|
+
private getWebGLFingerprint;
|
|
163
|
+
/**
|
|
164
|
+
* 获取Canvas指纹
|
|
165
|
+
* @returns Canvas指纹字符串
|
|
166
|
+
*/
|
|
167
|
+
private getCanvasFingerprint;
|
|
168
|
+
/**
|
|
169
|
+
* 获取音频上下文指纹
|
|
170
|
+
* @returns 音频指纹字符串
|
|
171
|
+
*/
|
|
172
|
+
private getAudioFingerprint;
|
|
173
|
+
/**
|
|
174
|
+
* 获取字体指纹
|
|
175
|
+
* @returns 字体指纹字符串
|
|
176
|
+
*/
|
|
177
|
+
private getFontFingerprint;
|
|
178
|
+
/**
|
|
179
|
+
* 获取插件指纹
|
|
180
|
+
* @returns 插件指纹字符串
|
|
181
|
+
*/
|
|
182
|
+
private getPluginsFingerprint;
|
|
183
|
+
/**
|
|
184
|
+
* 检测localStorage支持
|
|
185
|
+
* @returns 是否支持localStorage
|
|
186
|
+
*/
|
|
187
|
+
private hasLocalStorage;
|
|
188
|
+
/**
|
|
189
|
+
* 检测sessionStorage支持
|
|
190
|
+
* @returns 是否支持sessionStorage
|
|
191
|
+
*/
|
|
192
|
+
private hasSessionStorage;
|
|
193
|
+
/**
|
|
194
|
+
* 检测IndexedDB支持
|
|
195
|
+
* @returns 是否支持IndexedDB
|
|
196
|
+
*/
|
|
197
|
+
private hasIndexedDB;
|
|
198
|
+
/**
|
|
199
|
+
* 获取网络连接指纹
|
|
200
|
+
* @returns 网络连接指纹字符串
|
|
201
|
+
*/
|
|
202
|
+
private getConnectionFingerprint;
|
|
203
|
+
/**
|
|
204
|
+
* 将指纹信息哈希为唯一ID
|
|
205
|
+
* @param fingerprint 指纹信息
|
|
206
|
+
* @returns 返回哈希后的设备ID
|
|
207
|
+
*/
|
|
208
|
+
protected hashFingerprint: (fingerprint: DeviceFingerprint) => string;
|
|
209
|
+
}
|