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.esm.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import{WebClient as t}from"hina-cloud-core";import{ReportTypes as e,ConsoleTypes as r,PluginBase as i,VariablesTypes as o,PlatformTypes as n}from"hina-cloud-types";export*from"hina-cloud-types";import{isFunction as a,getPageXYInfo as s,isObject as c,merge as l,isArray as u,getElementParents as p,isElement as h,isString as f,getElementProperties as g,nowStamp as d,getScrollTop as v,generatorTrackId as m,ListenPageState as y,mitt as _,safeJSONParse as k,formatDecimal as T,getURL as b,isBoolean as w,handleDecodeURLComponent as x,handleEncodeURLComponent as A,supportHistory as R,replaceOld as C,getPlatform as P,getQueryParam as S,isNumber as L,noop as H,isValid as N,isEmptyObject as I,AjaxRequest as E,State as D,BatchSend as U,getCurrentDomain as O,isReferralTraffic as B,getReferrer as W,SearchKeyword as F,getUmtsParams as j,utmTypes as M,getCustomUmtsParams as z,getPageProperties as V,getBrowserInfo as J,getHostname as K}from"hina-cloud-utils";import{Monitor as Z}from"hina-cloud-monitor";var G=function(t,e){return G=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])},G(t,e)};function q(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}G(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var $=function(){return $=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},$.apply(this,arguments)};function X(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 Q(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}function Y(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"==typeof SuppressedError&&SuppressedError;var tt=["mark","/mark","strong","b","em","i","u","abbr","ins","del","s","sup"],et=["a","input","button","textarea"],rt=["abtestExperimentId","paramName","valueType","defaultValue","callback","timeoutMilliseconds","customProperties","customIds"],it=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 q(e,t),e.prototype.init=function(t){var e=this,i=this.options.autoTrackConfig,o=i.clickAutoTrack,n=i.isCollectUrl,u=i.isCollectElement,p=i.addCustomProperty;!0===o&&(this.isReady?this.context.log("ClickTrack plugin:插件已经运行,无需重复执行",r.WARN):(this.isReady=!0,document.addEventListener("click",(function(r){if(n()){var i=r||window.event;if(i){var o=i.target||i.srcElement,h=e.getTargetElement(o);if(h){if(a(u)&&!u(h))return!1;var f=e.getClickElementInfo(h),g=s(i,h),d=g.H_page_x,v=g.H_page_y;if(f.H_page_x=d,f.H_page_y=v,a(p)){var m=p(h);c(m)&&(f=l(f,m))}t(f)}}}}),!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(u(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=p(t),n=this.options.autoTrackConfig.trackAttr||[];if(u(o)&&o.length>0)try{for(var a=X(o),s=a.next();!s.done;s=a.next()){var c=s.value,l=c.tagName&&(null===(i=c.tagName)||void 0===i?void 0:i.toLowerCase());if(h(c)&&(this.isTrackList[l]||this.hasAttributes(c,n)))return c}}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(h(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=[];h(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(!h(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;a(e)&&(r=e(t));var i=this.getDomSelector(t),o=g(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())||!h(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}(i),ot=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 q(e,t),e.prototype.init=function(t){var e=this,i=this.options,o=i.autoTrackConfig,n=i.stayAutoTrackConfig;if(!0===o.stayAutoTrack)if(this.isReady)this.context.log("StayTrack plugin:插件已经运行,无需重复执行",r.WARN);else{this.isReady=!0;var s=n.isCollectUrl;a(s)||(s=function(){return!0}),this.timer&&(clearTimeout(this.timer),this.timer=null),this.previousTime=d(),window.addEventListener("load",(function(){e.previousOffsetTop=v()})),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,n=v(),a=d(),s=a-this.previousTime;(e||s>i&&n!==this.previousOffsetTop)&&t({H_viewport_position:this.previousOffsetTop,event_duration:Math.min(s/1e3,o)});this.previousTime=a,this.previousOffsetTop=n},e}(i),nt=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 q(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=k(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!a(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:T(t,3);var e=b(this.url),r=e.pathname,i=e.hash,o={H_url:this.url,H_url_path:r,H_url_hash:i};t&&(o.event_duration=t);var n=this.normalizePageLeaveAutoTrack().custom_props;return c(n)&&(o=$($({},o),n||{})),o},e}(i),at=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 q(e,t),e.prototype.init=function(){if(this.options.siteLinkerConfig){var t=this.getLinkerConfig().linker;u(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)&&w(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 u(t)&&t[1]?x(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 A(r)},e.prototype.rewriteUrl=function(t,e){var r=/([^?#]+)(\?[^#]*)?(#.*)?/.exec(t),i="";if(r){var o=r[1]||"",n=r[2]||"",a=r[3]||"",s="_hnsdk=".concat(this.getCurrentId()),c=function(t){var e=t.split("&"),r=[];return e.forEach((function(t){t.includes("_hnsdk")?r.push(s):r.push(t)})),r.join("&")};if(this.getPartHash(t)){var l=a.includes("?"),u=a.indexOf("_hnsdk");i=l?u>=0?"".concat(o).concat(n,"#").concat(a.substring(1,u)).concat(c(a.substring(u,a.length))):"".concat(o).concat(n,"#").concat(a.substring(1),"&").concat(s):"".concat(o).concat(n,"#").concat(a.substring(1),"?").concat(s)}else{i=(l=/^\?(\w)+/.test(n))?n.includes("_hnsdk")?"".concat(o,"?").concat(c(n.substring(1))).concat(a):"".concat(o).concat(n,"&").concat(s).concat(a):"".concat(o,"?").concat(s).concat(a)}return e&&(e.href=i),i}},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 c=void 0,l=void 0;"a"===n&&o.href?(c=o.href,l=o):(c=a.href,l=a);var u=b(c).protocol;"http:"!==u&&"https:"!==u||t.getPartUrl(c)&&t.rewriteUrl(c,l)}}};"PointerEvent"in window?document.addEventListener("pointerdown",e):document.addEventListener("mousedown",e)},e}(i),st=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 q(e,t),e.prototype.init=function(){if(R())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",$($({},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)},C(window.history,"pushState",o),C(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),ct=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 q(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=b(r).hash,o={fromPath:t.lastPath,fromHref:t.lastHref,toPath:i,toHref:r};t.lastHref=r,t.lastPath=i,_.emit("urlChange",$($({},o),{mode:"hash"}))})))},e.prototype.transform=function(){},e}(i),lt="4.0.0",ut=function(t){function e(e,r){var i=t.call(this,e,r)||this;return i.options=e,i.context=r,i.name="HinaABTest",i.isReady=!1,i.platform=P(),i.projectKey="",i.storageName="hina_webjs_sdk_abtest",i}return q(e,t),e.prototype.init=function(){var t=this;if(this.context.store.localStorage){var e=this.options.abTestingPluginConfig,i=null==e?void 0:e.url;if(f(i)){var o=S(i,"project-key");if(o){this.projectKey=o;var n=b(i).protocol,a=b(window.location.href).protocol;if(n&&n!==a)this.context.log("A/B Testing 初始化失败,".concat(a," 页面必须使用 ").concat(a," 的 URL"),r.WARN);else if(this.isReady)this.context.log("A/B Testing 插件已经运行,无需重复执行",r.WARN);else{var s=this.context.getUserUid();this.context.log("当前accountId为:".concat(s),r.INFO),_.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!",r.WARN)}else this.context.log("A/B Testing 初始化失败,浏览器不支持localStorage",r.WARN)},e.prototype.transform=function(){},e.prototype.valueMatchType=function(t,e){switch(e){case o.INTEGER:return L(t);case o.STRING:return f(t);case o.BOOLEAN:return w(t);default:return!1}},e.prototype.normalizeParams=function(t,e,i){var n,s;void 0===i&&(i=rt);var l={verify_success:!0,para:e};try{for(var u=X(i),p=u.next();!p.done;p=u.next()){var h=p.value;if(!l.verify_success)break;var g=e.customIds||{},d={};switch(h){case"abtestExperimentId":f(e.abtestExperimentId)&&e.abtestExperimentId.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(h,"参数未正确配置!").concat(h,": ").concat(e.abtestExperimentId),r.WARN),l.verify_success=!1);break;case"paramName":f(e.paramName)&&e.paramName.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(h,"参数未正确配置!").concat(h,": ").concat(e.paramName),r.WARN),l.verify_success=!1);break;case"valueType":[o.BOOLEAN,o.INTEGER,o.STRING].includes(e.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(h,"参数未正确配置!").concat(h,": ").concat(e.valueType),r.WARN),l.verify_success=!1);break;case"defaultValue":this.valueMatchType(e.defaultValue,e.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(h,"类型必须与valueType一致!"),r.WARN),l.verify_success=!1);break;case"callback":a(e.callback)||(this.context.log("".concat(t,"方法调用失败,").concat(h,"参数未正确配置")),e.callback=H,l.verify_success=!1);break;case"timeoutMilliseconds":(!L(e.timeoutMilliseconds)||e.timeoutMilliseconds<=0)&&(this.context.log("".concat(h,"参数错误:").concat(e.timeoutMilliseconds),r.WARN),e.timeoutMilliseconds=3e3),e.timeoutMilliseconds<200&&(e.timeoutMilliseconds=200);break;case"customProperties":e.customProperties=c(e.customProperties)?e.customProperties:{};break;case"customIds":for(var v in g)(f(g[v])||L(g[v]))&&(d[v]=g[v]);e.customIds=d}}}catch(t){n={error:t}}finally{try{p&&!p.done&&(s=u.return)&&s.call(u)}finally{if(n)throw n.error}}return l},e.prototype.sendTriggerEvent=function(t){var e=t.abtest_experiment_group_id,r=t.abtest_experiment_id;this.context.track("H_ABTestTrigger",{H_abtest_experiment_id:r,H_abtest_experiment_group_id:e})},e.prototype.getExpResult=function(t,e){var r,i;void 0===e&&(e=[]);var o,n=t.abtestExperimentId,a=t.paramName,s=t.valueType;if(0===e.length){var l=this.getStorageData();c(l)&&(e=l.result||[])}try{for(var u=X(e),p=u.next();!p.done;p=u.next()){var h=p.value,f=h.abtest_experiment_id,g=h.abtest_experiment_group_id,d=h.is_white_list,v=h.variables;if(f===n){var m=v.find((function(t){return t.name===a&&t.type===s}));if(m){d||this.sendTriggerEvent({abtest_experiment_id:f,abtest_experiment_group_id:g}),o=m.value;break}}}}catch(t){r={error:t}}finally{try{p&&!p.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}return o},e.prototype.getStorageData=function(){var t=this.context.store.localStorage.get(this.storageName);return N(t)?k(t):null},e.prototype.saveResponseData=function(t){var e=this.getStorageData(),r={updateTime:d()};if(e&&c(e)){var i=[],o=e.result||[];t.forEach((function(t){var e=t.abtest_experiment_group_id,r=t.abtest_experiment_id,n=t.variables,a=o.find((function(t){return t.abtest_experiment_id===r&&t.abtest_experiment_group_id===e}));if(a){var s=[];n.forEach((function(t){var e=t.name,r=t.type,i=a.variables.findIndex((function(t){return t.name===e&&t.type===r}));i>=0?a.variables[i]=t:s.push(t)})),a.variables=Y(Y([],Q(a.variables),!1),Q(s),!1)}else i.push(t)})),r.result=Y(Y([],Q(o),!1),Q(i),!1)}else r.result=t;this.context.store.localStorage.set(this.storageName,JSON.stringify(r))},e.prototype.createRequestData=function(t){var e=t.paramName,r=t.customProperties,i=t.customIds,o={anonymous_id:this.context.store.getAnonymousId(),platform:this.platform,abtest_lib_version:lt,param_name:e,properties:this.context.getPresetProperties()};return c(r)&&!I(r)&&(o.custom_properties=r),c(i)&&!I(i)&&(o.custom_ids=i),this.context.getUserUid()&&(o.login_id=this.context.getUserUid()),o},e.prototype.getResultFromServer=function(t){var e=this;return new Promise((function(r,i){var o=e.createRequestData(t);new E({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),r(o)):i()}))}))},e.prototype.asyncFetch=function(t){var e=this;return new Promise((function(r){e.getResultFromServer(t).then((function(t){r(t)})).catch((function(){t.callback(t.defaultValue)}))}))},e.prototype.preFetch=function(t,e){return this.isReady?!!c(e)||(this.context.log("".concat(t," 方法参数必须是对象"),r.WARN),!1):(this.context.log("A/B Testing 插件尚未运行,请先执行该插件",r.WARN),!1)},e.prototype.asyncFetchABTest=function(t){var e=this;if(this.preFetch("asyncFetchABTest",t)){var r=this.normalizeParams("asyncFetchABTest",t),i=r.verify_success,o=r.para;i?this.asyncFetch(o).then((function(t){var r=e.getExpResult(o,t.results);o.callback(r||o.defaultValue)})):o.callback(o.defaultValue)}},e.prototype.fetchCacheABTest=function(t){if(this.preFetch("fetchCacheABTest",t)){var e=this.normalizeParams("fetchCacheABTest",t),r=e.verify_success,i=e.para;if(r){var o=this.getExpResult(i);i.callback(o||i.defaultValue)}else i.callback(i.defaultValue)}},e.prototype.fastFetchABTest=function(t){var e=this;if(this.preFetch("fastFetchABTest",t)){var r=this.normalizeParams("fastFetchABTest",t),i=r.verify_success,o=r.para;if(i){var n=this.getExpResult(o);N(n)?o.callback(n):this.asyncFetch(o).then((function(){var t=e.getExpResult(o);o.callback(t||o.defaultValue)}))}else o.callback(o.defaultValue)}},e}(i),pt=function(t){function i(e,r){void 0===r&&(r=!0);var i=t.call(this,e,r)||this;return i.consolePrefix="埋点SDK",i.trackTags=et,i.presetProps={},i.useInstancing&&i.init(e),i}return q(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,url:!0,title:!0},sourceChannel:[],plugins:[]},o=t.performanceErrorConfig,n=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"]);this.options=l(i,n),this.options=$($({},this.options),{performanceErrorConfig:o}),this.initState(),this.normalizeConfig(),this.initAdvProps(),this.initPlugins(),this.isReady=!0}},i.prototype.initState=function(){this.store=new D(this.options),this.store.init()},i.prototype.normalizeConfig=function(){var t=this,i=this.options,o=i.serverUrl,s=i.sendType,l=i.batchSend,p=i.maxStringLength,h=i.isSinglePage,g=i.autoTrackConfig,d=void 0===g?{}:g,v=d.trackAttr,m=void 0===v?[]:v,y=d.collectTags,k=d.pageLeaveAutoTrack,T=d.pageviewAutoTrack;if(""===(o=(o=o||"").trim()))this.log("当前 serverUrl 为空,network 中不会发数据,请配置正确的 serverUrl!",r.WARN);else{var w=window.location.href,x=b(w).protocol||"";(b(o).protocol||"")!==x&&this.log("SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。",r.WARN)}[e.IMAGE,e.AJAX,e.BEACON].includes(s)||this.setConfig({sendType:e.AJAX});var A=p;if(!L(p)||p<0?A=1024:p>5120&&(A=5120),this.options.maxStringLength=A,(!0===k||c(k)&&I(k))&&(this.options.autoTrackConfig.pageLeaveAutoTrack={heartbeat_interval_time:5e3,max_duration:432e3}),u(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:tt,maxLevel:1};else if(c(y.div)){var R=1,C=y.div;L(C.maxLevel)&&[1,2,3].includes(C.maxLevel)&&(R=C.maxLevel),this.options.autoTrackConfig.collectTags.div={ignoreTags:tt,maxLevel:R}}else this.options.autoTrackConfig.collectTags.div=!1;else this.options.autoTrackConfig.collectTags={div:!1};this.updateTrackTags(),(!0===l||c(l)&&!I(l))&&(this.options.batchSend=$({dataSendTimeout:6e3,sendInterval:6e3,storageLimit:200},l),this.batchSender=new U(this.options,n.WEB,"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){if(a(h)){var i=h();c(i)&&(e=$($({},e),i))}t.autoTrack($($({},e),{H_referrer:r}))}})))},i.prototype.updateTrackTags=function(){var t=this.options.autoTrackConfig.collectTags,e=Y([],Q(et),!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.initAdvProps=function(){var t={},e=this.options,r=e.presetProperties,i=e.sourceChannel;Object.keys(r||{}).forEach((function(e){var i=r[e];if(e.includes("latest_")&&(e=e.slice(7),i)){var o=O();if("utm"!==e&&"url解析失败"===o)t["H_latest_".concat(e)]="url的domain解析失败";else if(B())switch(e){case"traffic_source_type":t.H_latest_traffic_source_type=F.getSourceFromReferrer();break;case"search_keyword":var n=F.getKeywordFromReferrer();n&&(t.H_latest_search_keyword=n);break;case"referrer":t.H_latest_referrer=W()}}}));var o=this.store.state.props||{},n={};r.latest_utm&&(n=j("H_latest_"));var a={};o.H_utm_source||(a=j("H_"));var s={},c={};if(u(i)&&i.length>0){var l=i.filter((function(t){return!M.includes(t)}));l.length>0&&(o["H_".concat(l[0])]||(c=z("H_",l)),s=z("H_latest_",l))}this.store.state.props=$($($($($($({},this.store.state.props),t),n),s),c),a),this.store.setProps(this.store.state.props)},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,p=e.batchSend,h=e.imgUseCrossOrigin,f=e.globalCallback,g=e.plugins,d=void 0===g?[]:g,v=e.performanceErrorConfig,m=e.autoTrackConfig,y=e.siteLinkerConfig,_=e.abTestingPluginConfig;d=d||[];var k=m.pageLeaveAutoTrack,T=new it(this.options,this),b=new ot(this.options,this),w=new st(this.options,this),x=new ct(this.options,this);if(this.plugins=[T,b,w,x],c(k)&&!I(k)){var A=new nt(this.options,this);this.plugins.push(A)}var R=(y||{}).linker;if(u(R)&&R.length>0){var C=new at(this.options,this);this.plugins.push(C)}if(c(_)&&!I(_)){var P=new ut(this.options,this);this.plugins.push(P)}if(d.forEach((function(e){var r=new e(t.options,t);t.plugins.push(r)})),c(v)&&!I(v)){var S=$({serverUrl:r,name:i,showLog:o,sendType:n,customHeaders:a,credentials:s,dataSendTimeout:l,batchSend:p,imgUseCrossOrigin:h,globalCallback:f},v);this.epmInstance=new Z(S,!0)}this.runPlugins(this.plugins)},i.prototype.use=function(t,e){var i=this,o=this.options,n=o.autoTrackConfig,a=o.siteLinkerConfig,s=o.abTestingPluginConfig,l=n.pageLeaveAutoTrack,u=function(t){var e=new t(i.options,i);i.plugins.push(e),e.init()};if(this.isReady){if(c(e))return"PageLeave"===t?c(l)&&!I(l)?this.log("PageLeave插件已运行,无需重复执行",r.WARN):(this.options.autoTrackConfig.pageLeaveAutoTrack=e,u(nt)):"SiteLinker"===t?c(a)&&!I(a)?this.log("SiteLinker插件已插件已运行,无需重复执行",r.WARN):(this.options.siteLinkerConfig=e,u(at)):"HinaABTest"===t&&(c(s)&&!I(s)?this.log("HinaABTest插件已运行,无需重复执行",r.WARN):(this.options.abTestingPluginConfig=e,u(ut))),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=l(this.options,t),this.normalizeConfig()},i.prototype.getConfig=function(t){return t?this.options[t]:this.options},i.prototype.setUserUId=function(t,e){if(L(t=null!=t?t:"")||f(t))if(t=String(t).trim(),this.store.getAccountId()!==t){this.store.setAccountId(t);var i=this.getReportData("track_signup","H_SignUp",{});this.report(i,e),_.emit("changeAccountId")}else this.log("setUserUId: uid is equal to account_id, , failed to execute setUserUId",r.WARN);else this.log("setUserUId: uid must be string or number",r.WARN)},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)&&!I(t)){var r=this.getReportData("user_set","",t);this.report(r,e)}},i.prototype.userSetOnce=function(t,e){if(c(t)&&!I(t)){var r=this.getReportData("user_setOnce","",t);this.report(r,e)}},i.prototype.userAdd=function(t,e){var i,o=this;f(t)&&((i={})[t]=1,t=i);if(c(t)&&!I(t)&&function(t){for(var e in t)if(!/-*\d+/.test(String(t[e])))return o.log("userAdd属性的值只能是数字",r.WARN),!1;return!0}(t)){var n=this.getReportData("user_add","",t);this.report(n,e)}},i.prototype.userAppend=function(t,e){var r={};if(c(t)&&(Object.keys(t).forEach((function(e){var i=t[e];u(i)?r[e]=i:r[e]=[i]})),!I(r))){var i=this.getReportData("user_append","",r);this.report(i,e)}},i.prototype.userUnset=function(t,e){var i=this,o={};if(f(t)&&(t=[t]),u(t)){if(t.forEach((function(t){f(t)?o[t]=!0:i.log("userUnset参数数组里面的值必须时string,已经过滤掉".concat(t),r.WARN)})),!I(o)){var n=this.getReportData("user_unset","",o);this.report(n,e)}}else this.log("userUnset参数必须是数组或字符串",r.WARN)},i.prototype.userDelete=function(t){var e=this.getReportData("user_delete","",{});this.report(e,t),this.store.setAccountId("")},i.prototype.registerCommonProperties=function(t){this.presetProps=l(this.presetProps,t)},i.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:$($($({},this.presetProps),V()),J(lt))}},i.prototype.clearPageRegister=function(t){var e=this;void 0===t&&(t=!0),!0===t?this.presetProps={}:u(t)&&t.forEach((function(t){t in e.presetProps&&delete e.presetProps[t]}))},i.prototype.checkReportProperties=function(t){var e=this,r=this.options.maxStringLength;Object.keys(t).forEach((function(i){var o=t[i];if(f(o)&&o.length>r)e.log("属性 ".concat(i," 已经做截取")),t[i]=o.slice(0,r);else if(c(o))e.checkReportProperties(o);else if(a(o))try{t[i]=o(t),a(t[i])?(e.log("属性--".concat(i," 格式不满足要求, 已被删除")),delete t[i]):c(t[i])?e.checkReportProperties(t[i]):f(t[i])&&t[i].length>r&&(t[i]=t[i].slice(0,r))}catch(r){e.log("属性--".concat(i," 格式不满足要求, 已被删除")),delete t[i]}}))},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){var i={};r=a(r)?r:H,c(e)?i=e:a(e)&&(r=e),this.autoTrack(i,r)},i.prototype.autoTrack=function(t,e){void 0===t&&(t={}),void 0===e&&(e=H);var r=this.getReportData("track","H_pageview",t);if(this.report(r,e),this.store.isSetFirstVisit){this.store.isSetFirstVisit=!1;var i=W();this.userSetOnce({H_first_referrer:i,H_first_referrer_host:i?K(i,"取值异常"):"",H_first_traffic_source_type:F.getSourceFromReferrer(),H_first_search_keyword:F.getKeywordFromReferrer(),H_first_visit_time:d(),H_first_browser_language:f(navigator.language)?navigator.language.toLowerCase():"取值异常"})}},i.prototype.report=function(t,e,i){var o,n,s=this.options,l=s.appJsBridge,u=s.serverUrl;if(this.log(t),l){var p=!0,h=null===window||void 0===window?void 0:window.Hina_Cloud_H5_Bridge;if(c(h)&&h.track)p=!1,h.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){p=!1;var g=JSON.stringify({eventName:t.event,eventType:t.type,properties:t});f.postMessage(g)}}if(p)return void this.log("JSBridge 发送数据失败",r.WARN);a(e)&&e(u,t)}else this.sendReportData(t,e,i)},i.prototype.getReportData=function(t,e,r){var i=this.store.getAnonymousId(),o=this.store.getAccountId(),n=d(),a=this.getReportProperties(t,e),s=$($({},a),r||{});this.checkReportProperties(s);var c={anonymous_id:i,type:t,event:e,time:n,_track_id:m(),properties:s};return o&&(c.account_id=o),c.send_time=d(),c},i.prototype.getReportProperties=function(t,e){void 0===t&&(t=""),void 0===e&&(e="");var r=l(this.presetProps),i=$($({device_id:this.store.getDeviceId()},this.store.state.props),r);return t&&"user"===t.slice(0,4)||(i=$($($({},i),V()),J(lt))),"track"===t&&(i.H_is_first_day=this.store.isFirstDay,this.store.isFirstDay=!1,"H_pageview"===e&&(i.H_is_first_time=this.store.isFirstTime,this.store.isFirstTime=!1)),i},i}(t);var ht=new pt({},!1);export{pt as HinaTrack,ht as default};
|
1
|
+
import{WebClient as t}from"hina-cloud-js-core";import{ReportTypes as e,ConsoleTypes as r,PluginBase as i,VariablesTypes as o,PlatformTypes as n}from"hina-cloud-type";export*from"hina-cloud-type";import{isFunction as a,getPageXYInfo as s,isObject as c,merge as l,isArray as u,getElementParents as p,isElement as h,isString as f,getElementProperties as g,nowStamp as d,getScrollTop as v,generatorTrackId as m,ListenPageState as y,mitt as _,safeJSONParse as k,formatDecimal as T,getURL as b,isBoolean as w,handleDecodeURLComponent as x,handleEncodeURLComponent as A,supportHistory as R,replaceOld as C,getPlatform as P,getQueryParam as S,isNumber as L,noop as H,isValid as N,isEmptyObject as I,AjaxRequest as E,State as D,BatchSend as U,getCurrentDomain as O,isReferralTraffic as B,getReferrer as W,SearchKeyword as F,getUmtsParams as j,utmTypes as M,getCustomUmtsParams as z,getPageProperties as V,getBrowserInfo as J,getHostname as K}from"hina-cloud-util";import{Monitor as Z}from"hina-cloud-js-monitor";var G=function(t,e){return G=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])},G(t,e)};function q(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}G(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var $=function(){return $=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},$.apply(this,arguments)};function X(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 Q(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}function Y(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"==typeof SuppressedError&&SuppressedError;var tt=["mark","/mark","strong","b","em","i","u","abbr","ins","del","s","sup"],et=["a","input","button","textarea"],rt=["abtestExperimentId","paramName","valueType","defaultValue","callback","timeoutMilliseconds","customProperties","customIds"],it=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 q(e,t),e.prototype.init=function(t){var e=this,i=this.options.autoTrackConfig,o=i.clickAutoTrack,n=i.isCollectUrl,u=i.isCollectElement,p=i.addCustomProperty;!0===o&&(this.isReady?this.context.log("ClickTrack plugin:插件已经运行,无需重复执行",r.WARN):(this.isReady=!0,document.addEventListener("click",(function(r){if(n()){var i=r||window.event;if(i){var o=i.target||i.srcElement,h=e.getTargetElement(o);if(h){if(a(u)&&!u(h))return!1;var f=e.getClickElementInfo(h),g=s(i,h),d=g.H_page_x,v=g.H_page_y;if(f.H_page_x=d,f.H_page_y=v,a(p)){var m=p(h);c(m)&&(f=l(f,m))}t(f)}}}}),!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(u(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=p(t),n=this.options.autoTrackConfig.trackAttr||[];if(u(o)&&o.length>0)try{for(var a=X(o),s=a.next();!s.done;s=a.next()){var c=s.value,l=c.tagName&&(null===(i=c.tagName)||void 0===i?void 0:i.toLowerCase());if(h(c)&&(this.isTrackList[l]||this.hasAttributes(c,n)))return c}}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(h(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=[];h(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(!h(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;a(e)&&(r=e(t));var i=this.getDomSelector(t),o=g(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())||!h(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}(i),ot=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 q(e,t),e.prototype.init=function(t){var e=this,i=this.options,o=i.autoTrackConfig,n=i.stayAutoTrackConfig;if(!0===o.stayAutoTrack)if(this.isReady)this.context.log("StayTrack plugin:插件已经运行,无需重复执行",r.WARN);else{this.isReady=!0;var s=n.isCollectUrl;a(s)||(s=function(){return!0}),this.timer&&(clearTimeout(this.timer),this.timer=null),this.previousTime=d(),window.addEventListener("load",(function(){e.previousOffsetTop=v()})),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,n=v(),a=d(),s=a-this.previousTime;(e||s>i&&n!==this.previousOffsetTop)&&t({H_viewport_position:this.previousOffsetTop,event_duration:Math.min(s/1e3,o)});this.previousTime=a,this.previousOffsetTop=n},e}(i),nt=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 q(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=k(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!a(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:T(t,3);var e=b(this.url),r=e.pathname,i=e.hash,o={H_url:this.url,H_url_path:r,H_url_hash:i};t&&(o.event_duration=t);var n=this.normalizePageLeaveAutoTrack().custom_props;return c(n)&&(o=$($({},o),n||{})),o},e}(i),at=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 q(e,t),e.prototype.init=function(){if(this.options.siteLinkerConfig){var t=this.getLinkerConfig().linker;u(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)&&w(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 u(t)&&t[1]?x(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 A(r)},e.prototype.rewriteUrl=function(t,e){var r=/([^?#]+)(\?[^#]*)?(#.*)?/.exec(t),i="";if(r){var o=r[1]||"",n=r[2]||"",a=r[3]||"",s="_hnsdk=".concat(this.getCurrentId()),c=function(t){var e=t.split("&"),r=[];return e.forEach((function(t){t.includes("_hnsdk")?r.push(s):r.push(t)})),r.join("&")};if(this.getPartHash(t)){var l=a.includes("?"),u=a.indexOf("_hnsdk");i=l?u>=0?"".concat(o).concat(n,"#").concat(a.substring(1,u)).concat(c(a.substring(u,a.length))):"".concat(o).concat(n,"#").concat(a.substring(1),"&").concat(s):"".concat(o).concat(n,"#").concat(a.substring(1),"?").concat(s)}else{i=(l=/^\?(\w)+/.test(n))?n.includes("_hnsdk")?"".concat(o,"?").concat(c(n.substring(1))).concat(a):"".concat(o).concat(n,"&").concat(s).concat(a):"".concat(o,"?").concat(s).concat(a)}return e&&(e.href=i),i}},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 c=void 0,l=void 0;"a"===n&&o.href?(c=o.href,l=o):(c=a.href,l=a);var u=b(c).protocol;"http:"!==u&&"https:"!==u||t.getPartUrl(c)&&t.rewriteUrl(c,l)}}};"PointerEvent"in window?document.addEventListener("pointerdown",e):document.addEventListener("mousedown",e)},e}(i),st=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 q(e,t),e.prototype.init=function(){if(R())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",$($({},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)},C(window.history,"pushState",o),C(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),ct=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 q(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=b(r).hash,o={fromPath:t.lastPath,fromHref:t.lastHref,toPath:i,toHref:r};t.lastHref=r,t.lastPath=i,_.emit("urlChange",$($({},o),{mode:"hash"}))})))},e.prototype.transform=function(){},e}(i),lt="4.0.1",ut=function(t){function e(e,r){var i=t.call(this,e,r)||this;return i.options=e,i.context=r,i.name="HinaABTest",i.isReady=!1,i.platform=P(),i.projectKey="",i.storageName="hina_webjs_sdk_abtest",i}return q(e,t),e.prototype.init=function(){var t=this;if(this.context.store.localStorage){var e=this.options.abTestingPluginConfig,i=null==e?void 0:e.url;if(f(i)){var o=S(i,"project-key");if(o){this.projectKey=o;var n=b(i).protocol,a=b(window.location.href).protocol;if(n&&n!==a)this.context.log("A/B Testing 初始化失败,".concat(a," 页面必须使用 ").concat(a," 的 URL"),r.WARN);else if(this.isReady)this.context.log("A/B Testing 插件已经运行,无需重复执行",r.WARN);else{var s=this.context.getUserUid();this.context.log("当前accountId为:".concat(s),r.INFO),_.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!",r.WARN)}else this.context.log("A/B Testing 初始化失败,浏览器不支持localStorage",r.WARN)},e.prototype.transform=function(){},e.prototype.valueMatchType=function(t,e){switch(e){case o.INTEGER:return L(t);case o.STRING:return f(t);case o.BOOLEAN:return w(t);default:return!1}},e.prototype.normalizeParams=function(t,e,i){var n,s;void 0===i&&(i=rt);var l={verify_success:!0,para:e};try{for(var u=X(i),p=u.next();!p.done;p=u.next()){var h=p.value;if(!l.verify_success)break;var g=e.customIds||{},d={};switch(h){case"abtestExperimentId":f(e.abtestExperimentId)&&e.abtestExperimentId.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(h,"参数未正确配置!").concat(h,": ").concat(e.abtestExperimentId),r.WARN),l.verify_success=!1);break;case"paramName":f(e.paramName)&&e.paramName.trim()||(this.context.log("".concat(t,"方法调用失败,").concat(h,"参数未正确配置!").concat(h,": ").concat(e.paramName),r.WARN),l.verify_success=!1);break;case"valueType":[o.BOOLEAN,o.INTEGER,o.STRING].includes(e.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(h,"参数未正确配置!").concat(h,": ").concat(e.valueType),r.WARN),l.verify_success=!1);break;case"defaultValue":this.valueMatchType(e.defaultValue,e.valueType)||(this.context.log("".concat(t,"方法调用失败,").concat(h,"类型必须与valueType一致!"),r.WARN),l.verify_success=!1);break;case"callback":a(e.callback)||(this.context.log("".concat(t,"方法调用失败,").concat(h,"参数未正确配置")),e.callback=H,l.verify_success=!1);break;case"timeoutMilliseconds":(!L(e.timeoutMilliseconds)||e.timeoutMilliseconds<=0)&&(this.context.log("".concat(h,"参数错误:").concat(e.timeoutMilliseconds),r.WARN),e.timeoutMilliseconds=3e3),e.timeoutMilliseconds<200&&(e.timeoutMilliseconds=200);break;case"customProperties":e.customProperties=c(e.customProperties)?e.customProperties:{};break;case"customIds":for(var v in g)(f(g[v])||L(g[v]))&&(d[v]=g[v]);e.customIds=d}}}catch(t){n={error:t}}finally{try{p&&!p.done&&(s=u.return)&&s.call(u)}finally{if(n)throw n.error}}return l},e.prototype.sendTriggerEvent=function(t){var e=t.abtest_experiment_group_id,r=t.abtest_experiment_id;this.context.track("H_ABTestTrigger",{H_abtest_experiment_id:r,H_abtest_experiment_group_id:e})},e.prototype.getExpResult=function(t,e){var r,i;void 0===e&&(e=[]);var o,n=t.abtestExperimentId,a=t.paramName,s=t.valueType;if(0===e.length){var l=this.getStorageData();c(l)&&(e=l.result||[])}try{for(var u=X(e),p=u.next();!p.done;p=u.next()){var h=p.value,f=h.abtest_experiment_id,g=h.abtest_experiment_group_id,d=h.is_white_list,v=h.variables;if(f===n){var m=v.find((function(t){return t.name===a&&t.type===s}));if(m){d||this.sendTriggerEvent({abtest_experiment_id:f,abtest_experiment_group_id:g}),o=m.value;break}}}}catch(t){r={error:t}}finally{try{p&&!p.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}return o},e.prototype.getStorageData=function(){var t=this.context.store.localStorage.get(this.storageName);return N(t)?k(t):null},e.prototype.saveResponseData=function(t){var e=this.getStorageData(),r={updateTime:d()};if(e&&c(e)){var i=[],o=e.result||[];t.forEach((function(t){var e=t.abtest_experiment_group_id,r=t.abtest_experiment_id,n=t.variables,a=o.find((function(t){return t.abtest_experiment_id===r&&t.abtest_experiment_group_id===e}));if(a){var s=[];n.forEach((function(t){var e=t.name,r=t.type,i=a.variables.findIndex((function(t){return t.name===e&&t.type===r}));i>=0?a.variables[i]=t:s.push(t)})),a.variables=Y(Y([],Q(a.variables),!1),Q(s),!1)}else i.push(t)})),r.result=Y(Y([],Q(o),!1),Q(i),!1)}else r.result=t;this.context.store.localStorage.set(this.storageName,JSON.stringify(r))},e.prototype.createRequestData=function(t){var e=t.paramName,r=t.customProperties,i=t.customIds,o={anonymous_id:this.context.store.getAnonymousId(),platform:this.platform,abtest_lib_version:lt,param_name:e,properties:this.context.getPresetProperties()};return c(r)&&!I(r)&&(o.custom_properties=r),c(i)&&!I(i)&&(o.custom_ids=i),this.context.getUserUid()&&(o.login_id=this.context.getUserUid()),o},e.prototype.getResultFromServer=function(t){var e=this;return new Promise((function(r,i){var o=e.createRequestData(t);new E({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),r(o)):i()}))}))},e.prototype.asyncFetch=function(t){var e=this;return new Promise((function(r){e.getResultFromServer(t).then((function(t){r(t)})).catch((function(){t.callback(t.defaultValue)}))}))},e.prototype.preFetch=function(t,e){return this.isReady?!!c(e)||(this.context.log("".concat(t," 方法参数必须是对象"),r.WARN),!1):(this.context.log("A/B Testing 插件尚未运行,请先执行该插件",r.WARN),!1)},e.prototype.asyncFetchABTest=function(t){var e=this;if(this.preFetch("asyncFetchABTest",t)){var r=this.normalizeParams("asyncFetchABTest",t),i=r.verify_success,o=r.para;i?this.asyncFetch(o).then((function(t){var r=e.getExpResult(o,t.results);o.callback(r||o.defaultValue)})):o.callback(o.defaultValue)}},e.prototype.fetchCacheABTest=function(t){if(this.preFetch("fetchCacheABTest",t)){var e=this.normalizeParams("fetchCacheABTest",t),r=e.verify_success,i=e.para;if(r){var o=this.getExpResult(i);i.callback(o||i.defaultValue)}else i.callback(i.defaultValue)}},e.prototype.fastFetchABTest=function(t){var e=this;if(this.preFetch("fastFetchABTest",t)){var r=this.normalizeParams("fastFetchABTest",t),i=r.verify_success,o=r.para;if(i){var n=this.getExpResult(o);N(n)?o.callback(n):this.asyncFetch(o).then((function(){var t=e.getExpResult(o);o.callback(t||o.defaultValue)}))}else o.callback(o.defaultValue)}},e}(i),pt=function(t){function i(e,r){void 0===r&&(r=!0);var i=t.call(this,e,r)||this;return i.consolePrefix="埋点SDK",i.trackTags=et,i.presetProps={},i.useInstancing&&i.init(e),i}return q(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,url:!0,title:!0},sourceChannel:[],plugins:[]},o=t.performanceErrorConfig,n=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"]);this.options=l(i,n),this.options=$($({},this.options),{performanceErrorConfig:o}),this.initState(),this.normalizeConfig(),this.initAdvProps(),this.initPlugins(),this.isReady=!0}},i.prototype.initState=function(){this.store=new D(this.options),this.store.init()},i.prototype.normalizeConfig=function(){var t=this,i=this.options,o=i.serverUrl,s=i.sendType,l=i.batchSend,p=i.maxStringLength,h=i.isSinglePage,g=i.autoTrackConfig,d=void 0===g?{}:g,v=d.trackAttr,m=void 0===v?[]:v,y=d.collectTags,k=d.pageLeaveAutoTrack,T=d.pageviewAutoTrack;if(""===(o=(o=o||"").trim()))this.log("当前 serverUrl 为空,network 中不会发数据,请配置正确的 serverUrl!",r.WARN);else{var w=window.location.href,x=b(w).protocol||"";(b(o).protocol||"")!==x&&this.log("SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。",r.WARN)}[e.IMAGE,e.AJAX,e.BEACON].includes(s)||this.setConfig({sendType:e.AJAX});var A=p;if(!L(p)||p<0?A=1024:p>5120&&(A=5120),this.options.maxStringLength=A,(!0===k||c(k)&&I(k))&&(this.options.autoTrackConfig.pageLeaveAutoTrack={heartbeat_interval_time:5e3,max_duration:432e3}),u(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:tt,maxLevel:1};else if(c(y.div)){var R=1,C=y.div;L(C.maxLevel)&&[1,2,3].includes(C.maxLevel)&&(R=C.maxLevel),this.options.autoTrackConfig.collectTags.div={ignoreTags:tt,maxLevel:R}}else this.options.autoTrackConfig.collectTags.div=!1;else this.options.autoTrackConfig.collectTags={div:!1};this.updateTrackTags(),(!0===l||c(l)&&!I(l))&&(this.options.batchSend=$({dataSendTimeout:6e3,sendInterval:6e3,storageLimit:200},l),this.batchSender=new U(this.options,n.WEB,"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){if(a(h)){var i=h();c(i)&&(e=$($({},e),i))}t.autoTrack($($({},e),{H_referrer:r}))}})))},i.prototype.updateTrackTags=function(){var t=this.options.autoTrackConfig.collectTags,e=Y([],Q(et),!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.initAdvProps=function(){var t={},e=this.options,r=e.presetProperties,i=e.sourceChannel;Object.keys(r||{}).forEach((function(e){var i=r[e];if(e.includes("latest_")&&(e=e.slice(7),i)){var o=O();if("utm"!==e&&"url解析失败"===o)t["H_latest_".concat(e)]="url的domain解析失败";else if(B())switch(e){case"traffic_source_type":t.H_latest_traffic_source_type=F.getSourceFromReferrer();break;case"search_keyword":var n=F.getKeywordFromReferrer();n&&(t.H_latest_search_keyword=n);break;case"referrer":t.H_latest_referrer=W()}}}));var o=this.store.state.props||{},n={};r.latest_utm&&(n=j("H_latest_"));var a={};o.H_utm_source||(a=j("H_"));var s={},c={};if(u(i)&&i.length>0){var l=i.filter((function(t){return!M.includes(t)}));l.length>0&&(o["H_".concat(l[0])]||(c=z("H_",l)),s=z("H_latest_",l))}this.store.state.props=$($($($($($({},this.store.state.props),t),n),s),c),a),this.store.setProps(this.store.state.props)},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,p=e.batchSend,h=e.imgUseCrossOrigin,f=e.globalCallback,g=e.plugins,d=void 0===g?[]:g,v=e.performanceErrorConfig,m=e.autoTrackConfig,y=e.siteLinkerConfig,_=e.abTestingPluginConfig;d=d||[];var k=m.pageLeaveAutoTrack,T=new it(this.options,this),b=new ot(this.options,this),w=new st(this.options,this),x=new ct(this.options,this);if(this.plugins=[T,b,w,x],c(k)&&!I(k)){var A=new nt(this.options,this);this.plugins.push(A)}var R=(y||{}).linker;if(u(R)&&R.length>0){var C=new at(this.options,this);this.plugins.push(C)}if(c(_)&&!I(_)){var P=new ut(this.options,this);this.plugins.push(P)}if(d.forEach((function(e){var r=new e(t.options,t);t.plugins.push(r)})),c(v)&&!I(v)){var S=$({serverUrl:r,name:i,showLog:o,sendType:n,customHeaders:a,credentials:s,dataSendTimeout:l,batchSend:p,imgUseCrossOrigin:h,globalCallback:f},v);this.epmInstance=new Z(S,!0)}this.runPlugins(this.plugins)},i.prototype.use=function(t,e){var i=this,o=this.options,n=o.autoTrackConfig,a=o.siteLinkerConfig,s=o.abTestingPluginConfig,l=n.pageLeaveAutoTrack,u=function(t){var e=new t(i.options,i);i.plugins.push(e),e.init()};if(this.isReady){if(c(e))return"PageLeave"===t?c(l)&&!I(l)?this.log("PageLeave插件已运行,无需重复执行",r.WARN):(this.options.autoTrackConfig.pageLeaveAutoTrack=e,u(nt)):"SiteLinker"===t?c(a)&&!I(a)?this.log("SiteLinker插件已插件已运行,无需重复执行",r.WARN):(this.options.siteLinkerConfig=e,u(at)):"HinaABTest"===t&&(c(s)&&!I(s)?this.log("HinaABTest插件已运行,无需重复执行",r.WARN):(this.options.abTestingPluginConfig=e,u(ut))),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=l(this.options,t),this.normalizeConfig()},i.prototype.getConfig=function(t){return t?this.options[t]:this.options},i.prototype.setUserUId=function(t,e){if(L(t=null!=t?t:"")||f(t))if(t=String(t).trim(),this.store.getAccountId()!==t){this.store.setAccountId(t);var i=this.getReportData("track_signup","H_SignUp",{});this.report(i,e),_.emit("changeAccountId")}else this.log("setUserUId: uid is equal to account_id, , failed to execute setUserUId",r.WARN);else this.log("setUserUId: uid must be string or number",r.WARN)},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)&&!I(t)){var r=this.getReportData("user_set","",t);this.report(r,e)}},i.prototype.userSetOnce=function(t,e){if(c(t)&&!I(t)){var r=this.getReportData("user_setOnce","",t);this.report(r,e)}},i.prototype.userAdd=function(t,e){var i,o=this;f(t)&&((i={})[t]=1,t=i);if(c(t)&&!I(t)&&function(t){for(var e in t)if(!/-*\d+/.test(String(t[e])))return o.log("userAdd属性的值只能是数字",r.WARN),!1;return!0}(t)){var n=this.getReportData("user_add","",t);this.report(n,e)}},i.prototype.userAppend=function(t,e){var r={};if(c(t)&&(Object.keys(t).forEach((function(e){var i=t[e];u(i)?r[e]=i:r[e]=[i]})),!I(r))){var i=this.getReportData("user_append","",r);this.report(i,e)}},i.prototype.userUnset=function(t,e){var i=this,o={};if(f(t)&&(t=[t]),u(t)){if(t.forEach((function(t){f(t)?o[t]=!0:i.log("userUnset参数数组里面的值必须时string,已经过滤掉".concat(t),r.WARN)})),!I(o)){var n=this.getReportData("user_unset","",o);this.report(n,e)}}else this.log("userUnset参数必须是数组或字符串",r.WARN)},i.prototype.userDelete=function(t){var e=this.getReportData("user_delete","",{});this.report(e,t),this.store.setAccountId("")},i.prototype.registerCommonProperties=function(t){this.presetProps=l(this.presetProps,t)},i.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:$($($({},this.presetProps),V()),J(lt))}},i.prototype.clearPageRegister=function(t){var e=this;void 0===t&&(t=!0),!0===t?this.presetProps={}:u(t)&&t.forEach((function(t){t in e.presetProps&&delete e.presetProps[t]}))},i.prototype.checkReportProperties=function(t){var e=this,r=this.options.maxStringLength;Object.keys(t).forEach((function(i){var o=t[i];if(f(o)&&o.length>r)e.log("属性 ".concat(i," 已经做截取")),t[i]=o.slice(0,r);else if(c(o))e.checkReportProperties(o);else if(a(o))try{t[i]=o(t),a(t[i])?(e.log("属性--".concat(i," 格式不满足要求, 已被删除")),delete t[i]):c(t[i])?e.checkReportProperties(t[i]):f(t[i])&&t[i].length>r&&(t[i]=t[i].slice(0,r))}catch(r){e.log("属性--".concat(i," 格式不满足要求, 已被删除")),delete t[i]}}))},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){var i={};r=a(r)?r:H,c(e)?i=e:a(e)&&(r=e),this.autoTrack(i,r)},i.prototype.autoTrack=function(t,e){void 0===t&&(t={}),void 0===e&&(e=H);var r=this.getReportData("track","H_pageview",t);if(this.report(r,e),this.store.isSetFirstVisit){this.store.isSetFirstVisit=!1;var i=W();this.userSetOnce({H_first_referrer:i,H_first_referrer_host:i?K(i,"取值异常"):"",H_first_traffic_source_type:F.getSourceFromReferrer(),H_first_search_keyword:F.getKeywordFromReferrer(),H_first_visit_time:d(),H_first_browser_language:f(navigator.language)?navigator.language.toLowerCase():"取值异常"})}},i.prototype.report=function(t,e,i){var o,n,s=this.options,l=s.appJsBridge,u=s.serverUrl;if(this.log(t),l){var p=!0,h=null===window||void 0===window?void 0:window.Hina_Cloud_H5_Bridge;if(c(h)&&h.track)p=!1,h.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){p=!1;var g=JSON.stringify({eventName:t.event,eventType:t.type,properties:t});f.postMessage(g)}}if(p)return void this.log("JSBridge 发送数据失败",r.WARN);a(e)&&e(u,t)}else this.sendReportData(t,e,i)},i.prototype.getReportData=function(t,e,r){var i=this.store.getAnonymousId(),o=this.store.getAccountId(),n=d(),a=this.getReportProperties(t,e),s=$($({},a),r||{});this.checkReportProperties(s);var c={anonymous_id:i,type:t,event:e,time:n,_track_id:m(),properties:s};return o&&(c.account_id=o),c.send_time=d(),c},i.prototype.getReportProperties=function(t,e){void 0===t&&(t=""),void 0===e&&(e="");var r=l(this.presetProps),i=$($({device_id:this.store.getDeviceId()},this.store.state.props),r);return t&&"user"===t.slice(0,4)||(i=$($($({},i),V()),J(lt))),"track"===t&&(i.H_is_first_day=this.store.isFirstDay,this.store.isFirstDay=!1,"H_pageview"===e&&(i.H_is_first_time=this.store.isFirstTime,this.store.isFirstTime=!1)),i},i}(t);var ht=new pt({},!1);export{pt as HinaTrack,ht as default};
|