hina-cloud-js-sdk 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/hina.cjs.js +1 -1
- package/dist/hina.esm.full.js +1 -1
- package/dist/hina.esm.js +1 -1
- package/dist/hina.full.js +1 -1
- package/dist/hina.iife.js +1 -1
- package/dist/index.d.ts +6 -6
- package/package.json +6 -6
package/dist/hina.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("hina-cloud-core"),e=require("hina-cloud-types"),i=require("hina-cloud-utils"),r=require("hina-cloud-monitor"),o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},o(t,e)};function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var s=function(){return s=Object.assign||function(t){for(var e,i=1,r=arguments.length;i<r;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},s.apply(this,arguments)};function a(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],r=0;if(i)return i.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 c(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var r,o,n=i.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=n.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(i=n.return)&&i.call(n)}finally{if(o)throw o.error}}return s}function l(t,e,i){if(i||2===arguments.length)for(var r,o=0,n=e.length;o<n;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var u=["mark","/mark","strong","b","em","i","u","abbr","ins","del","s","sup"],p=["a","input","button","textarea"],h=["abtestExperimentId","paramName","valueType","defaultValue","callback","timeoutMilliseconds","customProperties","customIds"],f=function(t){function r(e,i){var r=t.call(this,e,i)||this;return r.options=e,r.context=i,r.name="ClickTrackPlugin",r.isReady=!1,r.isTrackList={a:!0,button:!0},r}return n(r,t),r.prototype.init=function(t){var r=this,o=this.options.autoTrackConfig,n=o.clickAutoTrack,s=o.isCollectUrl,a=o.isCollectElement,c=o.addCustomProperty;!0===n&&(this.isReady?this.context.log("ClickTrack plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN):(this.isReady=!0,document.addEventListener("click",(function(e){if(s()){var o=e||window.event;if(o){var n=o.target||o.srcElement,l=r.getTargetElement(n);if(l){if(i.isFunction(a)&&!a(l))return!1;var u=r.getClickElementInfo(l),p=i.getPageXYInfo(o,l),h=p.H_page_x,f=p.H_page_y;if(u.H_page_x=h,u.H_page_y=f,i.isFunction(c)){var g=c(l);i.isObject(g)&&(u=i.merge(u,g))}t(u)}}}}),!0)))},r.prototype.transform=function(t){return this.context.getReportData("track","H_WebClick",t)},r.prototype.hasAttribute=function(t,e){var i;return t.hasAttribute?t.hasAttribute(e):t.attributes?!!(null===(i=t.attributes[e])||void 0===i?void 0:i.value):void 0},r.prototype.hasAttributes=function(t,e){if(i.isArray(e))for(var r=0;r<e.length;r++)if(this.hasAttribute(t,e[r]))return!0;return!1},r.prototype.hasElement=function(t){var e,r,o,n=i.getElementParents(t),s=this.options.autoTrackConfig.trackAttr||[];if(i.isArray(n)&&n.length>0)try{for(var c=a(n),l=c.next();!l.done;l=c.next()){var u=l.value,p=u.tagName&&(null===(o=u.tagName)||void 0===o?void 0:o.toLowerCase());if(i.isElement(u)&&(this.isTrackList[p]||this.hasAttributes(u,s)))return u}}catch(t){e={error:t}}finally{try{l&&!l.done&&(r=c.return)&&r.call(c)}finally{if(e)throw e.error}}},r.prototype.getDivMaxLevel=function(){var t;return(null===(t=this.options.autoTrackConfig.collectTags.div)||void 0===t?void 0:t.maxLevel)||1},r.prototype.isStyleTag=function(t){var e,i=(null===(e=this.options.autoTrackConfig.collectTags.div)||void 0===e?void 0:e.ignoreTags)||[];return null==i?void 0:i.includes(t)},r.prototype.getCollectableParent=function(t){var i;try{var r=t.parentNode,o=r?null===(i=r.tagName)||void 0===i?void 0:i.toLowerCase():"";if("body"===o)return!1;var n=this.getDivMaxLevel();if("div"===o&&(n>1||this.isCollectableDiv(r)))return r;if(r&&this.isStyleTag(o))return this.getCollectableParent(r)}catch(t){this.context.log(t,e.ConsoleTypes.ERROR)}return!1},r.prototype.isCollectableDiv=function(t){var r;try{var o=t.children||[];if(0===o.length)return!0;for(var n=0;n<o.length;n++){var s=o[n];if(i.isElement(s)){var a=null===(r=s.tagName)||void 0===r?void 0:r.toLowerCase(),c=this.getDivMaxLevel();if(!("div"===a&&c>1||this.isStyleTag(a)))return!1;if(!this.isCollectableDiv(s))return!1}}return!0}catch(t){this.context.log(t,e.ConsoleTypes.ERROR)}return!1},r.prototype.isDivLevelValid=function(t){for(var e=this.getDivMaxLevel(),i=t.getElementsByTagName("div"),r=i.length-1;r>=0;r--)if(this.getDivLevels(i[r],t)>e)return!1;return!0},r.prototype.getElementPath=function(t,e,r){for(var o,n,s=[];i.isElement(t)&&t.parentNode;){if(t.id&&!e&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.id)){var a=t.tagName||"";s.unshift("".concat(a.toLowerCase(),"#").concat(t.id));break}if(r&&t===r){s.unshift(null===(o=t.tagName)||void 0===o?void 0:o.toLowerCase());break}if(t===document.body){s.unshift("body");break}s.unshift(null===(n=t.tagName)||void 0===n?void 0:n.toLowerCase()),t=t.parentNode}return s.join(" > ")},r.prototype.getDivLevels=function(t,e){var i=this.getElementPath(t,!0,e).split(" > "),r=0;return i.forEach((function(t){"div"===t&&r++})),r},r.prototype.getTargetElement=function(t){var e;if(!i.isElement(t))return null;var r=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase();if(!i.isString(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 o=this.getCollectableParent(t);if(o&&this.isDivLevelValid(o))return o}return this.hasElement(t)||null},r.prototype.getClickElementInfo=function(t){var e=this.options.autoTrackConfig.isCollectInput,r=!1;i.isFunction(e)&&(r=e(t));var o=this.getDomSelector(t),n=i.getElementProperties(t,r);return n.H_element_selector=o,n.H_element_path=this.getElementPath(t,!1),n},r.prototype.getDomSelector=function(t){for(var e,r=[];t;){if("body"===(null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase())||!i.isElement(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(" > ")},r.prototype.getSelector=function(t){var e,i,r=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),o=-1;9!==(null===(i=t.parentNode)||void 0===i?void 0:i.nodeType)&&(o=this.getDomIndex(t));var n=t.getAttribute("id");return n&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(n)?"#".concat(n):r+(o>-1?":nth-of-type(".concat(o+1,")"):"")},r.prototype.getDomIndex=function(t){var e,i;if(t.parentNode)for(var r=0,o=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),n=t.parentNode.children,s=0;s<n.length;s++){var a=n[s];if((null===(i=a.tagName)||void 0===i?void 0:i.toLowerCase())===o){if(a===t)return r;r++}}return-1},r}(e.PluginBase),g=function(t){function r(e,r){var o=t.call(this,e,r)||this;return o.options=e,o.context=r,o.name="StayTrackPlugin",o.isReady=!1,o.timer=null,o.previousTime=i.nowStamp(),o.previousOffsetTop=0,o}return n(r,t),r.prototype.init=function(t){var r=this,o=this.options,n=o.autoTrackConfig,s=o.stayAutoTrackConfig;if(!0===n.stayAutoTrack)if(this.isReady)this.context.log("StayTrack plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN);else{this.isReady=!0;var a=s.isCollectUrl;i.isFunction(a)||(a=function(){return!0}),this.timer&&(clearTimeout(this.timer),this.timer=null),this.previousTime=i.nowStamp(),window.addEventListener("load",(function(){r.previousOffsetTop=i.getScrollTop()})),window.addEventListener("scroll",(function(){a()&&(r.timer||(r.timer=setTimeout((function(){r.run(t),clearTimeout(r.timer),r.timer=null}),1e3)))})),window.addEventListener("unload",(function(){a()&&r.run(t,!0)}))}},r.prototype.transform=function(t){return this.context.getReportData("track","H_WebStay",t)},r.prototype.run=function(t,e){void 0===e&&(e=!1);var r=this.options.autoTrackConfig,o=r.stayDelayTime,n=r.maxStayPageDuration,s=i.getScrollTop(),a=i.nowStamp(),c=a-this.previousTime;(e||c>o&&s!==this.previousOffsetTop)&&t({H_viewport_position:this.previousOffsetTop,event_duration:Math.min(c/1e3,n)});this.previousTime=a,this.previousOffsetTop=s},r}(e.PluginBase),d=function(t){function r(e,r){var o=t.call(this,e,r)||this;return o.options=e,o.context=r,o.name="PageLeave",o.isReady=!1,o.pageId=i.generatorTrackId(),o.storageName="hinasdk_pageleave_",o.heartbeatIntervalTime=5e3,o.maxDuration=432e3,o.heartbeatIntervalTimer=null,o.startTime=i.nowStamp(),o.url=window.location.href,o.pageShowStatus=!0,o}return n(r,t),r.prototype.init=function(){if(this.options.autoTrackConfig.pageLeaveAutoTrack)if(this.context.store.localStorage)if(this.isReady)this.context.log("PageLeave plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN);else{this.isReady=!0;var t=this.normalizePageLeaveAutoTrack(),r=t.heartbeat_interval_time,o=t.max_duration;r&&r>0&&(this.heartbeatIntervalTime=1e3*r),o&&o>0&&(this.maxDuration=Number(o)),this.startTime=i.nowStamp(),this.addPageLeaveEventListener(),document.hidden?this.pageShowStatus=!1:this.startHeartBeatInterval()}else this.context.log("PageLeave plugin需要使用localstorage存储数据,但是您的浏览器不支持localstorage,所以不能使用该功能",e.ConsoleTypes.WARN)},r.prototype.transform=function(){},r.prototype.normalizePageLeaveAutoTrack=function(){var t=this.options.autoTrackConfig.pageLeaveAutoTrack;return i.isObject(t)?t:{}},r.prototype.addPageLeaveEventListener=function(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()},r.prototype.addPageStartListener=function(){var t=this;"onpageshow"in window&&window.addEventListener("pageshow",(function(){t.pageStartHandler()}))},r.prototype.addPageSwitchListener=function(){var t=this;new i.ListenPageState({visible:function(){t.pageStartHandler(),t.startHeartBeatInterval()},hidden:function(){t.url=window.location.href,t.pageEndHandler(),t.stopHeartBeatInterval()}})},r.prototype.addSinglePageListener=function(){var t=this;i.mitt.on("urlChange",(function(e){var i=e.fromHref;i!==e.toHref&&(t.url=i,t.pageEndHandler(),t.stopHeartBeatInterval(),t.pageStartHandler(),t.startHeartBeatInterval())}))},r.prototype.addPageEndListener=function(){var t=this,e=["pagehide","beforeunload","unload"];e.forEach((function(i){"on".concat(e)in window&&window.addEventListener(i,(function(){t.pageEndHandler(),t.stopHeartBeatInterval()}))}))},r.prototype.pageStartHandler=function(){this.startTime=i.nowStamp(),this.pageShowStatus=!document.hidden,this.url=window.location.href},r.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()}},r.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()},r.prototype.reissueHeartBeatData=function(){for(var t=this.context.store.localStorage,e=t.length(),r=0;r<e;r++){var o=t.key(r);if(o&&o!==this.storageName+this.pageId&&o.includes(this.storageName)){var n=t.get(o),s=i.safeJSONParse(n);i.isObject(s)&&i.nowStamp()-s.time>s.heartbeat_interval_time+5e3&&(delete s.heartbeat_interval_time,this.context.report(s)),this.delHeartBeatData(o)}}},r.prototype.stopHeartBeatInterval=function(){this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)},r.prototype.delHeartBeatData=function(t){this.context.store.localStorage.remove(t||this.storageName+this.pageId)},r.prototype.isCollectUrl=function(){var t=this.normalizePageLeaveAutoTrack().isCollectUrl;return!i.isFunction(t)||t(this.url)},r.prototype.saveHeartBeatData=function(t){var e=this.getPageLeaveProperties();e.H_time=i.nowStamp(),"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))},r.prototype.getPageLeaveProperties=function(){var t=(i.nowStamp()-this.startTime)/1e3;t=t<=0||t>this.maxDuration?0:i.formatDecimal(t,3);var e=i.getURL(this.url),r=e.pathname,o=e.hash,n={H_url:this.url,H_url_path:r,H_url_hash:o};t&&(n.event_duration=t);var a=this.normalizePageLeaveAutoTrack().custom_props;return i.isObject(a)&&(n=s(s({},n),a||{})),n},r}(e.PluginBase),v=function(t){function r(e,i){var r=t.call(this,e,i)||this;return r.options=e,r.context=i,r.name="SiteLinker",r.isReady=!1,r.linker=[],r}return n(r,t),r.prototype.init=function(){if(this.options.siteLinkerConfig){var t=this.getLinkerConfig().linker;i.isArray(t)&&t.length>0?this.isReady?this.context.log("SiteLinker plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN):(this.isReady=!0,this.resolveOption(),this.setRefferId(),this.addClickListen()):this.context.log("siteLinker plugin: 请配置正确的linker参数",e.ConsoleTypes.WARN)}},r.prototype.transform=function(){},r.prototype.getLinkerConfig=function(){var t=this.options.siteLinkerConfig||{},e=t.linker;return{linker:(void 0===e?[]:e)||[],re_login:t.re_login}},r.prototype.resolveOption=function(){for(var t=this.getLinkerConfig().linker,r=t.length,o=[],n=0;n<r;n++){var s=t[n],a=s.part_url,c=s.after_hash;/[A-Za-z0-9]+\./.test(a)&&i.isBoolean(c)?o.push({part_url:a,after_hash:c}):this.context.log("The configuration of linker ".concat(n+1," is not supported.Please check format"),e.ConsoleTypes.WARN)}this.linker=o},r.prototype.setRefferId=function(){var t=this.getLinkerConfig().re_login,e=this.getUrlId(),i=e.startsWith("a");if(""!==(e=e.substring(1))){var r=this.context.store.getAnonymousId(),o=this.context.store.getAccountId();if(i){if(e!==r&&(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)}},r.prototype.getUrlId=function(){var t=window.location.href.match(/_hnsdk=([au][^\?\#\&\=]+)/);return i.isArray(t)&&t[1]?i.handleDecodeURLComponent(t[1]):""},r.prototype.getPartUrl=function(t){for(var e=this.linker.length,i=0;i<e;i++)if(t.includes(this.linker[i].part_url))return!0;return!1},r.prototype.getPartHash=function(t){for(var e=this.linker.length,i=0;i<e;i++)if(t.includes(this.linker[i].part_url))return this.linker[i].after_hash;return!1},r.prototype.getCurrentId=function(){var t=this.context.store.getAccountId(),e=this.context.store.getAnonymousId(),r=t?"u".concat(t):"a".concat(e);return i.handleEncodeURLComponent(r)},r.prototype.rewriteUrl=function(t,e){var i=/([^?#]+)(\?[^#]*)?(#.*)?/.exec(t),r="";if(i){var o=i[1]||"",n=i[2]||"",s=i[3]||"",a="_hnsdk=".concat(this.getCurrentId()),c=function(t){var e=t.split("&"),i=[];return e.forEach((function(t){t.includes("_hnsdk")?i.push(a):i.push(t)})),i.join("&")};if(this.getPartHash(t)){var l=s.includes("?"),u=s.indexOf("_hnsdk");r=l?u>=0?"".concat(o).concat(n,"#").concat(s.substring(1,u)).concat(c(s.substring(u,s.length))):"".concat(o).concat(n,"#").concat(s.substring(1),"&").concat(a):"".concat(o).concat(n,"#").concat(s.substring(1),"?").concat(a)}else{r=(l=/^\?(\w)+/.test(n))?n.includes("_hnsdk")?"".concat(o,"?").concat(c(n.substring(1))).concat(s):"".concat(o).concat(n,"&").concat(a).concat(s):"".concat(o,"?").concat(a).concat(s)}return e&&(e.href=r),r}},r.prototype.addClickListen=function(){var t=this,e=function(e){var r,o,n=e.target;if(n){var s=null===(r=n.tagName)||void 0===r?void 0:r.toLowerCase(),a=n.parentNode,c=null===(o=null==a?void 0:a.tagName)||void 0===o?void 0:o.toLowerCase();if("a"===s&&n.href||"a"===c&&a.href){var l=void 0,u=void 0;"a"===s&&n.href?(l=n.href,u=n):(l=a.href,u=a);var p=i.getURL(l).protocol;"http:"!==p&&"https:"!==p||t.getPartUrl(l)&&t.rewriteUrl(l,u)}}};"PointerEvent"in window?document.addEventListener("pointerdown",e):document.addEventListener("mousedown",e)},r}(e.PluginBase),y=function(t){function r(e,i){var r=t.call(this,e,i)||this;return r.options=e,r.context=i,r.name="HistoryPlugin",r.isReady=!1,r.lastHref=window.location.href,r.lastPath=window.location.pathname,r}return n(r,t),r.prototype.init=function(){if(i.supportHistory())if(this.isReady)this.context.log("History plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN);else{this.isReady=!0;var t=this,r=window.onpopstate,o=function(e,r){var o={fromPath:t.lastPath,fromHref:t.lastHref,toPath:e,toHref:r};t.lastPath=e,t.lastHref=r,i.mitt.emit("urlChange",s(s({},o),{mode:"history"}))};window.onpopstate=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var i=window.location.pathname,n=window.location.href;o(i,n),r&&r.apply(this,t)},i.replaceOld(window.history,"pushState",n),i.replaceOld(window.history,"replaceState",n)}function n(t){return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];t.apply(this,e);var r=window.location.pathname,n=window.location.href;o(r,n)}}},r.prototype.transform=function(){},r}(e.PluginBase),m=function(t){function r(e,i){var r=t.call(this,e,i)||this;return r.options=e,r.context=i,r.name="HashPlugin",r.isReady=!1,r.lastHref=window.location.href,r.lastPath=window.location.hash,r}return n(r,t),r.prototype.init=function(){var t=this;this.isReady?this.context.log("Hash plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN):(this.isReady=!0,window.addEventListener("hashchange",(function(e){var r=e.newURL,o=i.getURL(r).hash,n={fromPath:t.lastPath,fromHref:t.lastHref,toPath:o,toHref:r};t.lastHref=r,t.lastPath=o,i.mitt.emit("urlChange",s(s({},n),{mode:"hash"}))})))},r.prototype.transform=function(){},r}(e.PluginBase),T="4.0.0",b=function(t){function r(e,r){var o=t.call(this,e,r)||this;return o.options=e,o.context=r,o.name="HinaABTest",o.isReady=!1,o.platform=i.getPlatform(),o.projectKey="",o.storageName="hina_webjs_sdk_abtest",o}return n(r,t),r.prototype.init=function(){var t=this;if(this.context.store.localStorage){var r=this.options.abTestingPluginConfig,o=null==r?void 0:r.url;if(i.isString(o)){var n=i.getQueryParam(o,"project-key");if(n){this.projectKey=n;var s=i.getURL(o).protocol,a=i.getURL(window.location.href).protocol;if(s&&s!==a)this.context.log("A/B Testing 初始化失败,".concat(a," 页面必须使用 ").concat(a," 的 URL"),e.ConsoleTypes.WARN);else if(this.isReady)this.context.log("A/B Testing 插件已经运行,无需重复执行",e.ConsoleTypes.WARN);else{var c=this.context.getUserUid();this.context.log("当前accountId为:".concat(c),e.ConsoleTypes.INFO),i.mitt.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!",e.ConsoleTypes.WARN)}else this.context.log("A/B Testing 初始化失败,浏览器不支持localStorage",e.ConsoleTypes.WARN)},r.prototype.transform=function(){},r.prototype.valueMatchType=function(t,r){switch(r){case e.VariablesTypes.INTEGER:return i.isNumber(t);case e.VariablesTypes.STRING:return i.isString(t);case e.VariablesTypes.BOOLEAN:return i.isBoolean(t);default:return!1}},r.prototype.normalizeParams=function(t,r,o){var n,s;void 0===o&&(o=h);var c={verify_success:!0,para:r};try{for(var l=a(o),u=l.next();!u.done;u=l.next()){var p=u.value;if(!c.verify_success)break;var f=r.customIds||{},g={};switch(p){case"abtestExperimentId":i.isString(r.abtestExperimentId)&&r.abtestExperimentId.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(p,"参数未正确配置!").concat(p,": ").concat(r.abtestExperimentId),e.ConsoleTypes.WARN),c.verify_success=!1);break;case"paramName":i.isString(r.paramName)&&r.paramName.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(p,"参数未正确配置!").concat(p,": ").concat(r.paramName),e.ConsoleTypes.WARN),c.verify_success=!1);break;case"valueType":[e.VariablesTypes.BOOLEAN,e.VariablesTypes.INTEGER,e.VariablesTypes.STRING].includes(r.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(p,"参数未正确配置!").concat(p,": ").concat(r.valueType),e.ConsoleTypes.WARN),c.verify_success=!1);break;case"defaultValue":this.valueMatchType(r.defaultValue,r.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(p,"类型必须与valueType一致!"),e.ConsoleTypes.WARN),c.verify_success=!1);break;case"callback":i.isFunction(r.callback)||(this.context.log("".concat(t,"方法调用失败,").concat(p,"参数未正确配置")),r.callback=i.noop,c.verify_success=!1);break;case"timeoutMilliseconds":(!i.isNumber(r.timeoutMilliseconds)||r.timeoutMilliseconds<=0)&&(this.context.log("".concat(p,"参数错误:").concat(r.timeoutMilliseconds),e.ConsoleTypes.WARN),r.timeoutMilliseconds=3e3),r.timeoutMilliseconds<200&&(r.timeoutMilliseconds=200);break;case"customProperties":r.customProperties=i.isObject(r.customProperties)?r.customProperties:{};break;case"customIds":for(var d in f)(i.isString(f[d])||i.isNumber(f[d]))&&(g[d]=f[d]);r.customIds=g}}}catch(t){n={error:t}}finally{try{u&&!u.done&&(s=l.return)&&s.call(l)}finally{if(n)throw n.error}}return c},r.prototype.sendTriggerEvent=function(t){var e=t.abtest_experiment_group_id,i=t.abtest_experiment_id;this.context.track("H_ABTestTrigger",{H_abtest_experiment_id:i,H_abtest_experiment_group_id:e})},r.prototype.getExpResult=function(t,e){var r,o;void 0===e&&(e=[]);var n,s=t.abtestExperimentId,c=t.paramName,l=t.valueType;if(0===e.length){var u=this.getStorageData();i.isObject(u)&&(e=u.result||[])}try{for(var p=a(e),h=p.next();!h.done;h=p.next()){var f=h.value,g=f.abtest_experiment_id,d=f.abtest_experiment_group_id,v=f.is_white_list,y=f.variables;if(g===s){var m=y.find((function(t){return t.name===c&&t.type===l}));if(m){v||this.sendTriggerEvent({abtest_experiment_id:g,abtest_experiment_group_id:d}),n=m.value;break}}}}catch(t){r={error:t}}finally{try{h&&!h.done&&(o=p.return)&&o.call(p)}finally{if(r)throw r.error}}return n},r.prototype.getStorageData=function(){var t=this.context.store.localStorage.get(this.storageName);return i.isValid(t)?i.safeJSONParse(t):null},r.prototype.saveResponseData=function(t){var e=this.getStorageData(),r={updateTime:i.nowStamp()};if(e&&i.isObject(e)){var o=[],n=e.result||[];t.forEach((function(t){var e=t.abtest_experiment_group_id,i=t.abtest_experiment_id,r=t.variables,s=n.find((function(t){return t.abtest_experiment_id===i&&t.abtest_experiment_group_id===e}));if(s){var a=[];r.forEach((function(t){var e=t.name,i=t.type,r=s.variables.findIndex((function(t){return t.name===e&&t.type===i}));r>=0?s.variables[r]=t:a.push(t)})),s.variables=l(l([],c(s.variables),!1),c(a),!1)}else o.push(t)})),r.result=l(l([],c(n),!1),c(o),!1)}else r.result=t;this.context.store.localStorage.set(this.storageName,JSON.stringify(r))},r.prototype.createRequestData=function(t){var e=t.paramName,r=t.customProperties,o=t.customIds,n={anonymous_id:this.context.store.getAnonymousId(),platform:this.platform,abtest_lib_version:T,param_name:e,properties:this.context.getPresetProperties()};return i.isObject(r)&&!i.isEmptyObject(r)&&(n.custom_properties=r),i.isObject(o)&&!i.isEmptyObject(o)&&(n.custom_ids=o),this.context.getUserUid()&&(n.login_id=this.context.getUserUid()),n},r.prototype.getResultFromServer=function(t){var e=this;return new Promise((function(r,o){var n=e.createRequestData(t);new i.AjaxRequest({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 i=t.data;"SUCCESS"===(null==i?void 0:i.status)?(e.saveResponseData(i.results),r(i)):o()}))}))},r.prototype.asyncFetch=function(t){var e=this;return new Promise((function(i){e.getResultFromServer(t).then((function(t){i(t)})).catch((function(){t.callback(t.defaultValue)}))}))},r.prototype.preFetch=function(t,r){return this.isReady?!!i.isObject(r)||(this.context.log("".concat(t," 方法参数必须是对象"),e.ConsoleTypes.WARN),!1):(this.context.log("A/B Testing 插件尚未运行,请先执行该插件",e.ConsoleTypes.WARN),!1)},r.prototype.asyncFetchABTest=function(t){var e=this;if(this.preFetch("asyncFetchABTest",t)){var i=this.normalizeParams("asyncFetchABTest",t),r=i.verify_success,o=i.para;r?this.asyncFetch(o).then((function(t){var i=e.getExpResult(o,t.results);o.callback(i||o.defaultValue)})):o.callback(o.defaultValue)}},r.prototype.fetchCacheABTest=function(t){if(this.preFetch("fetchCacheABTest",t)){var e=this.normalizeParams("fetchCacheABTest",t),i=e.verify_success,r=e.para;if(i){var o=this.getExpResult(r);r.callback(o||r.defaultValue)}else r.callback(r.defaultValue)}},r.prototype.fastFetchABTest=function(t){var e=this;if(this.preFetch("fastFetchABTest",t)){var r=this.normalizeParams("fastFetchABTest",t),o=r.verify_success,n=r.para;if(o){var s=this.getExpResult(n);i.isValid(s)?n.callback(s):this.asyncFetch(n).then((function(){var t=e.getExpResult(n);n.callback(t||n.defaultValue)}))}else n.callback(n.defaultValue)}},r}(e.PluginBase),_=function(t){function o(e,i){void 0===i&&(i=!0);var r=t.call(this,e,i)||this;return r.consolePrefix="埋点SDK",r.trackTags=p,r.presetProps={},r.useInstancing&&r.init(e),r}return n(o,t),o.prototype.init=function(t){if(this.isReady)this.log("hinaSDK has been initialized",e.ConsoleTypes.ERROR);else{var r={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.ReportTypes.BEACON,customHeaders:{},credentials:!1,dataSendTimeout:3e3,presetProperties:{latest_utm:!0,latest_traffic_source_type:!0,latest_search_keyword:!0,latest_referrer:!0,url:!0,title:!0},sourceChannel:[],plugins:[]},o=t.performanceErrorConfig,n=function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(i[r[o]]=t[r[o]])}return i}(t,["performanceErrorConfig"]);this.options=i.merge(r,n),this.options=s(s({},this.options),{performanceErrorConfig:o}),this.initState(),this.normalizeConfig(),this.initAdvProps(),this.initPlugins(),this.isReady=!0}},o.prototype.initState=function(){this.store=new i.State(this.options),this.store.init()},o.prototype.normalizeConfig=function(){var t=this,r=this.options,o=r.serverUrl,n=r.sendType,a=r.batchSend,c=r.maxStringLength,l=r.isSinglePage,p=r.autoTrackConfig,h=void 0===p?{}:p,f=h.trackAttr,g=void 0===f?[]:f,d=h.collectTags,v=h.pageLeaveAutoTrack,y=h.pageviewAutoTrack;if(""===(o=(o=o||"").trim()))this.log("当前 serverUrl 为空,network 中不会发数据,请配置正确的 serverUrl!",e.ConsoleTypes.WARN);else{var m=window.location.href,T=i.getURL(m).protocol||"";(i.getURL(o).protocol||"")!==T&&this.log("SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。",e.ConsoleTypes.WARN)}[e.ReportTypes.IMAGE,e.ReportTypes.AJAX,e.ReportTypes.BEACON].includes(n)||this.setConfig({sendType:e.ReportTypes.AJAX});var b=c;if(!i.isNumber(c)||c<0?b=1024:c>5120&&(b=5120),this.options.maxStringLength=b,(!0===v||i.isObject(v)&&i.isEmptyObject(v))&&(this.options.autoTrackConfig.pageLeaveAutoTrack={heartbeat_interval_time:5e3,max_duration:432e3}),i.isArray(g)?(g=g.filter((function(t){return i.isString(t)}))).includes("hn-click")||g.push("hn-click"):g=["hn-click"],this.options.autoTrackConfig.trackAttr=g,i.isObject(d))if(!0===d.div)this.options.autoTrackConfig.collectTags.div={ignoreTags:u,maxLevel:1};else if(i.isObject(d.div)){var _=1,k=d.div;i.isNumber(k.maxLevel)&&[1,2,3].includes(k.maxLevel)&&(_=k.maxLevel),this.options.autoTrackConfig.collectTags.div={ignoreTags:u,maxLevel:_}}else this.options.autoTrackConfig.collectTags.div=!1;else this.options.autoTrackConfig.collectTags={div:!1};this.updateTrackTags(),(!0===a||i.isObject(a)&&!i.isEmptyObject(a))&&(this.options.batchSend=s({dataSendTimeout:6e3,sendInterval:6e3,storageLimit:200},a),this.batchSender=new i.BatchSend(this.options,e.PlatformTypes.WEB,"hinasdk_tab","hinasdk_data_")),"auto"===y?this.autoTrack():("singlePage"===y||l)&&(this.autoTrack(),i.mitt.on("urlChange",(function(e){var r=e.fromHref;if(r!==e.toHref){if(i.isFunction(l)){var o=l();i.isObject(o)&&(e=s(s({},e),o))}t.autoTrack(s(s({},e),{H_referrer:r}))}})))},o.prototype.updateTrackTags=function(){var t=this.options.autoTrackConfig.collectTags,e=l([],c(p),!1);Object.keys(t||{}).forEach((function(r){var o=t[r];!0!==o&&!i.isObject(o)||e.includes(r)||e.push(r)})),this.trackTags=e},o.prototype.initAdvProps=function(){var t={},e=this.options,r=e.presetProperties,o=e.sourceChannel;Object.keys(r||{}).forEach((function(e){var o=r[e];if(e.includes("latest_")&&(e=e.slice(7),o)){var n=i.getCurrentDomain();if("utm"!==e&&"url解析失败"===n)t["H_latest_".concat(e)]="url的domain解析失败";else if(i.isReferralTraffic())switch(e){case"traffic_source_type":t.H_latest_traffic_source_type=i.SearchKeyword.getSourceFromReferrer();break;case"search_keyword":var s=i.SearchKeyword.getKeywordFromReferrer();s&&(t.H_latest_search_keyword=s);break;case"referrer":t.H_latest_referrer=i.getReferrer()}}}));var n=this.store.state.props||{},a={};r.latest_utm&&(a=i.getUmtsParams("H_latest_"));var c={};n.H_utm_source||(c=i.getUmtsParams("H_"));var l={},u={};if(i.isArray(o)&&o.length>0){var p=o.filter((function(t){return!i.utmTypes.includes(t)}));p.length>0&&(n["H_".concat(p[0])]||(u=i.getCustomUmtsParams("H_",p)),l=i.getCustomUmtsParams("H_latest_",p))}this.store.state.props=s(s(s(s(s(s({},this.store.state.props),t),a),l),u),c),this.store.setProps(this.store.state.props)},o.prototype.initPlugins=function(){var t=this,e=this.options,o=e.serverUrl,n=e.name,a=e.showLog,c=e.sendType,l=e.customHeaders,u=e.credentials,p=e.dataSendTimeout,h=e.batchSend,T=e.imgUseCrossOrigin,_=e.globalCallback,k=e.plugins,w=void 0===k?[]:k,C=e.performanceErrorConfig,S=e.autoTrackConfig,P=e.siteLinkerConfig,A=e.abTestingPluginConfig;w=w||[];var x=S.pageLeaveAutoTrack,R=new f(this.options,this),L=new g(this.options,this),O=new y(this.options,this),E=new m(this.options,this);if(this.plugins=[R,L,O,E],i.isObject(x)&&!i.isEmptyObject(x)){var H=new d(this.options,this);this.plugins.push(H)}var N=(P||{}).linker;if(i.isArray(N)&&N.length>0){var I=new v(this.options,this);this.plugins.push(I)}if(i.isObject(A)&&!i.isEmptyObject(A)){var j=new b(this.options,this);this.plugins.push(j)}if(w.forEach((function(e){var i=new e(t.options,t);t.plugins.push(i)})),i.isObject(C)&&!i.isEmptyObject(C)){var D=s({serverUrl:o,name:n,showLog:a,sendType:c,customHeaders:l,credentials:u,dataSendTimeout:p,batchSend:h,imgUseCrossOrigin:T,globalCallback:_},C);this.epmInstance=new r.Monitor(D,!0)}this.runPlugins(this.plugins)},o.prototype.use=function(t,r){var o=this,n=this.options,s=n.autoTrackConfig,a=n.siteLinkerConfig,c=n.abTestingPluginConfig,l=s.pageLeaveAutoTrack,u=function(t){var e=new t(o.options,o);o.plugins.push(e),e.init()};if(this.isReady){if(i.isObject(r))return"PageLeave"===t?i.isObject(l)&&!i.isEmptyObject(l)?this.log("PageLeave插件已运行,无需重复执行",e.ConsoleTypes.WARN):(this.options.autoTrackConfig.pageLeaveAutoTrack=r,u(d)):"SiteLinker"===t?i.isObject(a)&&!i.isEmptyObject(a)?this.log("SiteLinker插件已插件已运行,无需重复执行",e.ConsoleTypes.WARN):(this.options.siteLinkerConfig=r,u(v)):"HinaABTest"===t&&(i.isObject(c)&&!i.isEmptyObject(c)?this.log("HinaABTest插件已运行,无需重复执行",e.ConsoleTypes.WARN):(this.options.abTestingPluginConfig=r,u(b))),this.getPluginInstance(t);this.log("".concat(t,"插件配置项必须是一个对象类型"),e.ConsoleTypes.WARN)}else this.log("请先初始化埋点SDK",e.ConsoleTypes.WARN)},o.prototype.getPluginInstance=function(t){return this.plugins.find((function(e){return e.name===t}))},o.prototype.setConfig=function(t){this.options=i.merge(this.options,t),this.normalizeConfig()},o.prototype.getConfig=function(t){return t?this.options[t]:this.options},o.prototype.setUserUId=function(t,r){if(t=null!=t?t:"",i.isNumber(t)||i.isString(t))if(t=String(t).trim(),this.store.getAccountId()!==t){this.store.setAccountId(t);var o=this.getReportData("track_signup","H_SignUp",{});this.report(o,r),i.mitt.emit("changeAccountId")}else this.log("setUserUId: uid is equal to account_id, , failed to execute setUserUId",e.ConsoleTypes.WARN);else this.log("setUserUId: uid must be string or number",e.ConsoleTypes.WARN)},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(i.isObject(t)&&!i.isEmptyObject(t)){var r=this.getReportData("user_set","",t);this.report(r,e)}},o.prototype.userSetOnce=function(t,e){if(i.isObject(t)&&!i.isEmptyObject(t)){var r=this.getReportData("user_setOnce","",t);this.report(r,e)}},o.prototype.userAdd=function(t,r){var o,n=this;i.isString(t)&&((o={})[t]=1,t=o);if(i.isObject(t)&&!i.isEmptyObject(t)&&function(t){for(var i in t)if(!/-*\d+/.test(String(t[i])))return n.log("userAdd属性的值只能是数字",e.ConsoleTypes.WARN),!1;return!0}(t)){var s=this.getReportData("user_add","",t);this.report(s,r)}},o.prototype.userAppend=function(t,e){var r={};if(i.isObject(t)&&(Object.keys(t).forEach((function(e){var o=t[e];i.isArray(o)?r[e]=o:r[e]=[o]})),!i.isEmptyObject(r))){var o=this.getReportData("user_append","",r);this.report(o,e)}},o.prototype.userUnset=function(t,r){var o=this,n={};if(i.isString(t)&&(t=[t]),i.isArray(t)){if(t.forEach((function(t){i.isString(t)?n[t]=!0:o.log("userUnset参数数组里面的值必须时string,已经过滤掉".concat(t),e.ConsoleTypes.WARN)})),!i.isEmptyObject(n)){var s=this.getReportData("user_unset","",n);this.report(s,r)}}else this.log("userUnset参数必须是数组或字符串",e.ConsoleTypes.WARN)},o.prototype.userDelete=function(t){var e=this.getReportData("user_delete","",{});this.report(e,t),this.store.setAccountId("")},o.prototype.registerCommonProperties=function(t){this.presetProps=i.merge(this.presetProps,t)},o.prototype.getPresetProperties=function(){return{H_is_first_day:this.store.isFirstDay,H_is_first_time:this.store.isFirstTime,device_id:this.store.getDeviceId(),anonymous_id:this.store.getAnonymousId(),account_id:this.store.getAccountId(),properties:s(s(s({},this.presetProps),i.getPageProperties()),i.getBrowserInfo(T))}},o.prototype.clearPageRegister=function(t){var e=this;void 0===t&&(t=!0),!0===t?this.presetProps={}:i.isArray(t)&&t.forEach((function(t){t in e.presetProps&&delete e.presetProps[t]}))},o.prototype.checkReportProperties=function(t){var e=this,r=this.options.maxStringLength;Object.keys(t).forEach((function(o){var n=t[o];if(i.isString(n)&&n.length>r)e.log("属性 ".concat(o," 已经做截取")),t[o]=n.slice(0,r);else if(i.isObject(n))e.checkReportProperties(n);else if(i.isFunction(n))try{t[o]=n(t),i.isFunction(t[o])?(e.log("属性--".concat(o," 格式不满足要求, 已被删除")),delete t[o]):i.isObject(t[o])?e.checkReportProperties(t[o]):i.isString(t[o])&&t[o].length>r&&(t[o]=t[o].slice(0,r))}catch(i){e.log("属性--".concat(o," 格式不满足要求, 已被删除")),delete t[o]}}))},o.prototype.track=function(t,r,o){if(o=o||function(){},i.isString(t)){r=i.isObject(r)?r:{};var n=this.getReportData("track",t,r);this.report(n,o)}else this.log("track事件名必须是字符串,属性必须是是一个对象",e.ConsoleTypes.WARN)},o.prototype.quick=function(t,e,r){var o={};r=i.isFunction(r)?r:i.noop,i.isObject(e)?o=e:i.isFunction(e)&&(r=e),this.autoTrack(o,r)},o.prototype.autoTrack=function(t,e){void 0===t&&(t={}),void 0===e&&(e=i.noop);var r=this.getReportData("track","H_pageview",t);if(this.report(r,e),this.store.isSetFirstVisit){this.store.isSetFirstVisit=!1;var o=i.getReferrer();this.userSetOnce({H_first_referrer:o,H_first_referrer_host:o?i.getHostname(o,"取值异常"):"",H_first_traffic_source_type:i.SearchKeyword.getSourceFromReferrer(),H_first_search_keyword:i.SearchKeyword.getKeywordFromReferrer(),H_first_visit_time:i.nowStamp(),H_first_browser_language:i.isString(navigator.language)?navigator.language.toLowerCase():"取值异常"})}},o.prototype.report=function(t,r,o){var n,s,a=this.options,c=a.appJsBridge,l=a.serverUrl;if(this.log(t),c){var u=!0,p=null===window||void 0===window?void 0:window.Hina_Cloud_H5_Bridge;if(i.isObject(p)&&p.track)u=!1,p.track(t.event,t.type,JSON.stringify(t));else{var h=null===(s=null===(n=null===window||void 0===window?void 0:window.webkit)||void 0===n?void 0:n.messageHandlers)||void 0===s?void 0:s.hinaNativeTracker;if(null==h?void 0:h.postMessage){u=!1;var f=JSON.stringify({eventName:t.event,eventType:t.type,properties:t});h.postMessage(f)}}if(u)return void this.log("JSBridge 发送数据失败",e.ConsoleTypes.WARN);i.isFunction(r)&&r(l,t)}else this.sendReportData(t,r,o)},o.prototype.getReportData=function(t,e,r){var o=this.store.getAnonymousId(),n=this.store.getAccountId(),a=i.nowStamp(),c=this.getReportProperties(t,e),l=s(s({},c),r||{});this.checkReportProperties(l);var u={anonymous_id:o,type:t,event:e,time:a,_track_id:i.generatorTrackId(),properties:l};return n&&(u.account_id=n),u.send_time=i.nowStamp(),u},o.prototype.getReportProperties=function(t,e){void 0===t&&(t=""),void 0===e&&(e="");var r=i.merge(this.presetProps),o=s(s({device_id:this.store.getDeviceId()},this.store.state.props),r);return t&&"user"===t.slice(0,4)||(o=s(s(s({},o),i.getPageProperties()),i.getBrowserInfo(T))),"track"===t&&(o.H_is_first_day=this.store.isFirstDay,this.store.isFirstDay=!1,"H_pageview"===e&&(o.H_is_first_time=this.store.isFirstTime,this.store.isFirstTime=!1)),o},o}(t.WebClient);var k=new _({},!1);exports.HinaTrack=_,exports.default=k,Object.keys(e).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})}));
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("hina-cloud-js-core"),e=require("hina-cloud-type"),i=require("hina-cloud-util"),r=require("hina-cloud-js-monitor"),o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},o(t,e)};function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var s=function(){return s=Object.assign||function(t){for(var e,i=1,r=arguments.length;i<r;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},s.apply(this,arguments)};function a(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],r=0;if(i)return i.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 c(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var r,o,n=i.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=n.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(i=n.return)&&i.call(n)}finally{if(o)throw o.error}}return s}function l(t,e,i){if(i||2===arguments.length)for(var r,o=0,n=e.length;o<n;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var u=["mark","/mark","strong","b","em","i","u","abbr","ins","del","s","sup"],p=["a","input","button","textarea"],h=["abtestExperimentId","paramName","valueType","defaultValue","callback","timeoutMilliseconds","customProperties","customIds"],f=function(t){function r(e,i){var r=t.call(this,e,i)||this;return r.options=e,r.context=i,r.name="ClickTrackPlugin",r.isReady=!1,r.isTrackList={a:!0,button:!0},r}return n(r,t),r.prototype.init=function(t){var r=this,o=this.options.autoTrackConfig,n=o.clickAutoTrack,s=o.isCollectUrl,a=o.isCollectElement,c=o.addCustomProperty;!0===n&&(this.isReady?this.context.log("ClickTrack plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN):(this.isReady=!0,document.addEventListener("click",(function(e){if(s()){var o=e||window.event;if(o){var n=o.target||o.srcElement,l=r.getTargetElement(n);if(l){if(i.isFunction(a)&&!a(l))return!1;var u=r.getClickElementInfo(l),p=i.getPageXYInfo(o,l),h=p.H_page_x,f=p.H_page_y;if(u.H_page_x=h,u.H_page_y=f,i.isFunction(c)){var g=c(l);i.isObject(g)&&(u=i.merge(u,g))}t(u)}}}}),!0)))},r.prototype.transform=function(t){return this.context.getReportData("track","H_WebClick",t)},r.prototype.hasAttribute=function(t,e){var i;return t.hasAttribute?t.hasAttribute(e):t.attributes?!!(null===(i=t.attributes[e])||void 0===i?void 0:i.value):void 0},r.prototype.hasAttributes=function(t,e){if(i.isArray(e))for(var r=0;r<e.length;r++)if(this.hasAttribute(t,e[r]))return!0;return!1},r.prototype.hasElement=function(t){var e,r,o,n=i.getElementParents(t),s=this.options.autoTrackConfig.trackAttr||[];if(i.isArray(n)&&n.length>0)try{for(var c=a(n),l=c.next();!l.done;l=c.next()){var u=l.value,p=u.tagName&&(null===(o=u.tagName)||void 0===o?void 0:o.toLowerCase());if(i.isElement(u)&&(this.isTrackList[p]||this.hasAttributes(u,s)))return u}}catch(t){e={error:t}}finally{try{l&&!l.done&&(r=c.return)&&r.call(c)}finally{if(e)throw e.error}}},r.prototype.getDivMaxLevel=function(){var t;return(null===(t=this.options.autoTrackConfig.collectTags.div)||void 0===t?void 0:t.maxLevel)||1},r.prototype.isStyleTag=function(t){var e,i=(null===(e=this.options.autoTrackConfig.collectTags.div)||void 0===e?void 0:e.ignoreTags)||[];return null==i?void 0:i.includes(t)},r.prototype.getCollectableParent=function(t){var i;try{var r=t.parentNode,o=r?null===(i=r.tagName)||void 0===i?void 0:i.toLowerCase():"";if("body"===o)return!1;var n=this.getDivMaxLevel();if("div"===o&&(n>1||this.isCollectableDiv(r)))return r;if(r&&this.isStyleTag(o))return this.getCollectableParent(r)}catch(t){this.context.log(t,e.ConsoleTypes.ERROR)}return!1},r.prototype.isCollectableDiv=function(t){var r;try{var o=t.children||[];if(0===o.length)return!0;for(var n=0;n<o.length;n++){var s=o[n];if(i.isElement(s)){var a=null===(r=s.tagName)||void 0===r?void 0:r.toLowerCase(),c=this.getDivMaxLevel();if(!("div"===a&&c>1||this.isStyleTag(a)))return!1;if(!this.isCollectableDiv(s))return!1}}return!0}catch(t){this.context.log(t,e.ConsoleTypes.ERROR)}return!1},r.prototype.isDivLevelValid=function(t){for(var e=this.getDivMaxLevel(),i=t.getElementsByTagName("div"),r=i.length-1;r>=0;r--)if(this.getDivLevels(i[r],t)>e)return!1;return!0},r.prototype.getElementPath=function(t,e,r){for(var o,n,s=[];i.isElement(t)&&t.parentNode;){if(t.id&&!e&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.id)){var a=t.tagName||"";s.unshift("".concat(a.toLowerCase(),"#").concat(t.id));break}if(r&&t===r){s.unshift(null===(o=t.tagName)||void 0===o?void 0:o.toLowerCase());break}if(t===document.body){s.unshift("body");break}s.unshift(null===(n=t.tagName)||void 0===n?void 0:n.toLowerCase()),t=t.parentNode}return s.join(" > ")},r.prototype.getDivLevels=function(t,e){var i=this.getElementPath(t,!0,e).split(" > "),r=0;return i.forEach((function(t){"div"===t&&r++})),r},r.prototype.getTargetElement=function(t){var e;if(!i.isElement(t))return null;var r=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase();if(!i.isString(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 o=this.getCollectableParent(t);if(o&&this.isDivLevelValid(o))return o}return this.hasElement(t)||null},r.prototype.getClickElementInfo=function(t){var e=this.options.autoTrackConfig.isCollectInput,r=!1;i.isFunction(e)&&(r=e(t));var o=this.getDomSelector(t),n=i.getElementProperties(t,r);return n.H_element_selector=o,n.H_element_path=this.getElementPath(t,!1),n},r.prototype.getDomSelector=function(t){for(var e,r=[];t;){if("body"===(null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase())||!i.isElement(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(" > ")},r.prototype.getSelector=function(t){var e,i,r=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),o=-1;9!==(null===(i=t.parentNode)||void 0===i?void 0:i.nodeType)&&(o=this.getDomIndex(t));var n=t.getAttribute("id");return n&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(n)?"#".concat(n):r+(o>-1?":nth-of-type(".concat(o+1,")"):"")},r.prototype.getDomIndex=function(t){var e,i;if(t.parentNode)for(var r=0,o=null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase(),n=t.parentNode.children,s=0;s<n.length;s++){var a=n[s];if((null===(i=a.tagName)||void 0===i?void 0:i.toLowerCase())===o){if(a===t)return r;r++}}return-1},r}(e.PluginBase),g=function(t){function r(e,r){var o=t.call(this,e,r)||this;return o.options=e,o.context=r,o.name="StayTrackPlugin",o.isReady=!1,o.timer=null,o.previousTime=i.nowStamp(),o.previousOffsetTop=0,o}return n(r,t),r.prototype.init=function(t){var r=this,o=this.options,n=o.autoTrackConfig,s=o.stayAutoTrackConfig;if(!0===n.stayAutoTrack)if(this.isReady)this.context.log("StayTrack plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN);else{this.isReady=!0;var a=s.isCollectUrl;i.isFunction(a)||(a=function(){return!0}),this.timer&&(clearTimeout(this.timer),this.timer=null),this.previousTime=i.nowStamp(),window.addEventListener("load",(function(){r.previousOffsetTop=i.getScrollTop()})),window.addEventListener("scroll",(function(){a()&&(r.timer||(r.timer=setTimeout((function(){r.run(t),clearTimeout(r.timer),r.timer=null}),1e3)))})),window.addEventListener("unload",(function(){a()&&r.run(t,!0)}))}},r.prototype.transform=function(t){return this.context.getReportData("track","H_WebStay",t)},r.prototype.run=function(t,e){void 0===e&&(e=!1);var r=this.options.autoTrackConfig,o=r.stayDelayTime,n=r.maxStayPageDuration,s=i.getScrollTop(),a=i.nowStamp(),c=a-this.previousTime;(e||c>o&&s!==this.previousOffsetTop)&&t({H_viewport_position:this.previousOffsetTop,event_duration:Math.min(c/1e3,n)});this.previousTime=a,this.previousOffsetTop=s},r}(e.PluginBase),d=function(t){function r(e,r){var o=t.call(this,e,r)||this;return o.options=e,o.context=r,o.name="PageLeave",o.isReady=!1,o.pageId=i.generatorTrackId(),o.storageName="hinasdk_pageleave_",o.heartbeatIntervalTime=5e3,o.maxDuration=432e3,o.heartbeatIntervalTimer=null,o.startTime=i.nowStamp(),o.url=window.location.href,o.pageShowStatus=!0,o}return n(r,t),r.prototype.init=function(){if(this.options.autoTrackConfig.pageLeaveAutoTrack)if(this.context.store.localStorage)if(this.isReady)this.context.log("PageLeave plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN);else{this.isReady=!0;var t=this.normalizePageLeaveAutoTrack(),r=t.heartbeat_interval_time,o=t.max_duration;r&&r>0&&(this.heartbeatIntervalTime=1e3*r),o&&o>0&&(this.maxDuration=Number(o)),this.startTime=i.nowStamp(),this.addPageLeaveEventListener(),document.hidden?this.pageShowStatus=!1:this.startHeartBeatInterval()}else this.context.log("PageLeave plugin需要使用localstorage存储数据,但是您的浏览器不支持localstorage,所以不能使用该功能",e.ConsoleTypes.WARN)},r.prototype.transform=function(){},r.prototype.normalizePageLeaveAutoTrack=function(){var t=this.options.autoTrackConfig.pageLeaveAutoTrack;return i.isObject(t)?t:{}},r.prototype.addPageLeaveEventListener=function(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()},r.prototype.addPageStartListener=function(){var t=this;"onpageshow"in window&&window.addEventListener("pageshow",(function(){t.pageStartHandler()}))},r.prototype.addPageSwitchListener=function(){var t=this;new i.ListenPageState({visible:function(){t.pageStartHandler(),t.startHeartBeatInterval()},hidden:function(){t.url=window.location.href,t.pageEndHandler(),t.stopHeartBeatInterval()}})},r.prototype.addSinglePageListener=function(){var t=this;i.mitt.on("urlChange",(function(e){var i=e.fromHref;i!==e.toHref&&(t.url=i,t.pageEndHandler(),t.stopHeartBeatInterval(),t.pageStartHandler(),t.startHeartBeatInterval())}))},r.prototype.addPageEndListener=function(){var t=this,e=["pagehide","beforeunload","unload"];e.forEach((function(i){"on".concat(e)in window&&window.addEventListener(i,(function(){t.pageEndHandler(),t.stopHeartBeatInterval()}))}))},r.prototype.pageStartHandler=function(){this.startTime=i.nowStamp(),this.pageShowStatus=!document.hidden,this.url=window.location.href},r.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()}},r.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()},r.prototype.reissueHeartBeatData=function(){for(var t=this.context.store.localStorage,e=t.length(),r=0;r<e;r++){var o=t.key(r);if(o&&o!==this.storageName+this.pageId&&o.includes(this.storageName)){var n=t.get(o),s=i.safeJSONParse(n);i.isObject(s)&&i.nowStamp()-s.time>s.heartbeat_interval_time+5e3&&(delete s.heartbeat_interval_time,this.context.report(s)),this.delHeartBeatData(o)}}},r.prototype.stopHeartBeatInterval=function(){this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)},r.prototype.delHeartBeatData=function(t){this.context.store.localStorage.remove(t||this.storageName+this.pageId)},r.prototype.isCollectUrl=function(){var t=this.normalizePageLeaveAutoTrack().isCollectUrl;return!i.isFunction(t)||t(this.url)},r.prototype.saveHeartBeatData=function(t){var e=this.getPageLeaveProperties();e.H_time=i.nowStamp(),"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))},r.prototype.getPageLeaveProperties=function(){var t=(i.nowStamp()-this.startTime)/1e3;t=t<=0||t>this.maxDuration?0:i.formatDecimal(t,3);var e=i.getURL(this.url),r=e.pathname,o=e.hash,n={H_url:this.url,H_url_path:r,H_url_hash:o};t&&(n.event_duration=t);var a=this.normalizePageLeaveAutoTrack().custom_props;return i.isObject(a)&&(n=s(s({},n),a||{})),n},r}(e.PluginBase),v=function(t){function r(e,i){var r=t.call(this,e,i)||this;return r.options=e,r.context=i,r.name="SiteLinker",r.isReady=!1,r.linker=[],r}return n(r,t),r.prototype.init=function(){if(this.options.siteLinkerConfig){var t=this.getLinkerConfig().linker;i.isArray(t)&&t.length>0?this.isReady?this.context.log("SiteLinker plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN):(this.isReady=!0,this.resolveOption(),this.setRefferId(),this.addClickListen()):this.context.log("siteLinker plugin: 请配置正确的linker参数",e.ConsoleTypes.WARN)}},r.prototype.transform=function(){},r.prototype.getLinkerConfig=function(){var t=this.options.siteLinkerConfig||{},e=t.linker;return{linker:(void 0===e?[]:e)||[],re_login:t.re_login}},r.prototype.resolveOption=function(){for(var t=this.getLinkerConfig().linker,r=t.length,o=[],n=0;n<r;n++){var s=t[n],a=s.part_url,c=s.after_hash;/[A-Za-z0-9]+\./.test(a)&&i.isBoolean(c)?o.push({part_url:a,after_hash:c}):this.context.log("The configuration of linker ".concat(n+1," is not supported.Please check format"),e.ConsoleTypes.WARN)}this.linker=o},r.prototype.setRefferId=function(){var t=this.getLinkerConfig().re_login,e=this.getUrlId(),i=e.startsWith("a");if(""!==(e=e.substring(1))){var r=this.context.store.getAnonymousId(),o=this.context.store.getAccountId();if(i){if(e!==r&&(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)}},r.prototype.getUrlId=function(){var t=window.location.href.match(/_hnsdk=([au][^\?\#\&\=]+)/);return i.isArray(t)&&t[1]?i.handleDecodeURLComponent(t[1]):""},r.prototype.getPartUrl=function(t){for(var e=this.linker.length,i=0;i<e;i++)if(t.includes(this.linker[i].part_url))return!0;return!1},r.prototype.getPartHash=function(t){for(var e=this.linker.length,i=0;i<e;i++)if(t.includes(this.linker[i].part_url))return this.linker[i].after_hash;return!1},r.prototype.getCurrentId=function(){var t=this.context.store.getAccountId(),e=this.context.store.getAnonymousId(),r=t?"u".concat(t):"a".concat(e);return i.handleEncodeURLComponent(r)},r.prototype.rewriteUrl=function(t,e){var i=/([^?#]+)(\?[^#]*)?(#.*)?/.exec(t),r="";if(i){var o=i[1]||"",n=i[2]||"",s=i[3]||"",a="_hnsdk=".concat(this.getCurrentId()),c=function(t){var e=t.split("&"),i=[];return e.forEach((function(t){t.includes("_hnsdk")?i.push(a):i.push(t)})),i.join("&")};if(this.getPartHash(t)){var l=s.includes("?"),u=s.indexOf("_hnsdk");r=l?u>=0?"".concat(o).concat(n,"#").concat(s.substring(1,u)).concat(c(s.substring(u,s.length))):"".concat(o).concat(n,"#").concat(s.substring(1),"&").concat(a):"".concat(o).concat(n,"#").concat(s.substring(1),"?").concat(a)}else{r=(l=/^\?(\w)+/.test(n))?n.includes("_hnsdk")?"".concat(o,"?").concat(c(n.substring(1))).concat(s):"".concat(o).concat(n,"&").concat(a).concat(s):"".concat(o,"?").concat(a).concat(s)}return e&&(e.href=r),r}},r.prototype.addClickListen=function(){var t=this,e=function(e){var r,o,n=e.target;if(n){var s=null===(r=n.tagName)||void 0===r?void 0:r.toLowerCase(),a=n.parentNode,c=null===(o=null==a?void 0:a.tagName)||void 0===o?void 0:o.toLowerCase();if("a"===s&&n.href||"a"===c&&a.href){var l=void 0,u=void 0;"a"===s&&n.href?(l=n.href,u=n):(l=a.href,u=a);var p=i.getURL(l).protocol;"http:"!==p&&"https:"!==p||t.getPartUrl(l)&&t.rewriteUrl(l,u)}}};"PointerEvent"in window?document.addEventListener("pointerdown",e):document.addEventListener("mousedown",e)},r}(e.PluginBase),y=function(t){function r(e,i){var r=t.call(this,e,i)||this;return r.options=e,r.context=i,r.name="HistoryPlugin",r.isReady=!1,r.lastHref=window.location.href,r.lastPath=window.location.pathname,r}return n(r,t),r.prototype.init=function(){if(i.supportHistory())if(this.isReady)this.context.log("History plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN);else{this.isReady=!0;var t=this,r=window.onpopstate,o=function(e,r){var o={fromPath:t.lastPath,fromHref:t.lastHref,toPath:e,toHref:r};t.lastPath=e,t.lastHref=r,i.mitt.emit("urlChange",s(s({},o),{mode:"history"}))};window.onpopstate=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var i=window.location.pathname,n=window.location.href;o(i,n),r&&r.apply(this,t)},i.replaceOld(window.history,"pushState",n),i.replaceOld(window.history,"replaceState",n)}function n(t){return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];t.apply(this,e);var r=window.location.pathname,n=window.location.href;o(r,n)}}},r.prototype.transform=function(){},r}(e.PluginBase),m=function(t){function r(e,i){var r=t.call(this,e,i)||this;return r.options=e,r.context=i,r.name="HashPlugin",r.isReady=!1,r.lastHref=window.location.href,r.lastPath=window.location.hash,r}return n(r,t),r.prototype.init=function(){var t=this;this.isReady?this.context.log("Hash plugin:插件已经运行,无需重复执行",e.ConsoleTypes.WARN):(this.isReady=!0,window.addEventListener("hashchange",(function(e){var r=e.newURL,o=i.getURL(r).hash,n={fromPath:t.lastPath,fromHref:t.lastHref,toPath:o,toHref:r};t.lastHref=r,t.lastPath=o,i.mitt.emit("urlChange",s(s({},n),{mode:"hash"}))})))},r.prototype.transform=function(){},r}(e.PluginBase),T="4.0.1",b=function(t){function r(e,r){var o=t.call(this,e,r)||this;return o.options=e,o.context=r,o.name="HinaABTest",o.isReady=!1,o.platform=i.getPlatform(),o.projectKey="",o.storageName="hina_webjs_sdk_abtest",o}return n(r,t),r.prototype.init=function(){var t=this;if(this.context.store.localStorage){var r=this.options.abTestingPluginConfig,o=null==r?void 0:r.url;if(i.isString(o)){var n=i.getQueryParam(o,"project-key");if(n){this.projectKey=n;var s=i.getURL(o).protocol,a=i.getURL(window.location.href).protocol;if(s&&s!==a)this.context.log("A/B Testing 初始化失败,".concat(a," 页面必须使用 ").concat(a," 的 URL"),e.ConsoleTypes.WARN);else if(this.isReady)this.context.log("A/B Testing 插件已经运行,无需重复执行",e.ConsoleTypes.WARN);else{var c=this.context.getUserUid();this.context.log("当前accountId为:".concat(c),e.ConsoleTypes.INFO),i.mitt.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!",e.ConsoleTypes.WARN)}else this.context.log("A/B Testing 初始化失败,浏览器不支持localStorage",e.ConsoleTypes.WARN)},r.prototype.transform=function(){},r.prototype.valueMatchType=function(t,r){switch(r){case e.VariablesTypes.INTEGER:return i.isNumber(t);case e.VariablesTypes.STRING:return i.isString(t);case e.VariablesTypes.BOOLEAN:return i.isBoolean(t);default:return!1}},r.prototype.normalizeParams=function(t,r,o){var n,s;void 0===o&&(o=h);var c={verify_success:!0,para:r};try{for(var l=a(o),u=l.next();!u.done;u=l.next()){var p=u.value;if(!c.verify_success)break;var f=r.customIds||{},g={};switch(p){case"abtestExperimentId":i.isString(r.abtestExperimentId)&&r.abtestExperimentId.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(p,"参数未正确配置!").concat(p,": ").concat(r.abtestExperimentId),e.ConsoleTypes.WARN),c.verify_success=!1);break;case"paramName":i.isString(r.paramName)&&r.paramName.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(p,"参数未正确配置!").concat(p,": ").concat(r.paramName),e.ConsoleTypes.WARN),c.verify_success=!1);break;case"valueType":[e.VariablesTypes.BOOLEAN,e.VariablesTypes.INTEGER,e.VariablesTypes.STRING].includes(r.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(p,"参数未正确配置!").concat(p,": ").concat(r.valueType),e.ConsoleTypes.WARN),c.verify_success=!1);break;case"defaultValue":this.valueMatchType(r.defaultValue,r.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(p,"类型必须与valueType一致!"),e.ConsoleTypes.WARN),c.verify_success=!1);break;case"callback":i.isFunction(r.callback)||(this.context.log("".concat(t,"方法调用失败,").concat(p,"参数未正确配置")),r.callback=i.noop,c.verify_success=!1);break;case"timeoutMilliseconds":(!i.isNumber(r.timeoutMilliseconds)||r.timeoutMilliseconds<=0)&&(this.context.log("".concat(p,"参数错误:").concat(r.timeoutMilliseconds),e.ConsoleTypes.WARN),r.timeoutMilliseconds=3e3),r.timeoutMilliseconds<200&&(r.timeoutMilliseconds=200);break;case"customProperties":r.customProperties=i.isObject(r.customProperties)?r.customProperties:{};break;case"customIds":for(var d in f)(i.isString(f[d])||i.isNumber(f[d]))&&(g[d]=f[d]);r.customIds=g}}}catch(t){n={error:t}}finally{try{u&&!u.done&&(s=l.return)&&s.call(l)}finally{if(n)throw n.error}}return c},r.prototype.sendTriggerEvent=function(t){var e=t.abtest_experiment_group_id,i=t.abtest_experiment_id;this.context.track("H_ABTestTrigger",{H_abtest_experiment_id:i,H_abtest_experiment_group_id:e})},r.prototype.getExpResult=function(t,e){var r,o;void 0===e&&(e=[]);var n,s=t.abtestExperimentId,c=t.paramName,l=t.valueType;if(0===e.length){var u=this.getStorageData();i.isObject(u)&&(e=u.result||[])}try{for(var p=a(e),h=p.next();!h.done;h=p.next()){var f=h.value,g=f.abtest_experiment_id,d=f.abtest_experiment_group_id,v=f.is_white_list,y=f.variables;if(g===s){var m=y.find((function(t){return t.name===c&&t.type===l}));if(m){v||this.sendTriggerEvent({abtest_experiment_id:g,abtest_experiment_group_id:d}),n=m.value;break}}}}catch(t){r={error:t}}finally{try{h&&!h.done&&(o=p.return)&&o.call(p)}finally{if(r)throw r.error}}return n},r.prototype.getStorageData=function(){var t=this.context.store.localStorage.get(this.storageName);return i.isValid(t)?i.safeJSONParse(t):null},r.prototype.saveResponseData=function(t){var e=this.getStorageData(),r={updateTime:i.nowStamp()};if(e&&i.isObject(e)){var o=[],n=e.result||[];t.forEach((function(t){var e=t.abtest_experiment_group_id,i=t.abtest_experiment_id,r=t.variables,s=n.find((function(t){return t.abtest_experiment_id===i&&t.abtest_experiment_group_id===e}));if(s){var a=[];r.forEach((function(t){var e=t.name,i=t.type,r=s.variables.findIndex((function(t){return t.name===e&&t.type===i}));r>=0?s.variables[r]=t:a.push(t)})),s.variables=l(l([],c(s.variables),!1),c(a),!1)}else o.push(t)})),r.result=l(l([],c(n),!1),c(o),!1)}else r.result=t;this.context.store.localStorage.set(this.storageName,JSON.stringify(r))},r.prototype.createRequestData=function(t){var e=t.paramName,r=t.customProperties,o=t.customIds,n={anonymous_id:this.context.store.getAnonymousId(),platform:this.platform,abtest_lib_version:T,param_name:e,properties:this.context.getPresetProperties()};return i.isObject(r)&&!i.isEmptyObject(r)&&(n.custom_properties=r),i.isObject(o)&&!i.isEmptyObject(o)&&(n.custom_ids=o),this.context.getUserUid()&&(n.login_id=this.context.getUserUid()),n},r.prototype.getResultFromServer=function(t){var e=this;return new Promise((function(r,o){var n=e.createRequestData(t);new i.AjaxRequest({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 i=t.data;"SUCCESS"===(null==i?void 0:i.status)?(e.saveResponseData(i.results),r(i)):o()}))}))},r.prototype.asyncFetch=function(t){var e=this;return new Promise((function(i){e.getResultFromServer(t).then((function(t){i(t)})).catch((function(){t.callback(t.defaultValue)}))}))},r.prototype.preFetch=function(t,r){return this.isReady?!!i.isObject(r)||(this.context.log("".concat(t," 方法参数必须是对象"),e.ConsoleTypes.WARN),!1):(this.context.log("A/B Testing 插件尚未运行,请先执行该插件",e.ConsoleTypes.WARN),!1)},r.prototype.asyncFetchABTest=function(t){var e=this;if(this.preFetch("asyncFetchABTest",t)){var i=this.normalizeParams("asyncFetchABTest",t),r=i.verify_success,o=i.para;r?this.asyncFetch(o).then((function(t){var i=e.getExpResult(o,t.results);o.callback(i||o.defaultValue)})):o.callback(o.defaultValue)}},r.prototype.fetchCacheABTest=function(t){if(this.preFetch("fetchCacheABTest",t)){var e=this.normalizeParams("fetchCacheABTest",t),i=e.verify_success,r=e.para;if(i){var o=this.getExpResult(r);r.callback(o||r.defaultValue)}else r.callback(r.defaultValue)}},r.prototype.fastFetchABTest=function(t){var e=this;if(this.preFetch("fastFetchABTest",t)){var r=this.normalizeParams("fastFetchABTest",t),o=r.verify_success,n=r.para;if(o){var s=this.getExpResult(n);i.isValid(s)?n.callback(s):this.asyncFetch(n).then((function(){var t=e.getExpResult(n);n.callback(t||n.defaultValue)}))}else n.callback(n.defaultValue)}},r}(e.PluginBase),_=function(t){function o(e,i){void 0===i&&(i=!0);var r=t.call(this,e,i)||this;return r.consolePrefix="埋点SDK",r.trackTags=p,r.presetProps={},r.useInstancing&&r.init(e),r}return n(o,t),o.prototype.init=function(t){if(this.isReady)this.log("hinaSDK has been initialized",e.ConsoleTypes.ERROR);else{var r={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.ReportTypes.BEACON,customHeaders:{},credentials:!1,dataSendTimeout:3e3,presetProperties:{latest_utm:!0,latest_traffic_source_type:!0,latest_search_keyword:!0,latest_referrer:!0,url:!0,title:!0},sourceChannel:[],plugins:[]},o=t.performanceErrorConfig,n=function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(i[r[o]]=t[r[o]])}return i}(t,["performanceErrorConfig"]);this.options=i.merge(r,n),this.options=s(s({},this.options),{performanceErrorConfig:o}),this.initState(),this.normalizeConfig(),this.initAdvProps(),this.initPlugins(),this.isReady=!0}},o.prototype.initState=function(){this.store=new i.State(this.options),this.store.init()},o.prototype.normalizeConfig=function(){var t=this,r=this.options,o=r.serverUrl,n=r.sendType,a=r.batchSend,c=r.maxStringLength,l=r.isSinglePage,p=r.autoTrackConfig,h=void 0===p?{}:p,f=h.trackAttr,g=void 0===f?[]:f,d=h.collectTags,v=h.pageLeaveAutoTrack,y=h.pageviewAutoTrack;if(""===(o=(o=o||"").trim()))this.log("当前 serverUrl 为空,network 中不会发数据,请配置正确的 serverUrl!",e.ConsoleTypes.WARN);else{var m=window.location.href,T=i.getURL(m).protocol||"";(i.getURL(o).protocol||"")!==T&&this.log("SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。",e.ConsoleTypes.WARN)}[e.ReportTypes.IMAGE,e.ReportTypes.AJAX,e.ReportTypes.BEACON].includes(n)||this.setConfig({sendType:e.ReportTypes.AJAX});var b=c;if(!i.isNumber(c)||c<0?b=1024:c>5120&&(b=5120),this.options.maxStringLength=b,(!0===v||i.isObject(v)&&i.isEmptyObject(v))&&(this.options.autoTrackConfig.pageLeaveAutoTrack={heartbeat_interval_time:5e3,max_duration:432e3}),i.isArray(g)?(g=g.filter((function(t){return i.isString(t)}))).includes("hn-click")||g.push("hn-click"):g=["hn-click"],this.options.autoTrackConfig.trackAttr=g,i.isObject(d))if(!0===d.div)this.options.autoTrackConfig.collectTags.div={ignoreTags:u,maxLevel:1};else if(i.isObject(d.div)){var _=1,k=d.div;i.isNumber(k.maxLevel)&&[1,2,3].includes(k.maxLevel)&&(_=k.maxLevel),this.options.autoTrackConfig.collectTags.div={ignoreTags:u,maxLevel:_}}else this.options.autoTrackConfig.collectTags.div=!1;else this.options.autoTrackConfig.collectTags={div:!1};this.updateTrackTags(),(!0===a||i.isObject(a)&&!i.isEmptyObject(a))&&(this.options.batchSend=s({dataSendTimeout:6e3,sendInterval:6e3,storageLimit:200},a),this.batchSender=new i.BatchSend(this.options,e.PlatformTypes.WEB,"hinasdk_tab","hinasdk_data_")),"auto"===y?this.autoTrack():("singlePage"===y||l)&&(this.autoTrack(),i.mitt.on("urlChange",(function(e){var r=e.fromHref;if(r!==e.toHref){if(i.isFunction(l)){var o=l();i.isObject(o)&&(e=s(s({},e),o))}t.autoTrack(s(s({},e),{H_referrer:r}))}})))},o.prototype.updateTrackTags=function(){var t=this.options.autoTrackConfig.collectTags,e=l([],c(p),!1);Object.keys(t||{}).forEach((function(r){var o=t[r];!0!==o&&!i.isObject(o)||e.includes(r)||e.push(r)})),this.trackTags=e},o.prototype.initAdvProps=function(){var t={},e=this.options,r=e.presetProperties,o=e.sourceChannel;Object.keys(r||{}).forEach((function(e){var o=r[e];if(e.includes("latest_")&&(e=e.slice(7),o)){var n=i.getCurrentDomain();if("utm"!==e&&"url解析失败"===n)t["H_latest_".concat(e)]="url的domain解析失败";else if(i.isReferralTraffic())switch(e){case"traffic_source_type":t.H_latest_traffic_source_type=i.SearchKeyword.getSourceFromReferrer();break;case"search_keyword":var s=i.SearchKeyword.getKeywordFromReferrer();s&&(t.H_latest_search_keyword=s);break;case"referrer":t.H_latest_referrer=i.getReferrer()}}}));var n=this.store.state.props||{},a={};r.latest_utm&&(a=i.getUmtsParams("H_latest_"));var c={};n.H_utm_source||(c=i.getUmtsParams("H_"));var l={},u={};if(i.isArray(o)&&o.length>0){var p=o.filter((function(t){return!i.utmTypes.includes(t)}));p.length>0&&(n["H_".concat(p[0])]||(u=i.getCustomUmtsParams("H_",p)),l=i.getCustomUmtsParams("H_latest_",p))}this.store.state.props=s(s(s(s(s(s({},this.store.state.props),t),a),l),u),c),this.store.setProps(this.store.state.props)},o.prototype.initPlugins=function(){var t=this,e=this.options,o=e.serverUrl,n=e.name,a=e.showLog,c=e.sendType,l=e.customHeaders,u=e.credentials,p=e.dataSendTimeout,h=e.batchSend,T=e.imgUseCrossOrigin,_=e.globalCallback,k=e.plugins,w=void 0===k?[]:k,C=e.performanceErrorConfig,S=e.autoTrackConfig,P=e.siteLinkerConfig,A=e.abTestingPluginConfig;w=w||[];var x=S.pageLeaveAutoTrack,R=new f(this.options,this),L=new g(this.options,this),O=new y(this.options,this),E=new m(this.options,this);if(this.plugins=[R,L,O,E],i.isObject(x)&&!i.isEmptyObject(x)){var H=new d(this.options,this);this.plugins.push(H)}var N=(P||{}).linker;if(i.isArray(N)&&N.length>0){var I=new v(this.options,this);this.plugins.push(I)}if(i.isObject(A)&&!i.isEmptyObject(A)){var j=new b(this.options,this);this.plugins.push(j)}if(w.forEach((function(e){var i=new e(t.options,t);t.plugins.push(i)})),i.isObject(C)&&!i.isEmptyObject(C)){var D=s({serverUrl:o,name:n,showLog:a,sendType:c,customHeaders:l,credentials:u,dataSendTimeout:p,batchSend:h,imgUseCrossOrigin:T,globalCallback:_},C);this.epmInstance=new r.Monitor(D,!0)}this.runPlugins(this.plugins)},o.prototype.use=function(t,r){var o=this,n=this.options,s=n.autoTrackConfig,a=n.siteLinkerConfig,c=n.abTestingPluginConfig,l=s.pageLeaveAutoTrack,u=function(t){var e=new t(o.options,o);o.plugins.push(e),e.init()};if(this.isReady){if(i.isObject(r))return"PageLeave"===t?i.isObject(l)&&!i.isEmptyObject(l)?this.log("PageLeave插件已运行,无需重复执行",e.ConsoleTypes.WARN):(this.options.autoTrackConfig.pageLeaveAutoTrack=r,u(d)):"SiteLinker"===t?i.isObject(a)&&!i.isEmptyObject(a)?this.log("SiteLinker插件已插件已运行,无需重复执行",e.ConsoleTypes.WARN):(this.options.siteLinkerConfig=r,u(v)):"HinaABTest"===t&&(i.isObject(c)&&!i.isEmptyObject(c)?this.log("HinaABTest插件已运行,无需重复执行",e.ConsoleTypes.WARN):(this.options.abTestingPluginConfig=r,u(b))),this.getPluginInstance(t);this.log("".concat(t,"插件配置项必须是一个对象类型"),e.ConsoleTypes.WARN)}else this.log("请先初始化埋点SDK",e.ConsoleTypes.WARN)},o.prototype.getPluginInstance=function(t){return this.plugins.find((function(e){return e.name===t}))},o.prototype.setConfig=function(t){this.options=i.merge(this.options,t),this.normalizeConfig()},o.prototype.getConfig=function(t){return t?this.options[t]:this.options},o.prototype.setUserUId=function(t,r){if(t=null!=t?t:"",i.isNumber(t)||i.isString(t))if(t=String(t).trim(),this.store.getAccountId()!==t){this.store.setAccountId(t);var o=this.getReportData("track_signup","H_SignUp",{});this.report(o,r),i.mitt.emit("changeAccountId")}else this.log("setUserUId: uid is equal to account_id, , failed to execute setUserUId",e.ConsoleTypes.WARN);else this.log("setUserUId: uid must be string or number",e.ConsoleTypes.WARN)},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(i.isObject(t)&&!i.isEmptyObject(t)){var r=this.getReportData("user_set","",t);this.report(r,e)}},o.prototype.userSetOnce=function(t,e){if(i.isObject(t)&&!i.isEmptyObject(t)){var r=this.getReportData("user_setOnce","",t);this.report(r,e)}},o.prototype.userAdd=function(t,r){var o,n=this;i.isString(t)&&((o={})[t]=1,t=o);if(i.isObject(t)&&!i.isEmptyObject(t)&&function(t){for(var i in t)if(!/-*\d+/.test(String(t[i])))return n.log("userAdd属性的值只能是数字",e.ConsoleTypes.WARN),!1;return!0}(t)){var s=this.getReportData("user_add","",t);this.report(s,r)}},o.prototype.userAppend=function(t,e){var r={};if(i.isObject(t)&&(Object.keys(t).forEach((function(e){var o=t[e];i.isArray(o)?r[e]=o:r[e]=[o]})),!i.isEmptyObject(r))){var o=this.getReportData("user_append","",r);this.report(o,e)}},o.prototype.userUnset=function(t,r){var o=this,n={};if(i.isString(t)&&(t=[t]),i.isArray(t)){if(t.forEach((function(t){i.isString(t)?n[t]=!0:o.log("userUnset参数数组里面的值必须时string,已经过滤掉".concat(t),e.ConsoleTypes.WARN)})),!i.isEmptyObject(n)){var s=this.getReportData("user_unset","",n);this.report(s,r)}}else this.log("userUnset参数必须是数组或字符串",e.ConsoleTypes.WARN)},o.prototype.userDelete=function(t){var e=this.getReportData("user_delete","",{});this.report(e,t),this.store.setAccountId("")},o.prototype.registerCommonProperties=function(t){this.presetProps=i.merge(this.presetProps,t)},o.prototype.getPresetProperties=function(){return{H_is_first_day:this.store.isFirstDay,H_is_first_time:this.store.isFirstTime,device_id:this.store.getDeviceId(),anonymous_id:this.store.getAnonymousId(),account_id:this.store.getAccountId(),properties:s(s(s({},this.presetProps),i.getPageProperties()),i.getBrowserInfo(T))}},o.prototype.clearPageRegister=function(t){var e=this;void 0===t&&(t=!0),!0===t?this.presetProps={}:i.isArray(t)&&t.forEach((function(t){t in e.presetProps&&delete e.presetProps[t]}))},o.prototype.checkReportProperties=function(t){var e=this,r=this.options.maxStringLength;Object.keys(t).forEach((function(o){var n=t[o];if(i.isString(n)&&n.length>r)e.log("属性 ".concat(o," 已经做截取")),t[o]=n.slice(0,r);else if(i.isObject(n))e.checkReportProperties(n);else if(i.isFunction(n))try{t[o]=n(t),i.isFunction(t[o])?(e.log("属性--".concat(o," 格式不满足要求, 已被删除")),delete t[o]):i.isObject(t[o])?e.checkReportProperties(t[o]):i.isString(t[o])&&t[o].length>r&&(t[o]=t[o].slice(0,r))}catch(i){e.log("属性--".concat(o," 格式不满足要求, 已被删除")),delete t[o]}}))},o.prototype.track=function(t,r,o){if(o=o||function(){},i.isString(t)){r=i.isObject(r)?r:{};var n=this.getReportData("track",t,r);this.report(n,o)}else this.log("track事件名必须是字符串,属性必须是是一个对象",e.ConsoleTypes.WARN)},o.prototype.quick=function(t,e,r){var o={};r=i.isFunction(r)?r:i.noop,i.isObject(e)?o=e:i.isFunction(e)&&(r=e),this.autoTrack(o,r)},o.prototype.autoTrack=function(t,e){void 0===t&&(t={}),void 0===e&&(e=i.noop);var r=this.getReportData("track","H_pageview",t);if(this.report(r,e),this.store.isSetFirstVisit){this.store.isSetFirstVisit=!1;var o=i.getReferrer();this.userSetOnce({H_first_referrer:o,H_first_referrer_host:o?i.getHostname(o,"取值异常"):"",H_first_traffic_source_type:i.SearchKeyword.getSourceFromReferrer(),H_first_search_keyword:i.SearchKeyword.getKeywordFromReferrer(),H_first_visit_time:i.nowStamp(),H_first_browser_language:i.isString(navigator.language)?navigator.language.toLowerCase():"取值异常"})}},o.prototype.report=function(t,r,o){var n,s,a=this.options,c=a.appJsBridge,l=a.serverUrl;if(this.log(t),c){var u=!0,p=null===window||void 0===window?void 0:window.Hina_Cloud_H5_Bridge;if(i.isObject(p)&&p.track)u=!1,p.track(t.event,t.type,JSON.stringify(t));else{var h=null===(s=null===(n=null===window||void 0===window?void 0:window.webkit)||void 0===n?void 0:n.messageHandlers)||void 0===s?void 0:s.hinaNativeTracker;if(null==h?void 0:h.postMessage){u=!1;var f=JSON.stringify({eventName:t.event,eventType:t.type,properties:t});h.postMessage(f)}}if(u)return void this.log("JSBridge 发送数据失败",e.ConsoleTypes.WARN);i.isFunction(r)&&r(l,t)}else this.sendReportData(t,r,o)},o.prototype.getReportData=function(t,e,r){var o=this.store.getAnonymousId(),n=this.store.getAccountId(),a=i.nowStamp(),c=this.getReportProperties(t,e),l=s(s({},c),r||{});this.checkReportProperties(l);var u={anonymous_id:o,type:t,event:e,time:a,_track_id:i.generatorTrackId(),properties:l};return n&&(u.account_id=n),u.send_time=i.nowStamp(),u},o.prototype.getReportProperties=function(t,e){void 0===t&&(t=""),void 0===e&&(e="");var r=i.merge(this.presetProps),o=s(s({device_id:this.store.getDeviceId()},this.store.state.props),r);return t&&"user"===t.slice(0,4)||(o=s(s(s({},o),i.getPageProperties()),i.getBrowserInfo(T))),"track"===t&&(o.H_is_first_day=this.store.isFirstDay,this.store.isFirstDay=!1,"H_pageview"===e&&(o.H_is_first_time=this.store.isFirstTime,this.store.isFirstTime=!1)),o},o}(t.WebClient);var k=new _({},!1);exports.HinaTrack=_,exports.default=k,Object.keys(e).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})}));
|