hina-cloud-js-sdk 4.0.3 → 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.
package/dist/hina.esm.js CHANGED
@@ -1 +1 @@
1
- import{WebClient as t}from"hina-cloud-js-core";import{ReportTypes as e,ConsoleTypes as r,PluginBase as i}from"hina-cloud-type";export*from"hina-cloud-type";import{getScrollLeft as o,getScrollTop as n,formatDecimal as a,isValid as s,isFunction as l,isNumber as u,isObject as c,merge as h,isArray as p,isString as f,nowStamp as d,getScreenWidth as g,getScreenHeight as v,generatorTrackId as m,ListenPageState as y,mitt as _,safeJSONParse as w,getURL as k,getReferrer as T,getHostname as H,isBoolean as b,handleDecodeURLComponent as C,handleEncodeURLComponent as L,rewriteUrl as P,supportHistory as S,replaceOld as x,getPlatform as A,AjaxRequest as R,AbtestBasePlugin as N,utmTypes as E,getQueryParam as I,getURLSearchParams as D,isEmptyObject as O,searchKeywords as U,searchTypes as B,socialTypes as j,normalizeMaxStringLength as W,BatchSend as z,WebState as F,getCurrentDomain as $,isReferralTraffic as M,Browser as J,getPageScrollHeight as K,setUserUId as Z,userAdd as V,userAppend as X,userUnset as G,noop as Y,checkReportProperties as q}from"hina-cloud-util";var Q=function(t,e){return Q=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},Q(t,e)};function tt(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}Q(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var et=function(){return et=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},et.apply(this,arguments)};function rt(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],i=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function it(t){return 1===(null==t?void 0:t.nodeType)}function ot(t,e){var r;if("input"===(null===(r=t.tagName)||void 0===r?void 0:r.toLowerCase()))return(["button","submit"].includes(t.type)||e)&&t.value||"";var i="";return t.textContent?i=t.textContent.trim():t.innerText&&(i=t.innerText.trim()),i&&(i=i.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),i||""}function nt(t,e){var r;if(!it(t))return{};var i,o={H_element_type:null===(r=t.tagName)||void 0===r?void 0:r.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:ot(t,e)};return i=o,Object.keys(i).reduce((function(t,e){return s(i[e])&&""!==i[e]&&(t[e]=i[e]),t}),{})}"function"==typeof SuppressedError&&SuppressedError;var at=["mark","/mark","strong","b","em","i","u","abbr","ins","del","s","sup"],st=["a","input","button","textarea"],lt=function(t){function e(e,r){var i=t.call(this,e,r)||this;return i.options=e,i.context=r,i.name="ClickTrackPlugin",i.isReady=!1,i.isTrackList={a:!0,button:!0},i}return tt(e,t),e.prototype.init=function(t){var e=this,i=this.options.autoTrackConfig,s=i.clickAutoTrack,p=i.isCollectUrl,f=i.isCollectElement,d=i.addCustomProperty;!0===s&&(this.isReady?this.context.log("ClickTrack plugin:插件已经运行,无需重复执行",r.WARN):(this.isReady=!0,document.addEventListener("click",(function(r){if(p()){var i=r||window.event;if(i){var s=i.target||i.srcElement,g=e.getTargetElement(s);if(g){if(l(f)&&!f(g))return!1;var v=e.getClickElementInfo(g),m=function(t,e){if(!t)return{};var r=o(),i=n(),s=e.getBoundingClientRect(),l=t.pageX||t.clientX+r||t.offsetX+((null==s?void 0:s.left)||0)+r,u=t.pageY||t.clientY+i||t.offsetY+((null==s?void 0:s.top)||0)+i;return{H_page_x:a(l,3),H_page_y:a(u,3)}}(i,g),y=m.H_page_x,_=m.H_page_y;v.H_page_x=y,v.H_page_y=_;var w=e.getElementPosition(g,v.H_element_path);if(u(w)&&w>=0&&(v.H_element_position=w),l(d)){var k=d(g);c(k)&&(v=h(v,k))}t(v)}}}}),!0)))},e.prototype.transform=function(t){return this.context.getReportData("track","H_WebClick",t)},e.prototype.hasAttribute=function(t,e){var r;return t.hasAttribute?t.hasAttribute(e):t.attributes?!!(null===(r=t.attributes[e])||void 0===r?void 0:r.value):void 0},e.prototype.hasAttributes=function(t,e){if(p(e))for(var r=0;r<e.length;r++)if(this.hasAttribute(t,e[r]))return!0;return!1},e.prototype.hasElement=function(t){var e,r,i,o=function(t){var e=[t];try{if(!it(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),n=this.options.autoTrackConfig.trackAttr||[];if(p(o)&&o.length>0)try{for(var a=rt(o),s=a.next();!s.done;s=a.next()){var l=s.value,u=l.tagName&&(null===(i=l.tagName)||void 0===i?void 0:i.toLowerCase());if(it(l)&&(this.isTrackList[u]||this.hasAttributes(l,n)))return l}}catch(t){e={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}},e.prototype.getDivMaxLevel=function(){var t;return(null===(t=this.options.autoTrackConfig.collectTags.div)||void 0===t?void 0:t.maxLevel)||1},e.prototype.isStyleTag=function(t){var e,r=(null===(e=this.options.autoTrackConfig.collectTags.div)||void 0===e?void 0:e.ignoreTags)||[];return null==r?void 0:r.includes(t)},e.prototype.getCollectableParent=function(t){var e;try{var i=t.parentNode,o=i?null===(e=i.tagName)||void 0===e?void 0:e.toLowerCase():"";if("body"===o)return!1;var n=this.getDivMaxLevel();if("div"===o&&(n>1||this.isCollectableDiv(i)))return i;if(i&&this.isStyleTag(o))return this.getCollectableParent(i)}catch(t){this.context.log(t,r.ERROR)}return!1},e.prototype.isCollectableDiv=function(t){var e;try{var i=t.children||[];if(0===i.length)return!0;for(var o=0;o<i.length;o++){var n=i[o];if(it(n)){var a=null===(e=n.tagName)||void 0===e?void 0:e.toLowerCase(),s=this.getDivMaxLevel();if(!("div"===a&&s>1||this.isStyleTag(a)))return!1;if(!this.isCollectableDiv(n))return!1}}return!0}catch(t){this.context.log(t,r.ERROR)}return!1},e.prototype.isDivLevelValid=function(t){for(var e=this.getDivMaxLevel(),r=t.getElementsByTagName("div"),i=r.length-1;i>=0;i--)if(this.getDivLevels(r[i],t)>e)return!1;return!0},e.prototype.getElementPath=function(t,e,r){for(var i,o,n=[];it(t)&&t.parentNode;){if(t.id&&!e&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.id)){var a=t.tagName||"";n.unshift("".concat(a.toLowerCase(),"#").concat(t.id));break}if(r&&t===r){n.unshift(null===(i=t.tagName)||void 0===i?void 0:i.toLowerCase());break}if(t===document.body){n.unshift("body");break}n.unshift(null===(o=t.tagName)||void 0===o?void 0:o.toLowerCase()),t=t.parentNode}return n.join(" > ")},e.prototype.getDivLevels=function(t,e){var r=this.getElementPath(t,!0,e).split(" > "),i=0;return r.forEach((function(t){"div"===t&&i++})),i},e.prototype.getTargetElement=function(t){var e;if(!it(t))return null;var r=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase();if(!f(r))return null;if(["body","html"].includes(r))return null;if(this.context.trackTags.includes(r)&&"div"!==r)return t;if("div"===r&&this.options.autoTrackConfig.collectTags.div&&(this.isDivLevelValid(t)&&(this.getDivMaxLevel()>1||this.isCollectableDiv(t))))return t;if(this.options.autoTrackConfig.collectTags.div&&this.isStyleTag(r)){var i=this.getCollectableParent(t);if(i&&this.isDivLevelValid(i))return i}return this.hasElement(t)||null},e.prototype.getClickElementInfo=function(t){var e=this.options.autoTrackConfig.isCollectInput,r=!1;l(e)&&(r=e(t));var i=this.getDomSelector(t),o=nt(t,r);return o.H_element_selector=i,o.H_element_path=this.getElementPath(t,!1),o},e.prototype.getDomSelector=function(t){for(var e,r=[];t;){if("body"===(null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase())||!it(t)){r.unshift("body");break}if(r.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 r.join(" > ")},e.prototype.getSelector=function(t){var e,r,i=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),o=-1;9!==(null===(r=t.parentNode)||void 0===r?void 0:r.nodeType)&&(o=this.getDomIndex(t));var n=t.getAttribute("id");return n&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(n)?"#".concat(n):i+(o>-1?":nth-of-type(".concat(o+1,")"):"")},e.prototype.getDomIndex=function(t){var e,r;if(t.parentNode)for(var i=0,o=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),n=t.parentNode.children,a=0;a<n.length;a++){var s=n[a];if((null===(r=s.tagName)||void 0===r?void 0:r.toLowerCase())===o){if(s===t)return i;i++}}return-1},e.prototype.getClosestLi=function(t){for(;t&&t!==document&&it(t);){if("li"===t.tagName.toLowerCase())return t;t=t.parentNode}return null},e.prototype.getSameTypeSiblings=function(t){for(var e,r,i=t.parentNode,o=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),n=[],a=0;a<i.children.length;a++){var s=i.children[a];it(s)&&(null===(r=s.tagName)||void 0===r?void 0:r.toLowerCase())===o&&n.push(s)}return n},e.prototype.getElementPosition=function(t,e){var r,i=this.getClosestLi(t);if(!i||!it(t)||!f(t.tagName))return null;var o=null===(r=t.tagName)||void 0===r?void 0:r.toLowerCase(),n=i.getElementsByTagName(o),a=n.length;if(a>1){for(var s=[],l=0;l<a;l++){this.getElementPath(n[l],!1)===e&&s.push(n[l])}if(s.length>0)return s.findIndex((function(e){return e===t}))}if(!i.parentNode)return-1;var u=this.getSameTypeSiblings(i);return 1===u.length?0:u.findIndex((function(t){return t===i}))},e}(i),ut=function(t){function e(e,r){var i=t.call(this,e,r)||this;return i.options=e,i.context=r,i.name="StayTrackPlugin",i.isReady=!1,i.timer=null,i.previousTime=d(),i.previousOffsetTop=0,i}return tt(e,t),e.prototype.init=function(t){var e=this,i=this.options,o=i.autoTrackConfig,a=i.stayAutoTrackConfig;if(!0===o.stayAutoTrack)if(this.isReady)this.context.log("StayTrack plugin:插件已经运行,无需重复执行",r.WARN);else{this.isReady=!0;var s=a.isCollectUrl;l(s)||(s=function(){return!0}),this.timer&&(clearTimeout(this.timer),this.timer=null),this.previousTime=d(),window.addEventListener("load",(function(){e.previousOffsetTop=n()})),window.addEventListener("scroll",(function(){s()&&(e.timer||(e.timer=setTimeout((function(){e.run(t),clearTimeout(e.timer),e.timer=null}),1e3)))})),window.addEventListener("unload",(function(){s()&&e.run(t,!0)}))}},e.prototype.transform=function(t){return this.context.getReportData("track","H_WebStay",t)},e.prototype.run=function(t,e){void 0===e&&(e=!1);var r=this.options.autoTrackConfig,i=r.stayDelayTime,o=r.maxStayPageDuration,a=n(),s=d(),l=s-this.previousTime;(e||l>i&&a!==this.previousOffsetTop)&&t({H_viewport_width:g(),H_viewport_height:v(),H_viewport_position:this.previousOffsetTop,event_duration:Math.min(l/1e3,o),H_url_path:window.location.pathname});this.previousTime=s,this.previousOffsetTop=a},e}(i),ct=function(t){function e(e,r){var i=t.call(this,e,r)||this;return i.options=e,i.context=r,i.name="PageLeave",i.isReady=!1,i.pageId=m(),i.storageName="hinasdk_pageleave_",i.heartbeatIntervalTime=5e3,i.maxDuration=432e3,i.heartbeatIntervalTimer=null,i.startTime=d(),i.url=window.location.href,i.pageShowStatus=!0,i}return tt(e,t),e.prototype.init=function(){if(this.options.autoTrackConfig.pageLeaveAutoTrack)if(this.context.store.localStorage)if(this.isReady)this.context.log("PageLeave plugin:插件已经运行,无需重复执行",r.WARN);else{this.isReady=!0;var t=this.normalizePageLeaveAutoTrack(),e=t.heartbeat_interval_time,i=t.max_duration;e&&e>0&&(this.heartbeatIntervalTime=1e3*e),i&&i>0&&(this.maxDuration=Number(i)),this.startTime=d(),this.addPageLeaveEventListener(),document.hidden?this.pageShowStatus=!1:this.startHeartBeatInterval()}else this.context.log("PageLeave plugin需要使用localstorage存储数据,但是您的浏览器不支持localstorage,所以不能使用该功能",r.WARN)},e.prototype.transform=function(){},e.prototype.normalizePageLeaveAutoTrack=function(){var t=this.options.autoTrackConfig.pageLeaveAutoTrack;return c(t)?t:{}},e.prototype.addPageLeaveEventListener=function(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()},e.prototype.addPageStartListener=function(){var t=this;"onpageshow"in window&&window.addEventListener("pageshow",(function(){t.pageStartHandler()}))},e.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()}})},e.prototype.addSinglePageListener=function(){var t=this;_.on("urlChange",(function(e){var r=e.fromHref;r!==e.toHref&&(t.url=r,t.pageEndHandler(),t.stopHeartBeatInterval(),t.pageStartHandler(),t.startHeartBeatInterval())}))},e.prototype.addPageEndListener=function(){var t=this,e=["pagehide","beforeunload","unload"];e.forEach((function(r){"on".concat(e)in window&&window.addEventListener(r,(function(){t.pageEndHandler(),t.stopHeartBeatInterval()}))}))},e.prototype.pageStartHandler=function(){this.startTime=d(),this.pageShowStatus=!document.hidden,this.url=window.location.href},e.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()}},e.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()},e.prototype.reissueHeartBeatData=function(){for(var t=this.context.store.localStorage,e=t.length(),r=0;r<e;r++){var i=t.key(r);if(i&&i!==this.storageName+this.pageId&&i.includes(this.storageName)){var o=t.get(i),n=w(o);c(n)&&d()-n.time>n.heartbeat_interval_time+5e3&&(delete n.heartbeat_interval_time,this.context.report(n)),this.delHeartBeatData(i)}}},e.prototype.stopHeartBeatInterval=function(){this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)},e.prototype.delHeartBeatData=function(t){this.context.store.localStorage.remove(t||this.storageName+this.pageId)},e.prototype.isCollectUrl=function(){var t=this.normalizePageLeaveAutoTrack().isCollectUrl;return!l(t)||t(this.url)},e.prototype.saveHeartBeatData=function(t){var e=this.getPageLeaveProperties();e.H_time=d(),"first_heartbeat"===t&&(e.event_duration=3);var r=this.context.getReportData("track","H_WebPageLeave",e);r.heartbeat_interval_time=this.heartbeatIntervalTime,this.context.store.localStorage.set(this.storageName+this.pageId,JSON.stringify(r))},e.prototype.getPageLeaveProperties=function(){var t=(d()-this.startTime)/1e3;t=t<=0||t>this.maxDuration?0:a(t,3);var e=k(this.url),r=e.pathname,i=e.hash,o=T(),s={H_url:this.url,H_url_path:r,H_url_hash:i,H_viewport_position:n(),H_referrer:o,H_referrer_host:o?H(o):"",event_duration:t},l=this.normalizePageLeaveAutoTrack().custom_props;return c(l)&&(s=et(et({},s),l||{})),s},e}(i),ht=function(t){function e(e,r){var i=t.call(this,e,r)||this;return i.options=e,i.context=r,i.name="SiteLinker",i.isReady=!1,i.linker=[],i}return tt(e,t),e.prototype.init=function(){if(this.options.siteLinkerConfig){var t=this.getLinkerConfig().linker;p(t)&&t.length>0?this.isReady?this.context.log("SiteLinker plugin:插件已经运行,无需重复执行",r.WARN):(this.isReady=!0,this.resolveOption(),this.setRefferId(),this.addClickListen()):this.context.log("siteLinker plugin: 请配置正确的linker参数",r.WARN)}},e.prototype.transform=function(){},e.prototype.getLinkerConfig=function(){var t=this.options.siteLinkerConfig||{},e=t.linker;return{linker:(void 0===e?[]:e)||[],re_login:t.re_login}},e.prototype.resolveOption=function(){for(var t=this.getLinkerConfig().linker,e=t.length,i=[],o=0;o<e;o++){var n=t[o],a=n.part_url,s=n.after_hash;/[A-Za-z0-9]+\./.test(a)&&b(s)?i.push({part_url:a,after_hash:s}):this.context.log("The configuration of linker ".concat(o+1," is not supported.Please check format"),r.WARN)}this.linker=i},e.prototype.setRefferId=function(){var t=this.getLinkerConfig().re_login,e=this.getUrlId(),r=e.startsWith("a");if(""!==(e=e.substring(1))){var i=this.context.store.getAnonymousId(),o=this.context.store.getAccountId();if(r){if(e!==i&&(this.context.store.state.anonymousId=e,this.context.store.save()),o){var n=this.context.getReportData("track_signup","H_SignUp",{});this.context.report(n)}}else(!o||t&&o!==e)&&this.context.setUserUId(e)}},e.prototype.getUrlId=function(){var t=window.location.href.match(/_hnsdk=([au][^\?\#\&\=]+)/);return p(t)&&t[1]?C(t[1]):""},e.prototype.getPartUrl=function(t){for(var e=this.linker.length,r=0;r<e;r++)if(t.includes(this.linker[r].part_url))return!0;return!1},e.prototype.getPartHash=function(t){for(var e=this.linker.length,r=0;r<e;r++)if(t.includes(this.linker[r].part_url))return this.linker[r].after_hash;return!1},e.prototype.getCurrentId=function(){var t=this.context.store.getAccountId(),e=this.context.store.getAnonymousId(),r=t?"u".concat(t):"a".concat(e);return L(r)},e.prototype.rewriteUrl=function(t,e){var r=this.getCurrentId(),i=this.getPartHash(t),o=P(t,r,i);return e&&(e.href=o),o},e.prototype.addClickListen=function(){var t=this,e=function(e){var r,i,o=e.target;if(o){var n=null===(r=o.tagName)||void 0===r?void 0:r.toLowerCase(),a=o.parentNode,s=null===(i=null==a?void 0:a.tagName)||void 0===i?void 0:i.toLowerCase();if("a"===n&&o.href||"a"===s&&a.href){var l=void 0,u=void 0;"a"===n&&o.href?(l=o.href,u=o):(l=a.href,u=a);var c=k(l).protocol;"http:"!==c&&"https:"!==c||t.getPartUrl(l)&&t.rewriteUrl(l,u)}}};"PointerEvent"in window?document.addEventListener("pointerdown",e):document.addEventListener("mousedown",e)},e}(i),pt=function(t){function e(e,r){var i=t.call(this,e,r)||this;return i.options=e,i.context=r,i.name="HistoryPlugin",i.isReady=!1,i.lastHref=window.location.href,i.lastPath=window.location.pathname,i}return tt(e,t),e.prototype.init=function(){if(S())if(this.isReady)this.context.log("History plugin:插件已经运行,无需重复执行",r.WARN);else{this.isReady=!0;var t=this,e=window.onpopstate,i=function(e,r){var i={fromPath:t.lastPath,fromHref:t.lastHref,toPath:e,toHref:r};t.lastPath=e,t.lastHref=r,_.emit("urlChange",et(et({},i),{mode:"history"}))};window.onpopstate=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var o=window.location.pathname,n=window.location.href;i(o,n),e&&e.apply(this,t)},x(window.history,"pushState",o),x(window.history,"replaceState",o)}function o(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];t.apply(this,e);var o=window.location.pathname,n=window.location.href;i(o,n)}}},e.prototype.transform=function(){},e}(i),ft=function(t){function e(e,r){var i=t.call(this,e,r)||this;return i.options=e,i.context=r,i.name="HashPlugin",i.isReady=!1,i.lastHref=window.location.href,i.lastPath=window.location.hash,i}return tt(e,t),e.prototype.init=function(){var t=this;this.isReady?this.context.log("Hash plugin:插件已经运行,无需重复执行",r.WARN):(this.isReady=!0,window.addEventListener("hashchange",(function(e){var r=e.newURL,i=k(r).hash,o={fromPath:t.lastPath,fromHref:t.lastHref,toPath:i,toHref:r};t.lastHref=r,t.lastPath=i,_.emit("urlChange",et(et({},o),{mode:"hash"}))})))},e.prototype.transform=function(){},e}(i),dt="4.0.4",gt=function(t){function e(e,r){var i=this,o=A();return(i=t.call(this,e,r,o,"hina_webjs_sdk_abtest",dt)||this).options=e,i.context=r,i.name="HinaABTest",i}return tt(e,t),e.prototype.getResultFromServer=function(t){var e=this;return new Promise((function(r,i){var o=e.createRequestData(t);new R({url:e.options.abTestingPluginConfig.url,data:JSON.stringify(o),contentType:"application/json",customHeaders:{"project-key":e.projectKey},timeout:t.timeoutMilliseconds}).run().then((function(t){var o=t.data;"SUCCESS"===(null==o?void 0:o.status)?e.saveResponseData(o.results).then((function(){r(o)})):i()}))}))},e}(N),vt=function(){function t(){}return t.getSourceFromReferrer=function(){var t=function(t,e){for(var r=0;r<t.length;r++)if(-1!==e.split("?")[0].indexOf(t[r]))return!0},e="(".concat(E.join("|"),")\\=[^&]+"),r=document.referrer||"",i=window.location.href;if(i){var o=i.match(new RegExp(e));return o&&o[0]?"付费广告流量":t(B,r)?"自然搜索流量":t(j,r)?"社交网站流量":""===r?"直接流量":"引荐流量"}return"获取url异常"},t.getReferSearchEngine=function(t){var e,r,i=H(t);if(!i||"hostname解析异常"===i)return"";var o={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 n in o){var a=o[n];try{for(var s=(e=void 0,rt(a)),l=s.next();!l.done;l=s.next()){if(l.value.test(i))return n}}catch(t){e={error:t}}finally{try{l&&!l.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}}return"未知搜索引擎"},t.getKeywordFromReferrer=function(){var t=document.referrer||"";if(0===t.indexOf("http")){var e=this.getReferSearchEngine(t),r=D(k(t).search);if(O(r))return"未取到值";for(var i in U){var o=U[i];if(i===e)if(p(o))for(var n=0;n<o.length;n++){var a=r[o[n]];if(a)return a}else if(r[o])return r[o]}return"未取到值"}return""===t?"未取到值_直接打开":"未取到值_非http的url"},t}();function mt(t){void 0===t&&(t="");var e,r=(e={},E.forEach((function(t){var r=I(window.location.href,t);r.length&&(e[t]=r)})),e),i={};return Object.keys(r).forEach((function(e){i[t+e]=r[e]})),i}var yt=function(t){function i(e,r){void 0===r&&(r=!0);var i=t.call(this,e,r)||this;return i.trackTags=st,i.customProperties={},i.generalProperties={H_lib_version:dt,H_lib:"js",H_lib_method:"code",H_timezone_offset:(new Date).getTimezoneOffset()},i.useInstancing&&i.init(e),i}return tt(i,t),i.prototype.init=function(t){if(this.isReady)this.log("hinaSDK has been initialized",r.ERROR);else{var i={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:e.BEACON,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,n=t.plugins,a=function(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(r[i[o]]=t[i[o]])}return r}(t,["performanceErrorConfig","plugins"]);this.options=h(i,a),this.options=et(et({},this.options),{performanceErrorConfig:o,plugins:n}),this.initState(),this.initAdvProps(),this.normalizeConfig(),this.initPlugins(),this.isReady=!0}},i.prototype.normalizeConfig=function(){var t=this,i=this.options,o=i.serverUrl,n=i.sendType,a=i.batchSend,s=i.maxStringLength,h=i.isSinglePage,d=i.autoTrackConfig,g=void 0===d?{}:d,v=g.trackAttr,m=void 0===v?[]:v,y=g.collectTags,w=g.pageLeaveAutoTrack,T=g.pageviewAutoTrack;if(""===(o=(o=o||"").trim()))this.log("当前 serverUrl 为空,network 中不会发数据,请配置正确的 serverUrl!",r.WARN);else{var H=window.location.href,b=k(H).protocol||"";(k(o).protocol||"")!==b&&this.log("SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。",r.WARN)}if([e.IMAGE,e.AJAX,e.BEACON].includes(n)||this.setConfig({sendType:e.AJAX}),this.options.maxStringLength=W(s),(!0===w||c(w)&&O(w))&&(this.options.autoTrackConfig.pageLeaveAutoTrack={heartbeat_interval_time:5e3,max_duration:432e3}),p(m)?(m=m.filter((function(t){return f(t)}))).includes("hn-click")||m.push("hn-click"):m=["hn-click"],this.options.autoTrackConfig.trackAttr=m,c(y))if(!0===y.div)this.options.autoTrackConfig.collectTags.div={ignoreTags:at,maxLevel:1};else if(c(y.div)){var C=1,L=y.div;u(L.maxLevel)&&[1,2,3].includes(L.maxLevel)&&(C=L.maxLevel),this.options.autoTrackConfig.collectTags.div={ignoreTags:at,maxLevel:C}}else this.options.autoTrackConfig.collectTags.div=!1;else this.options.autoTrackConfig.collectTags={div:!1};this.updateTrackTags(),(!0===a||c(a)&&!O(a))&&(this.options.batchSend=et({dataSendTimeout:6e3,sendInterval:6e3,storageLimit:200},a),this.batchSender=new z(this.options,"hinasdk_tab","hinasdk_data_")),"auto"===T?this.autoTrack():("singlePage"===T||h)&&(this.autoTrack(),_.on("urlChange",(function(e){var r=e.fromHref;if(r!==e.toHref){var i={};if(l(h)){var o=h();c(o)&&(i=et(et({},i),o))}t.autoTrack(et(et({},i),{H_referrer:r}))}})))},i.prototype.updateTrackTags=function(){var t=this.options.autoTrackConfig.collectTags,e=function(t,e,r){if(r||2===arguments.length)for(var i,o=0,n=e.length;o<n;o++)!i&&o in e||(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return t.concat(i||Array.prototype.slice.call(e))}([],function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var i,o,n=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(t){o={error:t}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a}(st),!1);Object.keys(t||{}).forEach((function(r){var i=t[r];!0!==i&&!c(i)||e.includes(r)||e.push(r)})),this.trackTags=e},i.prototype.initState=function(){this.store=new F(this.options),this.store.init()},i.prototype.initAdvProps=function(){var t={},e=this.options,r=e.presetProperties,i=e.sourceChannel;if(c(r))for(var o in r){var n=r[o];if(o.includes("latest_")&&(o=o.slice(7),n)){var a=$();if("utm"!==o&&"url解析失败"===a)t["H_latest_".concat(o)]="url的domain解析失败";else if(M())switch(o){case"traffic_source_type":t.H_latest_traffic_source_type=vt.getSourceFromReferrer();break;case"search_keyword":var s=vt.getKeywordFromReferrer();s&&(t.H_latest_search_keyword=s);break;case"referrer":t.H_latest_referrer=T()}}}var l=this.store.state.props||{},u={};r.latest_utm&&(u=mt("H_latest_"));var h={};l.H_utm_source||(h=mt("H_"));var f=[],d={};p(i)&&i.length>0&&(f=i.filter((function(t){return!E.includes(t)}))).length>0&&(d=et(et({},d),function(t,e){void 0===e&&(e=[]);var r={};return e.forEach((function(e){var i=I(window.location.href,e);i&&(r[e]=i,r["".concat(t).concat(e)]=i)})),r}("H_latest_",f))),this.store.state.props=et(et(et(et(et({},this.store.state.props),t),u),d),h),this.store.setProps(this.store.state.props),this.store.getUtmFromProps(f)},i.prototype.getGeneralProperties=function(){var t=new J;return this.generalProperties=et(et(et({},this.generalProperties),{H_screen_width:window.screen.width,H_screen_height:window.screen.height,H_viewport_width:g(),H_viewport_height:v(),H_page_height:K(),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:H(window.location.href,"url_host取值异常"),H_title:document.title}),this.store.hLatestUtm),this.generalProperties.H_latest_referrer&&(this.generalProperties.H_latest_referrer_host=H(this.generalProperties.H_latest_referrer,"hostname解析异常")),this.generalProperties},i.prototype.initPlugins=function(){var t=this,e=this.options,r=e.serverUrl,i=e.name,o=e.showLog,n=e.sendType,a=e.customHeaders,s=e.credentials,l=e.dataSendTimeout,u=e.batchSend,h=e.imgUseCrossOrigin,f=e.globalCallback,d=e.plugins,g=void 0===d?[]:d,v=e.performanceErrorConfig,m=e.autoTrackConfig,y=e.siteLinkerConfig,_=e.abTestingPluginConfig;g=g||[];var w=m.pageLeaveAutoTrack,k=new lt(this.options,this),T=new ut(this.options,this),H=new pt(this.options,this),b=new ft(this.options,this),C=new ct(this.options,this),L=new ht(this.options,this),P=new gt(this.options,this);C.disabled=!(c(w)&&!O(w));var S=(y||{}).linker;L.disabled=!(p(S)&&S.length>0),P.disabled=!(c(_)&&!O(_)),this.plugins=[k,T,H,b,C,L,P],p(g)&&g.forEach((function(e){if("Monitor"===e.componentName){if(c(v)&&!O(v))new e(et({serverUrl:r,name:i,showLog:o,sendType:n,customHeaders:a,credentials:s,dataSendTimeout:l,batchSend:u,imgUseCrossOrigin:h,globalCallback:f},v),!0)}else{var p=new e(t.options,t);t.plugins.push(p)}})),this.runPlugins(this.plugins)},i.prototype.use=function(t,e){if(this.isReady){if(c(e)){"PageLeave"===t?this.options.autoTrackConfig.pageLeaveAutoTrack=e:"SiteLinker"===t?this.options.siteLinkerConfig=e:"HinaABTest"===t&&(this.options.abTestingPluginConfig=e);var i=this.plugins.find((function(e){return e.name===t}));return i&&(i.disabled=!1,i.isReady?this.log("".concat(t,"插件已运行,无需重复执行"),r.WARN):i.init()),this.getPluginInstance(t)}this.log("".concat(t,"插件配置项必须是一个对象类型"),r.WARN)}else this.log("请先初始化埋点SDK",r.WARN)},i.prototype.getPluginInstance=function(t){return this.plugins.find((function(e){return e.name===t}))},i.prototype.setConfig=function(t){this.options=h(this.options,t),this.normalizeConfig()},i.prototype.getConfig=function(t){return t?this.options[t]:this.options},i.prototype.setUserUId=function(t,e){var r=this,i=this.store.getAccountId();Z(t,i,(function(t){r.store.setAccountId(t);var i=r.getReportData("track_signup","H_SignUp",{});r.report(i,e)}))},i.prototype.cleanUserUId=function(){this.store.setAccountId("")},i.prototype.getUserUid=function(){return this.store.state.accountId},i.prototype.setDeviceUId=function(t){this.store.setDeviceId(t)},i.prototype.getDeviceUId=function(){return this.store.getDeviceId()},i.prototype.userSet=function(t,e){if(c(t)&&!O(t)){var r=this.getReportData("user_set","",t);this.report(r,e)}},i.prototype.userSetOnce=function(t,e){if(c(t)&&!O(t)){var r=this.getReportData("user_setOnce","",t);this.report(r,e)}},i.prototype.userAdd=function(t,e){var r=this;V(t,(function(t){var i=r.getReportData("user_add","",t);r.report(i,e)}))},i.prototype.userAppend=function(t,e){var r=this;X(t,(function(t){var i=r.getReportData("user_append","",t);r.report(i,e)}))},i.prototype.userUnset=function(t,e){var r=this;G(t,(function(t){var i=r.getReportData("user_unset","",t);r.report(i,e)}))},i.prototype.userDelete=function(t){var e=this.getReportData("user_delete","",{});this.report(e,t),this.store.setAccountId("")},i.prototype.registerCommonProperties=function(t){this.customProperties=h(this.customProperties,t)},i.prototype.getPresetProperties=function(){return et(et({},this.getGeneralProperties()),this.customProperties)},i.prototype.clearPageRegister=function(t){var e=this;void 0===t&&(t=!0),!0===t?this.customProperties={}:p(t)&&t.forEach((function(t){t in e.customProperties&&delete e.customProperties[t]}))},i.prototype.track=function(t,e,i){if(i=i||function(){},f(t)){e=c(e)?e:{};var o=this.getReportData("track",t,e);this.report(o,i)}else this.log("track事件名必须是字符串,属性必须是是一个对象",r.WARN)},i.prototype.quick=function(t,e,r){if(!this.isReady)return this.log("请先初始化SDK");var i={};r=l(r)?r:Y,c(e)?i=e:l(e)&&(r=e),this.autoTrack(i,r)},i.prototype.autoTrack=function(t,e){void 0===t&&(t={}),void 0===e&&(e=Y);var r=(null==t?void 0:t.H_referrer)||T(),i=et(et(et({H_is_first_time:this.store.isFirstTime,H_url_path:window.location.pathname,H_referrer:r,H_referrer_host:r?H(r):""},this.store.hUtm),this.store.customUtm),t||{}),o=this.getReportData("track","H_pageview",i);if(this.report(o,e),this.store.isFirstTime){this.store.isFirstTime=!1;var n=T(),a=et(et({H_first_visit_time:d(),H_first_referrer:n,H_first_referrer_host:n?H(n,"取值异常"):"",H_first_traffic_source_type:vt.getSourceFromReferrer(),H_first_search_keyword:vt.getKeywordFromReferrer(),H_first_browser_language:f(navigator.language)?navigator.language.toLowerCase():"取值异常",H_first_browser_charset:document.characterSet||document.inputEncoding||"UTF-8"},this.store.hUtm),this.store.customUtm);this.userSetOnce(a)}},i.prototype.report=function(t,e,i){var o,n,a=this.options,s=a.appJsBridge,u=a.serverUrl;if(this.log(t),s){var h=!0,p=null===window||void 0===window?void 0:window.Hina_Cloud_H5_Bridge;if(c(p)&&p.track)h=!1,p.track(t.event,t.type,JSON.stringify(t));else{var f=null===(n=null===(o=null===window||void 0===window?void 0:window.webkit)||void 0===o?void 0:o.messageHandlers)||void 0===n?void 0:n.hinaNativeTracker;if(null==f?void 0:f.postMessage){h=!1;var d=JSON.stringify({eventName:t.event,eventType:t.type,properties:t});f.postMessage(d)}}if(h)return void this.log("JSBridge 发送数据失败",r.WARN);l(e)&&e(u,t)}else this.sendReportData(t,e,i)},i.prototype.getReportData=function(t,e,r){var i,o=this.store.getAnonymousId(),n=this.store.getAccountId(),a=d(),s=h(this.customProperties),l=this.getGeneralProperties();if("user"===t.slice(0,4)){var u=l.H_lib,c=l.H_lib_method,p=l.H_lib_version;i=et({device_id:this.store.getDeviceId(),H_lib:u,H_lib_method:c,H_lib_version:p},r||{})}else i=et(et(et({device_id:this.store.getDeviceId()},l),s),r||{});q(i,this.options.maxStringLength);var f={anonymous_id:o,type:t,event:e,time:a,_track_id:m(),properties:i};return n&&!/^[0-9a-f]{8,}-[0-9a-f]{4,}-[0-9a-f]{4,}-[0-9a-f]{4,}-[0-9a-f]{12,}$/.test(n)&&(f.account_id=n),f.send_time=d(),f},i}(t);var _t=new yt({},!1);export{yt as HinaTrack,_t as default};
1
+ import{WebClient}from"hina-cloud-js-core";import{ReportTypes,ConsoleTypes,PluginBase}from"hina-cloud-type";export*from"hina-cloud-type";import{isElement,isFunction,getPageXYInfo,getURL,isNumber,isObject,merge,isArray,isString,getElementProperties,nowStamp,getScrollTop,getScreenWidth,getScreenHeight,generatorTrackId,ListenPageState,mitt,safeJSONParse,formatDecimal,getReferrer,getHostname,isBoolean,handleDecodeURLComponent,handleEncodeURLComponent,rewriteUrl,supportHistory,replaceOld,getPlatform,AjaxRequest,AbtestBasePlugin,utmTypes,getQueryParam,getURLSearchParams,isEmptyObject,searchKeywords,searchTypes,socialTypes,normalizeMaxStringLength,BatchSend,WebState,getCurrentDomain,isReferralTraffic,Browser,getPageScrollHeight,setUserUId,userAdd,userAppend,userUnset,noop,checkReportProperties}from"hina-cloud-util";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 __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 __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"==typeof SuppressedError&&SuppressedError;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:插件已经运行,无需重复执行",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,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,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:插件已经运行,无需重复执行",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:插件已经运行,无需重复执行",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,所以不能使用该功能",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 value=localStorage.get(itemKey),result=safeJSONParse(value);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:插件已经运行,无需重复执行",ConsoleTypes.WARN):(this.isReady=!0,this.resolveOption(),this.setRefferId(),this.addClickListen()):this.context.log("siteLinker plugin: 请配置正确的linker参数",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"),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]?handleDecodeURLComponent(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(),hnId=accountId?"u".concat(accountId):"a".concat(anonymousId);return handleEncodeURLComponent(hnId)},SiteLinkerPlugin.prototype.rewriteUrl=function(url,dom){var sdkId=this.getCurrentId(),after_hash=this.getPartHash(url),normalizeUrl=rewriteUrl(url,sdkId,after_hash);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(supportHistory())if(this.isReady)this.context.log("History plugin:插件已经运行,无需重复执行",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:插件已经运行,无需重复执行",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 _this=this,platform=getPlatform();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=getURLSearchParams(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",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: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!",ConsoleTypes.WARN);else{var href=window.location.href,currentProtocol=getURL(href).protocol||"";(getURL(serverUrl).protocol||"")!==currentProtocol&&this.log("SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。",ConsoleTypes.WARN)}if([ReportTypes.IMAGE,ReportTypes.AJAX,ReportTypes.BEACON].includes(sendType)||this.setConfig({sendType:ReportTypes.AJAX}),this.options.maxStringLength=normalizeMaxStringLength(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=function(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(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}(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 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(isReferralTraffic())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:getPageScrollHeight(),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,"插件已运行,无需重复执行"),ConsoleTypes.WARN):instance.init()),this.getPluginInstance(pluginName)}this.log("".concat(pluginName,"插件配置项必须是一个对象类型"),ConsoleTypes.WARN)}else this.log("请先初始化埋点SDK",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,accountId=this.store.getAccountId();setUserUId(uid,accountId,(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;userAdd(data,(function(result){var props=_this.getReportData("user_add","",result);_this.report(props,callback)}))},HinaTrack.prototype.userAppend=function(data,callback){var _this=this;userAppend(data,(function(result){var props=_this.getReportData("user_append","",result);_this.report(props,callback)}))},HinaTrack.prototype.userUnset=function(data,callback){var _this=this;userUnset(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事件名必须是字符串,属性必须是是一个对象",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 发送数据失败",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);export{HinaTrack,hinaSdk as default};