hina-cloud-js-sdk 4.0.5 → 4.0.7

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};function e(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function r(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(r.prototype=o.prototype,new r)}var o,r,n,i=function(){return i=Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},i.apply(this,arguments)};function s(t,e,o,r){return new(o||(o=Promise))((function(n,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))}function a(t,e){var o,r,n,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(o=1,r&&(n=2&a[0]?r.return:a[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,a[1])).done)return n;switch(r=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(n=i.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){i.label=a[1];break}if(6===a[0]&&i.label<n[1]){i.label=n[1],n=a;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(a);break}n[2]&&i.ops.pop(),i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t],r=0}finally{o=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function c(t){var e="function"==typeof Symbol&&Symbol.iterator,o=e&&t[e],r=0;if(o)return o.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function u(t,e){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var r,n,i=o.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){n={error:t}}finally{try{r&&!r.done&&(o=i.return)&&o.call(i)}finally{if(n)throw n.error}}return s}function l(t,e,o){if(o||2===arguments.length)for(var r,n=0,i=e.length;n<i;n++)!r&&n in e||(r||(r=Array.prototype.slice.call(e,0,n)),r[n]=e[n]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError,exports.ConsoleTypes=void 0,(o=exports.ConsoleTypes||(exports.ConsoleTypes={})).LOG="log",o.INFO="info",o.WARN="warn",o.ERROR="error",o.ASSERT="assert",exports.ReportTypes=void 0,(r=exports.ReportTypes||(exports.ReportTypes={})).BEACON="beacon",r.IMAGE="image",r.AJAX="ajax",exports.VariablesTypes=void 0,(n=exports.VariablesTypes||(exports.VariablesTypes={})).INTEGER="INTEGER",n.STRING="STRING",n.BOOLEAN="BOOLEAN";var p=function(t,e){this.options=t,this.context=e,this.disabled=!1},h=["utm_source","utm_medium","utm_campaign","utm_content","utm_term"];l(l([],u(h),!1),u(["ha_utm"]),!1);var f=["www.baidu.","m.baidu.","m.sm.cn","so.com","sogou.com","youdao.com","google.","yahoo.com/","bing.com/","ask.com/"],d=["weibo.com","renren.com","kaixin001.com","douban.com","qzone.qq.com","zhihu.com","tieba.baidu.com","weixin.qq.com"],g={baidu:["wd","word","kw","keyword"],google:"q",bing:"q",yahoo:"p",sogou:["query","keyword"],so:"q",sm:"q"},v="hinasdk_domain_test",m=Object.prototype.toString;function y(t){return"[object Object]"===m.call(t)}function b(t){return null!=t}function w(t){return Array.isArray(t)}function _(t){return"function"==typeof t}function x(t){return"string"==typeof t}function T(t){return"number"==typeof t&&!Number.isNaN(t)}function S(t){return"boolean"==typeof t}function k(){}function C(t){try{return JSON.parse(t)}catch(t){}return t}function A(t){return 0===Object.keys(t).length}function H(){return Date.now&&_(Date.now)?Date.now():(new Date).getTime()}function R(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var o=Object.create(null);return t.forEach((function(t){t&&Object.keys(t).forEach((function(e){var r=t[e];y(r)?y(o[e])?o[e]=R(o[e],r):o[e]=R(r):o[e]=r}))})),o}function I(t){var e={};try{e=new URL(t)}catch(t){}return e}function P(t,e){if(!t)return t;var o=t.toString(),r=o.indexOf(".");return o=-1!==r?o.substring(0,r+e+1):o.substring(0),parseFloat(o)}function N(t){t=t||window.location.hostname,/^[a-zA-Z0-9\u4e00-\u9fa5\-\\.]+$/.exec(t)||(t="");var e=t.split(".");if(e.length>=2&&!/^(\d+\.)+\d+$/.test(t))for(var o=".".concat(e.splice(e.length-1,1));e.length>0;)if(o=".".concat(e.splice(e.length-1,1)).concat(o),document.cookie="".concat(v,"=true; path=/; domain=").concat(o),-1!==document.cookie.indexOf("".concat(v,"=true")))return document.cookie="".concat(v,"=true; path=/; domain=").concat(o,"; max-age=0"),o;return""}function L(){var t=N();return""===t?"url解析失败":t}function E(t){var e=t||document.referrer;return"string"!=typeof e?"referrer exception".concat(String(e)):(e.startsWith("https://www.baidu.com/")&&(e=e.split("?")[0]),"string"==typeof(e=e.slice(0,200))?e:"")}function O(t,e){return e&&"string"==typeof e||(e="hostname解析异常"),t&&(I(t).hostname||"")||e}function D(){var t=H(),e=Math.floor(1e6*Math.random());return Number(String(t).slice(-5)+String(e).slice(0,4))}function U(t,e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]"),t=decodeURIComponent(t);var o=new RegExp("[\\?&]".concat(e,"=([^&#]*)")).exec(t);return null===o||o&&"string"!=typeof o[1]&&o[1].length?"":decodeURIComponent(o[1])}function B(t){try{return btoa(encodeURIComponent(t).replace(/%([0-9A-F]{2})/g,(function(t,e){return String.fromCharCode(Number("0x".concat(e)))})))}catch(e){return t}}function W(t,e,o,r){if(void 0!==t&&(e in t||r)){var n=o(t[e]);_(n)&&(t[e]=n)}}var M=function(){function t(){this.name="CookieStorage"}return t.prototype.isSupport=function(t,e){var o=this;void 0===t&&(t="cookie_support_test"),void 0===e&&(e="1");return navigator.cookieEnabled&&(o.set(t,e),o.get(t)===e&&(o.remove(t),!0))},t.prototype.get=function(t){var e,o,r=document.cookie.split(";");try{for(var n=c(r),i=n.next();!i.done;i=n.next()){var s=i.value.split("=");if(s[0].trim()===t)return decodeURIComponent(s[1])}}catch(t){e={error:t}}finally{try{i&&!i.done&&(o=n.return)&&o.call(n)}finally{if(e)throw e.error}}return null},t.prototype.set=function(t,e,o,r,n,i,s){r=r||"/",t=t.trim(),e=e.trim();var a="".concat(t,"=").concat(encodeURIComponent(e),"; path=").concat(r,";");o=b(o)?o:63072e8,a+=" max-age=".concat(o,";"),s&&(a+=" secure;"),n&&(a+=" domain=".concat(n,";")),["Strict","Lax","None"].includes(i)&&(a+=" SameSite=".concat(i,";")),document.cookie=a},t.prototype.remove=function(t,e){void 0===e&&(e="/"),this.set(t,"1",0,e)},t.prototype.setDomain=function(t,e,o){var r=L();"url解析失败"===r&&(r=""),this.set(t,e,o,"/",r)},t}(),j=function(){function t(){this.name="LocalStorage"}return t.prototype.isSupport=function(){var t=!0;try{var e="__localStorageSupport__",o="testIsSupportStorage";this.set(e,o),this.get(e)!==o&&(t=!1),this.remove(e)}catch(e){t=!1}return t},t.prototype.key=function(t){return window.localStorage.key(t)},t.prototype.get=function(t){return window.localStorage.getItem(t)},t.prototype.length=function(){return window.localStorage.length},t.prototype.set=function(t,e){try{window.localStorage.setItem(t,e)}catch(t){}},t.prototype.remove=function(t){window.localStorage.removeItem(t)},t.prototype.parse=function(t){var e=this.get(t);try{e=JSON.parse(e)}catch(t){e=""}return e},t}(),q=function(){function t(){this.name="MemoryStorage",this.data={}}return t.prototype.get=function(t){var e=this.data[t];return b(null==e?void 0:e.expireTime)?e.expireTime<H()?null:e.value:null==e?void 0:e.value},t.prototype.set=function(t,e,o){if(b(o)){var r=H()+1e3*o;this.data[t]={value:e,expireTime:r}}this.data[t]={value:e}},t.prototype.setDomain=function(t,e,o){this.set(t,e,o)},t}();function F(t,e){if(void 0===e&&(e=exports.ConsoleTypes.LOG),"undefined"!=typeof console){var o=console[e]||console.log;"function"==typeof o&&o(t)}}var V,z={all:V=V||new Map,on:function(t,e){var o=V.get(t);o?o.push(e):V.set(t,[e])},emit:function(t,e){var o=V.get(t);o&&o.forEach((function(t){t(e)}))},off:function(t,e){var o=V.get(t);if(o)if(e){var r=o.indexOf(e);r>=0&&o.splice(r,1)}else V.set(t,[])}},K=function(){function t(t,e){this.options=t,this.isFirstTime=!1,this.isFirstDay=!1,this.state=e}return t.prototype.log=function(t,e){void 0===e&&(e=exports.ConsoleTypes.LOG),this.options.showLog&&F(t,e)},t.prototype.checkSetValue=function(t,e){return!(!T(e=null!=e?e:"")&&!x(e))||(this.log("".concat(t,": id must be string or number"),exports.ConsoleTypes.WARN),!1)},t.prototype.setDeviceId=function(t){void 0===t&&(t=""),this.checkSetValue("deviceId",t)&&this.set("deviceId",t)},t.prototype.setAccountId=function(t){void 0===t&&(t=""),this.checkSetValue("accountId",t)&&(this.set("accountId",t),z.emit("changeAccountId"))},t.prototype.setAnonymousId=function(t){this.state.anonymousId?this.log("Current anonymousId is ".concat(this.getAnonymousId(),", it has been set"),exports.ConsoleTypes.WARN):this.checkSetValue("anonymousId",t)&&this.set("anonymousId",t)},t.prototype.setProps=function(t){var e=R(this.state.props||{},t);for(var o in e)"string"==typeof e[o]&&(e[o]=e[o].slice(0,200));this.set("props",e)},t.prototype.getAnonymousId=function(){return this.state.anonymousId},t.prototype.getDeviceId=function(){return this.state.deviceId},t.prototype.getAccountId=function(){return this.state.accountId},t.prototype.clear=function(){this.state={},this.save()},t.prototype.set=function(t,e){this.state[t]=e,this.save()},t.prototype.afterInit=function(t){t?(this.isFirstDay=function(t){var e;try{var o=new Date,r=o.getFullYear(),n=o.getMonth()+1,i=o.getDate(),s=new Date(t),a=s.getFullYear(),c=s.getMonth()+1,u=s.getDate();e=r===a&&n===c&&i===u}catch(t){e=!1}return e}(this.state.firstVisitTime),this.save()):(this.isFirstDay=!0,this.isFirstTime=!0);var e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=16*Math.random()|0;return"x"===t?e.toString(16):(3&e|8).toString(16)}));this.getAnonymousId()||this.setAnonymousId(e),this.getDeviceId()||this.setDeviceId(e)},t}(),J=function(t){function o(e){var o=this,r={accountId:null,deviceId:null,anonymousId:null,sessionId:null,firstVisitTime:H(),props:{}};return(o=t.call(this,e,r)||this).options=e,o.storeName="hinasdk_crossdata",o.hLatestUtm={},o.hUtm={},o.customUtm={},o}return e(o,t),o.prototype.getUtmFromProps=function(t){for(var e in this.state.props){var o=this.state.props[e];e.startsWith("H_latest_")?this.hLatestUtm[e]=o:e.startsWith("H_")&&(this.hUtm[e]=o),t.includes(e)&&(this.customUtm[e]=o)}},o.prototype.init=function(){var t,e=new M,o=new q,r=new j;e.isSupport()?this.storage=e:(this.log("Cookie storage is not supported, SDK internal cache has been enabled",exports.ConsoleTypes.WARN),this.storage=o),r.isSupport()?this.localStorage=r:this.log("localStorage is not supported, SDK internal cache has been enabled",exports.ConsoleTypes.WARN),!(t=this.storage.get(this.storeName))&&this.localStorage&&(t=this.localStorage.get(this.storeName)),t&&function(t){try{JSON.parse(t)}catch(t){return!1}return!0}(t)?this.state=C(t):t=null,this.afterInit(t)},o.prototype.save=function(){this.storage.setDomain(this.storeName,JSON.stringify(this.state)),this.localStorage&&this.localStorage.set(this.storeName,JSON.stringify(this.state))},o.prototype.getCookie=function(){return this.storage.get(this.storeName)},o.prototype.setSessionId=function(t){this.set("sessionId",t)},o.prototype.getSessionId=function(){return this.state.sessionId||""},o.prototype.getSessionIdCreateTime=function(){var t=this.getSessionId().split("_")[0],e=Number(t);return Number.isNaN(e)?0:e},o}(K),G=function(){function t(){this.isReady=!1,this.isReady||this.init(),this.isReady=!0}return t.prototype.init=function(){this.os=this.getOs(),this.osVersion=this.getOsVersion();var t=this.getBrowser(),e=t.type,o=t.version;this.browserName=e,this.browserVersion=o,this.model=this.getModel()},t.prototype.getOs=function(){var t=navigator.userAgent;return/Windows/i.test(t)?/Phone/.test(t)||/WPDesktop/.test(t)?"Windows Phone":"Windows":/(iPhone|iPad|iPod)/.test(t)&&!window.MSStream?"iOS":/Android/.test(t)?"Android":/(BlackBerry|PlayBook|BB10)/i.test(t)?"BlackBerry":/Mac/i.test(t)?"Mac OS X":/Linux/.test(t)?"Linux":/CrOS/.test(t)?"Chrome OS":"取值异常"},t.prototype.getOsVersion=function(){var t=navigator.userAgent;if(/Windows/i.test(t)){var e=/Windows NT ([\d.]+)/;return t.match(e)?t.match(e)[1]:""}if(/(iPhone|iPad|iPod)/.test(t)&&!window.MSStream){e=/OS ([\d_]+)/;return t.match(e)?t.match(e)[1].replace(/_/g,"."):""}if(/Android/.test(t)){e=/Android ([\d.]+)/;return t.match(e)?t.match(e)[1]:""}if(/Mac/i.test(t)){e=/Mac OS X ([\d_]+)/;return t.match(e)?t.match(e)[1].replace(/_/g,"."):""}return""},t.prototype.getBrowser=function(){var t,e={type:"",version:""};try{var o=null===(t=navigator.userAgent)||void 0===t?void 0:t.toLowerCase(),r=[];if(null!==o.match(/baidubrowser/)?(e.type="baidu",r.push(/baidubrowser\/([\d.]+)/)):null!==o.match(/bidubrowser/)?(e.type="baidu",r.push(/bidubrowser\/([\d.]+)/)):null!==o.match(/edg/)?(e.type="edge",r.push(/edg\/([\d.]+)/)):null!==o.match(/edgios/)?(e.type="edge",r.push(/edgios\/([\d.]+)/)):null!==o.match(/liebaofast/)?(e.type="liebao",r.push(/liebaofast\/([\d.]+)/)):null!==o.match(/sogoumobilebrowser/)?(e.type="sogou",r.push(/sogoumobilebrowser\/([\d.]+)/)):null!==o.match(/lbbrowser/)?(e.type="liebao",r.push(/lbbrowser\/([\d.]+)/)):null!==o.match(/crios/)?(e.type="chrome",r.push(/crios\/([\d.]+)/)):null!==o.match(/qihoobrowser/)?(e.type="360",r.push(/qihoobrowser\/([\d.]+)/)):null!==o.match(/mxios/)?(e.type="maxthon",r.push(/mxios\/([\d.]+)/)):null!==o.match(/fxios/)?(e.type="firefox",r.push(/fxios\/([\d.\w]+)/)):null!==o.match(/edge/)?(e.type="edge",r.push(/edge\/([\d.]+)/)):null!==o.match(/metasr/)?(e.type="sogou",r.push(/metasr ([\d.]+)/)):null!==o.match(/micromessenger/)?(e.type="micromessenger",r.push(/micromessenger\/([\d.]+)/)):null!==o.match(/mqqbrowser/)?(e.type="qq",r.push(/mqqbrowser\/([\d.]+)/)):null!==o.match(/qqbrowserlite/)?(e.type="qq",r.push(/qqbrowserlite\/([\d.]+)/)):null!==o.match(/tencenttraveler/)?(e.type="qq",r.push(/tencenttraveler\/([\d.]+)/)):null!==o.match(/qqbrowser/)?(e.type="qq",r.push(/qqbrowser\/([\d.]+)/)):null!==o.match(/maxthon/)?(e.type="maxthon",r.push(/maxthon\/([\d.]+)/)):null!==o.match(/ubrowser/)?(e.type="uc",r.push(/ubrowser\/([\d.]+)/)):null!==o.match(/ucbrowser/)?(e.type="uc",r.push(/ucbrowser\/([\d.]+)/)):null!==o.match(/firefox/)?(e.type="firefox",r.push(/firefox\/([\d.]+)/)):null!==o.match(/opera/)?(e.type="opera",r.push(/opera\/([\d.]+)/)):null!==o.match(/opr/)?(e.type="opera",r.push(/opr\/([\d.]+)/)):null!==o.match(/chrome/)?(e.type="chrome",r.push(/chrome\/([\d.]+)/)):null!==o.match(/safari/)?(e.type="safari",r.push(/version\/([\d.]+)/)):null===o.match(/trident/)&&null===o.match(/msie/)||(e.type="ie"),"ie"===e.type){var n=o.match(/trident\/([\d.]+)/)?o.match(/trident\/([\d.]+)/)[1]:"",i=o.match(/msie ([\d.]+)/)?o.match(/msie ([\d.]+)/)[1]:"";""!==n?e.version=String(parseInt(n,10)+4):""!==i&&(e.version=i)}else r&&(e.version=o.match(r[0])?o.match(r[0])[1]:"")}catch(t){e.type="取值异常"}return e},t.prototype.getModel=function(){var t=navigator.userAgent;if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(t)){if(/iPhone|iPad|iPod/i.test(t))return t.match(/iPhone|iPad|iPod/i)[0];if(/Android/i.test(t))return t.match(/Android/i)[0]}var e=t.match(/Mac/);if(e)return e[0];var o=t.match(/Windows/);if(o)return o[0];var r=t.match(/Linux/);return r?r[0]:"取值异常"},t}();function $(){return document.documentElement.scrollTop||document.body.scrollTop||0}function X(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0}function Z(){return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0}var Y=function(){function t(t){this.visibleHandler=function(){},this.hiddenHandler=function(){};var e=t.visible,o=t.hidden;_(e)&&(this.visibleHandler=e),_(o)&&(this.hiddenHandler=o),this.init()}return t.prototype.isSupport=function(){return void 0!==document.hidden},t.prototype.init=function(){var t=this;this.isSupport()?document.addEventListener("visibilitychange",(function(){document.hidden?t.hiddenHandler():t.visibleHandler()})):(window.addEventListener("focus",this.visibleHandler),window.addEventListener("blur",this.hiddenHandler))},t}();var Q=function(){function t(t){this.options=t}return t.prototype.run=function(){var t=this;return new Promise((function(e){var o=t.options,r=o.imgUseCrossOrigin,n=o.url,i=o.data,s=new Image;r&&(s.crossOrigin="anonymous");var a=-1===n.indexOf("?")?"?":"&";s.src="".concat(n).concat(a).concat(i);var c=function(t){s=null,e({type:t})};s.onload=function(){c("success")},s.onerror=function(){c("success")}}))},t}(),tt=function(){function t(t){this.options=t}return t.prototype.run=function(){var t=this;return new Promise((function(e){var o=t.options,r=o.url,n=o.data,i=o.timeout,s=o.credentials,a=o.contentType,c=o.customHeaders,u=void 0===c?{}:c,l=new XMLHttpRequest;l.open("POST",r,!0),l.timeout=i||2e4,l.isMonitor=!0,s&&(l.withCredentials=!0),l.setRequestHeader("Content-Type",a||"application/x-www-form-urlencoded"),y(u)&&!A(u)&&Object.keys(u).forEach((function(t){l.setRequestHeader(t,u[t])})),l.send(n||null),l.ontimeout=function(){l.abort()},l.onreadystatechange=function(){4===l.readyState&&(l.status>=200&&l.status<300||304===l.status?e({data:JSON.parse(l.responseText)||{},type:"success"}):e({type:"fail",msg:"网络异常, 请求失败,状态码=".concat(l.status)}))}}))},t}(),et=function(){function t(t){this.options=t}return t.prototype.run=function(){var t=this;return new Promise((function(e){var o=t.options,r=o.url,n=o.data;navigator.sendBeacon&&e(navigator.sendBeacon(r,n)?{type:"success"}:{type:"fail",msg:"sendBeacon 请求失败"})}))},t}(),ot=function(){function t(t,e,o){void 0===e&&(e="hinasdk_tab"),void 0===o&&(o="hinasdk_data_"),this.options=t,this.batchKey=e,this.batchDataKey=o,this.isSending=!1,this.init()}return t.prototype.log=function(t,e){void 0===e&&(e=exports.ConsoleTypes.LOG),this.options.showLog&&F(t,e)},t.prototype.init=function(){var t=new j;t.isSupport()?(this.localStorage=t,this.isSupport=!0):(this.isSupport=!1,this.log("批量发送功能需要使用localstorage存储数据,但是您的浏览器不支持localstorage,所以不能使用该功能",exports.ConsoleTypes.WARN)),this.batchInterval()},t.prototype.getBatchConfig=function(){return this.options.batchSend},t.prototype.getStorageList=function(){if(!this.isSupport)return[];var t=[],e=this.localStorage.get(this.batchKey);return e&&(w(t=C(e))||(t=[])),t},t.prototype.batchInterval=function(){var t=this;if(this.isSupport){var e=this.getBatchConfig().sendInterval;setTimeout((function(){t.send().then((function(){t.batchInterval()}))}),e)}},t.prototype.send=function(){var t=this;return new Promise((function(e){var o=t.getStorageList();if(o.length>0&&t.isSupport){for(var r=t.getBatchConfig().dataSendTimeout,n=H(),i=[],s={},a=o.length,c=0;c<a;c++){var u=o[c],l=u.dataKey,p=u.expireTime;if(p>=n)s[l]={dataKey:l,expireTime:p},(y=t.localStorage.get(l))&&i.push(C(y));else t.localStorage.remove(l),o.splice(c,1),a--,c--}if(t.localStorage.set(t.batchKey,JSON.stringify(o)),0===i.length)e();else{var h=t.options,f=h.serverUrl,d=h.customHeaders,g=h.credentials,v=h.globalCallback,m=JSON.stringify(i),y=encodeURIComponent(B(m));t.isSending=!0,new tt({url:f,data:"data_list=".concat(y),timeout:r,credentials:g,customHeaders:d}).run().then((function(o){_(v)&&v(f,i,o.type,o.msg||""),"success"===o.type&&t.remove(s),e(),t.isSending=!1}))}}else e()}))},t.prototype.remove=function(t){var e=this;if(this.isSupport){var o=this.getStorageList(),r=Object.keys(t);if(r.forEach((function(t){e.localStorage.remove(t)})),o.length===r.length)this.localStorage.set(this.batchKey,JSON.stringify([]));else{var n=o.filter((function(e){return!t[e.dataKey]}));this.localStorage.set(this.batchKey,JSON.stringify(n))}}},t.prototype.add=function(t){if(this.isSupport){var e,o,r=this.getBatchConfig(),n=r.sendInterval,i=r.storageLimit,s=this.batchDataKey+(e=H(),o=Math.floor(1e6*Math.random()),"".concat(e,"_").concat(o)),a=this.getStorageList();a.unshift({dataKey:s,expireTime:H()+2*n}),this.localStorage.set(this.batchKey,JSON.stringify(a)),this.localStorage.set(s,JSON.stringify(t)),!this.isSending&&(a.length>i||"track_signup"===t.type||"H_pageview"===t.event)&&this.send()}},t}();function rt(t,e){Object.keys(t).forEach((function(o){var r=t[o];if(x(r)&&r.length>e)F("属性 ".concat(o," 已经做截取")),t[o]=r.slice(0,e);else if(y(r))rt(r,e);else if(_(r))try{t[o]=r(t),_(t[o])?(F("属性--".concat(o," 格式不满足要求, 已被删除"),exports.ConsoleTypes.WARN),delete t[o]):y(t[o])?rt(t[o],e):x(t[o])&&t[o].length>e&&(t[o]=t[o].slice(0,e))}catch(e){F("属性--".concat(o," 格式不满足要求, 已被删除"),exports.ConsoleTypes.WARN),delete t[o]}}))}var nt=["abtestExperimentId","paramName","valueType","defaultValue","callback","timeoutMilliseconds","customProperties","customIds"],it=function(t){function o(e,o,r,n,i){var s=t.call(this,e,o)||this;return s.options=e,s.context=o,s.name="AbtestBasePlugin",s.isReady=!1,s.platform="",s.storageName="",s.version="",s.projectKey="",s.platform=r,s.storageName=n,s.version=i,s}return e(o,t),o.prototype.init=function(){var t=this;if(this.context.store.localStorage){var e=this.options.abTestingPluginConfig,o=null==e?void 0:e.url;if(x(o)){var r=U(o,"project-key");if(r){if(this.projectKey=r,["Web","H5"].includes(this.platform)){var n=I(o).protocol,i=I(window.location.href).protocol;n&&n!==i&&this.context.log("A/B Testing 初始化失败,".concat(i," 页面必须使用 ").concat(i," 的 URL"),exports.ConsoleTypes.WARN)}if(this.isReady)this.context.log("A/B Testing 插件已经运行,无需重复执行",exports.ConsoleTypes.WARN);else{var s=this.context.getUserUid();this.context.log("当前accountId为:".concat(s),exports.ConsoleTypes.INFO),z.on("changeAccountId",(function(){t.context.store.localStorage.set(t.storageName,"")})),this.isReady=!0}}else this.context.log("A/B Testing 初始化失败,请使用正确的 URL(必须包含 project-key)")}else this.context.log("A/B Testing 初始化失败,请使用正确的 URL!",exports.ConsoleTypes.WARN)}else this.context.log("A/B Testing 初始化失败,浏览器不支持localStorage",exports.ConsoleTypes.WARN)},o.prototype.transform=function(){},o.prototype.valueMatchType=function(t,e){switch(e){case exports.VariablesTypes.INTEGER:return T(t);case exports.VariablesTypes.STRING:return x(t);case exports.VariablesTypes.BOOLEAN:return S(t);default:return!1}},o.prototype.normalizeParams=function(t,e,o){var r,n;void 0===o&&(o=nt);var i={verify_success:!0,para:e};try{for(var s=c(o),a=s.next();!a.done;a=s.next()){var u=a.value;if(!i.verify_success)break;switch(u){case"abtestExperimentId":x(e.abtestExperimentId)&&e.abtestExperimentId.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(u,"参数未正确配置!").concat(u,": ").concat(e.abtestExperimentId),exports.ConsoleTypes.WARN),i.verify_success=!1);break;case"paramName":x(e.paramName)&&e.paramName.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(u,"参数未正确配置!").concat(u,": ").concat(e.paramName),exports.ConsoleTypes.WARN),i.verify_success=!1);break;case"valueType":[exports.VariablesTypes.BOOLEAN,exports.VariablesTypes.INTEGER,exports.VariablesTypes.STRING].includes(e.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(u,"参数未正确配置!").concat(u,": ").concat(e.valueType),exports.ConsoleTypes.WARN),i.verify_success=!1);break;case"defaultValue":this.valueMatchType(e.defaultValue,e.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(u,"类型必须与valueType一致!"),exports.ConsoleTypes.WARN),i.verify_success=!1);break;case"callback":_(e.callback)||(this.context.log("".concat(t,"方法调用失败,").concat(u,"参数未正确配置")),e.callback=k,i.verify_success=!1);break;case"timeoutMilliseconds":(!T(e.timeoutMilliseconds)||e.timeoutMilliseconds<=0)&&(this.context.log("".concat(u,"参数错误:").concat(e.timeoutMilliseconds),exports.ConsoleTypes.WARN),e.timeoutMilliseconds=3e3),e.timeoutMilliseconds<200&&(e.timeoutMilliseconds=200);break;case"customProperties":e.customProperties=y(e.customProperties)?e.customProperties:{};break;case"customIds":var l=e.customIds||{},p={};for(var h in l)(x(l[h])||T(l[h]))&&(p[h]=l[h]);e.customIds=p}}}catch(t){r={error:t}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return i},o.prototype.sendTriggerEvent=function(t){var e=t.abtest_experiment_group_id,o=t.abtest_experiment_id;this.context.track("H_ABTestTrigger",{H_abtest_experiment_id:o,H_abtest_experiment_group_id:e})},o.prototype.getExpResult=function(t){return s(this,arguments,void 0,(function(t,e){var o,r,n,i,s,u,l,p,h,f,d,g,v,m,b;return void 0===e&&(e=[]),a(this,(function(a){switch(a.label){case 0:return o=t.abtestExperimentId,r=t.paramName,n=t.valueType,0!==e.length?[3,2]:[4,this.getStorageData()];case 1:y(s=a.sent())&&(e=s.result||[]),a.label=2;case 2:try{for(u=c(e),l=u.next();!l.done;l=u.next())if(p=l.value,h=p.abtest_experiment_id,f=p.abtest_experiment_group_id,d=p.is_white_list,g=p.variables,h===o&&(v=g.find((function(t){return t.name===r&&t.type===n})),v)){d||this.sendTriggerEvent({abtest_experiment_id:h,abtest_experiment_group_id:f}),i=v.value;break}}catch(t){m={error:t}}finally{try{l&&!l.done&&(b=u.return)&&b.call(u)}finally{if(m)throw m.error}}return[2,i]}}))}))},o.prototype.getStorageData=function(){return s(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,this.context.store.localStorage.get(this.storageName)];case 1:return(t=e.sent())?[2,C(t)]:[2,null]}}))}))},o.prototype.saveResponseData=function(t){return s(this,void 0,void 0,(function(){var e,o,r,n;return a(this,(function(i){switch(i.label){case 0:return[4,this.getStorageData()];case 1:return e=i.sent(),o={updateTime:H()},e&&y(e)?(r=[],n=e.result||[],t.forEach((function(t){var e=t.abtest_experiment_group_id,o=t.abtest_experiment_id,i=t.variables,s=n.find((function(t){return t.abtest_experiment_id===o&&t.abtest_experiment_group_id===e}));if(s){var a=[];i.forEach((function(t){var e=t.name,o=t.type,r=s.variables.findIndex((function(t){return t.name===e&&t.type===o}));r>=0?s.variables[r]=t:a.push(t)})),s.variables=l(l([],u(s.variables),!1),u(a),!1)}else r.push(t)})),o.result=l(l([],u(n),!1),u(r),!1)):o.result=t,this.context.store.localStorage.set(this.storageName,JSON.stringify(o)),[2]}}))}))},o.prototype.createRequestData=function(t){var e=t.paramName,o=t.customProperties,r=t.customIds,n={anonymous_id:this.context.store.getAnonymousId(),platform:this.platform,abtest_lib_version:this.version,param_name:e,properties:this.context.getPresetProperties()};return y(o)&&!A(o)&&(n.custom_properties=o),y(r)&&!A(r)&&(n.custom_ids=r),this.context.getUserUid()&&(n.login_id=this.context.getUserUid()),n},o.prototype.preFetch=function(t,e){return this.isReady?!!y(e)||(this.context.log("".concat(t," 方法参数必须是对象"),exports.ConsoleTypes.WARN),!1):(this.context.log("A/B Testing 插件尚未运行,请先执行该插件",exports.ConsoleTypes.WARN),!1)},o.prototype.asyncFetch=function(t){var e=this;return new Promise((function(o){e.getResultFromServer(t).then((function(t){o(t)})).catch((function(){t.callback(t.defaultValue)}))}))},o.prototype.asyncFetchABTest=function(t){var e=this;if(this.preFetch("asyncFetchABTest",t)){var o=this.normalizeParams("asyncFetchABTest",t),r=o.verify_success,n=o.para;r?this.asyncFetch(n).then((function(t){return s(e,void 0,void 0,(function(){var e;return a(this,(function(o){switch(o.label){case 0:return[4,this.getExpResult(n,t.results)];case 1:return e=o.sent(),n.callback(e||n.defaultValue),[2]}}))}))})):n.callback(n.defaultValue)}},o.prototype.fetchCacheABTest=function(t){return s(this,void 0,void 0,(function(){var e,o,r,n;return a(this,(function(i){switch(i.label){case 0:return this.preFetch("fetchCacheABTest",t)?(e=this.normalizeParams("fetchCacheABTest",t),o=e.verify_success,r=e.para,o?[4,this.getExpResult(r)]:[3,2]):[2];case 1:return n=i.sent(),r.callback(n||r.defaultValue),[3,3];case 2:r.callback(r.defaultValue),i.label=3;case 3:return[2]}}))}))},o.prototype.fastFetchABTest=function(t){return s(this,void 0,void 0,(function(){var e,o,r,n,i=this;return a(this,(function(c){switch(c.label){case 0:return this.preFetch("fastFetchABTest",t)?(e=this.normalizeParams("fastFetchABTest",t),o=e.verify_success,r=e.para,o?[4,this.getExpResult(r)]:[3,2]):[2];case 1:return b(n=c.sent())?r.callback(n):this.asyncFetch(r).then((function(){return s(i,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,this.getExpResult(r)];case 1:return t=e.sent(),r.callback(t||r.defaultValue),[2]}}))}))})),[3,3];case 2:r.callback(r.defaultValue),c.label=3;case 3:return[2]}}))}))},o}(p);function st(t){return 1===(null==t?void 0:t.nodeType)}function at(t,e){var o;if("input"===(null===(o=t.tagName)||void 0===o?void 0:o.toLowerCase())){var r=t.type||t.getAttribute("type");return(["button","submit"].includes(r)||e)&&(t.textContent||t.value)||""}var n="";return t.textContent?n=t.textContent.trim():t.innerText&&(n=t.innerText.trim()),n&&(n=n.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),n||""}function ct(t,e){var o;if(!st(t))return{};var r,n={H_element_type:null===(o=t.tagName)||void 0===o?void 0:o.toLowerCase(),H_element_name:t.getAttribute("name"),H_element_id:t.getAttribute("id"),H_element_target_url:t.getAttribute("href"),H_element_class_name:t.classList.value||t.className,H_element_content:at(t,e)};return r=n,Object.keys(r).reduce((function(t,e){return b(r[e])&&""!==r[e]&&(t[e]=r[e]),t}),{})}function ut(t,e){if(!t)return{};var o=document.documentElement.scrollLeft||document.body.scrollLeft||0,r=$(),n=e.getBoundingClientRect(),i=t.pageX||t.clientX+o||t.offsetX+((null==n?void 0:n.left)||0)+o,s=t.pageY||t.clientY+r||t.offsetY+((null==n?void 0:n.top)||0)+r;return{H_page_x:P(i,3),H_page_y:P(s,3)}}var lt=function(){function t(t,e){void 0===e&&(e=!0),this.isReady=!1,this.consolePrefix="埋点SDK",this.useInstancing=!0,this.plugins=[],this.options=t,this.useInstancing=e}return t.prototype.log=function(t,e){void 0===e&&(e=exports.ConsoleTypes.LOG),this.options.showLog&&("string"==typeof t&&this.consolePrefix&&(t="".concat(this.consolePrefix,":").concat(t)),F(t,e))},t.prototype.runPlugins=function(t){var e=this;t.forEach((function(t){t.disabled||t.init((function(o){if(t.transform){var r=t.transform(o);r&&e.report(r)}}))}))},t.prototype.applyPlugins=function(t){var e=this;if(this.isReady){w(t)||(t=[t]);var o=[];t.forEach((function(t){var r=new t(e.options,e);e.plugins.push(r),o.push(r)})),this.runPlugins(o)}else this.log("请先初始化SDK实例",exports.ConsoleTypes.WARN)},t}(),pt=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return e(o,t),o.prototype.sendReportData=function(t,e,o){var r=this.options,n=r.batchSend,i=r.globalCallback,s=r.serverUrl,a=r.dataSendTimeout,c=r.sendType,u=r.customHeaders,l=r.credentials,p=r.imgUseCrossOrigin;if(c=o||c,s){if(y(t)&&!A(t))if(n)this.batchSender.add(t);else{var h=t;x(t)||(h=function(t){try{return JSON.stringify(t)}catch(e){return t}}(t));var f=B(h),d={data:"data=".concat(encodeURIComponent(f)),url:s,timeout:a,imgUseCrossOrigin:p,customHeaders:u,credentials:l};(c===exports.ReportTypes.BEACON&&navigator.sendBeacon?new et(d):c===exports.ReportTypes.IMAGE&&d.data.length<2048?new Q(d):new tt(d)).run().then((function(o){return _(i)&&i(s,t,o.type,o.msg||""),_(e)&&e(s,t,o.type,o.msg||""),o}))}}else this.log("当前 serverUrl 为空,network 中不会发数据,请配置正确的 serverUrl!",exports.ConsoleTypes.WARN)},o}(lt);var ht=["mark","/mark","strong","b","em","i","u","abbr","ins","del","s","sup"],ft=["a","input","button","textarea"],dt=function(t){function o(e,o){var r=t.call(this,e,o)||this;return r.options=e,r.context=o,r.name="ClickTrackPlugin",r.isReady=!1,r.isTrackList={a:!0,button:!0},r}return e(o,t),o.prototype.init=function(t){var e=this,o=this.options.autoTrackConfig,r=o.clickAutoTrack,n=o.isCollectUrl,i=o.isCollectElement,s=o.addCustomProperty;!0===r&&(this.isReady?this.context.log("ClickTrack plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN):(this.isReady=!0,document.addEventListener("click",(function(o){if(n()){var r=o||window.event;if(r){var a=r.target||r.srcElement,c=e.getTargetElement(a);if(c){if(_(i)&&!i(c))return!1;var u=e.getClickElementInfo(c),l=ut(r,c),p=l.H_page_x,h=l.H_page_y,f=I(window.location.href).pathname;u.H_url_path=f,u.H_page_x=p,u.H_page_y=h;var d=e.getElementPosition(c,u.H_element_path);if(T(d)&&d>=0&&(u.H_element_position=d),_(s)){var g=s(c);y(g)&&(u=R(u,g))}t(u)}}}}),!0)))},o.prototype.transform=function(t){return this.context.getReportData("track","H_WebClick",t)},o.prototype.hasAttribute=function(t,e){var o;return t.hasAttribute?t.hasAttribute(e):t.attributes?!!(null===(o=t.attributes[e])||void 0===o?void 0:o.value):void 0},o.prototype.hasAttributes=function(t,e){if(w(e))for(var o=0;o<e.length;o++)if(this.hasAttribute(t,e[o]))return!0;return!1},o.prototype.hasElement=function(t){var e,o,r,n=function(t){var e=[t];try{if(!st(t))return e;if(null===t||null===t.parentElement)return e;for(;null!==t.parentElement;)t=t.parentElement,e.push(t);return e}catch(t){}return e}(t),i=this.options.autoTrackConfig.trackAttr||[];if(w(n)&&n.length>0)try{for(var s=c(n),a=s.next();!a.done;a=s.next()){var u=a.value,l=u.tagName&&(null===(r=u.tagName)||void 0===r?void 0:r.toLowerCase());if(st(u)&&(this.isTrackList[l]||this.hasAttributes(u,i)))return u}}catch(t){e={error:t}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(e)throw e.error}}},o.prototype.getDivMaxLevel=function(){var t;return(null===(t=this.options.autoTrackConfig.collectTags.div)||void 0===t?void 0:t.maxLevel)||1},o.prototype.isStyleTag=function(t){var e,o=(null===(e=this.options.autoTrackConfig.collectTags.div)||void 0===e?void 0:e.ignoreTags)||[];return null==o?void 0:o.includes(t)},o.prototype.getCollectableParent=function(t){var e;try{var o=t.parentNode,r=o?null===(e=o.tagName)||void 0===e?void 0:e.toLowerCase():"";if("body"===r)return!1;var n=this.getDivMaxLevel();if("div"===r&&(n>1||this.isCollectableDiv(o)))return o;if(o&&this.isStyleTag(r))return this.getCollectableParent(o)}catch(t){this.context.log(t,exports.ConsoleTypes.ERROR)}return!1},o.prototype.isCollectableDiv=function(t){var e;try{var o=t.children||[];if(0===o.length)return!0;for(var r=0;r<o.length;r++){var n=o[r];if(st(n)){var i=null===(e=n.tagName)||void 0===e?void 0:e.toLowerCase(),s=this.getDivMaxLevel();if(!("div"===i&&s>1||this.isStyleTag(i)))return!1;if(!this.isCollectableDiv(n))return!1}}return!0}catch(t){this.context.log(t,exports.ConsoleTypes.ERROR)}return!1},o.prototype.isDivLevelValid=function(t){for(var e=this.getDivMaxLevel(),o=t.getElementsByTagName("div"),r=o.length-1;r>=0;r--)if(this.getDivLevels(o[r],t)>e)return!1;return!0},o.prototype.getElementPath=function(t,e,o){for(var r,n,i=[];st(t)&&t.parentNode;){if(t.id&&!e&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.id)){var s=t.tagName||"";i.unshift("".concat(s.toLowerCase(),"#").concat(t.id));break}if(o&&t===o){i.unshift(null===(r=t.tagName)||void 0===r?void 0:r.toLowerCase());break}if(t===document.body){i.unshift("body");break}i.unshift(null===(n=t.tagName)||void 0===n?void 0:n.toLowerCase()),t=t.parentNode}return i.join(" > ")},o.prototype.getDivLevels=function(t,e){var o=this.getElementPath(t,!0,e).split(" > "),r=0;return o.forEach((function(t){"div"===t&&r++})),r},o.prototype.getTargetElement=function(t){var e;if(!st(t))return null;var o=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase();if(!x(o))return null;if(["body","html"].includes(o))return null;if(this.context.trackTags.includes(o)&&"div"!==o)return t;if("div"===o&&this.options.autoTrackConfig.collectTags.div&&(this.isDivLevelValid(t)&&(this.getDivMaxLevel()>1||this.isCollectableDiv(t))))return t;if(this.options.autoTrackConfig.collectTags.div&&this.isStyleTag(o)){var r=this.getCollectableParent(t);if(r&&this.isDivLevelValid(r))return r}return this.hasElement(t)||null},o.prototype.getClickElementInfo=function(t){var e=this.options.autoTrackConfig.isCollectInput,o=!1;_(e)&&(o=e(t));var r=this.getDomSelector(t),n=ct(t,o);return n.H_element_selector=r,n.H_element_path=this.getElementPath(t,!1),n},o.prototype.getDomSelector=function(t){for(var e,o=[];t;){if("body"===(null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase())||!st(t)){o.unshift("body");break}if(o.unshift(this.getSelector(t)),(null==t?void 0:t.getAttribute("id"))&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.getAttribute("id")))break;t=t.parentNode}return o.join(" > ")},o.prototype.getSelector=function(t){var e,o,r=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),n=-1;9!==(null===(o=t.parentNode)||void 0===o?void 0:o.nodeType)&&(n=this.getDomIndex(t));var i=t.getAttribute("id");return i&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(i)?"#".concat(i):r+(n>-1?":nth-of-type(".concat(n+1,")"):"")},o.prototype.getDomIndex=function(t){var e,o;if(t.parentNode)for(var r=0,n=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),i=t.parentNode.children,s=0;s<i.length;s++){var a=i[s];if((null===(o=a.tagName)||void 0===o?void 0:o.toLowerCase())===n){if(a===t)return r;r++}}return-1},o.prototype.getClosestLi=function(t){for(;t&&t!==document&&st(t);){if("li"===t.tagName.toLowerCase())return t;t=t.parentNode}return null},o.prototype.getSameTypeSiblings=function(t){for(var e,o,r=t.parentNode,n=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),i=[],s=0;s<r.children.length;s++){var a=r.children[s];st(a)&&(null===(o=a.tagName)||void 0===o?void 0:o.toLowerCase())===n&&i.push(a)}return i},o.prototype.getElementPosition=function(t,e){var o,r=this.getClosestLi(t);if(!r||!st(t)||!x(t.tagName))return null;var n=null===(o=t.tagName)||void 0===o?void 0:o.toLowerCase(),i=r.getElementsByTagName(n),s=i.length;if(s>1){for(var a=[],c=0;c<s;c++){this.getElementPath(i[c],!1)===e&&a.push(i[c])}if(a.length>0)return a.findIndex((function(e){return e===t}))}if(!r.parentNode)return-1;var u=this.getSameTypeSiblings(r);return 1===u.length?0:u.findIndex((function(t){return t===r}))},o}(p),gt=function(t){function o(e,o){var r=t.call(this,e,o)||this;return r.options=e,r.context=o,r.name="StayTrackPlugin",r.isReady=!1,r.timer=null,r.previousTime=H(),r.previousOffsetTop=0,r}return e(o,t),o.prototype.init=function(t){var e=this,o=this.options,r=o.autoTrackConfig,n=o.stayAutoTrackConfig;if(!0===r.stayAutoTrack)if(this.isReady)this.context.log("StayTrack plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN);else{this.isReady=!0;var i=n.isCollectUrl;_(i)||(i=function(){return!0}),this.timer&&(clearTimeout(this.timer),this.timer=null),this.previousTime=H(),window.addEventListener("load",(function(){e.previousOffsetTop=$()})),window.addEventListener("scroll",(function(){i()&&(e.timer||(e.timer=setTimeout((function(){e.run(t),clearTimeout(e.timer),e.timer=null}),1e3)))})),window.addEventListener("unload",(function(){i()&&e.run(t,!0)}))}},o.prototype.transform=function(t){return this.context.getReportData("track","H_WebStay",t)},o.prototype.run=function(t,e){void 0===e&&(e=!1);var o=this.options.autoTrackConfig,r=o.stayDelayTime,n=o.maxStayPageDuration,i=$(),s=H(),a=s-this.previousTime;(e||a>r&&i!==this.previousOffsetTop)&&t({H_viewport_width:Z(),H_viewport_height:X(),H_viewport_position:this.previousOffsetTop,event_duration:Math.min(a/1e3,n),H_url_path:window.location.pathname});this.previousTime=s,this.previousOffsetTop=i},o}(p),vt=function(t){function o(e,o){var r=t.call(this,e,o)||this;return r.options=e,r.context=o,r.name="PageLeave",r.isReady=!1,r.pageId=D(),r.storageName="hinasdk_pageleave_",r.heartbeatIntervalTime=5e3,r.maxDuration=432e3,r.heartbeatIntervalTimer=null,r.startTime=H(),r.url=window.location.href,r.pageShowStatus=!0,r}return e(o,t),o.prototype.init=function(){if(this.options.autoTrackConfig.pageLeaveAutoTrack)if(this.context.store.localStorage)if(this.isReady)this.context.log("PageLeave plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN);else{this.isReady=!0;var t=this.normalizePageLeaveAutoTrack(),e=t.heartbeat_interval_time,o=t.max_duration;e&&e>0&&(this.heartbeatIntervalTime=1e3*e),o&&o>0&&(this.maxDuration=Number(o)),this.startTime=H(),this.addPageLeaveEventListener(),document.hidden?this.pageShowStatus=!1:this.startHeartBeatInterval()}else this.context.log("PageLeave plugin需要使用localstorage存储数据,但是您的浏览器不支持localstorage,所以不能使用该功能",exports.ConsoleTypes.WARN)},o.prototype.transform=function(){},o.prototype.normalizePageLeaveAutoTrack=function(){var t=this.options.autoTrackConfig.pageLeaveAutoTrack;return y(t)?t:{}},o.prototype.addPageLeaveEventListener=function(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()},o.prototype.addPageStartListener=function(){var t=this;"onpageshow"in window&&window.addEventListener("pageshow",(function(){t.pageStartHandler()}))},o.prototype.addPageSwitchListener=function(){var t=this;new Y({visible:function(){t.pageStartHandler(),t.startHeartBeatInterval()},hidden:function(){t.url=window.location.href,t.pageEndHandler(),t.stopHeartBeatInterval()}})},o.prototype.addSinglePageListener=function(){var t=this;z.on("urlChange",(function(e){var o=e.fromHref;o!==e.toHref&&(t.url=o,t.pageEndHandler(),t.stopHeartBeatInterval(),t.pageStartHandler(),t.startHeartBeatInterval())}))},o.prototype.addPageEndListener=function(){var t=this,e=["pagehide","beforeunload","unload"];e.forEach((function(o){"on".concat(e)in window&&window.addEventListener(o,(function(){t.pageEndHandler(),t.stopHeartBeatInterval()}))}))},o.prototype.pageStartHandler=function(){this.startTime=H(),this.pageShowStatus=!document.hidden,this.url=window.location.href},o.prototype.pageEndHandler=function(){if(this.pageShowStatus){if(this.pageShowStatus=!1,this.isCollectUrl()){var t=this.getPageLeaveProperties(),e=this.context.getReportData("track","H_WebPageLeave",t);this.context.report(e)}this.delHeartBeatData()}},o.prototype.startHeartBeatInterval=function(){var t=this;this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),this.isCollectUrl()&&(this.heartbeatIntervalTimer=setInterval((function(){t.saveHeartBeatData()}),this.heartbeatIntervalTime),this.saveHeartBeatData("first_heartbeat")),this.reissueHeartBeatData()},o.prototype.reissueHeartBeatData=function(){for(var t=this.context.store.localStorage,e=t.length(),o=0;o<e;o++){var r=t.key(o);if(r&&r!==this.storageName+this.pageId&&r.includes(this.storageName)){var n=C(t.get(r));y(n)&&H()-n.time>n.heartbeat_interval_time+5e3&&(delete n.heartbeat_interval_time,this.context.report(n)),this.delHeartBeatData(r)}}},o.prototype.stopHeartBeatInterval=function(){this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)},o.prototype.delHeartBeatData=function(t){this.context.store.localStorage.remove(t||this.storageName+this.pageId)},o.prototype.isCollectUrl=function(){var t=this.normalizePageLeaveAutoTrack().isCollectUrl;return!_(t)||t(this.url)},o.prototype.saveHeartBeatData=function(t){var e=this.getPageLeaveProperties();e.H_time=H(),"first_heartbeat"===t&&(e.event_duration=3);var o=this.context.getReportData("track","H_WebPageLeave",e);o.heartbeat_interval_time=this.heartbeatIntervalTime,this.context.store.localStorage.set(this.storageName+this.pageId,JSON.stringify(o))},o.prototype.getPageLeaveProperties=function(){var t=(H()-this.startTime)/1e3;t=t<=0||t>this.maxDuration?0:P(t,3);var e=I(this.url),o=e.pathname,r=e.hash,n=E(),s={H_url:this.url,H_url_path:o,H_url_hash:r,H_viewport_position:$(),H_referrer:n,H_referrer_host:n?O(n):"",event_duration:t},a=this.normalizePageLeaveAutoTrack().custom_props;return y(a)&&(s=i(i({},s),a||{})),s},o}(p),mt=function(t){function o(e,o){var r=t.call(this,e,o)||this;return r.options=e,r.context=o,r.name="SiteLinker",r.isReady=!1,r.linker=[],r}return e(o,t),o.prototype.init=function(){if(this.options.siteLinkerConfig){var t=this.getLinkerConfig().linker;w(t)&&t.length>0?this.isReady?this.context.log("SiteLinker plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN):(this.isReady=!0,this.resolveOption(),this.setRefferId(),this.addClickListen()):this.context.log("siteLinker plugin: 请配置正确的linker参数",exports.ConsoleTypes.WARN)}},o.prototype.transform=function(){},o.prototype.getLinkerConfig=function(){var t=this.options.siteLinkerConfig||{},e=t.linker;return{linker:(void 0===e?[]:e)||[],re_login:t.re_login}},o.prototype.resolveOption=function(){for(var t=this.getLinkerConfig().linker,e=t.length,o=[],r=0;r<e;r++){var n=t[r],i=n.part_url,s=n.after_hash;/[A-Za-z0-9]+\./.test(i)&&S(s)?o.push({part_url:i,after_hash:s}):this.context.log("The configuration of linker ".concat(r+1," is not supported.Please check format"),exports.ConsoleTypes.WARN)}this.linker=o},o.prototype.setRefferId=function(){var t=this.getLinkerConfig().re_login,e=this.getUrlId(),o=e.startsWith("a");if(""!==(e=e.substring(1))){var r=this.context.store.getAnonymousId(),n=this.context.store.getAccountId();if(o){if(e!==r&&(this.context.store.state.anonymousId=e,this.context.store.save()),n){var i=this.context.getReportData("track_signup","H_SignUp",{});this.context.report(i)}}else(!n||t&&n!==e)&&this.context.setUserUId(e)}},o.prototype.getUrlId=function(){var t=window.location.href.match(/_hnsdk=([au][^\?\#\&\=]+)/);return w(t)&&t[1]?function(t){var e=t;try{e=decodeURIComponent(t)}catch(t){}return e}(t[1]):""},o.prototype.getPartUrl=function(t){for(var e=this.linker.length,o=0;o<e;o++)if(t.includes(this.linker[o].part_url))return!0;return!1},o.prototype.getPartHash=function(t){for(var e=this.linker.length,o=0;o<e;o++)if(t.includes(this.linker[o].part_url))return this.linker[o].after_hash;return!1},o.prototype.getCurrentId=function(){var t=this.context.store.getAccountId(),e=this.context.store.getAnonymousId();return function(t){var e=t;try{e=encodeURIComponent(t)}catch(t){}return e}(t?"u".concat(t):"a".concat(e))},o.prototype.rewriteUrl=function(t,e){var o=function(t,e,o){var r=/([^?#]+)(\?[^#]*)?(#.*)?/.exec(t),n="";if(r){var i=r[1]||"",s=r[2]||"",a=r[3]||"",c="_hnsdk=".concat(e),u=function(t){var e=t.split("&"),o=[];return e.forEach((function(t){t.includes("_hnsdk")?o.push(c):o.push(t)})),o.join("&")};if(o){var l=a.includes("?"),p=a.indexOf("_hnsdk");n=l?p>=0?"".concat(i).concat(s,"#").concat(a.substring(1,p)).concat(u(a.substring(p,a.length))):"".concat(i).concat(s,"#").concat(a.substring(1),"&").concat(c):"".concat(i).concat(s,"#").concat(a.substring(1),"?").concat(c)}else n=(l=/^\?(\w)+/.test(s))?s.includes("_hnsdk")?"".concat(i,"?").concat(u(s.substring(1))).concat(a):"".concat(i).concat(s,"&").concat(c).concat(a):"".concat(i,"?").concat(c).concat(a);return n}}(t,this.getCurrentId(),this.getPartHash(t));return e&&(e.href=o),o},o.prototype.addClickListen=function(){var t=this,e=function(e){var o,r,n=e.target;if(n){var i=null===(o=n.tagName)||void 0===o?void 0:o.toLowerCase(),s=n.parentNode,a=null===(r=null==s?void 0:s.tagName)||void 0===r?void 0:r.toLowerCase();if("a"===i&&n.href||"a"===a&&s.href){var c=void 0,u=void 0;"a"===i&&n.href?(c=n.href,u=n):(c=s.href,u=s);var l=I(c).protocol;"http:"!==l&&"https:"!==l||t.getPartUrl(c)&&t.rewriteUrl(c,u)}}};"PointerEvent"in window?document.addEventListener("pointerdown",e):document.addEventListener("mousedown",e)},o}(p),yt=function(t){function o(e,o){var r=t.call(this,e,o)||this;return r.options=e,r.context=o,r.name="HistoryPlugin",r.isReady=!1,r.lastHref=window.location.href,r.lastPath=window.location.pathname,r}return e(o,t),o.prototype.init=function(){if(window&&window.history.pushState&&window.history.replaceState)if(this.isReady)this.context.log("History plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN);else{this.isReady=!0;var t=this,e=window.onpopstate,o=function(e,o){var r={fromPath:t.lastPath,fromHref:t.lastHref,toPath:e,toHref:o};t.lastPath=e,t.lastHref=o,z.emit("urlChange",i(i({},r),{mode:"history"}))};window.onpopstate=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n=window.location.pathname,i=window.location.href;o(n,i),e&&e.apply(this,t)},W(window.history,"pushState",r),W(window.history,"replaceState",r)}function r(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];t.apply(this,e);var n=window.location.pathname,i=window.location.href;o(n,i)}}},o.prototype.transform=function(){},o}(p),bt=function(t){function o(e,o){var r=t.call(this,e,o)||this;return r.options=e,r.context=o,r.name="HashPlugin",r.isReady=!1,r.lastHref=window.location.href,r.lastPath=window.location.hash,r}return e(o,t),o.prototype.init=function(){var t=this;this.isReady?this.context.log("Hash plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN):(this.isReady=!0,window.addEventListener("hashchange",(function(e){var o=e.newURL,r=I(o).hash,n={fromPath:t.lastPath,fromHref:t.lastHref,toPath:r,toHref:o};t.lastHref=o,t.lastPath=r,z.emit("urlChange",i(i({},n),{mode:"hash"}))})))},o.prototype.transform=function(){},o}(p),wt="4.0.5",_t=function(t){function o(e,o){var r,n,i=this,s=(n=null===(r=navigator.userAgent)||void 0===r?void 0:r.toLowerCase(),/android|webos|iphone|ipod|blackberry/i.test(n)?"H5":"Web");return(i=t.call(this,e,o,s,"hina_webjs_sdk_abtest",wt)||this).options=e,i.context=o,i.name="HinaABTest",i}return e(o,t),o.prototype.getResultFromServer=function(t){var e=this;return new Promise((function(o,r){var n=e.createRequestData(t);new tt({url:e.options.abTestingPluginConfig.url,data:JSON.stringify(n),contentType:"application/json",customHeaders:{"project-key":e.projectKey},timeout:t.timeoutMilliseconds}).run().then((function(t){var n=t.data;"SUCCESS"===(null==n?void 0:n.status)?e.saveResponseData(n.results).then((function(){o(n)})):r()}))}))},o}(it),xt=function(){function t(){}return t.getSourceFromReferrer=function(){var t=function(t,e){for(var o=0;o<t.length;o++)if(-1!==e.split("?")[0].indexOf(t[o]))return!0},e="(".concat(h.join("|"),")\\=[^&]+"),o=document.referrer||"",r=window.location.href;if(r){var n=r.match(new RegExp(e));return n&&n[0]?"付费广告流量":t(f,o)?"自然搜索流量":t(d,o)?"社交网站流量":""===o?"直接流量":"引荐流量"}return"获取url异常"},t.getReferSearchEngine=function(t){var e,o,r=O(t);if(!r||"hostname解析异常"===r)return"";var n={baidu:[/^.*\.baidu\.com$/],bing:[/^.*\.bing\.com$/],google:[/^www\.google\.com$/,/^www\.google\.com\.[a-z]{2}$/,/^www\.google\.[a-z]{2}$/],sm:[/^m\.sm\.cn$/],so:[/^.+\.so\.com$/],sogou:[/^.*\.sogou\.com$/],yahoo:[/^.*\.yahoo\.com$/]};for(var i in n){var s=n[i];try{for(var a=(e=void 0,c(s)),u=a.next();!u.done;u=a.next()){if(u.value.test(r))return i}}catch(t){e={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(e)throw e.error}}}return"未知搜索引擎"},t.getKeywordFromReferrer=function(){var t=document.referrer||"";if(0===t.indexOf("http")){var e=this.getReferSearchEngine(t),o=function(t){t=t||"";var e={};return new URLSearchParams(t).forEach((function(t,o){e[o]=t})),e}(I(t).search);if(A(o))return"未取到值";for(var r in g){var n=g[r];if(r===e)if(w(n))for(var i=0;i<n.length;i++){var s=o[n[i]];if(s)return s}else if(o[n])return o[n]}return"未取到值"}return""===t?"未取到值_直接打开":"未取到值_非http的url"},t}();function Tt(t){void 0===t&&(t="");var e,o=(e={},h.forEach((function(t){var o=U(window.location.href,t);o.length&&(e[t]=o)})),e),r={};return Object.keys(o).forEach((function(e){r[t+e]=o[e]})),r}var St=function(t){function o(e,o){void 0===o&&(o=!0);var r=t.call(this,e,o)||this;return r.trackTags=ft,r.customProperties={},r.generalProperties={H_lib_version:wt,H_lib:"js",H_lib_method:"code",H_timezone_offset:(new Date).getTimezoneOffset()},r.useInstancing&&r.init(e),r}return e(o,t),o.prototype.init=function(t){if(this.isReady)this.log("hinaSDK has been initialized",exports.ConsoleTypes.ERROR);else{var e={name:"",serverUrl:"",showLog:!1,autoTrackConfig:{clickAutoTrack:!0,stayAutoTrack:!0,isCollectUrl:function(){return!0},isCollectElement:function(){return!0},isCollectInput:function(){return!1},addCustomProperty:function(){},stayDelayTime:4e3,maxStayPageDuration:18e3,collectTags:{div:!1},trackAttr:["hn-click"],pageviewAutoTrack:!1,pageLeaveAutoTrack:!1},stayAutoTrackConfig:{isCollectUrl:function(){return!0}},maxStringLength:1024,imgUseCrossOrigin:!1,isSinglePage:!1,batchSend:!1,appJsBridge:!1,sendType:exports.ReportTypes.AJAX,customHeaders:{},credentials:!1,dataSendTimeout:3e3,presetProperties:{latest_utm:!0,latest_traffic_source_type:!0,latest_search_keyword:!0,latest_referrer:!0},sourceChannel:[],plugins:[]},o=t.performanceErrorConfig,r=t.plugins,n=function(t,e){var o={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++)e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(o[r[n]]=t[r[n]])}return o}(t,["performanceErrorConfig","plugins"]);this.options=R(e,n),this.options=i(i({},this.options),{performanceErrorConfig:o,plugins:r}),this.initState(),this.initAdvProps(),this.normalizeConfig(),this.initPlugins(),this.isReady=!0}},o.prototype.normalizeConfig=function(){var t=this,e=this.options,o=e.serverUrl,r=e.sendType,n=e.batchSend,s=e.maxStringLength,a=e.isSinglePage,c=e.autoTrackConfig,u=void 0===c?{}:c,l=u.trackAttr,p=void 0===l?[]:l,h=u.collectTags,f=u.pageLeaveAutoTrack,d=u.pageviewAutoTrack;if(""===(o=(o=o||"").trim()))this.log("当前 serverUrl 为空,network 中不会发数据,请配置正确的 serverUrl!",exports.ConsoleTypes.WARN);else{var g=I(window.location.href).protocol||"";(I(o).protocol||"")!==g&&this.log("SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。",exports.ConsoleTypes.WARN)}if([exports.ReportTypes.IMAGE,exports.ReportTypes.AJAX,exports.ReportTypes.BEACON].includes(r)||this.setConfig({sendType:exports.ReportTypes.AJAX}),this.options.maxStringLength=function(t){var e=t;return!T(t)||t<0?e=1024:t>5120&&(e=5120),e}(s),(!0===f||y(f)&&A(f))&&(this.options.autoTrackConfig.pageLeaveAutoTrack={heartbeat_interval_time:5e3,max_duration:432e3}),w(p)?(p=p.filter((function(t){return x(t)}))).includes("hn-click")||p.push("hn-click"):p=["hn-click"],this.options.autoTrackConfig.trackAttr=p,y(h))if(!0===h.div)this.options.autoTrackConfig.collectTags.div={ignoreTags:ht,maxLevel:1};else if(y(h.div)){var v=1,m=h.div;T(m.maxLevel)&&[1,2,3].includes(m.maxLevel)&&(v=m.maxLevel),this.options.autoTrackConfig.collectTags.div={ignoreTags:ht,maxLevel:v}}else this.options.autoTrackConfig.collectTags.div=!1;else this.options.autoTrackConfig.collectTags={div:!1};this.updateTrackTags(),(!0===n||y(n)&&!A(n))&&(this.options.batchSend=i({dataSendTimeout:6e3,sendInterval:6e3,storageLimit:200},n),this.batchSender=new ot(this.options,"hinasdk_tab","hinasdk_data_")),"auto"===d?this.autoTrack():("singlePage"===d||a)&&(this.autoTrack(),z.on("urlChange",(function(e){var o=e.fromHref;if(o!==e.toHref){var r={};if(_(a)){var n=a();y(n)&&(r=i(i({},r),n))}t.autoTrack(i(i({},r),{H_referrer:o}))}})))},o.prototype.updateTrackTags=function(){var t=this.options.autoTrackConfig.collectTags,e=l([],u(ft),!1);Object.keys(t||{}).forEach((function(o){var r=t[o];!0!==r&&!y(r)||e.includes(o)||e.push(o)})),this.trackTags=e},o.prototype.initState=function(){this.store=new J(this.options),this.store.init()},o.prototype.initAdvProps=function(){var t,e={},o=this.options,r=o.presetProperties,n=o.sourceChannel;if(y(r))for(var s in r){var a=r[s];if(s.includes("latest_")&&(s=s.slice(7),a)){var c=L();if("utm"!==s&&"url解析失败"===c)e["H_latest_".concat(s)]="url的domain解析失败";else if(""===(t=(t=void 0)||document.referrer)||N(O(t))!==N())switch(s){case"traffic_source_type":e.H_latest_traffic_source_type=xt.getSourceFromReferrer();break;case"search_keyword":var u=xt.getKeywordFromReferrer();u&&(e.H_latest_search_keyword=u);break;case"referrer":e.H_latest_referrer=E()}}}var l=this.store.state.props||{},p={};r.latest_utm&&(p=Tt("H_latest_"));var f={};l.H_utm_source||(f=Tt("H_"));var d=[],g={};w(n)&&n.length>0&&(d=n.filter((function(t){return!h.includes(t)}))).length>0&&(g=i(i({},g),function(t,e){void 0===e&&(e=[]);var o={};return e.forEach((function(e){var r=U(window.location.href,e);r&&(o[e]=r,o["".concat(t).concat(e)]=r)})),o}("H_latest_",d))),this.store.state.props=i(i(i(i(i({},this.store.state.props),e),p),g),f),this.store.setProps(this.store.state.props),this.store.getUtmFromProps(d)},o.prototype.getGeneralProperties=function(){var t=new G;return this.generalProperties=i(i(i({},this.generalProperties),{H_screen_width:window.screen.width,H_screen_height:window.screen.height,H_viewport_width:Z(),H_viewport_height:X(),H_page_height:document.documentElement.scrollHeight||document.body.scrollHeight,H_browser:t.browserName,H_browser_version:t.browserVersion,H_os:t.os,H_os_version:t.osVersion,H_model:t.model,H_is_first_day:this.store.isFirstDay,H_url:window.location.href,H_url_host:O(window.location.href,"url_host取值异常"),H_title:document.title}),this.store.hLatestUtm),this.generalProperties.H_latest_referrer&&(this.generalProperties.H_latest_referrer_host=O(this.generalProperties.H_latest_referrer,"hostname解析异常")),this.generalProperties},o.prototype.initPlugins=function(){var t=this,e=this.options,o=e.serverUrl,r=e.name,n=e.showLog,s=e.sendType,a=e.customHeaders,c=e.credentials,u=e.dataSendTimeout,l=e.batchSend,p=e.imgUseCrossOrigin,h=e.globalCallback,f=e.plugins,d=void 0===f?[]:f,g=e.performanceErrorConfig,v=e.autoTrackConfig,m=e.siteLinkerConfig,b=e.abTestingPluginConfig;d=d||[];var _=v.pageLeaveAutoTrack,x=new dt(this.options,this),T=new gt(this.options,this),S=new yt(this.options,this),k=new bt(this.options,this),C=new vt(this.options,this),H=new mt(this.options,this),R=new _t(this.options,this);C.disabled=!(y(_)&&!A(_));var I=(m||{}).linker;H.disabled=!(w(I)&&I.length>0),R.disabled=!(y(b)&&!A(b)),this.plugins=[x,T,S,k,C,H,R],w(d)&&d.forEach((function(e){if("Monitor"===e.componentName){if(y(g)&&!A(g))new e(i({serverUrl:o,name:r,showLog:n,sendType:s,customHeaders:a,credentials:c,dataSendTimeout:u,batchSend:l,imgUseCrossOrigin:p,globalCallback:h},g),!0)}else{var f=new e(t.options,t);t.plugins.push(f)}})),this.runPlugins(this.plugins)},o.prototype.use=function(t,e){if(this.isReady){if(y(e)){"PageLeave"===t?this.options.autoTrackConfig.pageLeaveAutoTrack=e:"SiteLinker"===t?this.options.siteLinkerConfig=e:"HinaABTest"===t&&(this.options.abTestingPluginConfig=e);var o=this.plugins.find((function(e){return e.name===t}));return o&&(o.disabled=!1,o.isReady?this.log("".concat(t,"插件已运行,无需重复执行"),exports.ConsoleTypes.WARN):o.init()),this.getPluginInstance(t)}this.log("".concat(t,"插件配置项必须是一个对象类型"),exports.ConsoleTypes.WARN)}else this.log("请先初始化埋点SDK",exports.ConsoleTypes.WARN)},o.prototype.getPluginInstance=function(t){return this.plugins.find((function(e){return e.name===t}))},o.prototype.setConfig=function(t){this.options=R(this.options,t),this.normalizeConfig()},o.prototype.getConfig=function(t){return t?this.options[t]:this.options},o.prototype.setUserUId=function(t,e){var o=this;!function(t,e,o){T(t=null!=t?t:"")||x(t)?e!==(t=String(t).trim())?o(t):F("setUserUId: uid is equal to account_id, failed to execute setUserUId",exports.ConsoleTypes.WARN):F("setUserUId: uid must be string or number",exports.ConsoleTypes.WARN)}(t,this.store.getAccountId(),(function(t){o.store.setAccountId(t);var r=o.getReportData("track_signup","H_SignUp",{});o.report(r,e)}))},o.prototype.cleanUserUId=function(){this.store.setAccountId("")},o.prototype.getUserUid=function(){return this.store.state.accountId},o.prototype.setDeviceUId=function(t){this.store.setDeviceId(t)},o.prototype.getDeviceUId=function(){return this.store.getDeviceId()},o.prototype.userSet=function(t,e){if(y(t)&&!A(t)){var o=this.getReportData("user_set","",t);this.report(o,e)}},o.prototype.userSetOnce=function(t,e){if(y(t)&&!A(t)){var o=this.getReportData("user_setOnce","",t);this.report(o,e)}},o.prototype.userAdd=function(t,e){var o=this;!function(t,e){var o;x(t)&&((o={})[t]=1,t=o),y(t)&&!A(t)&&function(t){for(var e in t)if(!/-*\d+/.test(String(t[e])))return F("userAdd属性的值只能是数字",exports.ConsoleTypes.WARN),!1;return!0}(t)&&e(t)}(t,(function(t){var r=o.getReportData("user_add","",t);o.report(r,e)}))},o.prototype.userAppend=function(t,e){var o=this;!function(t,e){var o={};y(t)&&(Object.keys(t).forEach((function(e){var r=t[e];w(r)?o[e]=r:o[e]=[r]})),A(o)||e(o))}(t,(function(t){var r=o.getReportData("user_append","",t);o.report(r,e)}))},o.prototype.userUnset=function(t,e){var o=this;!function(t,e){var o={};x(t)&&(t=[t]),w(t)?(t.forEach((function(t){x(t)?o[t]=!0:F("userUnset参数数组里面的值必须是string,已经过滤掉".concat(t),exports.ConsoleTypes.WARN)})),A(o)||e(o)):F("userUnset参数必须是数组或字符串",exports.ConsoleTypes.WARN)}(t,(function(t){var r=o.getReportData("user_unset","",t);o.report(r,e)}))},o.prototype.userDelete=function(t){var e=this.getReportData("user_delete","",{});this.report(e,t),this.store.setAccountId("")},o.prototype.registerCommonProperties=function(t){this.customProperties=R(this.customProperties,t)},o.prototype.getPresetProperties=function(){return i(i({},this.getGeneralProperties()),this.customProperties)},o.prototype.clearPageRegister=function(t){var e=this;void 0===t&&(t=!0),!0===t?this.customProperties={}:w(t)&&t.forEach((function(t){t in e.customProperties&&delete e.customProperties[t]}))},o.prototype.track=function(t,e,o){if(o=o||function(){},x(t)){e=y(e)?e:{};var r=this.getReportData("track",t,e);this.report(r,o)}else this.log("track事件名必须是字符串,属性必须是是一个对象",exports.ConsoleTypes.WARN)},o.prototype.quick=function(t,e,o){if(!this.isReady)return this.log("请先初始化SDK");var r={};o=_(o)?o:k,y(e)?r=e:_(e)&&(o=e),this.autoTrack(r,o)},o.prototype.autoTrack=function(t,e){void 0===t&&(t={}),void 0===e&&(e=k);var o=(null==t?void 0:t.H_referrer)||E(),r=i(i(i({H_is_first_time:this.store.isFirstTime,H_url_path:window.location.pathname,H_referrer:o,H_referrer_host:o?O(o):""},this.store.hUtm),this.store.customUtm),t||{}),n=this.getReportData("track","H_pageview",r);if(this.report(n,e),this.store.isFirstTime){this.store.isFirstTime=!1;var s=E(),a=i(i({H_first_visit_time:H(),H_first_referrer:s,H_first_referrer_host:s?O(s,"取值异常"):"",H_first_traffic_source_type:xt.getSourceFromReferrer(),H_first_search_keyword:xt.getKeywordFromReferrer(),H_first_browser_language:x(navigator.language)?navigator.language.toLowerCase():"取值异常",H_first_browser_charset:document.characterSet||document.inputEncoding||"UTF-8"},this.store.hUtm),this.store.customUtm);this.userSetOnce(a)}},o.prototype.report=function(t,e,o){var r,n,i=this.options,s=i.appJsBridge,a=i.serverUrl;if(this.log(t),s){var c=!0,u=null===window||void 0===window?void 0:window.Hina_Cloud_H5_Bridge;if(y(u)&&u.track)c=!1,u.track(t.event,t.type,JSON.stringify(t));else{var l=null===(n=null===(r=null===window||void 0===window?void 0:window.webkit)||void 0===r?void 0:r.messageHandlers)||void 0===n?void 0:n.hinaNativeTracker;if(null==l?void 0:l.postMessage){c=!1;var p=JSON.stringify({eventName:t.event,eventType:t.type,properties:t});l.postMessage(p)}}if(c)return void this.log("JSBridge 发送数据失败",exports.ConsoleTypes.WARN);_(e)&&e(a,t)}else this.sendReportData(t,e,o)},o.prototype.getReportData=function(t,e,o){var r,n=this.store.getAnonymousId(),s=this.store.getAccountId(),a=H(),c=R(this.customProperties),u=this.getGeneralProperties();if("user"===t.slice(0,4)){var l=u.H_lib,p=u.H_lib_method,h=u.H_lib_version;r=i({device_id:this.store.getDeviceId(),H_lib:l,H_lib_method:p,H_lib_version:h},o||{})}else r=i(i(i({device_id:this.store.getDeviceId()},u),c),o||{});rt(r,this.options.maxStringLength);var f={anonymous_id:n,type:t,event:e,time:a,_track_id:D(),properties:r};return s&&!/^[0-9a-f]{8,}-[0-9a-f]{4,}-[0-9a-f]{4,}-[0-9a-f]{4,}-[0-9a-f]{12,}$/.test(s)&&(f.account_id=s),f.send_time=H(),f},o}(pt);var kt=new St({},!1);exports.HinaTrack=St,exports.PluginBase=p,exports.default=kt;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var extendStatics=function(d,b){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)Object.prototype.hasOwnProperty.call(b,p)&&(d[p]=b[p])},extendStatics(d,b)};function __extends(d,b){if("function"!=typeof b&&null!==b)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}var ConsoleTypes,ReportTypes,VariablesTypes,__assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++)for(var p in s=arguments[i])Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p]);return t},__assign.apply(this,arguments)};function __awaiter(thisArg,_arguments,P,generator){return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){var value;result.done?resolve(result.value):(value=result.value,value instanceof P?value:new P((function(resolve){resolve(value)}))).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))}function __generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]},g=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return g.next=verb(0),g.throw=verb(1),g.return=verb(2),"function"==typeof Symbol&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return function(op){if(f)throw new TypeError("Generator is already executing.");for(;g&&(g=0,op[0]&&(_=0)),_;)try{if(f=1,y&&(t=2&op[0]?y.return:op[0]?y.throw||((t=y.return)&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;switch(y=0,t&&(op=[2&op[0],t.value]),op[0]){case 0:case 1:t=op;break;case 4:return _.label++,{value:op[1],done:!1};case 5:_.label++,y=op[1],op=[0];continue;case 7:op=_.ops.pop(),_.trys.pop();continue;default:if(!(t=_.trys,(t=t.length>0&&t[t.length-1])||6!==op[0]&&2!==op[0])){_=0;continue}if(3===op[0]&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(6===op[0]&&_.label<t[1]){_.label=t[1],t=op;break}if(t&&_.label<t[2]){_.label=t[2],_.ops.push(op);break}t[2]&&_.ops.pop(),_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e],y=0}finally{f=t=0}if(5&op[0])throw op[1];return{value:op[0]?op[1]:void 0,done:!0}}([n,v])}}}function __values(o){var s="function"==typeof Symbol&&Symbol.iterator,m=s&&o[s],i=0;if(m)return m.call(o);if(o&&"number"==typeof o.length)return{next:function(){return o&&i>=o.length&&(o=void 0),{value:o&&o[i++],done:!o}}};throw new TypeError(s?"Object is not iterable.":"Symbol.iterator is not defined.")}function __read(o,n){var m="function"==typeof Symbol&&o[Symbol.iterator];if(!m)return o;var r,e,i=m.call(o),ar=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)ar.push(r.value)}catch(error){e={error:error}}finally{try{r&&!r.done&&(m=i.return)&&m.call(i)}finally{if(e)throw e.error}}return ar}function __spreadArray(to,from,pack){if(pack||2===arguments.length)for(var ar,i=0,l=from.length;i<l;i++)!ar&&i in from||(ar||(ar=Array.prototype.slice.call(from,0,i)),ar[i]=from[i]);return to.concat(ar||Array.prototype.slice.call(from))}"function"==typeof SuppressedError&&SuppressedError,exports.ConsoleTypes=void 0,(ConsoleTypes=exports.ConsoleTypes||(exports.ConsoleTypes={})).LOG="log",ConsoleTypes.INFO="info",ConsoleTypes.WARN="warn",ConsoleTypes.ERROR="error",ConsoleTypes.ASSERT="assert",exports.ReportTypes=void 0,(ReportTypes=exports.ReportTypes||(exports.ReportTypes={})).BEACON="beacon",ReportTypes.IMAGE="image",ReportTypes.AJAX="ajax",exports.VariablesTypes=void 0,(VariablesTypes=exports.VariablesTypes||(exports.VariablesTypes={})).INTEGER="INTEGER",VariablesTypes.STRING="STRING",VariablesTypes.BOOLEAN="BOOLEAN";var PluginBase=function(options,context){this.options=options,this.context=context,this.disabled=!1},utmTypes=["utm_source","utm_medium","utm_campaign","utm_content","utm_term"];__spreadArray(__spreadArray([],__read(utmTypes),!1),__read(["ha_utm"]),!1);var searchTypes=["www.baidu","baidu.com","m.sm.cn","so.com","sogou.com","youdao.com","google.com","yahoo.com","bing.com","ask.com"],socialTypes=["weibo.com","renren.com","kaixin001.com","douban.com","qzone.qq.com","zhihu.com","tieba.baidu.com","weixin.qq.com"],searchKeywords={baidu:["wd","word","kw","keyword"],google:"q",bing:"q",yahoo:"p",sogou:["query","keyword"],so:"q",sm:"q"},toString=Object.prototype.toString;function isObject(val){return"[object Object]"===toString.call(val)}function isValid(val){return null!=val}function isArray(val){return Array.isArray(val)}function isFunction(val){return"function"==typeof val}function isString(val){return"string"==typeof val}function isNumber(val){return"number"==typeof val&&!Number.isNaN(val)}function isBoolean(val){return"boolean"==typeof val}function noop(){}function safeJSONParse(val){try{return JSON.parse(val)}catch(e){}return val}function isEmptyObject(obj){return 0===Object.keys(obj).length}function nowStamp(){return Date.now&&isFunction(Date.now)?Date.now():(new Date).getTime()}function merge(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];var result=Object.create(null);return args.forEach((function(obj){obj&&Object.keys(obj).forEach((function(key){var val=obj[key];isObject(val)?isObject(result[key])?result[key]=merge(result[key],val):result[key]=merge(val):result[key]=val}))})),result}function getURL(url){var urlObj={};try{urlObj=new URL(url)}catch(e){}return urlObj}function formatDecimal(num,decimal){if(!num)return num;var str=num.toString(),index=str.indexOf(".");return str=-1!==index?str.substring(0,index+decimal+1):str.substring(0),parseFloat(str)}function getCookieTopLevelDomain(hostname){hostname=hostname||window.location.hostname,/^[a-zA-Z0-9\u4e00-\u9fa5\-\\.]+$/.exec(hostname)||(hostname="");var splitResult=hostname.split(".");if(splitResult.length>=2&&!/^(\d+\.)+\d+$/.test(hostname))for(var domainStr=".".concat(splitResult.splice(splitResult.length-1,1));splitResult.length>0;)if(domainStr=".".concat(splitResult.splice(splitResult.length-1,1)).concat(domainStr),document.cookie="".concat("hinasdk_domain_test","=true; path=/; domain=").concat(domainStr),-1!==document.cookie.indexOf("".concat("hinasdk_domain_test","=true")))return document.cookie="".concat("hinasdk_domain_test","=true; path=/; domain=").concat(domainStr,"; max-age=0"),domainStr;return""}function getCurrentDomain(){var cookieDomain=getCookieTopLevelDomain();return""===cookieDomain?"url解析失败":cookieDomain}function getReferrer(value){var referrer=value||document.referrer;return"string"!=typeof referrer?"referrer exception".concat(String(referrer)):(referrer.startsWith("https://www.baidu.com/")&&(referrer=referrer.split("?")[0]),"string"==typeof(referrer=referrer.slice(0,200))?referrer:"")}function getHostname(url,defaultValue){return defaultValue&&"string"==typeof defaultValue||(defaultValue="hostname解析异常"),url&&(getURL(url).hostname||"")||defaultValue}function generatorTrackId(){var now=nowStamp(),num=Math.floor(1e6*Math.random());return Number(String(now).slice(-5)+String(num).slice(0,4))}function getQueryParam(url,key){key=key.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]"),url=decodeURIComponent(url);var results=new RegExp("[\\?&]".concat(key,"=([^&#]*)")).exec(url);return null===results||results&&"string"!=typeof results[1]&&results[1].length?"":decodeURIComponent(results[1])}function base64Encode(str){try{return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x".concat(t)))})))}catch(e){return str}}function replaceOld(source,name,replacement,isForced){if(void 0!==source&&(name in source||isForced)){var wrapped=replacement(source[name]);isFunction(wrapped)&&(source[name]=wrapped)}}var CookieStorage=function(){function CookieStorage(){this.name="CookieStorage"}return CookieStorage.prototype.isSupport=function(testKey,testValue){var _this=this;void 0===testKey&&(testKey="cookie_support_test"),void 0===testValue&&(testValue="1");return navigator.cookieEnabled&&(_this.set(testKey,testValue),_this.get(testKey)===testValue&&(_this.remove(testKey),!0))},CookieStorage.prototype.get=function(name){var e_1,_a,cookieList=document.cookie.split(";");try{for(var cookieList_1=__values(cookieList),cookieList_1_1=cookieList_1.next();!cookieList_1_1.done;cookieList_1_1=cookieList_1.next()){var cookiePair=cookieList_1_1.value.split("=");if(cookiePair[0].trim()===name)return decodeURIComponent(cookiePair[1])}}catch(e_1_1){e_1={error:e_1_1}}finally{try{cookieList_1_1&&!cookieList_1_1.done&&(_a=cookieList_1.return)&&_a.call(cookieList_1)}finally{if(e_1)throw e_1.error}}return null},CookieStorage.prototype.set=function(name,value,timeStamp,path,domain,sameSite,secure){path=path||"/",name=name.trim(),value=value.trim();var cookieStr="".concat(name,"=").concat(encodeURIComponent(value),"; path=").concat(path,";");timeStamp=isValid(timeStamp)?timeStamp:63072e8,cookieStr+=" max-age=".concat(timeStamp,";"),secure&&(cookieStr+=" secure;"),domain&&(cookieStr+=" domain=".concat(domain,";")),["Strict","Lax","None"].includes(sameSite)&&(cookieStr+=" SameSite=".concat(sameSite,";")),document.cookie=cookieStr},CookieStorage.prototype.remove=function(name,path){void 0===path&&(path="/"),this.set(name,"1",0,path)},CookieStorage.prototype.setDomain=function(name,value,timeStamp){var domain=getCurrentDomain();"url解析失败"===domain&&(domain=""),this.set(name,value,timeStamp,"/",domain)},CookieStorage}(),LocalStorage=function(){function LocalStorage(){this.name="LocalStorage"}return LocalStorage.prototype.isSupport=function(){var supported=!0;try{var supportName="__localStorageSupport__",val="testIsSupportStorage";this.set(supportName,val),this.get(supportName)!==val&&(supported=!1),this.remove(supportName)}catch(e){supported=!1}return supported},LocalStorage.prototype.key=function(index){return window.localStorage.key(index)},LocalStorage.prototype.get=function(key){return window.localStorage.getItem(key)},LocalStorage.prototype.length=function(){return window.localStorage.length},LocalStorage.prototype.set=function(key,value){try{window.localStorage.setItem(key,value)}catch(e){}},LocalStorage.prototype.remove=function(key){window.localStorage.removeItem(key)},LocalStorage.prototype.parse=function(key){var result=this.get(key);try{result=JSON.parse(result)}catch(e){result=""}return result},LocalStorage}(),MemoryStorage=function(){function MemoryStorage(){this.name="MemoryStorage",this.data={}}return MemoryStorage.prototype.get=function(key){var result=this.data[key];return isValid(null==result?void 0:result.expireTime)?result.expireTime<nowStamp()?null:result.value:null==result?void 0:result.value},MemoryStorage.prototype.set=function(key,value,expires){if(isValid(expires)){var expireTime=nowStamp()+1e3*expires;this.data[key]={value:value,expireTime:expireTime}}this.data[key]={value:value}},MemoryStorage.prototype.setDomain=function(name,value,timeStamp){this.set(name,value,timeStamp)},MemoryStorage}();function log(message,type){if(void 0===type&&(type=exports.ConsoleTypes.LOG),"undefined"!=typeof console){var func=console[type]||console.log;"function"==typeof func&&func(message)}}var all,mitt={all:all=all||new Map,on:function(type,handler){var handlers=all.get(type);handlers?handlers.push(handler):all.set(type,[handler])},emit:function(type,event){var handlers=all.get(type);handlers&&handlers.forEach((function(handler){handler(event)}))},off:function(type,handler){var handlers=all.get(type);if(handlers)if(handler){var index=handlers.indexOf(handler);index>=0&&handlers.splice(index,1)}else all.set(type,[])}},State=function(){function State(options,state){this.options=options,this.isFirstTime=!1,this.isFirstDay=!1,this.state=state}return State.prototype.log=function(message,type){void 0===type&&(type=exports.ConsoleTypes.LOG),this.options.showLog&&log(message,type)},State.prototype.checkSetValue=function(name,value){return!(!isNumber(value=null!=value?value:"")&&!isString(value))||(this.log("".concat(name,": id must be string or number"),exports.ConsoleTypes.WARN),!1)},State.prototype.setDeviceId=function(id){void 0===id&&(id=""),this.checkSetValue("deviceId",id)&&this.set("deviceId",id)},State.prototype.setAccountId=function(id){void 0===id&&(id=""),this.checkSetValue("accountId",id)&&(this.set("accountId",id),mitt.emit("changeAccountId"))},State.prototype.setAnonymousId=function(id){this.state.anonymousId?this.log("Current anonymousId is ".concat(this.getAnonymousId(),", it has been set"),exports.ConsoleTypes.WARN):this.checkSetValue("anonymousId",id)&&this.set("anonymousId",id)},State.prototype.setProps=function(props){var newProps=merge(this.state.props||{},props);for(var key in newProps)"string"==typeof newProps[key]&&(newProps[key]=newProps[key].slice(0,200));this.set("props",newProps)},State.prototype.getAnonymousId=function(){return this.state.anonymousId},State.prototype.getDeviceId=function(){return this.state.deviceId},State.prototype.getAccountId=function(){return this.state.accountId},State.prototype.clear=function(){this.state={},this.save()},State.prototype.set=function(name,value){this.state[name]=value,this.save()},State.prototype.afterInit=function(cacheData){cacheData?(this.isFirstDay=function(timestamp){var result;try{var oDate=new Date,oYear=oDate.getFullYear(),oMonth=oDate.getMonth()+1,oDay=oDate.getDate(),prevDate=new Date(timestamp),prevYear=prevDate.getFullYear(),prevMonth=prevDate.getMonth()+1,prevDay=prevDate.getDate();result=oYear===prevYear&&oMonth===prevMonth&&oDay===prevDay}catch(e){result=!1}return result}(this.state.firstVisitTime),this.save()):(this.isFirstDay=!0,this.isFirstTime=!0);var uuid="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(c){var r=16*Math.random()|0;return"x"===c?r.toString(16):(3&r|8).toString(16)}));this.getAnonymousId()||this.setAnonymousId(uuid),this.getDeviceId()||this.setDeviceId(uuid)},State}(),WebState=function(_super){function WebState(options){var _this=this,state={accountId:null,deviceId:null,anonymousId:null,sessionId:null,firstVisitTime:nowStamp(),props:{}};return(_this=_super.call(this,options,state)||this).options=options,_this.storeName="hinasdk_crossdata",_this.hLatestUtm={},_this.hUtm={},_this.customUtm={},_this}return __extends(WebState,_super),WebState.prototype.getUtmFromProps=function(sourceChannel){for(var key in this.state.props){var value=this.state.props[key];key.startsWith("H_latest_")?this.hLatestUtm[key]=value:key.startsWith("H_")&&(this.hUtm[key]=value),sourceChannel.includes(key)&&(this.customUtm[key]=value)}},WebState.prototype.init=function(){var oldState,cookieStorage=new CookieStorage,memoryStorage=new MemoryStorage,localStorage=new LocalStorage;cookieStorage.isSupport()?this.storage=cookieStorage:(this.log("Cookie storage is not supported, SDK internal cache has been enabled",exports.ConsoleTypes.WARN),this.storage=memoryStorage),localStorage.isSupport()?this.localStorage=localStorage:this.log("localStorage is not supported, SDK internal cache has been enabled",exports.ConsoleTypes.WARN),!(oldState=this.storage.get(this.storeName))&&this.localStorage&&(oldState=this.localStorage.get(this.storeName)),oldState&&function(val){try{JSON.parse(val)}catch(e){return!1}return!0}(oldState)?this.state=safeJSONParse(oldState):oldState=null,this.afterInit(oldState)},WebState.prototype.save=function(){this.storage.setDomain(this.storeName,JSON.stringify(this.state)),this.localStorage&&this.localStorage.set(this.storeName,JSON.stringify(this.state))},WebState.prototype.getCookie=function(){return this.storage.get(this.storeName)},WebState.prototype.setSessionId=function(id){this.set("sessionId",id)},WebState.prototype.getSessionId=function(){return this.state.sessionId||""},WebState.prototype.getSessionIdCreateTime=function(){var timeStr=this.getSessionId().split("_")[0],time=Number(timeStr);return Number.isNaN(time)?0:time},WebState}(State),Browser=function(){function Browser(){this.isReady=!1,this.isReady||this.init(),this.isReady=!0}return Browser.prototype.init=function(){this.os=this.getOs(),this.osVersion=this.getOsVersion();var _a=this.getBrowser(),type=_a.type,version=_a.version;this.browserName=type,this.browserVersion=version,this.model=this.getModel()},Browser.prototype.getOs=function(){var a=navigator.userAgent;return/Windows/i.test(a)?/Phone/.test(a)||/WPDesktop/.test(a)?"Windows Phone":"Windows":/(iPhone|iPad|iPod)/.test(a)&&!window.MSStream?"iOS":/Android/.test(a)?"Android":/(BlackBerry|PlayBook|BB10)/i.test(a)?"BlackBerry":/Mac/i.test(a)?"Mac OS X":/Linux/.test(a)?"Linux":/CrOS/.test(a)?"Chrome OS":"取值异常"},Browser.prototype.getOsVersion=function(){var a=navigator.userAgent;if(/Windows/i.test(a)){var reg=/Windows NT ([\d.]+)/;return a.match(reg)?a.match(reg)[1]:""}if(/(iPhone|iPad|iPod)/.test(a)&&!window.MSStream){reg=/OS ([\d_]+)/;return a.match(reg)?a.match(reg)[1].replace(/_/g,"."):""}if(/Android/.test(a)){reg=/Android ([\d.]+)/;return a.match(reg)?a.match(reg)[1]:""}if(/Mac/i.test(a)){reg=/Mac OS X ([\d_]+)/;return a.match(reg)?a.match(reg)[1].replace(/_/g,"."):""}return""},Browser.prototype.getBrowser=function(){var _a,browser={type:"",version:""};try{var ua=null===(_a=navigator.userAgent)||void 0===_a?void 0:_a.toLowerCase(),versionMatch=[];if(null!==ua.match(/baidubrowser/)?(browser.type="baidu",versionMatch.push(/baidubrowser\/([\d.]+)/)):null!==ua.match(/bidubrowser/)?(browser.type="baidu",versionMatch.push(/bidubrowser\/([\d.]+)/)):null!==ua.match(/edg/)?(browser.type="edge",versionMatch.push(/edg\/([\d.]+)/)):null!==ua.match(/edgios/)?(browser.type="edge",versionMatch.push(/edgios\/([\d.]+)/)):null!==ua.match(/liebaofast/)?(browser.type="liebao",versionMatch.push(/liebaofast\/([\d.]+)/)):null!==ua.match(/sogoumobilebrowser/)?(browser.type="sogou",versionMatch.push(/sogoumobilebrowser\/([\d.]+)/)):null!==ua.match(/lbbrowser/)?(browser.type="liebao",versionMatch.push(/lbbrowser\/([\d.]+)/)):null!==ua.match(/crios/)?(browser.type="chrome",versionMatch.push(/crios\/([\d.]+)/)):null!==ua.match(/qihoobrowser/)?(browser.type="360",versionMatch.push(/qihoobrowser\/([\d.]+)/)):null!==ua.match(/mxios/)?(browser.type="maxthon",versionMatch.push(/mxios\/([\d.]+)/)):null!==ua.match(/fxios/)?(browser.type="firefox",versionMatch.push(/fxios\/([\d.\w]+)/)):null!==ua.match(/edge/)?(browser.type="edge",versionMatch.push(/edge\/([\d.]+)/)):null!==ua.match(/metasr/)?(browser.type="sogou",versionMatch.push(/metasr ([\d.]+)/)):null!==ua.match(/micromessenger/)?(browser.type="micromessenger",versionMatch.push(/micromessenger\/([\d.]+)/)):null!==ua.match(/mqqbrowser/)?(browser.type="qq",versionMatch.push(/mqqbrowser\/([\d.]+)/)):null!==ua.match(/qqbrowserlite/)?(browser.type="qq",versionMatch.push(/qqbrowserlite\/([\d.]+)/)):null!==ua.match(/tencenttraveler/)?(browser.type="qq",versionMatch.push(/tencenttraveler\/([\d.]+)/)):null!==ua.match(/qqbrowser/)?(browser.type="qq",versionMatch.push(/qqbrowser\/([\d.]+)/)):null!==ua.match(/maxthon/)?(browser.type="maxthon",versionMatch.push(/maxthon\/([\d.]+)/)):null!==ua.match(/ubrowser/)?(browser.type="uc",versionMatch.push(/ubrowser\/([\d.]+)/)):null!==ua.match(/ucbrowser/)?(browser.type="uc",versionMatch.push(/ucbrowser\/([\d.]+)/)):null!==ua.match(/firefox/)?(browser.type="firefox",versionMatch.push(/firefox\/([\d.]+)/)):null!==ua.match(/opera/)?(browser.type="opera",versionMatch.push(/opera\/([\d.]+)/)):null!==ua.match(/opr/)?(browser.type="opera",versionMatch.push(/opr\/([\d.]+)/)):null!==ua.match(/chrome/)?(browser.type="chrome",versionMatch.push(/chrome\/([\d.]+)/)):null!==ua.match(/safari/)?(browser.type="safari",versionMatch.push(/version\/([\d.]+)/)):null===ua.match(/trident/)&&null===ua.match(/msie/)||(browser.type="ie"),"ie"===browser.type){var tridentVersion=ua.match(/trident\/([\d.]+)/)?ua.match(/trident\/([\d.]+)/)[1]:"",msieVersion=ua.match(/msie ([\d.]+)/)?ua.match(/msie ([\d.]+)/)[1]:"";""!==tridentVersion?browser.version=String(parseInt(tridentVersion,10)+4):""!==msieVersion&&(browser.version=msieVersion)}else versionMatch&&(browser.version=ua.match(versionMatch[0])?ua.match(versionMatch[0])[1]:"")}catch(e){browser.type="取值异常"}return browser},Browser.prototype.getModel=function(){var userAgent=navigator.userAgent;if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent)){if(/iPhone|iPad|iPod/i.test(userAgent))return userAgent.match(/iPhone|iPad|iPod/i)[0];if(/Android/i.test(userAgent))return userAgent.match(/Android/i)[0]}var mac=userAgent.match(/Mac/);if(mac)return mac[0];var windows=userAgent.match(/Windows/);if(windows)return windows[0];var linux=userAgent.match(/Linux/);return linux?linux[0]:"取值异常"},Browser}();function getScrollTop(){return document.documentElement.scrollTop||document.body.scrollTop||0}function getScreenHeight(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0}function getScreenWidth(){return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0}var ListenPageState=function(){function ListenPageState(payload){this.visibleHandler=function(){},this.hiddenHandler=function(){};var visible=payload.visible,hidden=payload.hidden;isFunction(visible)&&(this.visibleHandler=visible),isFunction(hidden)&&(this.hiddenHandler=hidden),this.init()}return ListenPageState.prototype.isSupport=function(){return void 0!==document.hidden},ListenPageState.prototype.init=function(){var _this=this;this.isSupport()?document.addEventListener("visibilitychange",(function(){document.hidden?_this.hiddenHandler():_this.visibleHandler()})):(window.addEventListener("focus",this.visibleHandler),window.addEventListener("blur",this.hiddenHandler))},ListenPageState}();var ImageRequest=function(){function ImageRequest(options){this.options=options}return ImageRequest.prototype.run=function(){var _this=this;return new Promise((function(resolve){var _a=_this.options,imgUseCrossOrigin=_a.imgUseCrossOrigin,url=_a.url,data=_a.data,img=new Image;imgUseCrossOrigin&&(img.crossOrigin="anonymous");var spliceStr=-1===url.indexOf("?")?"?":"&";img.src="".concat(url).concat(spliceStr).concat(data);var callback=function(type){img=null,resolve({type:type})};img.onload=function(){callback("success")},img.onerror=function(){callback("success")}}))},ImageRequest}(),AjaxRequest=function(){function AjaxRequest(options){this.options=options}return AjaxRequest.prototype.run=function(){var _this=this;return new Promise((function(resolve){var _a=_this.options,url=_a.url,data=_a.data,timeout=_a.timeout,credentials=_a.credentials,contentType=_a.contentType,_b=_a.customHeaders,customHeaders=void 0===_b?{}:_b,xhr=new XMLHttpRequest;xhr.open("POST",url,!0),xhr.timeout=timeout||2e4,xhr.isMonitor=!0,credentials&&(xhr.withCredentials=!0),xhr.setRequestHeader("Content-Type",contentType||"application/x-www-form-urlencoded"),isObject(customHeaders)&&!isEmptyObject(customHeaders)&&Object.keys(customHeaders).forEach((function(key){xhr.setRequestHeader(key,customHeaders[key])})),xhr.send(data||null),xhr.onreadystatechange=function(){4===xhr.readyState&&(xhr.status>=200&&xhr.status<300||304===xhr.status?resolve({data:JSON.parse(xhr.responseText)||{},type:"success"}):resolve({type:"fail",msg:"网络异常, 请求失败,状态码=".concat(xhr.status)}))}}))},AjaxRequest}(),BeaconRequest=function(){function BeaconRequest(options){this.options=options}return BeaconRequest.prototype.run=function(){var _this=this;return new Promise((function(resolve){var _a=_this.options,url=_a.url,data=_a.data;navigator.sendBeacon&&resolve(navigator.sendBeacon(url,data)?{type:"success"}:{type:"fail",msg:"sendBeacon 请求失败"})}))},BeaconRequest}(),BatchSend=function(){function BatchSend(options,batchKey,batchDataKey){void 0===batchKey&&(batchKey="hinasdk_tab"),void 0===batchDataKey&&(batchDataKey="hinasdk_data_"),this.options=options,this.batchKey=batchKey,this.batchDataKey=batchDataKey,this.isSending=!1,this.init()}return BatchSend.prototype.log=function(message,type){void 0===type&&(type=exports.ConsoleTypes.LOG),this.options.showLog&&log(message,type)},BatchSend.prototype.init=function(){var localStorage=new LocalStorage;localStorage.isSupport()?(this.localStorage=localStorage,this.isSupport=!0):(this.isSupport=!1,this.log("批量发送功能需要使用localstorage存储数据,但是您的浏览器不支持localstorage,所以不能使用该功能",exports.ConsoleTypes.WARN)),this.batchInterval()},BatchSend.prototype.getBatchConfig=function(){return this.options.batchSend},BatchSend.prototype.getStorageList=function(){if(!this.isSupport)return[];var list=[],tabStorage=this.localStorage.get(this.batchKey);return tabStorage&&(isArray(list=safeJSONParse(tabStorage))||(list=[])),list},BatchSend.prototype.batchInterval=function(){var _this=this;if(this.isSupport){var sendInterval=this.getBatchConfig().sendInterval;setTimeout((function(){_this.send().then((function(){_this.batchInterval()}))}),sendInterval)}},BatchSend.prototype.send=function(){var _this=this;return new Promise((function(resolve){var tabStorageList=_this.getStorageList();if(tabStorageList.length>0&&_this.isSupport){for(var dataSendTimeout=_this.getBatchConfig().dataSendTimeout,now=nowStamp(),list_1=[],removeKeyToValues_1={},len=tabStorageList.length,i=0;i<len;i++){var _a=tabStorageList[i],dataKey=_a.dataKey,expireTime=_a.expireTime;if(expireTime>=now)removeKeyToValues_1[dataKey]={dataKey:dataKey,expireTime:expireTime},(data=_this.localStorage.get(dataKey))&&list_1.push(safeJSONParse(data));else _this.localStorage.remove(dataKey),tabStorageList.splice(i,1),len--,i--}if(_this.localStorage.set(_this.batchKey,JSON.stringify(tabStorageList)),0===list_1.length)resolve();else{var _b=_this.options,serverUrl_1=_b.serverUrl,customHeaders=_b.customHeaders,credentials=_b.credentials,globalCallback_1=_b.globalCallback,listStr=JSON.stringify(list_1),data=encodeURIComponent(base64Encode(listStr));_this.isSending=!0,new AjaxRequest({url:serverUrl_1,data:"data_list=".concat(data),timeout:dataSendTimeout,credentials:credentials,customHeaders:customHeaders}).run().then((function(res){isFunction(globalCallback_1)&&globalCallback_1(serverUrl_1,list_1,res.type,res.msg||""),"success"===res.type&&_this.remove(removeKeyToValues_1),resolve(),_this.isSending=!1}))}}else resolve()}))},BatchSend.prototype.remove=function(removeKeyToValues){var _this=this;if(this.isSupport){var tabStorageList=this.getStorageList(),removeKeys=Object.keys(removeKeyToValues);if(removeKeys.forEach((function(key){_this.localStorage.remove(key)})),tabStorageList.length===removeKeys.length)this.localStorage.set(this.batchKey,JSON.stringify([]));else{var list=tabStorageList.filter((function(item){return!removeKeyToValues[item.dataKey]}));this.localStorage.set(this.batchKey,JSON.stringify(list))}}},BatchSend.prototype.add=function(data){if(this.isSupport){var now,num,_a=this.getBatchConfig(),sendInterval=_a.sendInterval,storageLimit=_a.storageLimit,dataKey=this.batchDataKey+(now=nowStamp(),num=Math.floor(1e6*Math.random()),"".concat(now,"_").concat(num)),tabStorage=this.getStorageList();tabStorage.unshift({dataKey:dataKey,expireTime:nowStamp()+2*sendInterval}),this.localStorage.set(this.batchKey,JSON.stringify(tabStorage)),this.localStorage.set(dataKey,JSON.stringify(data)),!this.isSending&&(tabStorage.length>storageLimit||"track_signup"===data.type||"H_pageview"===data.event)&&this.send()}},BatchSend}();function checkReportProperties(props,maxStringLength){Object.keys(props).forEach((function(key){var value=props[key];if(isString(value)&&value.length>maxStringLength)log("属性 ".concat(key," 已经做截取")),props[key]=value.slice(0,maxStringLength);else if(isObject(value))checkReportProperties(value,maxStringLength);else if(isFunction(value))try{props[key]=value(props),isFunction(props[key])?(log("属性--".concat(key," 格式不满足要求, 已被删除"),exports.ConsoleTypes.WARN),delete props[key]):isObject(props[key])?checkReportProperties(props[key],maxStringLength):isString(props[key])&&props[key].length>maxStringLength&&(props[key]=props[key].slice(0,maxStringLength))}catch(e){log("属性--".concat(key," 格式不满足要求, 已被删除"),exports.ConsoleTypes.WARN),delete props[key]}}))}var DEFAULT_ABTEST_VALIDATE_KEYS=["abtestExperimentId","paramName","valueType","defaultValue","callback","timeoutMilliseconds","customProperties","customIds"],AbtestBasePlugin=function(_super){function AbtestBasePlugin(options,context,platform,storageName,version){var _this=_super.call(this,options,context)||this;return _this.options=options,_this.context=context,_this.name="AbtestBasePlugin",_this.isReady=!1,_this.platform="",_this.storageName="",_this.version="",_this.projectKey="",_this.platform=platform,_this.storageName=storageName,_this.version=version,_this}return __extends(AbtestBasePlugin,_super),AbtestBasePlugin.prototype.init=function(){var _this=this;if(this.context.store.localStorage){var abTestingPluginConfig=this.options.abTestingPluginConfig,url=null==abTestingPluginConfig?void 0:abTestingPluginConfig.url;if(isString(url)){var projectKey=getQueryParam(url,"project-key");if(projectKey){if(this.projectKey=projectKey,["Web","H5"].includes(this.platform)){var protocol=getURL(url).protocol,websiteProtocol=getURL(window.location.href).protocol;protocol&&protocol!==websiteProtocol&&this.context.log("A/B Testing 初始化失败,".concat(websiteProtocol," 页面必须使用 ").concat(websiteProtocol," 的 URL"),exports.ConsoleTypes.WARN)}if(this.isReady)this.context.log("A/B Testing 插件已经运行,无需重复执行",exports.ConsoleTypes.WARN);else{var accountId=this.context.getUserUid();this.context.log("当前accountId为:".concat(accountId),exports.ConsoleTypes.INFO),mitt.on("changeAccountId",(function(){_this.context.store.localStorage.set(_this.storageName,"")})),this.isReady=!0}}else this.context.log("A/B Testing 初始化失败,请使用正确的 URL(必须包含 project-key)")}else this.context.log("A/B Testing 初始化失败,请使用正确的 URL!",exports.ConsoleTypes.WARN)}else this.context.log("A/B Testing 初始化失败,浏览器不支持localStorage",exports.ConsoleTypes.WARN)},AbtestBasePlugin.prototype.transform=function(){},AbtestBasePlugin.prototype.valueMatchType=function(value,type){switch(type){case exports.VariablesTypes.INTEGER:return isNumber(value);case exports.VariablesTypes.STRING:return isString(value);case exports.VariablesTypes.BOOLEAN:return isBoolean(value);default:return!1}},AbtestBasePlugin.prototype.normalizeParams=function(prefixLog,params,validateKeys){var e_1,_a;void 0===validateKeys&&(validateKeys=DEFAULT_ABTEST_VALIDATE_KEYS);var result={verify_success:!0,para:params};try{for(var validateKeys_1=__values(validateKeys),validateKeys_1_1=validateKeys_1.next();!validateKeys_1_1.done;validateKeys_1_1=validateKeys_1.next()){var key=validateKeys_1_1.value;if(!result.verify_success)break;switch(key){case"abtestExperimentId":isString(params.abtestExperimentId)&&params.abtestExperimentId.trim()||(this.context.log("".concat(prefixLog,"方法调用失败,").concat(key,"参数未正确配置!").concat(key,": ").concat(params.abtestExperimentId),exports.ConsoleTypes.WARN),result.verify_success=!1);break;case"paramName":isString(params.paramName)&&params.paramName.trim()||(this.context.log("".concat(prefixLog,"方法调用失败,").concat(key,"参数未正确配置!").concat(key,": ").concat(params.paramName),exports.ConsoleTypes.WARN),result.verify_success=!1);break;case"valueType":[exports.VariablesTypes.BOOLEAN,exports.VariablesTypes.INTEGER,exports.VariablesTypes.STRING].includes(params.valueType)||(this.context.log("".concat(prefixLog,"方法调用失败,").concat(key,"参数未正确配置!").concat(key,": ").concat(params.valueType),exports.ConsoleTypes.WARN),result.verify_success=!1);break;case"defaultValue":this.valueMatchType(params.defaultValue,params.valueType)||(this.context.log("".concat(prefixLog,"方法调用失败,").concat(key,"类型必须与valueType一致!"),exports.ConsoleTypes.WARN),result.verify_success=!1);break;case"callback":isFunction(params.callback)||(this.context.log("".concat(prefixLog,"方法调用失败,").concat(key,"参数未正确配置")),params.callback=noop,result.verify_success=!1);break;case"timeoutMilliseconds":(!isNumber(params.timeoutMilliseconds)||params.timeoutMilliseconds<=0)&&(this.context.log("".concat(key,"参数错误:").concat(params.timeoutMilliseconds),exports.ConsoleTypes.WARN),params.timeoutMilliseconds=3e3),params.timeoutMilliseconds<200&&(params.timeoutMilliseconds=200);break;case"customProperties":params.customProperties=isObject(params.customProperties)?params.customProperties:{};break;case"customIds":var customIds=params.customIds||{},resultIds={};for(var key_1 in customIds)(isString(customIds[key_1])||isNumber(customIds[key_1]))&&(resultIds[key_1]=customIds[key_1]);params.customIds=resultIds}}}catch(e_1_1){e_1={error:e_1_1}}finally{try{validateKeys_1_1&&!validateKeys_1_1.done&&(_a=validateKeys_1.return)&&_a.call(validateKeys_1)}finally{if(e_1)throw e_1.error}}return result},AbtestBasePlugin.prototype.sendTriggerEvent=function(data){var abtest_experiment_group_id=data.abtest_experiment_group_id,abtest_experiment_id=data.abtest_experiment_id;this.context.track("H_ABTestTrigger",{H_abtest_experiment_id:abtest_experiment_id,H_abtest_experiment_group_id:abtest_experiment_group_id})},AbtestBasePlugin.prototype.getExpResult=function(params_1){return __awaiter(this,arguments,void 0,(function(params,list){var abtestExperimentId,paramName,valueType,result,storageData,list_1,list_1_1,item,abtest_experiment_id,abtest_experiment_group_id,is_white_list,variables,detail,e_2,_a;return void 0===list&&(list=[]),__generator(this,(function(_b){switch(_b.label){case 0:return abtestExperimentId=params.abtestExperimentId,paramName=params.paramName,valueType=params.valueType,0!==list.length?[3,2]:[4,this.getStorageData()];case 1:isObject(storageData=_b.sent())&&(list=storageData.result||[]),_b.label=2;case 2:try{for(list_1=__values(list),list_1_1=list_1.next();!list_1_1.done;list_1_1=list_1.next())if(item=list_1_1.value,abtest_experiment_id=item.abtest_experiment_id,abtest_experiment_group_id=item.abtest_experiment_group_id,is_white_list=item.is_white_list,variables=item.variables,abtest_experiment_id===abtestExperimentId&&(detail=variables.find((function(item){return item.name===paramName&&item.type===valueType})),detail)){is_white_list||this.sendTriggerEvent({abtest_experiment_id:abtest_experiment_id,abtest_experiment_group_id:abtest_experiment_group_id}),result=detail.value;break}}catch(e_2_1){e_2={error:e_2_1}}finally{try{list_1_1&&!list_1_1.done&&(_a=list_1.return)&&_a.call(list_1)}finally{if(e_2)throw e_2.error}}return[2,result]}}))}))},AbtestBasePlugin.prototype.getStorageData=function(){return __awaiter(this,void 0,void 0,(function(){var data;return __generator(this,(function(_a){switch(_a.label){case 0:return[4,this.context.store.localStorage.get(this.storageName)];case 1:return(data=_a.sent())?[2,safeJSONParse(data)]:[2,null]}}))}))},AbtestBasePlugin.prototype.saveResponseData=function(list){return __awaiter(this,void 0,void 0,(function(){var storageData,data,newList_1,oldList_1;return __generator(this,(function(_a){switch(_a.label){case 0:return[4,this.getStorageData()];case 1:return storageData=_a.sent(),data={updateTime:nowStamp()},storageData&&isObject(storageData)?(newList_1=[],oldList_1=storageData.result||[],list.forEach((function(item){var abtest_experiment_group_id=item.abtest_experiment_group_id,abtest_experiment_id=item.abtest_experiment_id,variables=item.variables,existsDetail=oldList_1.find((function(it){return it.abtest_experiment_id===abtest_experiment_id&&it.abtest_experiment_group_id===abtest_experiment_group_id}));if(existsDetail){var newVariables_1=[];variables.forEach((function(it){var name=it.name,type=it.type,index=existsDetail.variables.findIndex((function(t){return t.name===name&&t.type===type}));index>=0?existsDetail.variables[index]=it:newVariables_1.push(it)})),existsDetail.variables=__spreadArray(__spreadArray([],__read(existsDetail.variables),!1),__read(newVariables_1),!1)}else newList_1.push(item)})),data.result=__spreadArray(__spreadArray([],__read(oldList_1),!1),__read(newList_1),!1)):data.result=list,this.context.store.localStorage.set(this.storageName,JSON.stringify(data)),[2]}}))}))},AbtestBasePlugin.prototype.createRequestData=function(params){var paramName=params.paramName,customProperties=params.customProperties,customIds=params.customIds,requestData={anonymous_id:this.context.store.getAnonymousId(),platform:this.platform,abtest_lib_version:this.version,param_name:paramName,properties:this.context.getPresetProperties()};return isObject(customProperties)&&!isEmptyObject(customProperties)&&(requestData.custom_properties=customProperties),isObject(customIds)&&!isEmptyObject(customIds)&&(requestData.custom_ids=customIds),this.context.getUserUid()&&(requestData.login_id=this.context.getUserUid()),requestData},AbtestBasePlugin.prototype.preFetch=function(prefixLog,params){return this.isReady?!!isObject(params)||(this.context.log("".concat(prefixLog," 方法参数必须是对象"),exports.ConsoleTypes.WARN),!1):(this.context.log("A/B Testing 插件尚未运行,请先执行该插件",exports.ConsoleTypes.WARN),!1)},AbtestBasePlugin.prototype.asyncFetch=function(params){var _this=this;return new Promise((function(resolve){_this.getResultFromServer(params).then((function(res){resolve(res)})).catch((function(){params.callback(params.defaultValue)}))}))},AbtestBasePlugin.prototype.asyncFetchABTest=function(params){var _this=this;if(this.preFetch("asyncFetchABTest",params)){var _a=this.normalizeParams("asyncFetchABTest",params),verify_success=_a.verify_success,para=_a.para;verify_success?this.asyncFetch(para).then((function(res){return __awaiter(_this,void 0,void 0,(function(){var result;return __generator(this,(function(_a){switch(_a.label){case 0:return[4,this.getExpResult(para,res.results)];case 1:return result=_a.sent(),para.callback(result||para.defaultValue),[2]}}))}))})):para.callback(para.defaultValue)}},AbtestBasePlugin.prototype.fetchCacheABTest=function(params){return __awaiter(this,void 0,void 0,(function(){var _a,verify_success,para,result;return __generator(this,(function(_b){switch(_b.label){case 0:return this.preFetch("fetchCacheABTest",params)?(_a=this.normalizeParams("fetchCacheABTest",params),verify_success=_a.verify_success,para=_a.para,verify_success?[4,this.getExpResult(para)]:[3,2]):[2];case 1:return result=_b.sent(),para.callback(result||para.defaultValue),[3,3];case 2:para.callback(para.defaultValue),_b.label=3;case 3:return[2]}}))}))},AbtestBasePlugin.prototype.fastFetchABTest=function(params){return __awaiter(this,void 0,void 0,(function(){var _a,verify_success,para,result,_this=this;return __generator(this,(function(_b){switch(_b.label){case 0:return this.preFetch("fastFetchABTest",params)?(_a=this.normalizeParams("fastFetchABTest",params),verify_success=_a.verify_success,para=_a.para,verify_success?[4,this.getExpResult(para)]:[3,2]):[2];case 1:return isValid(result=_b.sent())?para.callback(result):this.asyncFetch(para).then((function(){return __awaiter(_this,void 0,void 0,(function(){var result;return __generator(this,(function(_a){switch(_a.label){case 0:return[4,this.getExpResult(para)];case 1:return result=_a.sent(),para.callback(result||para.defaultValue),[2]}}))}))})),[3,3];case 2:para.callback(para.defaultValue),_b.label=3;case 3:return[2]}}))}))},AbtestBasePlugin}(PluginBase);function isElement(val){return 1===(null==val?void 0:val.nodeType)}function getInputElementContent(element,isCollectInput){var _a;if("input"===(null===(_a=element.tagName)||void 0===_a?void 0:_a.toLowerCase())){var type=element.type||element.getAttribute("type");return(["button","submit"].includes(type)||isCollectInput)&&(element.textContent||element.value)||""}var textContent="";return element.textContent?textContent=element.textContent.trim():element.innerText&&(textContent=element.innerText.trim()),textContent&&(textContent=textContent.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),textContent||""}function getElementProperties(element,isCollectInput){var _a;if(!isElement(element))return{};var obj,props={H_element_type:null===(_a=element.tagName)||void 0===_a?void 0:_a.toLowerCase(),H_element_name:element.getAttribute("name"),H_element_id:element.getAttribute("id"),H_element_target_url:element.getAttribute("href"),H_element_class_name:element.classList.value||element.className,H_element_content:getInputElementContent(element,isCollectInput)};return obj=props,Object.keys(obj).reduce((function(acc,key){return isValid(obj[key])&&""!==obj[key]&&(acc[key]=obj[key]),acc}),{})}function getPageXYInfo(event,target){if(!event)return{};var scrollLeft=document.documentElement.scrollLeft||document.body.scrollLeft||0,scrollTop=getScrollTop(),rect=target.getBoundingClientRect(),pageX=event.pageX||event.clientX+scrollLeft||event.offsetX+((null==rect?void 0:rect.left)||0)+scrollLeft,pageY=event.pageY||event.clientY+scrollTop||event.offsetY+((null==rect?void 0:rect.top)||0)+scrollTop;return{H_page_x:formatDecimal(pageX,3),H_page_y:formatDecimal(pageY,3)}}var BaseCore=function(){function BaseCore(options,useInstancing){void 0===useInstancing&&(useInstancing=!0),this.isReady=!1,this.consolePrefix="埋点SDK",this.useInstancing=!0,this.plugins=[],this.options=options,this.useInstancing=useInstancing}return BaseCore.prototype.log=function(message,type){void 0===type&&(type=exports.ConsoleTypes.LOG),this.options.showLog&&("string"==typeof message&&this.consolePrefix&&(message="".concat(this.consolePrefix,":").concat(message)),log(message,type))},BaseCore.prototype.runPlugins=function(plugins){var _this=this;plugins.forEach((function(plugin){plugin.disabled||plugin.init((function(data){if(plugin.transform){var result=plugin.transform(data);result&&_this.report(result)}}))}))},BaseCore.prototype.applyPlugins=function(plugins){var _this=this;if(this.isReady){isArray(plugins)||(plugins=[plugins]);var currentPlugins=[];plugins.forEach((function(Plugin){var instance=new Plugin(_this.options,_this);_this.plugins.push(instance),currentPlugins.push(instance)})),this.runPlugins(currentPlugins)}else this.log("请先初始化SDK实例",exports.ConsoleTypes.WARN)},BaseCore}(),WebClient=function(_super){function WebClient(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(WebClient,_super),WebClient.prototype.sendReportData=function(data,callback,type){var _a=this.options,batchSend=_a.batchSend,globalCallback=_a.globalCallback,serverUrl=_a.serverUrl,dataSendTimeout=_a.dataSendTimeout,sendType=_a.sendType,customHeaders=_a.customHeaders,credentials=_a.credentials,imgUseCrossOrigin=_a.imgUseCrossOrigin;if(sendType=type||sendType,serverUrl){if(isObject(data)&&!isEmptyObject(data))if(batchSend)this.batchSender.add(data);else{var dataStr=data;isString(data)||(dataStr=function(obj){try{return JSON.stringify(obj)}catch(e){return obj}}(data));var base64Data=base64Encode(dataStr),params={data:"data=".concat(encodeURIComponent(base64Data)),url:serverUrl,timeout:dataSendTimeout,imgUseCrossOrigin:imgUseCrossOrigin,customHeaders:customHeaders,credentials:credentials};(sendType===exports.ReportTypes.BEACON&&navigator.sendBeacon?new BeaconRequest(params):sendType===exports.ReportTypes.IMAGE&&params.data.length<2048?new ImageRequest(params):new AjaxRequest(params)).run().then((function(res){return isFunction(globalCallback)&&globalCallback(serverUrl,data,res.type,res.msg||""),isFunction(callback)&&callback(serverUrl,data,res.type,res.msg||""),res}))}}else this.log("当前 serverUrl 为空,network 中不会发数据,请配置正确的 serverUrl!",exports.ConsoleTypes.WARN)},WebClient}(BaseCore);var ignoreTags=["mark","/mark","strong","b","em","i","u","abbr","ins","del","s","sup"],defaultTags=["a","input","button","textarea"],ClickTrackPlugin=function(_super){function ClickTrackPlugin(options,context){var _this=_super.call(this,options,context)||this;return _this.options=options,_this.context=context,_this.name="ClickTrackPlugin",_this.isReady=!1,_this.isTrackList={a:!0,button:!0},_this}return __extends(ClickTrackPlugin,_super),ClickTrackPlugin.prototype.init=function(notify){var _this=this,_a=this.options.autoTrackConfig,clickAutoTrack=_a.clickAutoTrack,isCollectUrl=_a.isCollectUrl,isCollectElement=_a.isCollectElement,addCustomProperty=_a.addCustomProperty;!0===clickAutoTrack&&(this.isReady?this.context.log("ClickTrack plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN):(this.isReady=!0,document.addEventListener("click",(function(e){if(isCollectUrl()){var event=e||window.event;if(event){var eventTarget=event.target||event.srcElement,target=_this.getTargetElement(eventTarget);if(target){if(isFunction(isCollectElement)&&!isCollectElement(target))return!1;var props=_this.getClickElementInfo(target),_a=getPageXYInfo(event,target),H_page_x=_a.H_page_x,H_page_y=_a.H_page_y,pathname=getURL(window.location.href).pathname;props.H_url_path=pathname,props.H_page_x=H_page_x,props.H_page_y=H_page_y;var element_position=_this.getElementPosition(target,props.H_element_path);if(isNumber(element_position)&&element_position>=0&&(props.H_element_position=element_position),isFunction(addCustomProperty)){var customProperty=addCustomProperty(target);isObject(customProperty)&&(props=merge(props,customProperty))}notify(props)}}}}),!0)))},ClickTrackPlugin.prototype.transform=function(data){return this.context.getReportData("track","H_WebClick",data)},ClickTrackPlugin.prototype.hasAttribute=function(element,attrName){var _a;return element.hasAttribute?element.hasAttribute(attrName):element.attributes?!!(null===(_a=element.attributes[attrName])||void 0===_a?void 0:_a.value):void 0},ClickTrackPlugin.prototype.hasAttributes=function(element,attrNames){if(isArray(attrNames))for(var i=0;i<attrNames.length;i++)if(this.hasAttribute(element,attrNames[i]))return!0;return!1},ClickTrackPlugin.prototype.hasElement=function(element){var e_1,_a,_b,elementsList=function(element){var pathArr=[element];try{if(!isElement(element))return pathArr;if(null===element||null===element.parentElement)return pathArr;for(;null!==element.parentElement;)element=element.parentElement,pathArr.push(element);return pathArr}catch(error){}return pathArr}(element),trackAttr=this.options.autoTrackConfig.trackAttr||[];if(isArray(elementsList)&&elementsList.length>0)try{for(var elementsList_1=__values(elementsList),elementsList_1_1=elementsList_1.next();!elementsList_1_1.done;elementsList_1_1=elementsList_1.next()){var ele=elementsList_1_1.value,tagName=ele.tagName&&(null===(_b=ele.tagName)||void 0===_b?void 0:_b.toLowerCase());if(isElement(ele)&&(this.isTrackList[tagName]||this.hasAttributes(ele,trackAttr)))return ele}}catch(e_1_1){e_1={error:e_1_1}}finally{try{elementsList_1_1&&!elementsList_1_1.done&&(_a=elementsList_1.return)&&_a.call(elementsList_1)}finally{if(e_1)throw e_1.error}}},ClickTrackPlugin.prototype.getDivMaxLevel=function(){var _a;return(null===(_a=this.options.autoTrackConfig.collectTags.div)||void 0===_a?void 0:_a.maxLevel)||1},ClickTrackPlugin.prototype.isStyleTag=function(tagName){var _a,ignoreTags=(null===(_a=this.options.autoTrackConfig.collectTags.div)||void 0===_a?void 0:_a.ignoreTags)||[];return null==ignoreTags?void 0:ignoreTags.includes(tagName)},ClickTrackPlugin.prototype.getCollectableParent=function(target){var _a;try{var parentNode=target.parentNode,parentTagName=parentNode?null===(_a=parentNode.tagName)||void 0===_a?void 0:_a.toLowerCase():"";if("body"===parentTagName)return!1;var maxLevel=this.getDivMaxLevel();if("div"===parentTagName&&(maxLevel>1||this.isCollectableDiv(parentNode)))return parentNode;if(parentNode&&this.isStyleTag(parentTagName))return this.getCollectableParent(parentNode)}catch(error){this.context.log(error,exports.ConsoleTypes.ERROR)}return!1},ClickTrackPlugin.prototype.isCollectableDiv=function(element){var _a;try{var children=element.children||[];if(0===children.length)return!0;for(var i=0;i<children.length;i++){var child=children[i];if(isElement(child)){var tagName=null===(_a=child.tagName)||void 0===_a?void 0:_a.toLowerCase(),maxLevel=this.getDivMaxLevel();if(!("div"===tagName&&maxLevel>1||this.isStyleTag(tagName)))return!1;if(!this.isCollectableDiv(child))return!1}}return!0}catch(error){this.context.log(error,exports.ConsoleTypes.ERROR)}return!1},ClickTrackPlugin.prototype.isDivLevelValid=function(rootElement){for(var maxLevel=this.getDivMaxLevel(),htmlCollection=rootElement.getElementsByTagName("div"),i=htmlCollection.length-1;i>=0;i--)if(this.getDivLevels(htmlCollection[i],rootElement)>maxLevel)return!1;return!0},ClickTrackPlugin.prototype.getElementPath=function(element,ignoreId,rootElement){for(var _a,_b,names=[];isElement(element)&&element.parentNode;){if(element.id&&!ignoreId&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(element.id)){var tagName=element.tagName||"";names.unshift("".concat(tagName.toLowerCase(),"#").concat(element.id));break}if(rootElement&&element===rootElement){names.unshift(null===(_a=element.tagName)||void 0===_a?void 0:_a.toLowerCase());break}if(element===document.body){names.unshift("body");break}names.unshift(null===(_b=element.tagName)||void 0===_b?void 0:_b.toLowerCase()),element=element.parentNode}return names.join(" > ")},ClickTrackPlugin.prototype.getDivLevels=function(element,rootElement){var pathArr=this.getElementPath(element,!0,rootElement).split(" > "),level=0;return pathArr.forEach((function(tag){"div"===tag&&level++})),level},ClickTrackPlugin.prototype.getTargetElement=function(eventTarget){var _a;if(!isElement(eventTarget))return null;var tagName=null===(_a=eventTarget.tagName)||void 0===_a?void 0:_a.toLowerCase();if(!isString(tagName))return null;if(["body","html"].includes(tagName))return null;if(this.context.trackTags.includes(tagName)&&"div"!==tagName)return eventTarget;if("div"===tagName&&this.options.autoTrackConfig.collectTags.div&&(this.isDivLevelValid(eventTarget)&&(this.getDivMaxLevel()>1||this.isCollectableDiv(eventTarget))))return eventTarget;if(this.options.autoTrackConfig.collectTags.div&&this.isStyleTag(tagName)){var parentTrackDiv=this.getCollectableParent(eventTarget);if(parentTrackDiv&&this.isDivLevelValid(parentTrackDiv))return parentTrackDiv}return this.hasElement(eventTarget)||null},ClickTrackPlugin.prototype.getClickElementInfo=function(element){var isCollectInput=this.options.autoTrackConfig.isCollectInput,isCollectInputValue=!1;isFunction(isCollectInput)&&(isCollectInputValue=isCollectInput(element));var selector=this.getDomSelector(element),props=getElementProperties(element,isCollectInputValue);return props.H_element_selector=selector,props.H_element_path=this.getElementPath(element,!1),props},ClickTrackPlugin.prototype.getDomSelector=function(element){for(var _a,paths=[];element;){if("body"===(null===(_a=element.tagName)||void 0===_a?void 0:_a.toLowerCase())||!isElement(element)){paths.unshift("body");break}if(paths.unshift(this.getSelector(element)),(null==element?void 0:element.getAttribute("id"))&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(element.getAttribute("id")))break;element=element.parentNode}return paths.join(" > ")},ClickTrackPlugin.prototype.getSelector=function(element){var _a,_b,tagName=null===(_a=element.tagName)||void 0===_a?void 0:_a.toLowerCase(),i=-1;9!==(null===(_b=element.parentNode)||void 0===_b?void 0:_b.nodeType)&&(i=this.getDomIndex(element));var idValue=element.getAttribute("id");return idValue&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(idValue)?"#".concat(idValue):tagName+(i>-1?":nth-of-type(".concat(i+1,")"):"")},ClickTrackPlugin.prototype.getDomIndex=function(element){var _a,_b;if(element.parentNode)for(var index=0,tagName=null===(_a=element.tagName)||void 0===_a?void 0:_a.toLowerCase(),children=element.parentNode.children,i=0;i<children.length;i++){var child=children[i];if((null===(_b=child.tagName)||void 0===_b?void 0:_b.toLowerCase())===tagName){if(child===element)return index;index++}}return-1},ClickTrackPlugin.prototype.getClosestLi=function(element){for(;element&&element!==document&&isElement(element);){if("li"===element.tagName.toLowerCase())return element;element=element.parentNode}return null},ClickTrackPlugin.prototype.getSameTypeSiblings=function(element){for(var _a,_b,parentNode=element.parentNode,tagName=null===(_a=element.tagName)||void 0===_a?void 0:_a.toLowerCase(),list=[],i=0;i<parentNode.children.length;i++){var child=parentNode.children[i];isElement(child)&&(null===(_b=child.tagName)||void 0===_b?void 0:_b.toLowerCase())===tagName&&list.push(child)}return list},ClickTrackPlugin.prototype.getElementPosition=function(element,path){var _a,liElm=this.getClosestLi(element);if(!liElm||!isElement(element)||!isString(element.tagName))return null;var tagName=null===(_a=element.tagName)||void 0===_a?void 0:_a.toLowerCase(),targetElementCollection=liElm.getElementsByTagName(tagName),len=targetElementCollection.length;if(len>1){for(var clickElms=[],i=0;i<len;i++){this.getElementPath(targetElementCollection[i],!1)===path&&clickElms.push(targetElementCollection[i])}if(clickElms.length>0)return clickElms.findIndex((function(el){return el===element}))}if(!liElm.parentNode)return-1;var siblings=this.getSameTypeSiblings(liElm);return 1===siblings.length?0:siblings.findIndex((function(el){return el===liElm}))},ClickTrackPlugin}(PluginBase),StayTrackPlugin=function(_super){function StayTrackPlugin(options,context){var _this=_super.call(this,options,context)||this;return _this.options=options,_this.context=context,_this.name="StayTrackPlugin",_this.isReady=!1,_this.timer=null,_this.previousTime=nowStamp(),_this.previousOffsetTop=0,_this}return __extends(StayTrackPlugin,_super),StayTrackPlugin.prototype.init=function(notify){var _this=this,_a=this.options,autoTrackConfig=_a.autoTrackConfig,stayAutoTrackConfig=_a.stayAutoTrackConfig;if(!0===autoTrackConfig.stayAutoTrack)if(this.isReady)this.context.log("StayTrack plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN);else{this.isReady=!0;var isCollectUrl=stayAutoTrackConfig.isCollectUrl;isFunction(isCollectUrl)||(isCollectUrl=function(){return!0}),this.timer&&(clearTimeout(this.timer),this.timer=null),this.previousTime=nowStamp(),window.addEventListener("load",(function(){_this.previousOffsetTop=getScrollTop()})),window.addEventListener("scroll",(function(){isCollectUrl()&&(_this.timer||(_this.timer=setTimeout((function(){_this.run(notify),clearTimeout(_this.timer),_this.timer=null}),1e3)))})),window.addEventListener("unload",(function(){isCollectUrl()&&_this.run(notify,!0)}))}},StayTrackPlugin.prototype.transform=function(data){return this.context.getReportData("track","H_WebStay",data)},StayTrackPlugin.prototype.run=function(notify,isClosePage){void 0===isClosePage&&(isClosePage=!1);var autoTrackConfig=this.options.autoTrackConfig,stayDelayTime=autoTrackConfig.stayDelayTime,maxStayPageDuration=autoTrackConfig.maxStayPageDuration,offsetTop=getScrollTop(),nowTime=nowStamp(),duration=nowTime-this.previousTime;(isClosePage||duration>stayDelayTime&&offsetTop!==this.previousOffsetTop)&&notify({H_viewport_width:getScreenWidth(),H_viewport_height:getScreenHeight(),H_viewport_position:this.previousOffsetTop,event_duration:Math.min(duration/1e3,maxStayPageDuration),H_url_path:window.location.pathname});this.previousTime=nowTime,this.previousOffsetTop=offsetTop},StayTrackPlugin}(PluginBase),PageLeavePlugin=function(_super){function PageLeavePlugin(options,context){var _this=_super.call(this,options,context)||this;return _this.options=options,_this.context=context,_this.name="PageLeave",_this.isReady=!1,_this.pageId=generatorTrackId(),_this.storageName="hinasdk_pageleave_",_this.heartbeatIntervalTime=5e3,_this.maxDuration=432e3,_this.heartbeatIntervalTimer=null,_this.startTime=nowStamp(),_this.url=window.location.href,_this.pageShowStatus=!0,_this}return __extends(PageLeavePlugin,_super),PageLeavePlugin.prototype.init=function(){if(this.options.autoTrackConfig.pageLeaveAutoTrack)if(this.context.store.localStorage)if(this.isReady)this.context.log("PageLeave plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN);else{this.isReady=!0;var _a=this.normalizePageLeaveAutoTrack(),heartbeat_interval_time=_a.heartbeat_interval_time,max_duration=_a.max_duration;heartbeat_interval_time&&heartbeat_interval_time>0&&(this.heartbeatIntervalTime=1e3*heartbeat_interval_time),max_duration&&max_duration>0&&(this.maxDuration=Number(max_duration)),this.startTime=nowStamp(),this.addPageLeaveEventListener(),document.hidden?this.pageShowStatus=!1:this.startHeartBeatInterval()}else this.context.log("PageLeave plugin需要使用localstorage存储数据,但是您的浏览器不支持localstorage,所以不能使用该功能",exports.ConsoleTypes.WARN)},PageLeavePlugin.prototype.transform=function(){},PageLeavePlugin.prototype.normalizePageLeaveAutoTrack=function(){var pageLeaveAutoTrack=this.options.autoTrackConfig.pageLeaveAutoTrack;return isObject(pageLeaveAutoTrack)?pageLeaveAutoTrack:{}},PageLeavePlugin.prototype.addPageLeaveEventListener=function(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()},PageLeavePlugin.prototype.addPageStartListener=function(){var _this=this;"onpageshow"in window&&window.addEventListener("pageshow",(function(){_this.pageStartHandler()}))},PageLeavePlugin.prototype.addPageSwitchListener=function(){var _this=this;new ListenPageState({visible:function(){_this.pageStartHandler(),_this.startHeartBeatInterval()},hidden:function(){_this.url=window.location.href,_this.pageEndHandler(),_this.stopHeartBeatInterval()}})},PageLeavePlugin.prototype.addSinglePageListener=function(){var _this=this;mitt.on("urlChange",(function(params){var fromHref=params.fromHref;fromHref!==params.toHref&&(_this.url=fromHref,_this.pageEndHandler(),_this.stopHeartBeatInterval(),_this.pageStartHandler(),_this.startHeartBeatInterval())}))},PageLeavePlugin.prototype.addPageEndListener=function(){var _this=this,events=["pagehide","beforeunload","unload"];events.forEach((function(event){"on".concat(events)in window&&window.addEventListener(event,(function(){_this.pageEndHandler(),_this.stopHeartBeatInterval()}))}))},PageLeavePlugin.prototype.pageStartHandler=function(){this.startTime=nowStamp(),this.pageShowStatus=!document.hidden,this.url=window.location.href},PageLeavePlugin.prototype.pageEndHandler=function(){if(this.pageShowStatus){if(this.pageShowStatus=!1,this.isCollectUrl()){var properties=this.getPageLeaveProperties(),data=this.context.getReportData("track","H_WebPageLeave",properties);this.context.report(data)}this.delHeartBeatData()}},PageLeavePlugin.prototype.startHeartBeatInterval=function(){var _this=this;this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),this.isCollectUrl()&&(this.heartbeatIntervalTimer=setInterval((function(){_this.saveHeartBeatData()}),this.heartbeatIntervalTime),this.saveHeartBeatData("first_heartbeat")),this.reissueHeartBeatData()},PageLeavePlugin.prototype.reissueHeartBeatData=function(){for(var localStorage=this.context.store.localStorage,storageLen=localStorage.length(),i=0;i<storageLen;i++){var itemKey=localStorage.key(i);if(itemKey&&itemKey!==this.storageName+this.pageId&&itemKey.includes(this.storageName)){var result=safeJSONParse(localStorage.get(itemKey));isObject(result)&&nowStamp()-result.time>result.heartbeat_interval_time+5e3&&(delete result.heartbeat_interval_time,this.context.report(result)),this.delHeartBeatData(itemKey)}}},PageLeavePlugin.prototype.stopHeartBeatInterval=function(){this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)},PageLeavePlugin.prototype.delHeartBeatData=function(storageKey){this.context.store.localStorage.remove(storageKey||this.storageName+this.pageId)},PageLeavePlugin.prototype.isCollectUrl=function(){var isCollectUrl=this.normalizePageLeaveAutoTrack().isCollectUrl;return!isFunction(isCollectUrl)||isCollectUrl(this.url)},PageLeavePlugin.prototype.saveHeartBeatData=function(type){var properties=this.getPageLeaveProperties();properties.H_time=nowStamp(),"first_heartbeat"===type&&(properties.event_duration=3);var props=this.context.getReportData("track","H_WebPageLeave",properties);props.heartbeat_interval_time=this.heartbeatIntervalTime,this.context.store.localStorage.set(this.storageName+this.pageId,JSON.stringify(props))},PageLeavePlugin.prototype.getPageLeaveProperties=function(){var duration=(nowStamp()-this.startTime)/1e3;duration=duration<=0||duration>this.maxDuration?0:formatDecimal(duration,3);var _a=getURL(this.url),pathname=_a.pathname,hash=_a.hash,referrer=getReferrer(),properties={H_url:this.url,H_url_path:pathname,H_url_hash:hash,H_viewport_position:getScrollTop(),H_referrer:referrer,H_referrer_host:referrer?getHostname(referrer):"",event_duration:duration},custom_props=this.normalizePageLeaveAutoTrack().custom_props;return isObject(custom_props)&&(properties=__assign(__assign({},properties),custom_props||{})),properties},PageLeavePlugin}(PluginBase),SiteLinkerPlugin=function(_super){function SiteLinkerPlugin(options,context){var _this=_super.call(this,options,context)||this;return _this.options=options,_this.context=context,_this.name="SiteLinker",_this.isReady=!1,_this.linker=[],_this}return __extends(SiteLinkerPlugin,_super),SiteLinkerPlugin.prototype.init=function(){if(this.options.siteLinkerConfig){var linker=this.getLinkerConfig().linker;isArray(linker)&&linker.length>0?this.isReady?this.context.log("SiteLinker plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN):(this.isReady=!0,this.resolveOption(),this.setRefferId(),this.addClickListen()):this.context.log("siteLinker plugin: 请配置正确的linker参数",exports.ConsoleTypes.WARN)}},SiteLinkerPlugin.prototype.transform=function(){},SiteLinkerPlugin.prototype.getLinkerConfig=function(){var _a=this.options.siteLinkerConfig||{},_b=_a.linker;return{linker:(void 0===_b?[]:_b)||[],re_login:_a.re_login}},SiteLinkerPlugin.prototype.resolveOption=function(){for(var linker=this.getLinkerConfig().linker,len=linker.length,arr=[],i=0;i<len;i++){var _a=linker[i],part_url=_a.part_url,after_hash=_a.after_hash;/[A-Za-z0-9]+\./.test(part_url)&&isBoolean(after_hash)?arr.push({part_url:part_url,after_hash:after_hash}):this.context.log("The configuration of linker ".concat(i+1," is not supported.Please check format"),exports.ConsoleTypes.WARN)}this.linker=arr},SiteLinkerPlugin.prototype.setRefferId=function(){var re_login=this.getLinkerConfig().re_login,urlId=this.getUrlId(),isAnonymousId=urlId.startsWith("a");if(""!==(urlId=urlId.substring(1))){var anonymousId=this.context.store.getAnonymousId(),accountId=this.context.store.getAccountId();if(isAnonymousId){if(urlId!==anonymousId&&(this.context.store.state.anonymousId=urlId,this.context.store.save()),accountId){var props=this.context.getReportData("track_signup","H_SignUp",{});this.context.report(props)}}else(!accountId||re_login&&accountId!==urlId)&&this.context.setUserUId(urlId)}},SiteLinkerPlugin.prototype.getUrlId=function(){var hnId=window.location.href.match(/_hnsdk=([au][^\?\#\&\=]+)/);return isArray(hnId)&&hnId[1]?function(val){var result=val;try{result=decodeURIComponent(val)}catch(e){}return result}(hnId[1]):""},SiteLinkerPlugin.prototype.getPartUrl=function(url){for(var len=this.linker.length,i=0;i<len;i++)if(url.includes(this.linker[i].part_url))return!0;return!1},SiteLinkerPlugin.prototype.getPartHash=function(url){for(var len=this.linker.length,i=0;i<len;i++)if(url.includes(this.linker[i].part_url))return this.linker[i].after_hash;return!1},SiteLinkerPlugin.prototype.getCurrentId=function(){var accountId=this.context.store.getAccountId(),anonymousId=this.context.store.getAnonymousId();return function(val){var result=val;try{result=encodeURIComponent(val)}catch(e){}return result}(accountId?"u".concat(accountId):"a".concat(anonymousId))},SiteLinkerPlugin.prototype.rewriteUrl=function(url,dom){var normalizeUrl=function(url,sdkId,after_hash){var arr=/([^?#]+)(\?[^#]*)?(#.*)?/.exec(url),normalizeUrl="";if(arr){var host=arr[1]||"",search=arr[2]||"",hash=arr[3]||"",hnId="_hnsdk=".concat(sdkId),changeHnId=function(str){var list=str.split("&"),result=[];return list.forEach((function(value){value.includes("_hnsdk")?result.push(hnId):result.push(value)})),result.join("&")};if(after_hash){var hasQuery=hash.includes("?"),index=hash.indexOf("_hnsdk");normalizeUrl=hasQuery?index>=0?"".concat(host).concat(search,"#").concat(hash.substring(1,index)).concat(changeHnId(hash.substring(index,hash.length))):"".concat(host).concat(search,"#").concat(hash.substring(1),"&").concat(hnId):"".concat(host).concat(search,"#").concat(hash.substring(1),"?").concat(hnId)}else normalizeUrl=(hasQuery=/^\?(\w)+/.test(search))?search.includes("_hnsdk")?"".concat(host,"?").concat(changeHnId(search.substring(1))).concat(hash):"".concat(host).concat(search,"&").concat(hnId).concat(hash):"".concat(host,"?").concat(hnId).concat(hash);return normalizeUrl}}(url,this.getCurrentId(),this.getPartHash(url));return dom&&(dom.href=normalizeUrl),normalizeUrl},SiteLinkerPlugin.prototype.addClickListen=function(){var _this=this,handleClick=function(event){var _a,_b,target=event.target;if(target){var tagName=null===(_a=target.tagName)||void 0===_a?void 0:_a.toLowerCase(),parentNode=target.parentNode,parentTagName=null===(_b=null==parentNode?void 0:parentNode.tagName)||void 0===_b?void 0:_b.toLowerCase();if("a"===tagName&&target.href||"a"===parentTagName&&parentNode.href){var sdkUrl=void 0,sdkTarget=void 0;"a"===tagName&&target.href?(sdkUrl=target.href,sdkTarget=target):(sdkUrl=parentNode.href,sdkTarget=parentNode);var protocol=getURL(sdkUrl).protocol;"http:"!==protocol&&"https:"!==protocol||_this.getPartUrl(sdkUrl)&&_this.rewriteUrl(sdkUrl,sdkTarget)}}};"PointerEvent"in window?document.addEventListener("pointerdown",handleClick):document.addEventListener("mousedown",handleClick)},SiteLinkerPlugin}(PluginBase),HistoryPlugin=function(_super){function HistoryPlugin(options,context){var _this=_super.call(this,options,context)||this;return _this.options=options,_this.context=context,_this.name="HistoryPlugin",_this.isReady=!1,_this.lastHref=window.location.href,_this.lastPath=window.location.pathname,_this}return __extends(HistoryPlugin,_super),HistoryPlugin.prototype.init=function(){if(window&&window.history.pushState&&window.history.replaceState)if(this.isReady)this.context.log("History plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN);else{this.isReady=!0;var self=this,originalOnpopstate=window.onpopstate,handleRouterChange=function(currentPath,currentHref){var params={fromPath:self.lastPath,fromHref:self.lastHref,toPath:currentPath,toHref:currentHref};self.lastPath=currentPath,self.lastHref=currentHref,mitt.emit("urlChange",__assign(__assign({},params),{mode:"history"}))};window.onpopstate=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];var currentPath=window.location.pathname,currentHref=window.location.href;handleRouterChange(currentPath,currentHref),originalOnpopstate&&originalOnpopstate.apply(this,args)},replaceOld(window.history,"pushState",historyReplaceFn),replaceOld(window.history,"replaceState",historyReplaceFn)}function historyReplaceFn(originalHistoryFn){return function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];originalHistoryFn.apply(this,args);var currentPath=window.location.pathname,currentHref=window.location.href;handleRouterChange(currentPath,currentHref)}}},HistoryPlugin.prototype.transform=function(){},HistoryPlugin}(PluginBase),HashPlugin=function(_super){function HashPlugin(options,context){var _this=_super.call(this,options,context)||this;return _this.options=options,_this.context=context,_this.name="HashPlugin",_this.isReady=!1,_this.lastHref=window.location.href,_this.lastPath=window.location.hash,_this}return __extends(HashPlugin,_super),HashPlugin.prototype.init=function(){var _this=this;this.isReady?this.context.log("Hash plugin:插件已经运行,无需重复执行",exports.ConsoleTypes.WARN):(this.isReady=!0,window.addEventListener("hashchange",(function(event){var newURL=event.newURL,currentPath=getURL(newURL).hash,params={fromPath:_this.lastPath,fromHref:_this.lastHref,toPath:currentPath,toHref:newURL};_this.lastHref=newURL,_this.lastPath=currentPath,mitt.emit("urlChange",__assign(__assign({},params),{mode:"hash"}))})))},HashPlugin.prototype.transform=function(){},HashPlugin}(PluginBase),AbTestingPlugin=function(_super){function AbTestingPlugin(options,context){var _a,ua,_this=this,platform=(ua=null===(_a=navigator.userAgent)||void 0===_a?void 0:_a.toLowerCase(),/android|webos|iphone|ipod|blackberry/i.test(ua)?"H5":"Web");return(_this=_super.call(this,options,context,platform,"hina_webjs_sdk_abtest","4.0.7")||this).options=options,_this.context=context,_this.name="HinaABTest",_this}return __extends(AbTestingPlugin,_super),AbTestingPlugin.prototype.getResultFromServer=function(params){var _this=this;return new Promise((function(resolve,reject){var requestData=_this.createRequestData(params);new AjaxRequest({url:_this.options.abTestingPluginConfig.url,data:JSON.stringify(requestData),contentType:"application/json",customHeaders:{"project-key":_this.projectKey},timeout:params.timeoutMilliseconds}).run().then((function(res){var data=res.data;"SUCCESS"===(null==data?void 0:data.status)?_this.saveResponseData(data.results).then((function(){resolve(data)})):reject()}))}))},AbTestingPlugin}(AbtestBasePlugin),SearchKeyword=function(){function SearchKeyword(){}return SearchKeyword.getSourceFromReferrer=function(){var getMatchStrFromArr=function(arr,str){for(var i=0;i<arr.length;i++)if(-1!==str.split("?")[0].indexOf(arr[i]))return!0},utm_reg="(".concat(utmTypes.join("|"),")\\=[^&]+"),referrer=document.referrer||"",url=window.location.href;if(url){var utm_match=url.match(new RegExp(utm_reg));return utm_match&&utm_match[0]?"付费广告流量":getMatchStrFromArr(searchTypes,referrer)?"自然搜索流量":getMatchStrFromArr(socialTypes,referrer)?"社交网站流量":""===referrer?"直接流量":"引荐流量"}return"获取url异常"},SearchKeyword.getReferSearchEngine=function(referrerUrl){var e_1,_a,hostname=getHostname(referrerUrl);if(!hostname||"hostname解析异常"===hostname)return"";var regexps={baidu:[/^.*\.baidu\.com$/],bing:[/^.*\.bing\.com$/],google:[/^www\.google\.com$/,/^www\.google\.com\.[a-z]{2}$/,/^www\.google\.[a-z]{2}$/],sm:[/^m\.sm\.cn$/],so:[/^.+\.so\.com$/],sogou:[/^.*\.sogou\.com$/],yahoo:[/^.*\.yahoo\.com$/]};for(var regexp in regexps){var regexList=regexps[regexp];try{for(var regexList_1=(e_1=void 0,__values(regexList)),regexList_1_1=regexList_1.next();!regexList_1_1.done;regexList_1_1=regexList_1.next()){if(regexList_1_1.value.test(hostname))return regexp}}catch(e_1_1){e_1={error:e_1_1}}finally{try{regexList_1_1&&!regexList_1_1.done&&(_a=regexList_1.return)&&_a.call(regexList_1)}finally{if(e_1)throw e_1.error}}}return"未知搜索引擎"},SearchKeyword.getKeywordFromReferrer=function(){var referrerUrl=document.referrer||"";if(0===referrerUrl.indexOf("http")){var searchEngine=this.getReferSearchEngine(referrerUrl),query=function(queryString){queryString=queryString||"";var args={};return new URLSearchParams(queryString).forEach((function(value,key){args[key]=value})),args}(getURL(referrerUrl).search);if(isEmptyObject(query))return"未取到值";for(var key in searchKeywords){var value=searchKeywords[key];if(key===searchEngine)if(isArray(value))for(var i=0;i<value.length;i++){var val=query[value[i]];if(val)return val}else if(query[value])return query[value]}return"未取到值"}return""===referrerUrl?"未取到值_直接打开":"未取到值_非http的url"},SearchKeyword}();function getUmtsParams(prefix){void 0===prefix&&(prefix="");var params,utms=(params={},utmTypes.forEach((function(key){var result=getQueryParam(window.location.href,key);result.length&&(params[key]=result)})),params),allUtms={};return Object.keys(utms).forEach((function(key){allUtms[prefix+key]=utms[key]})),allUtms}var HinaTrack=function(_super){function HinaTrack(options,useInstancing){void 0===useInstancing&&(useInstancing=!0);var _this=_super.call(this,options,useInstancing)||this;return _this.trackTags=defaultTags,_this.customProperties={},_this.generalProperties={H_lib_version:"4.0.7",H_lib:"js",H_lib_method:"code",H_timezone_offset:(new Date).getTimezoneOffset()},_this.useInstancing&&_this.init(options),_this}return __extends(HinaTrack,_super),HinaTrack.prototype.init=function(options){if(this.isReady)this.log("hinaSDK has been initialized",exports.ConsoleTypes.ERROR);else{var default_config={name:"",serverUrl:"",showLog:!1,autoTrackConfig:{clickAutoTrack:!0,stayAutoTrack:!0,isCollectUrl:function(){return!0},isCollectElement:function(){return!0},isCollectInput:function(){return!1},addCustomProperty:function(){},stayDelayTime:4e3,maxStayPageDuration:18e3,collectTags:{div:!1},trackAttr:["hn-click"],pageviewAutoTrack:!1,pageLeaveAutoTrack:!1},stayAutoTrackConfig:{isCollectUrl:function(){return!0}},maxStringLength:1024,imgUseCrossOrigin:!1,isSinglePage:!1,batchSend:!1,appJsBridge:!1,sendType:exports.ReportTypes.AJAX,customHeaders:{},credentials:!1,dataSendTimeout:3e3,presetProperties:{latest_utm:!0,latest_traffic_source_type:!0,latest_search_keyword:!0,latest_referrer:!0},sourceChannel:[],plugins:[]},performanceErrorConfig=options.performanceErrorConfig,plugins=options.plugins,others=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(null!=s&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]])}return t}(options,["performanceErrorConfig","plugins"]);this.options=merge(default_config,others),this.options=__assign(__assign({},this.options),{performanceErrorConfig:performanceErrorConfig,plugins:plugins}),this.initState(),this.initAdvProps(),this.normalizeConfig(),this.initPlugins(),this.isReady=!0}},HinaTrack.prototype.normalizeConfig=function(){var _this=this,_a=this.options,serverUrl=_a.serverUrl,sendType=_a.sendType,batchSend=_a.batchSend,maxStringLength=_a.maxStringLength,isSinglePage=_a.isSinglePage,_b=_a.autoTrackConfig,_c=void 0===_b?{}:_b,_d=_c.trackAttr,trackAttr=void 0===_d?[]:_d,collectTags=_c.collectTags,pageLeaveAutoTrack=_c.pageLeaveAutoTrack,pageviewAutoTrack=_c.pageviewAutoTrack;if(""===(serverUrl=(serverUrl=serverUrl||"").trim()))this.log("当前 serverUrl 为空,network 中不会发数据,请配置正确的 serverUrl!",exports.ConsoleTypes.WARN);else{var currentProtocol=getURL(window.location.href).protocol||"";(getURL(serverUrl).protocol||"")!==currentProtocol&&this.log("SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。",exports.ConsoleTypes.WARN)}if([exports.ReportTypes.IMAGE,exports.ReportTypes.AJAX,exports.ReportTypes.BEACON].includes(sendType)||this.setConfig({sendType:exports.ReportTypes.AJAX}),this.options.maxStringLength=function(maxStringLength){var maxLength=maxStringLength;return!isNumber(maxStringLength)||maxStringLength<0?maxLength=1024:maxStringLength>5120&&(maxLength=5120),maxLength}(maxStringLength),(!0===pageLeaveAutoTrack||isObject(pageLeaveAutoTrack)&&isEmptyObject(pageLeaveAutoTrack))&&(this.options.autoTrackConfig.pageLeaveAutoTrack={heartbeat_interval_time:5e3,max_duration:432e3}),isArray(trackAttr)?(trackAttr=trackAttr.filter((function(v){return isString(v)}))).includes("hn-click")||trackAttr.push("hn-click"):trackAttr=["hn-click"],this.options.autoTrackConfig.trackAttr=trackAttr,isObject(collectTags))if(!0===collectTags.div)this.options.autoTrackConfig.collectTags.div={ignoreTags:ignoreTags,maxLevel:1};else if(isObject(collectTags.div)){var maxLevel=1,oDiv=collectTags.div;isNumber(oDiv.maxLevel)&&[1,2,3].includes(oDiv.maxLevel)&&(maxLevel=oDiv.maxLevel),this.options.autoTrackConfig.collectTags.div={ignoreTags:ignoreTags,maxLevel:maxLevel}}else this.options.autoTrackConfig.collectTags.div=!1;else this.options.autoTrackConfig.collectTags={div:!1};this.updateTrackTags(),(!0===batchSend||isObject(batchSend)&&!isEmptyObject(batchSend))&&(this.options.batchSend=__assign({dataSendTimeout:6e3,sendInterval:6e3,storageLimit:200},batchSend),this.batchSender=new BatchSend(this.options,"hinasdk_tab","hinasdk_data_")),"auto"===pageviewAutoTrack?this.autoTrack():("singlePage"===pageviewAutoTrack||isSinglePage)&&(this.autoTrack(),mitt.on("urlChange",(function(data){var fromHref=data.fromHref;if(fromHref!==data.toHref){var payload={};if(isFunction(isSinglePage)){var extra=isSinglePage();isObject(extra)&&(payload=__assign(__assign({},payload),extra))}_this.autoTrack(__assign(__assign({},payload),{H_referrer:fromHref}))}})))},HinaTrack.prototype.updateTrackTags=function(){var collectTags=this.options.autoTrackConfig.collectTags,tags=__spreadArray([],__read(defaultTags),!1);Object.keys(collectTags||{}).forEach((function(key){var value=collectTags[key];!0!==value&&!isObject(value)||tags.includes(key)||tags.push(key)})),this.trackTags=tags},HinaTrack.prototype.initState=function(){this.store=new WebState(this.options),this.store.init()},HinaTrack.prototype.initAdvProps=function(){var referrer,advProps={},_a=this.options,presetProperties=_a.presetProperties,sourceChannel=_a.sourceChannel;if(isObject(presetProperties))for(var key in presetProperties){var value=presetProperties[key];if(key.includes("latest_")&&(key=key.slice(7),value)){var url_domain=getCurrentDomain();if("utm"!==key&&"url解析失败"===url_domain)advProps["H_latest_".concat(key)]="url的domain解析失败";else if(""===(referrer=(referrer=void 0)||document.referrer)||getCookieTopLevelDomain(getHostname(referrer))!==getCookieTopLevelDomain())switch(key){case"traffic_source_type":advProps.H_latest_traffic_source_type=SearchKeyword.getSourceFromReferrer();break;case"search_keyword":var searchKeyword=SearchKeyword.getKeywordFromReferrer();searchKeyword&&(advProps.H_latest_search_keyword=searchKeyword);break;case"referrer":advProps.H_latest_referrer=getReferrer()}}}var props=this.store.state.props||{},latestAllUtms={};presetProperties.latest_utm&&(latestAllUtms=getUmtsParams("H_latest_"));var firstAllUtms={};props.H_utm_source||(firstAllUtms=getUmtsParams("H_"));var source=[],customUtm={};isArray(sourceChannel)&&sourceChannel.length>0&&(source=sourceChannel.filter((function(val){return!utmTypes.includes(val)}))).length>0&&(customUtm=__assign(__assign({},customUtm),function(prefix,utms){void 0===utms&&(utms=[]);var allUtms={};return utms.forEach((function(key){var result=getQueryParam(window.location.href,key);result&&(allUtms[key]=result,allUtms["".concat(prefix).concat(key)]=result)})),allUtms}("H_latest_",source))),this.store.state.props=__assign(__assign(__assign(__assign(__assign({},this.store.state.props),advProps),latestAllUtms),customUtm),firstAllUtms),this.store.setProps(this.store.state.props),this.store.getUtmFromProps(source)},HinaTrack.prototype.getGeneralProperties=function(){var browserInfo=new Browser;return this.generalProperties=__assign(__assign(__assign({},this.generalProperties),{H_screen_width:window.screen.width,H_screen_height:window.screen.height,H_viewport_width:getScreenWidth(),H_viewport_height:getScreenHeight(),H_page_height:document.documentElement.scrollHeight||document.body.scrollHeight,H_browser:browserInfo.browserName,H_browser_version:browserInfo.browserVersion,H_os:browserInfo.os,H_os_version:browserInfo.osVersion,H_model:browserInfo.model,H_is_first_day:this.store.isFirstDay,H_url:window.location.href,H_url_host:getHostname(window.location.href,"url_host取值异常"),H_title:document.title}),this.store.hLatestUtm),this.generalProperties.H_latest_referrer&&(this.generalProperties.H_latest_referrer_host=getHostname(this.generalProperties.H_latest_referrer,"hostname解析异常")),this.generalProperties},HinaTrack.prototype.initPlugins=function(){var _this=this,_a=this.options,serverUrl=_a.serverUrl,name=_a.name,showLog=_a.showLog,sendType=_a.sendType,customHeaders=_a.customHeaders,credentials=_a.credentials,dataSendTimeout=_a.dataSendTimeout,batchSend=_a.batchSend,imgUseCrossOrigin=_a.imgUseCrossOrigin,globalCallback=_a.globalCallback,_b=_a.plugins,plugins=void 0===_b?[]:_b,performanceErrorConfig=_a.performanceErrorConfig,autoTrackConfig=_a.autoTrackConfig,siteLinkerConfig=_a.siteLinkerConfig,abTestingPluginConfig=_a.abTestingPluginConfig;plugins=plugins||[];var pageLeaveAutoTrack=autoTrackConfig.pageLeaveAutoTrack,clickCrackPlugin=new ClickTrackPlugin(this.options,this),stayTrackPlugin=new StayTrackPlugin(this.options,this),historyPlugin=new HistoryPlugin(this.options,this),hashPlugin=new HashPlugin(this.options,this),pageLeavePlugin=new PageLeavePlugin(this.options,this),siteLinkerPlugin=new SiteLinkerPlugin(this.options,this),abTestingPlugin=new AbTestingPlugin(this.options,this);pageLeavePlugin.disabled=!(isObject(pageLeaveAutoTrack)&&!isEmptyObject(pageLeaveAutoTrack));var linker=(siteLinkerConfig||{}).linker;siteLinkerPlugin.disabled=!(isArray(linker)&&linker.length>0),abTestingPlugin.disabled=!(isObject(abTestingPluginConfig)&&!isEmptyObject(abTestingPluginConfig)),this.plugins=[clickCrackPlugin,stayTrackPlugin,historyPlugin,hashPlugin,pageLeavePlugin,siteLinkerPlugin,abTestingPlugin],isArray(plugins)&&plugins.forEach((function(Plugin){if("Monitor"===Plugin.componentName){if(isObject(performanceErrorConfig)&&!isEmptyObject(performanceErrorConfig))new Plugin(__assign({serverUrl:serverUrl,name:name,showLog:showLog,sendType:sendType,customHeaders:customHeaders,credentials:credentials,dataSendTimeout:dataSendTimeout,batchSend:batchSend,imgUseCrossOrigin:imgUseCrossOrigin,globalCallback:globalCallback},performanceErrorConfig),!0)}else{var instance=new Plugin(_this.options,_this);_this.plugins.push(instance)}})),this.runPlugins(this.plugins)},HinaTrack.prototype.use=function(pluginName,options){if(this.isReady){if(isObject(options)){"PageLeave"===pluginName?this.options.autoTrackConfig.pageLeaveAutoTrack=options:"SiteLinker"===pluginName?this.options.siteLinkerConfig=options:"HinaABTest"===pluginName&&(this.options.abTestingPluginConfig=options);var instance=this.plugins.find((function(plugin){return plugin.name===pluginName}));return instance&&(instance.disabled=!1,instance.isReady?this.log("".concat(pluginName,"插件已运行,无需重复执行"),exports.ConsoleTypes.WARN):instance.init()),this.getPluginInstance(pluginName)}this.log("".concat(pluginName,"插件配置项必须是一个对象类型"),exports.ConsoleTypes.WARN)}else this.log("请先初始化埋点SDK",exports.ConsoleTypes.WARN)},HinaTrack.prototype.getPluginInstance=function(pluginName){return this.plugins.find((function(plugin){return plugin.name===pluginName}))},HinaTrack.prototype.setConfig=function(options){this.options=merge(this.options,options),this.normalizeConfig()},HinaTrack.prototype.getConfig=function(key){return key?this.options[key]:this.options},HinaTrack.prototype.setUserUId=function(uid,callback){var _this=this;!function(uid,accountId,callback){isNumber(uid=null!=uid?uid:"")||isString(uid)?accountId!==(uid=String(uid).trim())?callback(uid):log("setUserUId: uid is equal to account_id, failed to execute setUserUId",exports.ConsoleTypes.WARN):log("setUserUId: uid must be string or number",exports.ConsoleTypes.WARN)}(uid,this.store.getAccountId(),(function(id){_this.store.setAccountId(id);var props=_this.getReportData("track_signup","H_SignUp",{});_this.report(props,callback)}))},HinaTrack.prototype.cleanUserUId=function(){this.store.setAccountId("")},HinaTrack.prototype.getUserUid=function(){return this.store.state.accountId},HinaTrack.prototype.setDeviceUId=function(uid){this.store.setDeviceId(uid)},HinaTrack.prototype.getDeviceUId=function(){return this.store.getDeviceId()},HinaTrack.prototype.userSet=function(data,callback){if(isObject(data)&&!isEmptyObject(data)){var props=this.getReportData("user_set","",data);this.report(props,callback)}},HinaTrack.prototype.userSetOnce=function(data,callback){if(isObject(data)&&!isEmptyObject(data)){var props=this.getReportData("user_setOnce","",data);this.report(props,callback)}},HinaTrack.prototype.userAdd=function(data,callback){var _this=this;!function(data,callback){var _a;isString(data)&&((_a={})[data]=1,data=_a),isObject(data)&&!isEmptyObject(data)&&function(params){for(var key in params)if(!/-*\d+/.test(String(params[key])))return log("userAdd属性的值只能是数字",exports.ConsoleTypes.WARN),!1;return!0}(data)&&callback(data)}(data,(function(result){var props=_this.getReportData("user_add","",result);_this.report(props,callback)}))},HinaTrack.prototype.userAppend=function(data,callback){var _this=this;!function(data,callback){var result={};isObject(data)&&(Object.keys(data).forEach((function(key){var value=data[key];isArray(value)?result[key]=value:result[key]=[value]})),isEmptyObject(result)||callback(result))}(data,(function(result){var props=_this.getReportData("user_append","",result);_this.report(props,callback)}))},HinaTrack.prototype.userUnset=function(data,callback){var _this=this;!function(data,callback){var obj={};isString(data)&&(data=[data]),isArray(data)?(data.forEach((function(value){isString(value)?obj[value]=!0:log("userUnset参数数组里面的值必须是string,已经过滤掉".concat(value),exports.ConsoleTypes.WARN)})),isEmptyObject(obj)||callback(obj)):log("userUnset参数必须是数组或字符串",exports.ConsoleTypes.WARN)}(data,(function(result){var props=_this.getReportData("user_unset","",result);_this.report(props,callback)}))},HinaTrack.prototype.userDelete=function(callback){var props=this.getReportData("user_delete","",{});this.report(props,callback),this.store.setAccountId("")},HinaTrack.prototype.registerCommonProperties=function(params){this.customProperties=merge(this.customProperties,params)},HinaTrack.prototype.getPresetProperties=function(){return __assign(__assign({},this.getGeneralProperties()),this.customProperties)},HinaTrack.prototype.clearPageRegister=function(payload){var _this=this;void 0===payload&&(payload=!0),!0===payload?this.customProperties={}:isArray(payload)&&payload.forEach((function(key){key in _this.customProperties&&delete _this.customProperties[key]}))},HinaTrack.prototype.track=function(event,properties,callback){if(callback=callback||function(){},isString(event)){properties=isObject(properties)?properties:{};var props=this.getReportData("track",event,properties);this.report(props,callback)}else this.log("track事件名必须是字符串,属性必须是是一个对象",exports.ConsoleTypes.WARN)},HinaTrack.prototype.quick=function(name,data,callback){if(!this.isReady)return this.log("请先初始化SDK");var params={};callback=isFunction(callback)?callback:noop,isObject(data)?params=data:isFunction(data)&&(callback=data),this.autoTrack(params,callback)},HinaTrack.prototype.autoTrack=function(data,callback){void 0===data&&(data={}),void 0===callback&&(callback=noop);var referrer=(null==data?void 0:data.H_referrer)||getReferrer(),options=__assign(__assign(__assign({H_is_first_time:this.store.isFirstTime,H_url_path:window.location.pathname,H_referrer:referrer,H_referrer_host:referrer?getHostname(referrer):""},this.store.hUtm),this.store.customUtm),data||{}),props=this.getReportData("track","H_pageview",options);if(this.report(props,callback),this.store.isFirstTime){this.store.isFirstTime=!1;var referrer_1=getReferrer(),data_1=__assign(__assign({H_first_visit_time:nowStamp(),H_first_referrer:referrer_1,H_first_referrer_host:referrer_1?getHostname(referrer_1,"取值异常"):"",H_first_traffic_source_type:SearchKeyword.getSourceFromReferrer(),H_first_search_keyword:SearchKeyword.getKeywordFromReferrer(),H_first_browser_language:isString(navigator.language)?navigator.language.toLowerCase():"取值异常",H_first_browser_charset:document.characterSet||document.inputEncoding||"UTF-8"},this.store.hUtm),this.store.customUtm);this.userSetOnce(data_1)}},HinaTrack.prototype.report=function(data,callback,type){var _a,_b,_c=this.options,appJsBridge=_c.appJsBridge,serverUrl=_c.serverUrl;if(this.log(data),appJsBridge){var isError=!0,jsBridge=null===window||void 0===window?void 0:window.Hina_Cloud_H5_Bridge;if(isObject(jsBridge)&&jsBridge.track)isError=!1,jsBridge.track(data.event,data.type,JSON.stringify(data));else{var Tracker=null===(_b=null===(_a=null===window||void 0===window?void 0:window.webkit)||void 0===_a?void 0:_a.messageHandlers)||void 0===_b?void 0:_b.hinaNativeTracker;if(null==Tracker?void 0:Tracker.postMessage){isError=!1;var params=JSON.stringify({eventName:data.event,eventType:data.type,properties:data});Tracker.postMessage(params)}}if(isError)return void this.log("JSBridge 发送数据失败",exports.ConsoleTypes.WARN);isFunction(callback)&&callback(serverUrl,data)}else this.sendReportData(data,callback,type)},HinaTrack.prototype.getReportData=function(type,event,data){var properties,anonymous_id=this.store.getAnonymousId(),accountId=this.store.getAccountId(),time=nowStamp(),customProperties=merge(this.customProperties),generalProperties=this.getGeneralProperties();if("user"===type.slice(0,4)){var H_lib=generalProperties.H_lib,H_lib_method=generalProperties.H_lib_method,H_lib_version=generalProperties.H_lib_version;properties=__assign({device_id:this.store.getDeviceId(),H_lib:H_lib,H_lib_method:H_lib_method,H_lib_version:H_lib_version},data||{})}else properties=__assign(__assign(__assign({device_id:this.store.getDeviceId()},generalProperties),customProperties),data||{});checkReportProperties(properties,this.options.maxStringLength);var isLogin=accountId&&!/^[0-9a-f]{8,}-[0-9a-f]{4,}-[0-9a-f]{4,}-[0-9a-f]{4,}-[0-9a-f]{12,}$/.test(accountId),props={anonymous_id:anonymous_id,type:type,event:event,time:time,_track_id:generatorTrackId(),properties:__assign(__assign({},properties),{H_is_login_id:!!isLogin})};return isLogin&&(props.account_id=accountId),props.send_time=nowStamp(),props},HinaTrack}(WebClient);var hinaSdk=new HinaTrack({},!1);exports.HinaTrack=HinaTrack,exports.PluginBase=PluginBase,exports.default=hinaSdk;