@macroui/event-tracker 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/event-tracker.cjs +4252 -879
  2. package/dist/event-tracker.cjs.map +1 -0
  3. package/dist/event-tracker.js +4252 -879
  4. package/dist/event-tracker.js.map +1 -0
  5. package/dist/event-tracker.min.js +2 -1
  6. package/dist/event-tracker.min.js.map +1 -0
  7. package/dist/event-tracker.mjs +4212 -880
  8. package/dist/event-tracker.mjs.map +1 -0
  9. package/dist/plugin/debug-sender.cjs +53 -2
  10. package/dist/plugin/debug-sender.mjs +53 -2
  11. package/dist/plugin/experiment.cjs +181 -0
  12. package/dist/plugin/experiment.cjs.map +1 -0
  13. package/dist/plugin/experiment.mjs +178 -0
  14. package/dist/plugin/experiment.mjs.map +1 -0
  15. package/dist/plugin/indexeddb-sender.cjs +51 -2
  16. package/dist/plugin/indexeddb-sender.mjs +51 -2
  17. package/dist/plugin/otel-bridge.cjs +164 -0
  18. package/dist/plugin/otel-bridge.cjs.map +1 -0
  19. package/dist/plugin/otel-bridge.mjs +162 -0
  20. package/dist/plugin/otel-bridge.mjs.map +1 -0
  21. package/dist/plugin/predictive-batcher.cjs +61 -0
  22. package/dist/plugin/predictive-batcher.cjs.map +1 -0
  23. package/dist/plugin/predictive-batcher.mjs +58 -0
  24. package/dist/plugin/predictive-batcher.mjs.map +1 -0
  25. package/dist/plugin/webview-bridge.cjs +83 -31
  26. package/dist/plugin/webview-bridge.mjs +83 -31
  27. package/dist/stats.cjs +148 -0
  28. package/dist/stats.cjs.map +1 -0
  29. package/dist/stats.mjs +145 -0
  30. package/dist/stats.mjs.map +1 -0
  31. package/dist/types/core/env.d.ts +2 -0
  32. package/dist/types/core/failed-queue.d.ts +19 -2
  33. package/dist/types/core/idle.d.ts +23 -0
  34. package/dist/types/core/payload-signer.d.ts +31 -0
  35. package/dist/types/core/pii.d.ts +46 -0
  36. package/dist/types/core/platform.d.ts +23 -0
  37. package/dist/types/core/privacy.d.ts +42 -0
  38. package/dist/types/core/replay.d.ts +41 -0
  39. package/dist/types/core/retry-policy.d.ts +11 -8
  40. package/dist/types/core/send-pipeline.d.ts +5 -1
  41. package/dist/types/core/stats.d.ts +77 -0
  42. package/dist/types/core/tracker.d.ts +7 -1
  43. package/dist/types/core/wasm-crypto.d.ts +28 -0
  44. package/dist/types/edge/index.d.ts +41 -0
  45. package/dist/types/federation.d.ts +34 -0
  46. package/dist/types/index.d.ts +42 -1
  47. package/dist/types/plugins/audience-sync/index.d.ts +67 -0
  48. package/dist/types/plugins/cross-domain/index.d.ts +20 -0
  49. package/dist/types/plugins/csp-compliant/index.d.ts +17 -0
  50. package/dist/types/plugins/experiment/index.d.ts +43 -0
  51. package/dist/types/plugins/otel-bridge/index.d.ts +22 -0
  52. package/dist/types/plugins/otel-exporter/index.d.ts +50 -0
  53. package/dist/types/plugins/pii-detector/index.d.ts +8 -0
  54. package/dist/types/plugins/predictive-batcher/index.d.ts +29 -0
  55. package/dist/types/plugins/privacy/index.d.ts +19 -0
  56. package/dist/types/plugins/rate-limiter/index.d.ts +41 -0
  57. package/dist/types/plugins/schema-registry/index.d.ts +41 -0
  58. package/dist/types/plugins/webview-bridge/index.d.ts +33 -9
  59. package/dist/types/send/ajax-sender.d.ts +6 -1
  60. package/dist/types/send/batch-sender.d.ts +12 -1
  61. package/dist/types/send/encode.d.ts +13 -1
  62. package/dist/types/send/offscreen-sender.d.ts +25 -0
  63. package/dist/types/send/sender.d.ts +20 -3
  64. package/dist/types/send/ws-sender.d.ts +38 -0
  65. package/dist/types/types/config.d.ts +17 -1
  66. package/dist/types/types/index.d.ts +1 -1
  67. package/package.json +1 -1
  68. package/dist/types/types.test-d.d.ts +0 -5
  69. package/dist/types.test-d.ts +0 -103
@@ -1 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).EventTracker={})}(this,function(t){"use strict";var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},r.apply(this,arguments)};function i(t,e,n,r){return new(n||(n=Promise))(function(i,o){function s(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function s(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}function a(){return"undefined"!=typeof window&&void 0!==window.document}function c(){try{if(!a()||!window.localStorage)return!1;var t="__et_test__";return window.localStorage.setItem(t,"1"),window.localStorage.removeItem(t),!0}catch(t){return!1}}function u(){return a()&&"function"==typeof Image}function l(){if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues){var t=new Uint8Array(16);crypto.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128;var e=Array.from(t,function(t){return t.toString(16).padStart(2,"0")});return e.slice(0,4).join("")+"-"+e.slice(4,6).join("")+"-"+e.slice(6,8).join("")+"-"+e.slice(8,10).join("")+"-"+e.slice(10,16).join("")}var n=Date.now(),r="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random();return n>0?(e=(n+e)%16|0,n=Math.floor(n/16)):(e=(r+e)%16|0,r=Math.floor(r/16)),("x"===t?e:3&e|8).toString(16)})}"function"==typeof SuppressedError&&SuppressedError;var d=function(){function t(t){this.config=t}return t.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog("log",t)&&this.out("log",t)},t.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog("warn",t)&&this.out("warn",t)},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog("error",t)&&this.out("error",t)},t.prototype.shouldLog=function(t,e){if(2===this.config.debug){if("error"===t)throw e[0]instanceof Error?e[0]:new Error(String(e[0]));return!0}return 1===this.config.debug&&("warn"===t||"error"===t)||!(!this.config.show_log||"log"!==t)},t.prototype.out=function(t,e){var n="undefined"!=typeof console&&console[t]?console[t]:console.log;try{n.call.apply(n,s([console,"[EventTracker]"],e,!1))}catch(t){}},t}(),f="et_distinct_id",p="et_anonymous_id",h="et_login_id",g="et_original_id",y=function(){function t(t,e){void 0===e&&(e={});var n=this;this.store=t,this.opts=e,this.loginId="",this.originalId="",this.anonymousId=this.readOrCreate(p,function(){return l()},this.opts.getAnonymousId,this.opts.setAnonymousId),this.firstId=this.readOrCreate("et_first_id",function(){return l()},this.opts.getFirstId,this.opts.setFirstId),this.distinctId=this.readOrCreate(f,function(){return n.anonymousId},this.opts.getDistinctId,this.opts.setDistinctId)}return t.prototype.readOrCreate=function(t,e,n,r){if(n)try{var i=n();if(i)return i}catch(t){}var o=this.store.get(t);if(o)return o;var s=e();return this.persist(t,s,r),s},t.prototype.persist=function(t,e,n){if(n)try{return void n(e)}catch(t){}this.store.set(t,e)},t.prototype.getDistinctId=function(){return this.distinctId},t.prototype.getAnonymousId=function(){return this.anonymousId},t.prototype.getFirstId=function(){return this.firstId},t.prototype.getLoginId=function(){return this.loginId},t.prototype.getOriginalId=function(){return this.originalId},t.prototype.identify=function(t,e){if(void 0===e&&(e=!0),t!==this.loginId){var n=this.distinctId;this.distinctId=t,this.loginId=t,this.originalId=n,this.persist(f,t,this.opts.setDistinctId),e?this.persist(h,t):this.store.remove(h),this.persist(g,n)}},t.prototype.resetAnonymousIdentity=function(t){this.distinctId=t||this.anonymousId,this.loginId="",this.originalId="",this.persist(f,this.distinctId,this.opts.setDistinctId),this.store.remove(h),this.store.remove(g),t&&(this.anonymousId=t,this.persist(p,t,this.opts.setAnonymousId))},t.prototype.login=function(t){this.identify(t,!0)},t.prototype.logout=function(){this.resetAnonymousIdentity()},t}(),v={PageView:"$pageview",WebPageLoad:"$WebPageLoad",WebPageLeave:"$WebPageLeave",WebClick:"$WebClick",WebStay:"$WebStay",SignUp:"$SignUp",BindID:"$BindID",UnbindID:"$UnbindID",ABTestTrigger:"$ABTestTrigger",PlanPopupClick:"$PlanPopupClick",PlanPopupDisplay:"$PlanPopupDisplay",ChannelLinkReaching:"$ChannelLinkReaching",ElementExposure:"$element_exposure",ScrollDepth:"$scrolldepth",ExitClick:"$exit_click",PageLeave:"$page_leave",HeatmapEvent:"$heatmap_event"},_={AppId:"$app_id",AppVersion:"$app_version",Lib:"$lib",LibMethod:"$lib_method",LibDetail:"$lib_detail",LibVersion:"$lib_version",ScreenWidth:"$screen_width",ScreenHeight:"$screen_height",ViewportWidth:"$viewport_width",ViewportHeight:"$viewport_height",TimezoneOffset:"$timezone_offset",UserAgent:"$user_agent",Language:"$language",FirstBrowserCharset:"$first_browser_charset",FirstBrowserLanguage:"$first_browser_language",URL:"$url",URLPath:"$url_path",Title:"$title",Referrer:"$referrer",ReferrerHost:"$referrer_host",LatestReferrer:"$latest_referrer",LatestReferrerHost:"$latest_referrer_host",LatestLandingPage:"$latest_landing_page",LatestSearchKeyword:"$latest_search_keyword",LatestTrafficSourceType:"$latest_traffic_source_type",FirstReferrer:"$first_referrer",FirstReferrerHost:"$first_referrer_host",FirstSearchKeyword:"$first_search_keyword",FirstTrafficSourceType:"$first_traffic_source_type",FirstVisitTime:"$first_visit_time",SearchKeywordId:"$search_keyword_id",SearchKeywordIdHash:"$search_keyword_id_hash",SearchKeywordIdType:"$search_keyword_id_type",IsFirstDay:"$is_first_day",IsFirstTime:"$is_first_time",LatestUtmSource:"$latest_utm_source",LatestUtmMedium:"$latest_utm_medium",LatestUtmCampaign:"$latest_utm_campaign",LatestUtmContent:"$latest_utm_content",LatestUtmTerm:"$latest_utm_term",Utms:"$utms",DistinctId:"$distinct_id",AnonymousId:"$anonymous_id",FirstId:"$first_id",OriginalId:"$original_id",LoginId:"$login_id",IsLoginId:"$is_login_id",IdentityLoginId:"$identity_login_id",IdentityAnonymousId:"$identity_anonymous_id",IdentityCookieId:"$identity_cookie_id",IdentityEmail:"$identity_email",IdentityMobile:"$identity_mobile",ElementSelector:"$element_selector",ElementPath:"$element_path",ElementType:"$element_type",ElementId:"$element_id",ElementClassName:"$element_class_name",ElementName:"$element_name",ElementContent:"$element_content",ElementTargetUrl:"$element_target_url",ElementPosition:"$element_position",PageX:"$page_x",PageY:"$page_y",PageHeight:"$page_height",PageResourceSize:"$page_resource_size",EventDuration:"$event_duration",ViewportPosition:"$viewport_position",LatestWxAdClickId:"$latest_wx_ad_click_id",LatestWxAdCallbacks:"$latest_wx_ad_callbacks",LatestWxAdHashKey:"$latest_wx_ad_hash_key",IsChannelCallbackEvent:"$is_channel_callback_event",EventSessionId:"$event_session_id",Time:"$time",Event:"$event",Option:"$option",Project:"$project",Token:"$token",SignupMethod:"$signup_method"},m="event-tracker",b="1.1.0",w=function(){function t(){this.preset={}}return t.prototype.setPreset=function(t){this.preset=r({},t)},t.prototype.register=function(t){Object.assign(this.preset,t)},t.prototype.registerOnce=function(t){for(var e=0,n=Object.keys(t);e<n.length;e++){var r=n[e];r in this.preset||(this.preset[r]=t[r])}},t.prototype.clearRegister=function(){this.preset={}},t.prototype.unsetRegister=function(t){Object.prototype.hasOwnProperty.call(this.preset,t)&&delete this.preset[t]},t.prototype.getPreset=function(){return r({},this.preset)},t.prototype.build=function(t,e){void 0===e&&(e={});var n=r(r({},this.preset),e);if(n[_.Lib]=t.lib_name||"event-tracker",n[_.LibVersion]=t.lib_version||"0.1.0",t.app_id&&(n[_.AppId]=t.app_id),t.app_version&&(n[_.AppVersion]=t.app_version),a())try{n[_.URL]=location.href,n[_.URLPath]=location.pathname,n[_.Title]=document.title,document.referrer&&(n[_.Referrer]=document.referrer);var i=window.screen&&window.screen.width||0,o=window.screen&&window.screen.height||0;i&&(n[_.ScreenWidth]=i),o&&(n[_.ScreenHeight]=o);var s=window.innerWidth||document.documentElement&&document.documentElement.clientWidth||0,c=window.innerHeight||document.documentElement&&document.documentElement.clientHeight||0;s&&(n[_.ViewportWidth]=s),c&&(n[_.ViewportHeight]=c),navigator&&(n[_.Language]=navigator.language||"",n[_.UserAgent]=t.user_agent||navigator.userAgent||"",n[_.TimezoneOffset]=(new Date).getTimezoneOffset())}catch(t){}if(a()&&!1!==t.is_collect_utm){for(var u=function(t){var e={};if(!t)return e;for(var n=(t.startsWith("?")?t.substring(1):t).split("&"),r=0,i=n;r<i.length;r++){var o=i[r],s=o.indexOf("=");if(-1!==s){var a=decodeURIComponent(o.substring(0,s)),c=decodeURIComponent(o.substring(s+1));a.startsWith("utm_")&&(e[a]=c)}}return e}(location.search),l=0,d=Object.entries(u);l<d.length;l++){var f=d[l],p=f[0],h=f[1];n[_.LatestUtmSource.replace("Source",k(p.replace("utm_","")))]=h}n[_.LatestTrafficSourceType]=n[_.LatestUtmSource]?"付费广告流量":"直接流量"}return n},t}();function k(t){return t.charAt(0).toUpperCase()+t.slice(1)}var I=function(){function t(){this.backing=new Map}return t.prototype.get=function(t){return this.backing.has(t)?this.backing.get(t):null},t.prototype.set=function(t,e){this.backing.set(t,e)},t.prototype.remove=function(t){this.backing.delete(t)},t.prototype.keys=function(t){return void 0===t&&(t=""),Array.from(this.backing.keys()).filter(function(e){return e.startsWith(t)})},t}(),S=function(){function t(t,e,n){void 0===e&&(e=!0),void 0===n&&(n=!1),this.domain=t,this.crossSubdomain=e,this.secure=n}return t.prototype.get=function(t){for(var e=encodeURIComponent(t)+"=",n=document.cookie.split(";"),r=0;r<n.length;r++){for(var i=n[r];" "===i.charAt(0);)i=i.substring(1);if(0===i.indexOf(e))return decodeURIComponent(i.substring(e.length,i.length))}return null},t.prototype.set=function(t,e,n){void 0===n&&(n=365);var r="";if(n){var i=new Date;i.setTime(i.getTime()+24*n*60*60*1e3),r="; expires="+i.toUTCString()}var o=encodeURIComponent(t)+"="+encodeURIComponent(e)+r+"; path=/";this.domain&&this.crossSubdomain&&(o+="; domain="+this.domain),this.secure&&(o+="; Secure"),document.cookie=o},t.prototype.remove=function(t){this.set(t,"",-1)},t.prototype.keys=function(t){return void 0===t&&(t=""),document.cookie.split(";").map(function(t){var e=t.indexOf("=");return decodeURIComponent((e>-1?t.substring(0,e):t).trim())}).filter(function(e){return e.startsWith(t)})},t}(),E=function(){function t(){}return t.prototype.get=function(t){try{return window.localStorage.getItem(t)}catch(t){return null}},t.prototype.set=function(t,e){try{window.localStorage.setItem(t,e)}catch(t){}},t.prototype.remove=function(t){try{window.localStorage.removeItem(t)}catch(t){}},t.prototype.keys=function(t){void 0===t&&(t="");var e=[];try{for(var n=0;n<window.localStorage.length;n++){var r=window.localStorage.key(n);r&&r.startsWith(t)&&e.push(r)}}catch(t){}return e},t}();function A(t){return function(){if(!a()||!document.cookie)return!1;document.cookie="__et_test__=1";var t=-1!==document.cookie.indexOf("__et_test__");return document.cookie="__et_test__=; expires=Thu, 01 Jan 1970 00:00:00 GMT",t}()?new S(null==t?void 0:t.cookieDomain,null==t?void 0:t.cookieCrossSubdomain,null==t?void 0:t.secureCookie):c()?new E:new I}function $(t,e){var n=JSON.stringify(t);return e?e(n):n}function P(t,e){var n=JSON.stringify(t);return e?e(n):n}function T(t,e,n){var r=Array.isArray(t)?t[0]||"":t,i=r.indexOf("?")>=0;return"".concat(r).concat(i?"&":"?","data=").concat(encodeURIComponent(e))}var x=function(){function t(){this.name="image"}return t.prototype.canUse=function(){return u()},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,r,i;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,Promise.resolve($(t,e.config.encryptor))];case 1:return n=o.sent(),r=T(e.config.server_url||"",n),[4,new Promise(function(t){var e,n="function"==typeof(e=((0,eval)("this")||globalThis).Image)?new e:{src:"",onload:void 0,onerror:void 0,onabort:void 0},i=function(){return t()};n.onload=i,n.onerror=i,n.onabort=i,n.src=r,setTimeout(i,3e3)})];case 2:return o.sent(),[3,4];case 3:return i=o.sent(),e.logger.error("ImageSender failed:",i),[3,4];case 4:return[2]}})})},t}(),L=function(){function t(){this.name="beacon"}return t.prototype.canUse=function(){return a()&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,r,i,s;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,Promise.resolve($(t,e.config.encryptor))];case 1:return n=o.sent(),r=T(e.config.server_url||"",n),i=new Blob([n],{type:"application/x-www-form-urlencoded"}),navigator.sendBeacon(r,i)||e.logger.warn("BeaconSender returned false, URL:",r.slice(0,80)),[3,3];case 2:return s=o.sent(),e.logger.error("BeaconSender failed:",s),[3,3];case 3:return[2]}})})},t}(),C=function(){function t(){this.name="ajax"}return t.prototype.canUse=function(){return a()&&"function"==typeof fetch},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,r,i,s,a,c,u,l,d,f,p;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,Promise.resolve($(t,e.config.encryptor))];case 1:return n=o.sent(),r=Array.isArray(e.config.server_url)?e.config.server_url[0]:e.config.server_url,i="data=".concat(encodeURIComponent(n)),[4,fetch(r,{method:"POST",mode:"cors",credentials:"omit",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i,keepalive:!0})];case 2:return(s=o.sent()).ok?null===(d=(l=e.config).callback)||void 0===d||d.call(l,t):(e.logger.warn("AjaxSender non-2xx:",s.status),null===(u=(c=e.config).on_error)||void 0===u||u.call(c,new Error("HTTP ".concat(s.status)),t)),[3,4];case 3:return a=o.sent(),e.logger.error("AjaxSender failed:",a),null===(p=(f=e.config).on_error)||void 0===p||p.call(f,a,t),[3,4];case 4:return[2]}})})},t.prototype.sendBatch=function(t,e){return i(this,void 0,void 0,function(){var n,r,i,s;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,Promise.resolve(P(t,e.config.encryptor))];case 1:return n=o.sent(),r=Array.isArray(e.config.server_url)?e.config.server_url[0]:e.config.server_url,i="data=".concat(encodeURIComponent(n),"&batch=1"),[4,fetch(r,{method:"POST",mode:"cors",credentials:"omit",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i,keepalive:!0})];case 2:return o.sent(),[3,4];case 3:return s=o.sent(),e.logger.error("AjaxSender.sendBatch failed:",s),[3,4];case 4:return[2]}})})},t}(),D=Object.freeze({__proto__:null,AjaxSender:C}),O="et_batch_queue",U=function(){function t(){this.name="batch",this.timer=null}return t.prototype.canUse=function(){return"undefined"!=typeof window&&!!window.localStorage},t.prototype.start=function(t){var e=this;if(this.canUse()){var n=t.config.batch_send,r="object"==typeof n&&(null==n?void 0:n.send_interval)||t.config.datasend_timeout||6e3;this.timer=setInterval(function(){return e.flush(t)},r)}},t.prototype.stop=function(){this.timer&&clearInterval(this.timer),this.timer=null},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,r;return o(this,function(i){switch(i.label){case 0:return this.enqueue(t,e.config),n="object"==typeof e.config.batch_send&&(null===(r=e.config.batch_send)||void 0===r?void 0:r.max_length)||50,this.read(e.config).length>=n?[4,this.flush(e)]:[3,2];case 1:i.sent(),i.label=2;case 2:return[2]}})})},t.prototype.enqueue=function(t,e){var n=this.read(e);n.push(t),this.write(n,e)},t.prototype.read=function(t){try{var e=window.localStorage.getItem(O);if(!e)return[];var n=JSON.parse(e);return Array.isArray(n)?n:[]}catch(t){return[]}},t.prototype.write=function(t,e){try{var n=P(t,e.encryptor),r="string"==typeof n?n:JSON.stringify(t);window.localStorage.setItem(O,r)}catch(n){var i=t.slice(Math.floor(t.length/2));try{var o=P(i,e.encryptor),s="string"==typeof o?o:JSON.stringify(i);window.localStorage.setItem(O,s)}catch(t){}}},t.prototype.flush=function(t){return i(this,void 0,void 0,function(){var e,n,r,i,s,a;return o(this,function(o){switch(o.label){case 0:if(!(e=this.read(t.config)).length)return[2];try{window.localStorage.removeItem(O)}catch(t){}return[4,Promise.resolve().then(function(){return D})];case 1:return(n=new(o.sent().AjaxSender)).canUse()?[4,n.sendBatch(e,t)]:[3,3];case 2:return o.sent(),[3,7];case 3:r=new L,i=0,s=e,o.label=4;case 4:return i<s.length?(a=s[i],[4,r.send(a,t)]):[3,7];case 5:o.sent(),o.label=6;case 6:return i++,[3,4];case 7:return[2]}})})},t}(),R=function(){function t(t){this.stage=t,this.list=[],this.stopped=!1,this.stopFlag=!1}return t.prototype.register=function(t){var e;this.unregister(t.name),this.list.push({priority:null!==(e=t.priority)&&void 0!==e?e:100,spec:t}),this.list.sort(function(t,e){return t.priority-e.priority})},t.prototype.unregister=function(t){this.list=this.list.filter(function(e){return e.spec.name!==t})},t.prototype.list2=function(){return this.list.map(function(t){return"".concat(t.spec.name,"@").concat(t.priority)})},t.prototype.reset=function(){this.stopFlag=!1},t.prototype.run=function(t,e){var n=this;this.stopFlag=!1;for(var r={data:t,meta:{stage:this.stage},cancellationToken:{stop:function(){n.stopFlag=!0}},owner:e},i=0,o=this.list;i<o.length;i++){var s=o[i].spec;if(this.stopFlag)break;var a=s.entry(r);void 0!==a&&(r.data=a)}return r.data},t}(),j=function(){function t(){this.hooks={sdkReady:new Set,sdkInitPara:new Set,sdkAfterInitPara:new Set,sdkInitAPI:new Set,sdkAfterInitAPI:new Set,changeDistinctId:new Set,switch:new Set}}return t.prototype.on=function(t,e){var n=this;if(!this.hooks[t])throw new Error("[Lifecycle] unknown hook: ".concat(t));return this.hooks[t].add(e),function(){return n.off(t,e)}},t.prototype.off=function(t,e){var n;null===(n=this.hooks[t])||void 0===n||n.delete(e)},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=this.hooks[t];if(r)for(var i=0,o=Array.from(r);i<o.length;i++){var s=o[i];try{s.apply(void 0,e)}catch(e){"undefined"!=typeof console&&console.error&&console.error("[EventTracker] hook ".concat(t," error:"),e)}}},t.prototype.clear=function(){for(var t=0,e=Object.keys(this.hooks);t<e.length;t++){var n=e[t];this.hooks[n].clear()}},t.prototype.inspect=function(){for(var t={},e=0,n=Object.keys(this.hooks);e<n.length;e++){var r=n[e];t[r]=this.hooks[r].size}return t},t}(),N=function(){function t(){this.lifecycle=new j,this.plugins=[],this.commonWays={},this.stages={buildDataStage:new R("buildDataStage"),businessStage:new R("businessStage"),sendDataStage:new R("sendDataStage")}}return t.prototype.on=function(t,e){return this.lifecycle.on(t,e)},t.prototype.off=function(t,e){this.lifecycle.off(t,e)},t.prototype.emit=function(t){for(var e,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];(e=this.lifecycle).emit.apply(e,s([t],n,!1))},t.prototype.intercept=function(t,e){this.stages[t].register(e)},t.prototype.invoke=function(t){for(var e,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];(e=this.lifecycle).emit.apply(e,s([t],n,!1))},t.prototype.install=function(t,e){var n=this.plugins.findIndex(function(e){return e.name===t.name});if(n>=0&&(this.uninstall(this.plugins[n]),this.plugins.splice(n,1)),this.plugins.push(t),t.install){var i=r(r({},e),{registry:this,stages:this.stages});try{t.install(i)}catch(e){"undefined"!=typeof console&&console.error&&console.error("[EventTracker] plugin ".concat(t.name," install failed:"),e)}}},t.prototype.uninstall=function(t,e){var n;try{null===(n=t.uninstall)||void 0===n||n.call(t,e)}catch(e){"undefined"!=typeof console&&console.error&&console.error("[EventTracker] plugin ".concat(t.name," uninstall failed:"),e)}},t.prototype.list=function(){return this.plugins.map(function(t){return t.name})},t}(),M="event-tracker",B=function(){function t(){this.bc=null,this.listeners=new Set,this.sourceId="".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,8)),this.localStorageKey="et_channel_".concat(M),this.pollTimer=null,this.initBroadcastChannel(),this.bc||this.initLocalStoragePolling()}return t.prototype.initBroadcastChannel=function(){var t=this;if("undefined"!=typeof BroadcastChannel)try{this.bc=new BroadcastChannel(M),this.bc.onmessage=function(e){var n;(null===(n=e.data)||void 0===n?void 0:n.source)!==t.sourceId&&t.listeners.forEach(function(t){return t(e.data)})}}catch(t){this.bc=null}},t.prototype.initLocalStoragePolling=function(){var t=this;"undefined"!=typeof window&&window.addEventListener("storage",function(e){if(e.key===t.localStorageKey&&e.newValue)try{var n=JSON.parse(e.newValue);if(n.source===t.sourceId)return;t.listeners.forEach(function(t){return t(n)})}catch(t){}})},t.prototype.post=function(t,e){var n={type:t,source:this.sourceId,payload:e};if(this.bc)try{this.bc.postMessage(n)}catch(t){}else try{localStorage.setItem(this.localStorageKey,JSON.stringify(n))}catch(t){}},t.prototype.on=function(t){var e=this;return this.listeners.add(t),function(){return e.listeners.delete(t)}},t.prototype.close=function(){if(this.bc){try{this.bc.close()}catch(t){}this.bc=null}this.listeners.clear(),this.pollTimer&&(clearInterval(this.pollTimer),this.pollTimer=null)},t.prototype.getSourceId=function(){return this.sourceId},t}(),W=function(){function t(t,e){this.config=t,this.logger=e}return t.prototype.backoff=function(t){return Math.min(1e3*Math.pow(2,t),3e4)},t.prototype.execute=function(t){return i(this,arguments,void 0,function(t,e,n){var r,i,s,a,c,u,l,d;return void 0===e&&(e=function(){return!0}),o(this,function(o){switch(o.label){case 0:r=null!==(l=this.config.max_retry_count)&&void 0!==l?l:3,i=null!==(d=this.config.max_retry_duration)&&void 0!==d?d:6e4,s=Date.now(),a=null,c=0,o.label=1;case 1:if(!(c<=r))return[3,8];o.label=2;case 2:return o.trys.push([2,4,,7]),[4,t()];case 3:return o.sent(),[2,{ok:!0,attempts:c+1,finalErr:null}];case 4:return u=o.sent(),e(a=u)?Date.now()-s+this.backoff(c)>i?(this.logger.warn("[EventTracker] max_retry_duration reached, give up"),null==n||n(a,c+1),[2,{ok:!1,attempts:c+1,finalErr:a}]):c<r?[4,this.sleep(this.backoff(c))]:[3,6]:[2,{ok:!1,attempts:c+1,finalErr:a}];case 5:o.sent(),o.label=6;case 6:return[3,7];case 7:return c++,[3,1];case 8:return null==n||n(a,r+1),[2,{ok:!1,attempts:r+1,finalErr:a}]}})})},t.prototype.sleep=function(t){return new Promise(function(e){return setTimeout(e,t)})},t}(),F="et_failed_queue",H=function(){function t(t){var e;void 0===t&&(t={}),this.config={max:null!==(e=t.max)&&void 0!==e?e:50,encryptor:t.encryptor}}return t.prototype.read=function(){if(!a()||!c())return[];try{var t=localStorage.getItem(F);if(!t)return[];var e=JSON.parse(t);return Array.isArray(e)?e:[]}catch(t){return[]}},t.prototype.enqueue=function(t){if(a()&&c()){var e=this.read();e.push(t),e.length>this.config.max&&e.splice(0,e.length-this.config.max);try{this.config.encryptor;var n=JSON.stringify(e);localStorage.setItem(F,n)}catch(t){var r=e.slice(Math.floor(e.length/2));try{localStorage.setItem(F,JSON.stringify(r))}catch(t){}}}},t.prototype.clear=function(){if(a()&&c())try{localStorage.removeItem(F)}catch(t){}},t.prototype.takeAll=function(){var t=this.read();return this.clear(),t},t}(),V=function(t){function e(e,n,r){void 0===r&&(r={});var i=t.call(this,n)||this;return i.name=i.constructor.name,i.code=e,i.cause=r.cause,i.context=r.context,i.timestamp=Date.now(),"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(i,i.constructor),i}return n(e,t),e.prototype.toJSON=function(){return{name:this.name,code:this.code,message:this.message,timestamp:this.timestamp,context:this.context,stack:this.stack}},e}(Error),q=function(t){function e(e,n){return t.call(this,"INIT",e,n)||this}return n(e,t),e}(V),z=function(t){function e(e,n,r){var i=t.call(this,"SEND",e,r)||this;return i.attempts=n,i}return n(e,t),e}(V),J=function(t){function e(e,n){return t.call(this,"ENCRYPT",e,n)||this}return n(e,t),e}(V),K=function(t){function e(e,n){return t.call(this,"IDENTITY",e,n)||this}return n(e,t),e}(V),G=function(t){function e(e,n){return t.call(this,"STORAGE",e,n)||this}return n(e,t),e}(V),Y=function(t){function e(e,n,r){var i=t.call(this,"PLUGIN",n,r)||this;return i.plugin=e,i}return n(e,t),e}(V),Q=function(t){function e(e,n){return t.call(this,"CONFIG",e,n)||this}return n(e,t),e}(V);var X=function(){if("undefined"!=typeof globalThis&&globalThis.TextEncoder)return new globalThis.TextEncoder;var t=require("util").TextEncoder;return globalThis.TextEncoder=t,new t}();function Z(t){if("undefined"!=typeof btoa){for(var e="",n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e)}return Buffer.from(t).toString("base64")}function tt(t,e){for(var n=2166136261,r=3421674724,i=0;i<t.length;i++)n^=t.charCodeAt(i),n=Math.imul(n,16777619)>>>0,r^=e.charCodeAt(i%e.length),r=Math.imul(r,1099511628211)>>>0;return(BigInt(n)<<32n|BigInt(r)).toString(36)}function et(t,e){return i(this,void 0,void 0,function(){var n,r,i;return o(this,function(o){switch(o.label){case 0:return n=function(){var t;if("undefined"!=typeof globalThis&&(null===(t=globalThis.crypto)||void 0===t?void 0:t.subtle))return globalThis.crypto.subtle;var e=require("crypto").webcrypto;return globalThis.crypto=e,e.subtle}(),[4,n.importKey("raw",X.encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign"])];case 1:return r=o.sent(),i=Uint8Array.bind,[4,n.sign("HMAC",r,X.encode(t))];case 2:return[2,Z(new(i.apply(Uint8Array,[void 0,o.sent()])))]}})})}function nt(t,e,n){return i(this,void 0,void 0,function(){var r,i,s;return o(this,function(o){switch(o.label){case 0:return[4,et(t,e)];case 1:if((r=o.sent()).length!==n.length)return[2,!1];for(i=0,s=0;s<r.length;s++)i|=r.charCodeAt(s)^n.charCodeAt(s);return[2,0===i]}})})}function rt(t){var e=this;if(!t)throw new V("IDENTITY","createSignedIdentity: secret is required",{context:{hint:"set config.identity_secret to enable signed identity"}});return{sign:function(e){return tt(e,t)},signAsync:function(e){return et(e,t)},verify:function(e,n){return tt(e,t)===n},verifyAsync:function(e,n){return nt(e,t,n)},encode:function(e){return"".concat(e,"|").concat(tt(e,t))},decode:function(e){var n=e.lastIndexOf("|");if(n<=0)return null;var r=e.slice(0,n),i=e.slice(n+1);return tt(r,t)!==i?null:r},encodeAsync:function(n){return i(e,void 0,void 0,function(){var e,r;return o(this,function(i){switch(i.label){case 0:return r=(e="".concat(n,"|")).concat,[4,et(n,t)];case 1:return[2,r.apply(e,[i.sent()])]}})})},decodeAsync:function(n){return i(e,void 0,void 0,function(){var e,r,i;return o(this,function(o){switch(o.label){case 0:return(e=n.lastIndexOf("|"))<=0?[2,null]:(r=n.slice(0,e),i=n.slice(e+1),[4,nt(r,t,i)]);case 1:return o.sent()?[2,r]:[2,null]}})})}}}var it=function(){function t(t,e,n,r,i,o,s){this.config=t,this.registry=e,this.identity=n,this.presetProps=r,this.retryPolicy=i,this.failedQueue=o,this.logger=s,this.pending=[],this.senders=[],this.abortControllers=new Map}return t.prototype.setSenders=function(t){this.senders=t},t.prototype.setBatchSender=function(t){this.batchSender=t},t.prototype.buildEvent=function(t,e){var n,r;void 0===e&&(e={});var i=(null===(r=(n=this.config).get_client_timestamp)||void 0===r?void 0:r.call(n))||Date.now(),o=this.presetProps.build(this.config,e.properties||{}),s={type:t,time:i,distinct_id:this.identity.getDistinctId(),anonymous_id:this.identity.getAnonymousId(),first_id:this.identity.getFirstId(),login_id:this.identity.getLoginId()||void 0,original_id:this.identity.getOriginalId()||void 0,properties:o,lib:{$lib:this.config.lib_name||m,$lib_version:this.config.lib_version||b},token:this.config.app_id,project:this.config.app_id};return e.event&&(s.event=e.event),s},t.prototype.send=function(t,e){var n=this;if(this.config.disabled)null==e||e(null);else{this.registry.invoke("sdkInitAPI",t);var r=this.config.encryptEvent;if(r)try{var i=r(t);i&&"object"==typeof i&&(t=i)}catch(t){this.logger.error("encryptEvent hook failed:",t)}if(this.config.encryptor)try{var o=this.config.encryptor(JSON.stringify(t));"string"==typeof o?(t._encrypted=o,this.dispatchAfterEncrypt(t,e)):o.then(function(r){t._encrypted=r,n.dispatchAfterEncrypt(t,e)},function(r){n.logger.error(new J("async encryptor failed",{cause:r})),n.dispatchAfterEncrypt(t,e)})}catch(n){this.logger.error(new J("encryptor threw",{cause:n})),this.dispatchAfterEncrypt(t,e)}else this.dispatchAfterEncrypt(t,e)}},t.prototype.dispatchAfterEncrypt=function(t,e){var n=this;if(t.properties=this.registry.stages.sendDataStage.run(t.properties,this),"batch"===this.config.send_type&&this.batchSender){var r=Promise.resolve(this.batchSender.send(t,{config:this.config,logger:this.logger})).then(function(){return null==e?void 0:e(null)}).catch(function(t){return null==e?void 0:e(t)});this.trackPending(r)}else{var i=this.pickSender(),o=this.retryPolicy.execute(function(){return Promise.resolve(i.send(t,{config:n.config,logger:n.logger}))},function(){return!0},function(e){n.failedQueue.enqueue(t),n.logger.warn("event send failed, queued:",e.message)}).then(function(t){null==e||e(t.ok?null:t.finalErr)});this.trackPending(o)}},t.prototype.pickSender=function(){var t=this.config.send_type;if(t&&"batch"!==t){var e=this.senders.find(function(e){return e.name===t&&e.canUse()});if(e)return e}return this.senders.find(function(t){return"beacon"===t.name&&t.canUse()})||this.senders.find(function(t){return"ajax"===t.name&&t.canUse()})||this.senders.find(function(t){return"image"===t.name&&t.canUse()})||this.senders[0]},t.prototype.trackPending=function(t){var e={promise:t,resolve:function(){},reject:function(){}};new Promise(function(t,n){e.resolve=t,e.reject=n}),t.then(function(){return e.resolve()},function(t){return e.reject(t)}),this.pending.push(e)},t.prototype.flush=function(){return i(this,void 0,void 0,function(){var t;return o(this,function(e){switch(e.label){case 0:if(!this.batchSender)return[3,4];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.batchSender.flush({config:this.config,logger:this.logger})];case 2:return e.sent(),[3,4];case 3:return t=e.sent(),this.logger.warn("batch flush failed:",t),[3,4];case 4:return[4,this.waitUntilIdle()];case 5:return e.sent(),[2]}})})},t.prototype.waitUntilIdle=function(){return i(this,void 0,void 0,function(){var t;return o(this,function(e){switch(e.label){case 0:return this.pending.length?(t=this.pending.splice(0),[4,Promise.allSettled(t.map(function(t){return t.promise}))]):[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}})})},t.prototype.abortAll=function(t){for(var e=0,n=this.abortControllers;e<n.length;e++){n[e][1].abort(t)}this.abortControllers.clear(),this.pending=[]},t.prototype.takeAbortController=function(t){var e=new AbortController;return this.abortControllers.set(t,e),e},t.prototype.releaseAbortController=function(t){this.abortControllers.delete(t)},t}(),ot={send_type:"image",max_retry_count:3,debug:0,storage_type:"memory",is_collect_utm:!0,send_timeout:5e3,max_retry_duration:3e4},st=function(){function t(){this.lib_name=m,this.lib_version=b,this.DEFAULT_SEND_TYPE="image",this._senders=[],this._inited=!1,this.__noop=function(){},this.instanceId="".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,8))}return t.prototype.init=function(t){var e;if(this._inited)null===(e=this._logger)||void 0===e||e.warn("EventTracker already initialized, re-init ignored");else{if(this._config=r(r({},ot),t),this._config.lib_name=this._config.lib_name||m,this._config.lib_version=this._config.lib_version||b,!this._config.server_url)throw new q("server_url is required");if(!this._config.app_id)throw new q("app_id is required");var n,i;this._logger=new d({debug:this._config.debug,show_log:this._config.show_log}),this._store=A({cookieDomain:this._config.cookie_domain,cookieCrossSubdomain:this._config.cookie_cross_subdomain,secureCookie:this._config.secure_cookie}),this._config.identity_secret&&(this._signedIdentity=rt(this._config.identity_secret)),this._identity=new y(this._store,{getDistinctId:this._config.get_distinct_id,setDistinctId:this._config.set_distinct_id,getAnonymousId:this._config.get_anonymous_id,setAnonymousId:this._config.set_anonymous_id,getFirstId:this._config.get_first_id,setFirstId:this._config.set_first_id}),this._presetProps=new w,this._config.preset_properties&&this._presetProps.setPreset(this._config.preset_properties),this._registry=new N,this._channel=new B,this._retryPolicy=new W(this._config,this._logger),this._failedQueue=new H({max:200,encryptor:this._config.encryptor}),this._senders=[new x,new L,new C],this._batchSender=new U,this._pipeline=new it(this._config,this._registry,this._identity,this._presetProps,this._retryPolicy,this._failedQueue,this._logger),this._pipeline.setSenders(this._senders),this._pipeline.setBatchSender(this._batchSender),"batch"===this._config.send_type&&this._batchSender.start({config:this._config,logger:this._logger}),n=this,i=this._presetProps,n._registerAttached||(n._registerAttached=!0,n.register=function(t){return i.register(t),this},n.registerOnce=function(t){return i.registerOnce(t),this},n.clearAllRegister=function(){return i.clearRegister(),this},n.unsetRegister=function(t){return i.unsetRegister(t),this},n.registerPage=function(t){return i.registerOnce(t),this},n.registerSession=function(t){return i.register(t),this},n.registerSessionOnce=function(t){return i.registerOnce(t),this}),function(t,e){t._identityAttached||(t._identityAttached=!0,t.identify=function(n,r){return void 0===r&&(r=!0),e.identify(n,r),t.getRegistry().invoke("changeDistinctId",n),this},t.login=function(n){return e.login(n),t.getRegistry().invoke("changeDistinctId",n),this},t.logout=function(n){return e.resetAnonymousIdentity(n),t.getRegistry().invoke("changeDistinctId",e.getDistinctId()),this},t.resetAnonymousIdentity=t.logout,t.alias=function(n,r){(r||e.getDistinctId())!==n&&(e.identify(n,!0),t.track("$SignUp",{$signup_method:"alias"}),t.getRegistry().invoke("changeDistinctId",n))},t.getDistinctId=function(){return e.getDistinctId()},t.getAnonymousId=function(){return e.getAnonymousId()},t.getFirstId=function(){return e.getFirstId()},t.getLoginId=function(){return e.getLoginId()},t.getOriginalId=function(){return e.getOriginalId()})}(this,this._identity),function(t,e){if(!t._profileAttached){t._profileAttached=!0;var n=function(t,n,r){var i=e.buildEvent(t,{properties:n});e.send(i,r)};t.setProfile=function(t,e){return n("profile_set",t,e)},t.setOnceProfile=function(t,e){return n("profile_set_once",t,e)},t.incrementProfile=function(t,e){return n("profile_increment",t,e)},t.appendProfile=function(t,e){return n("profile_append",t,e)},t.unsetProfile=function(t,e){var r;return n("profile_unset",((r={})[t]=!0,r),e)},t.deleteProfile=function(t){return n("profile_delete",{},t)}}}(this,this._pipeline),function(t,e){t._trackAttached||(t._trackAttached=!0,t.track=function(t,n,r){void 0===n&&(n={});var i=e.buildEvent("track",{event:t,properties:n});e.send(i,r)},t.trackSignup=function(n,i,o){void 0===i&&(i={});var s=e.buildEvent("track_signup",{event:"$SignUp",properties:r(r({},i),{$signup_method:i.$signup_method||""})});s.original_id=t.getOriginalId(),t.identify(n,!0),s.distinct_id=n,s.login_id=n,e.send(s,o)},t.trackLinkage=function(e,n){t.track("$Linkage",e,n)},t.trackLink=function(e,n,i){if(void 0===n&&(n={}),a()){var o="string"==typeof e?document.querySelector(e):e;o&&o.addEventListener("click",function(){t.track("$WebClick",r(r({},n),{$element_selector:o.id?"#".concat(o.id):o.tagName.toLowerCase(),$element_target_url:o instanceof HTMLAnchorElement?o.href:void 0}),i)},{once:!0})}},t.trackLinks=function(e,n,r){if(void 0===n&&(n={}),a())for(var i=0,o=("string"==typeof e?Array.from(document.querySelectorAll(e)):e&&"length"in e&&!("click"in e)?Array.from(e):e);i<o.length;i++){var s=o[i];t.trackLink(s,n,r)}},t.trackHeatMap=function(e,n){return t.track("$heatmap_event",e,n)},t.trackWebClick=function(e,n){return t.track("$WebClick",e,n)},t.trackWebStay=function(e,n){return t.track("$WebStay",e,n)})}(this,this._pipeline),this._registry.invoke("sdkReady",this._config),this._registry.invoke("sdkInitPara",this._config),this._inited=!0,this._logger.log("EventTracker initialized:",{app_id:this._config.app_id,send_type:this._config.send_type}),this._registry.invoke("sdkAfterInitPara",this._config),this._registry.invoke("sdkInitAPI",this),this._registry.invoke("sdkAfterInitAPI",this)}},t.prototype.use=function(t){var e=this;if(!this._inited)return setTimeout(function(){return e.use(t)},0),this;var n={config:this._config,registry:this._registry,stages:this._registry.stages,sdk:this,kit:{},channel:this._channel,store:this._store,uninstall:function(){return e._registry.uninstall(t,n)}};return this._registry.install(t,n),this},t.prototype.track=function(t,e,n){},t.prototype.trackSignup=function(t,e,n){},t.prototype.trackLinkage=function(t,e){},t.prototype.trackLink=function(t,e,n){},t.prototype.trackLinks=function(t,e,n){},t.prototype.trackHeatMap=function(t,e){},t.prototype.trackWebClick=function(t,e){},t.prototype.trackWebStay=function(t,e){},t.prototype.identify=function(t,e){return this},t.prototype.login=function(t){return this},t.prototype.logout=function(t){return this},t.prototype.resetAnonymousIdentity=function(t){return this},t.prototype.alias=function(t,e){},t.prototype.getDistinctId=function(){return""},t.prototype.getAnonymousId=function(){return""},t.prototype.getFirstId=function(){return""},t.prototype.getLoginId=function(){return""},t.prototype.getOriginalId=function(){return""},t.prototype.register=function(t){return this},t.prototype.registerOnce=function(t){return this},t.prototype.clearAllRegister=function(){return this},t.prototype.unsetRegister=function(t){return this},t.prototype.registerPage=function(t){return this},t.prototype.registerSession=function(t){return this},t.prototype.registerSessionOnce=function(t){return this},t.prototype.setProfile=function(t,e){},t.prototype.setOnceProfile=function(t,e){},t.prototype.incrementProfile=function(t,e){},t.prototype.appendProfile=function(t,e){},t.prototype.unsetProfile=function(t,e){},t.prototype.deleteProfile=function(t){},t.prototype.disable=function(){return this._config.disabled=!0,this._logger.warn("EventTracker disabled"),this},t.prototype.enable=function(){return this._config.disabled=!1,this},t.prototype.setServerURL=function(t){return this.switchServer(t)},t.prototype.switchServer=function(t){return t?(this._config.server_url=t,this._registry.invoke("switch",t),this):this},t.prototype.flush=function(){return i(this,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:return this._inited?[4,this._pipeline.flush()]:[2];case 1:return t.sent(),[2]}})})},t.prototype.waitUntilIdle=function(){return i(this,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:return this._inited?[4,this._pipeline.waitUntilIdle()]:[2];case 1:return t.sent(),[2]}})})},t.prototype.abort=function(t){this._pipeline.abortAll(t)},t.prototype.close=function(){var t,e;null===(t=this._batchSender)||void 0===t||t.stop(),null===(e=this._channel)||void 0===e||e.close(),this.abort("closed")},t.prototype.uuid=function(){return l()},t.prototype.getPresetProperties=function(){return this._presetProps.build(this._config,{})},t.prototype.shutdown=function(){this.close()},t.prototype.getConfig=function(){return r({},this._config)},t.prototype.getLogger=function(){return this._logger},t.prototype.getRegistry=function(){return this._registry},t.prototype.getRetryPolicy=function(){return this._retryPolicy},t.prototype.getFailedQueue=function(){return this._failedQueue},t.prototype.getChannel=function(){return this._channel},t.prototype.getPipeline=function(){return this._pipeline},t.prototype.getSignedIdentity=function(){return this._signedIdentity},t.prototype.isBrowser=function(){return a()},t.prototype.isInitialized=function(){return this._inited},t}(),at=new Map;"undefined"!=typeof window&&(window.eventTracker=new st);var ct="et_session_id",ut="et_session_last_active";function lt(t){return function(e){return function(t,e){for(var n=e||"default",r="",i=0;i<t.length;i++)r+=String.fromCharCode(t.charCodeAt(i)^n.charCodeAt(i%n.length));return"undefined"!=typeof btoa?btoa(r):Buffer.from(r,"binary").toString("base64")}(e,t)}}function dt(t){return function(e){for(var n="undefined"!=typeof atob?atob(e):Buffer.from(e,"base64").toString("binary"),r="",i=t||"default",o=0;o<n.length;o++)r+=String.fromCharCode(n.charCodeAt(o)^i.charCodeAt(o%i.length));return r}}var ft=new TextEncoder,pt=new TextDecoder;function ht(t){if("undefined"!=typeof btoa){for(var e="",n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e)}return Buffer.from(t).toString("base64")}function gt(t){return i(this,void 0,void 0,function(){var e,n;return o(this,function(r){switch(r.label){case 0:return[4,(e=yt()).digest("SHA-256",ft.encode(t))];case 1:return n=r.sent(),[2,e.importKey("raw",n,{name:"AES-GCM"},!1,["encrypt","decrypt"])]}})})}function yt(){var t;if("undefined"!=typeof globalThis&&(null===(t=globalThis.crypto)||void 0===t?void 0:t.subtle))return globalThis.crypto.subtle;try{var e=require("crypto").webcrypto;return globalThis.crypto=e,e.subtle}catch(t){throw new Error("[encrypt] Web Crypto API not available (need https/localhost or Node 18+)")}}function vt(t){return{name:"encryptor",install:function(e){var n=e.sdk,r=e.config;r.encryptor=t.encrypt,r.decoder=t.decrypt;var i=r;i.encryptEvent=t.encryptEvent,i.decryptEvent=t.decryptEvent;var o=n;o.__encryptor=t.encrypt,o.__decoder=t.decrypt,o.__encryptEvent=t.encryptEvent,o.__decryptEvent=t.decryptEvent},uninstall:function(t){if(t){var e=t.config,n=t.sdk;delete e.encryptor,delete e.decoder;var r=e;delete r.encryptEvent,delete r.decryptEvent;var i=n;delete i.__encryptor,delete i.__decoder,delete i.__encryptEvent,delete i.__decryptEvent}}}}var _t=new st;"undefined"!=typeof window&&(window.eventTracker=_t),t.ConfigError=Q,t.EncryptError=J,t.EventTracker=st,t.FailedQueue=H,t.IdentityError=K,t.IdentityManager=y,t.InitError=q,t.InstanceChannel=B,t.LIB_NAME=m,t.LIB_VERSION=b,t.Logger=d,t.PluginError=Y,t.PluginRegistry=N,t.PresetEvent=v,t.PresetProperty=_,t.PresetPropertyBuilder=w,t.RetryPolicy=W,t.SDKError=V,t.SendError=z,t.SendPipeline=it,t.StorageError=G,t.aesGcmDecryptAsync=function(t){var e=this,n=null;return function(r){return i(e,void 0,void 0,function(){var e,i,s,a,c,u;return o(this,function(o){switch(o.label){case 0:return n||(n=gt(t)),[4,n];case 1:return e=o.sent(),i=yt(),s=function(t){if("undefined"!=typeof atob){for(var e=atob(t),n=new Uint8Array(e.length),r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}return new Uint8Array(Buffer.from(t,"base64"))}(r),a=s.slice(0,12),c=s.slice(12),[4,i.decrypt({name:"AES-GCM",iv:a},e,c)];case 2:return u=o.sent(),[2,pt.decode(u)]}})})}},t.aesGcmEncryptAsync=function(t){var e=this,n=null;return function(r){return i(e,void 0,void 0,function(){var e,i,s,a,c,u;return o(this,function(o){switch(o.label){case 0:return n||(n=gt(t)),[4,n];case 1:return e=o.sent(),i=yt(),s=globalThis.crypto.getRandomValues(new Uint8Array(12)),c=Uint8Array.bind,[4,i.encrypt({name:"AES-GCM",iv:s},e,ft.encode(r))];case 2:return a=new(c.apply(Uint8Array,[void 0,o.sent()])),(u=new Uint8Array(s.length+a.length)).set(s,0),u.set(a,s.length),[2,ht(u)]}})})}},t.autoTrack=function(t){var e;void 0===t&&(t={});var n=null,r=Date.now(),i=new Set,o=null!==(e=t.scrollThresholds)&&void 0!==e?e:[25,50,75,100];function s(t,e){void 0===e&&(e={}),n&&n.track(t,e)}function c(){try{return location.pathname+location.search+location.hash}catch(t){return""}}function u(t,e){document.addEventListener("click",function(n){var r,i=n.target;if(i){var o=i.closest(t||"a, button, [data-track-click]");if(o){var a=((r={})[_.ElementSelector]=function(t){if(t.id)return"#".concat(t.id);var e=[],n=t,r=function(){var t=n,r=t.tagName.toLowerCase();t.classList&&t.classList.length&&(r+="."+Array.from(t.classList).slice(0,2).join("."));var i=t.parentElement;if(i){var o=Array.from(i.children).filter(function(e){return e instanceof Element&&e.tagName===t.tagName});o.length>1&&(r+=":nth-of-type(".concat(o.indexOf(t)+1,")"))}e.unshift(r),n=i};for(;n&&n!==document.body&&e.length<5;)r();return e.join(" > ")}(o),r[_.ElementType]=o.tagName.toLowerCase(),r[_.ElementContent]=(o.textContent||"").trim().slice(0,100),r[_.ElementId]=o.id||void 0,r[_.ElementClassName]=o.className||void 0,r);o instanceof HTMLAnchorElement&&(a.$element_href=o.href);for(var c=0,u=e;c<u.length;c++){var l=u[c],d=o.getAttribute(l);null!=d&&(a[l]=d)}s(v.WebClick,a)}}},!0)}function l(){var t=function(){var t,e=Date.now()-r;s(v.WebStay,((t={})[_.EventDuration]=e,t[_.URLPath]=c(),t))};window.addEventListener("beforeunload",t),document.addEventListener("visibilitychange",function(){"hidden"===document.visibilityState?t():r=Date.now()})}return{name:"auto-track",install:function(e){var r=e.sdk;a()&&(n=r,!1!==t.pageview&&function(){var t=function(){var t;s(v.PageView,((t={})[_.URLPath]=c(),t[_.Title]=document.title,t[_.Referrer]=document.referrer,t))};setTimeout(t,0);var e=function(e){var n=history[e];history[e]=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var i=n.apply(this,e);return setTimeout(t,0),i}};e("pushState"),e("replaceState"),window.addEventListener("popstate",function(){return setTimeout(t,0)}),window.addEventListener("hashchange",function(){return setTimeout(t,0)})}(),!1!==t.webclick&&u(t.webclickSelector,t.webclickAttrs||["data-track-id","data-sensors-click"]),!1!==t.webstay&&l(),t.scrolldepth&&(i=new Set,window.addEventListener("scroll",function(){var t,e=document.documentElement.scrollHeight-window.innerHeight;if(!(e<=0))for(var n=Math.min(100,Math.round(window.scrollY/e*100)),r=0,a=o;r<a.length;r++){var u=a[r];n>=u&&!i.has(u)&&(i.add(u),s("$scroll_depth",((t={percent:u})[_.URLPath]=c(),t)))}},{passive:!0})))}}},t.createSignedIdentity=rt,t.debugSender=function(t){return void 0===t&&(t={}),{name:"debug-sender",install:function(e){var n,r,i,o,s,a=e.config,c=e.stages,l=e.registry,d=e.sdk;if(null!==(n=t.enable)&&void 0!==n?n:!!a.debug_mode){var f,p,h=null!==(i=null!==(r=t.url)&&void 0!==r?r:a.debug_mode_url)&&void 0!==i?i:(f=a.server_url,(p=Array.isArray(f)?f[0]:f).includes("?")?p+"&debug":p+"?debug"),g=null!==(s=null!==(o=t.upload)&&void 0!==o?o:a.debug_mode_upload)&&void 0!==s?s:"true";c.sendDataStage.register({name:"debug-sender",priority:30,entry:function(e){var n=e.data;try{var r=$(n,a.encryptor);Promise.resolve(r).then(function(r){var i=T(h,r);if(u()){var o=new Image(1,1);o.onload=function(){var e;try{null===(e=t.onSuccess)||void 0===e||e.call(t,n)}catch(t){}try{"undefined"!=typeof alert&&alert("debug数据发送成功"+(n.event||""))}catch(t){}},o.onerror=function(){var e,r=new Error("Image load failed");try{null===(e=t.onError)||void 0===e||e.call(t,r,n)}catch(t){}try{"undefined"!=typeof alert&&alert("debug失败 错误原因"+JSON.stringify({message:r.message}))}catch(t){}},o.src=i}else e.cancellationToken.stop()}).catch(function(t){d.getLogger().error("debug-sender error:",t)})}catch(t){d.getLogger().error("debug-sender error:",t)}return n}}),l.on("sdkAfterInitAPI",function(){Object.defineProperty(globalThis,"__et_debug_upload__",{value:g,writable:!0})})}},uninstall:function(){try{delete globalThis.__et_debug_upload__}catch(t){}}}},t.default=_t,t.defaultDecryptor=dt,t.defaultEncryptor=lt,t.encryptor=vt,t.exposure=function(t){void 0===t&&(t={});var e=null,n=null,r=new WeakSet;function i(){var i,o;if("IntersectionObserver"in window){var s=null!==(i=t.threshold)&&void 0!==i?i:.5,a=null!==(o=t.duration)&&void 0!==o?o:500;if(n=new IntersectionObserver(function(n){for(var i=function(n){if(n.intersectionRatio>=s){var i=n.target,o=setTimeout(function(){var o;if(!r.has(i)&&(r.add(i),e)){var s=((o={})[_.ElementSelector]=function(t){if(t.id)return"#".concat(t.id);for(var e=[],n=t;n&&n!==document.body&&e.length<5;){var r=n.tagName.toLowerCase();n.classList&&n.classList.length&&(r+="."+Array.from(n.classList).slice(0,2).join(".")),e.unshift(r),n=n.parentElement}return e.join(" > ")}(i),o[_.ElementType]=i.tagName.toLowerCase(),o.$intersection_ratio=n.intersectionRatio,o.$exposure_duration=a,o);if(i instanceof HTMLElement&&i.dataset)for(var c=t.attrPrefix||"data-exp-",u=0,l=Object.keys(i.dataset);u<l.length;u++){var d=l[u];d.startsWith(c)&&(s[d]=i.dataset[d])}e.track(v.ElementExposure,s)}},a),c=function(){clearTimeout(o),i.removeEventListener("mouseleave",c)};i.addEventListener("mouseleave",c)}},o=0,c=n;o<c.length;o++){i(c[o])}},{threshold:[s]}),t.selector)document.querySelectorAll(t.selector).forEach(function(t){return n.observe(t)})}}return{name:"exposure",install:function(t){var n=t.sdk;a()&&(e=n,"complete"===document.readyState?i():window.addEventListener("load",i,{once:!0}))},uninstall:function(){null==n||n.disconnect(),n=null,e=null}}},t.hmacSignAsync=et,t.hmacVerifyAsync=nt,t.indexedDBSender=function(t){void 0===t&&(t={});var e=t.dbName||"event-tracker-outbox",n=t.storeName||"outbox",r=t.max||500,i=null,o={name:"indexeddb-sender",priority:60,entry:function(t){if("sendDataStage"===t.meta.stage){var o=t.data;return null!=i||(i=a()&&"undefined"!=typeof indexedDB?new Promise(function(t){try{var r=indexedDB.open(e,1);r.onupgradeneeded=function(){var t=r.result;t.objectStoreNames.contains(n)||t.createObjectStore(n,{autoIncrement:!0})},r.onsuccess=function(){return t(r.result)},r.onerror=function(){return t(null)}}catch(e){t(null)}}):Promise.resolve(null)),i.then(function(t){if(t)try{var e=t.transaction(n,"readwrite").objectStore(n),i=$(o),s=e.count();s.onsuccess=function(){s.result>=r&&e.delete(IDBKeyRange.lowerBound(0,!0)),e.add({time:Date.now(),payload:i})}}catch(t){}}).catch(function(){}),o}}};return{name:"indexeddb-sender",install:function(t){var e=t.stages;a()&&e.sendDataStage.register(o)},uninstall:function(){i=null}}},t.initPara=function(t){var e=t.client_id||"instance-".concat(at.size+1),n=at.get(e);return n?(n.switchServer(t.server_url),t.app_id&&(n.getConfig().app_id=t.app_id),n):((n=new st).init(t),at.set(e,n),n)},t.isSDKError=function(t){return t instanceof V},t.listInstances=function(){return Array.from(at.values())},t.pageLeave=function(t){var e=null,n=Date.now();function r(t){var r;if(e){var i=Date.now()-n;e.track(v.WebPageLeave,((r={})[_.EventDuration]=i,r[_.URLPath]=location.pathname+location.search+location.hash,r[_.Title]=document.title,r[_.ViewportPosition]=window.scrollY||0,r.$page_leave_reason=t,r))}}return{name:"pageleave",install:function(t){var i=t.sdk;if(a()){e=i,n=Date.now();document.addEventListener("visibilitychange",function(){"visible"===document.visibilityState&&(n=Date.now())}),window.addEventListener("pagehide",function(){return r("pagehide")}),window.addEventListener("beforeunload",function(){return r("unload")}),document.addEventListener("visibilitychange",function(){"hidden"===document.visibilityState&&r("hidden")})}},uninstall:function(){e=null}}},t.pageLoad=function(t){void 0===t&&(t={});var e=null;function n(){var t;if(e){var n=((t={})[_.URLPath]=location.pathname+location.search+location.hash,t[_.Title]=document.title,t);try{var r="undefined"!=typeof performance?performance:null;if(r){var i=r.getEntriesByType("navigation")[0];i&&("number"==typeof i.domContentLoadedEventEnd&&(n.$dom_ready_time=Math.round(i.domContentLoadedEventEnd-i.startTime)),"number"==typeof i.domInteractive&&(n.$dom_interactive_time=Math.round(i.domInteractive-i.startTime)),"number"==typeof i.loadEventEnd&&"number"==typeof i.startTime&&(n.$load_time=Math.round(i.loadEventEnd-i.startTime)),"number"==typeof i.responseEnd&&"number"==typeof i.requestStart&&(n.$response_time=Math.round(i.responseEnd-i.requestStart)),"number"==typeof i.transferSize&&(n[_.PageResourceSize]=i.transferSize));var o=r.getEntriesByName("first-paint")[0],s=r.getEntriesByName("first-contentful-paint")[0];o&&(n.$first_paint=Math.round(o.startTime)),s&&(n.$first_contentful_paint=Math.round(s.startTime))}}catch(t){}try{document.documentElement&&(n[_.PageHeight]=document.documentElement.scrollHeight,n[_.ViewportPosition]=window.scrollY||0)}catch(t){}e.track(v.WebPageLoad,n)}}return{name:"pageload",install:function(r){var i=r.sdk;if(a()){e=i;var o=!1!==t.immediate;"complete"===document.readyState?o?n():window.addEventListener("load",n,{once:!0}):window.addEventListener("load",function(){o?n():setTimeout(n,0)},{once:!0})}}}},t.registerAppid=function(t){return at.get(t)},t.sessionEvent=function(t){var e;void 0===t&&(t={});var n=null!==(e=t.timeout)&&void 0!==e?e:18e5,r=null,i=null,o="",s=0;function c(t){o=l(),s=Date.now(),i&&(i.set(ct,o),i.set(ut,String(s))),r&&"start"===t&&r.track("$session_start",{$event_session_id:o})}var u={name:"session-event",priority:10,entry:function(t){if("buildDataStage"===t.meta.stage){var e;e=Date.now(),(!o||s&&e-s>n)&&c(e-s>n?"timeout":"start"),s=e,i&&i.set(ut,String(s));var r=t.data;r&&r.properties&&(r.properties[_.EventSessionId]=o)}}};return{name:"session-event",install:function(t){var e=t.sdk,l=t.stages,d=t.store;if(a()){r=e,i=d;var f=d.get(ct),p=Number(d.get(ut)||"0");f&&p&&Date.now()-p<n?(o=f,s=p):c("start"),l.buildDataStage.register(u),window.addEventListener("storage",function(t){t.key!==ct||t.newValue||(o="")})}},uninstall:function(){r=null,i=null}}},t.tracker=_t,t.webviewBridge=function(t){return void 0===t&&(t={}),{name:"webview-bridge",install:function(e){var n=e.sdk,r=e.config;if(a()){var i=window[t.defineName||"vapph5define"];if(i&&"function"==typeof i.call){var o={call:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return i.call.apply(i,s([t],e,!1))},on:function(t,e){return i.handle(t,e)},isInApp:function(){return!0===i.isInApp||!0===i.call("isInApp")}};if(n.bridge=o,r.is_webview=!0,!1!==t.fetchOnInit)try{var c=t.protocolName||"getAppInfo",u=i.call(c);if(u&&"object"==typeof u){for(var l=t.fieldMap||{},d=0,f=Object.entries(l);d<f.length;d++){var p=f[d],h=p[0],g=u[p[1]];null!=g&&(r[h]=g)}n.register({$app_version:u.app_version||u.appVersion,$app_id:u.app_id||u.appId,$channel:u.channel,$lib:u.lib||u.lib_name||u.libName})}}catch(t){}}}}}},t.xorEncryptor=function(t){return vt({encrypt:lt(t),decrypt:dt(t)})},Object.defineProperty(t,"__esModule",{value:!0})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).EventTracker={})}(this,function(t){"use strict";var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},r.apply(this,arguments)};function i(t,e,n,r){return new(n||(n=Promise))(function(i,o){function s(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}Object.create;function s(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}Object.create;"function"==typeof SuppressedError&&SuppressedError;function a(){return"undefined"!=typeof window&&void 0!==window.document}function c(){try{if(!a()||!window.localStorage)return!1;var t="__et_test__";return window.localStorage.setItem(t,"1"),window.localStorage.removeItem(t),!0}catch(t){return!1}}function u(){return a()&&"function"==typeof Image}function l(){if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues){var t=new Uint8Array(16);crypto.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128;var e=Array.from(t,function(t){return t.toString(16).padStart(2,"0")});return e.slice(0,4).join("")+"-"+e.slice(4,6).join("")+"-"+e.slice(6,8).join("")+"-"+e.slice(8,10).join("")+"-"+e.slice(10,16).join("")}var n=Date.now(),r="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random();return n>0?(e=(n+e)%16|0,n=Math.floor(n/16)):(e=(r+e)%16|0,r=Math.floor(r/16)),("x"===t?e:3&e|8).toString(16)})}var d=function(){function t(t){this.config=t}return t.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog("log",t)&&this.out("log",t)},t.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog("warn",t)&&this.out("warn",t)},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.shouldLog("error",t)&&this.out("error",t)},t.prototype.shouldLog=function(t,e){if(2===this.config.debug){if("error"===t)throw e[0]instanceof Error?e[0]:new Error(String(e[0]));return!0}return 1===this.config.debug&&("warn"===t||"error"===t)||!(!this.config.show_log||"log"!==t)},t.prototype.out=function(t,e){var n="undefined"!=typeof console&&console[t]?console[t]:console.log;try{n.call.apply(n,s([console,"[EventTracker]"],e,!1))}catch(t){}},t}(),f="et_distinct_id",h="et_anonymous_id",p="et_login_id",g="et_original_id",v=function(){function t(t,e){void 0===e&&(e={});var n=this;this.store=t,this.opts=e,this.loginId="",this.originalId="",this.anonymousId=this.readOrCreate(h,function(){return l()},this.opts.getAnonymousId,this.opts.setAnonymousId),this.firstId=this.readOrCreate("et_first_id",function(){return l()},this.opts.getFirstId,this.opts.setFirstId),this.distinctId=this.readOrCreate(f,function(){return n.anonymousId},this.opts.getDistinctId,this.opts.setDistinctId)}return t.prototype.readOrCreate=function(t,e,n,r){if(n)try{var i=n();if(i)return i}catch(t){}var o=this.store.get(t);if(o)return o;var s=e();return this.persist(t,s,r),s},t.prototype.persist=function(t,e,n){if(n)try{return void n(e)}catch(t){}this.store.set(t,e)},t.prototype.getDistinctId=function(){return this.distinctId},t.prototype.getAnonymousId=function(){return this.anonymousId},t.prototype.getFirstId=function(){return this.firstId},t.prototype.getLoginId=function(){return this.loginId},t.prototype.getOriginalId=function(){return this.originalId},t.prototype.identify=function(t,e){if(void 0===e&&(e=!0),t!==this.loginId){var n=this.distinctId;this.distinctId=t,this.loginId=t,this.originalId=n,this.persist(f,t,this.opts.setDistinctId),e?this.persist(p,t):this.store.remove(p),this.persist(g,n)}},t.prototype.resetAnonymousIdentity=function(t){this.distinctId=t||this.anonymousId,this.loginId="",this.originalId="",this.persist(f,this.distinctId,this.opts.setDistinctId),this.store.remove(p),this.store.remove(g),t&&(this.anonymousId=t,this.persist(h,t,this.opts.setAnonymousId))},t.prototype.login=function(t){this.identify(t,!0)},t.prototype.logout=function(){this.resetAnonymousIdentity()},t}(),y={PageView:"$pageview",WebPageLoad:"$WebPageLoad",WebPageLeave:"$WebPageLeave",WebClick:"$WebClick",WebStay:"$WebStay",SignUp:"$SignUp",BindID:"$BindID",UnbindID:"$UnbindID",ABTestTrigger:"$ABTestTrigger",PlanPopupClick:"$PlanPopupClick",PlanPopupDisplay:"$PlanPopupDisplay",ChannelLinkReaching:"$ChannelLinkReaching",ElementExposure:"$element_exposure",ScrollDepth:"$scrolldepth",ExitClick:"$exit_click",PageLeave:"$page_leave",HeatmapEvent:"$heatmap_event"},m={AppId:"$app_id",AppVersion:"$app_version",Lib:"$lib",LibMethod:"$lib_method",LibDetail:"$lib_detail",LibVersion:"$lib_version",ScreenWidth:"$screen_width",ScreenHeight:"$screen_height",ViewportWidth:"$viewport_width",ViewportHeight:"$viewport_height",TimezoneOffset:"$timezone_offset",UserAgent:"$user_agent",Language:"$language",FirstBrowserCharset:"$first_browser_charset",FirstBrowserLanguage:"$first_browser_language",URL:"$url",URLPath:"$url_path",Title:"$title",Referrer:"$referrer",ReferrerHost:"$referrer_host",LatestReferrer:"$latest_referrer",LatestReferrerHost:"$latest_referrer_host",LatestLandingPage:"$latest_landing_page",LatestSearchKeyword:"$latest_search_keyword",LatestTrafficSourceType:"$latest_traffic_source_type",FirstReferrer:"$first_referrer",FirstReferrerHost:"$first_referrer_host",FirstSearchKeyword:"$first_search_keyword",FirstTrafficSourceType:"$first_traffic_source_type",FirstVisitTime:"$first_visit_time",SearchKeywordId:"$search_keyword_id",SearchKeywordIdHash:"$search_keyword_id_hash",SearchKeywordIdType:"$search_keyword_id_type",IsFirstDay:"$is_first_day",IsFirstTime:"$is_first_time",LatestUtmSource:"$latest_utm_source",LatestUtmMedium:"$latest_utm_medium",LatestUtmCampaign:"$latest_utm_campaign",LatestUtmContent:"$latest_utm_content",LatestUtmTerm:"$latest_utm_term",Utms:"$utms",DistinctId:"$distinct_id",AnonymousId:"$anonymous_id",FirstId:"$first_id",OriginalId:"$original_id",LoginId:"$login_id",IsLoginId:"$is_login_id",IdentityLoginId:"$identity_login_id",IdentityAnonymousId:"$identity_anonymous_id",IdentityCookieId:"$identity_cookie_id",IdentityEmail:"$identity_email",IdentityMobile:"$identity_mobile",ElementSelector:"$element_selector",ElementPath:"$element_path",ElementType:"$element_type",ElementId:"$element_id",ElementClassName:"$element_class_name",ElementName:"$element_name",ElementContent:"$element_content",ElementTargetUrl:"$element_target_url",ElementPosition:"$element_position",PageX:"$page_x",PageY:"$page_y",PageHeight:"$page_height",PageResourceSize:"$page_resource_size",EventDuration:"$event_duration",ViewportPosition:"$viewport_position",LatestWxAdClickId:"$latest_wx_ad_click_id",LatestWxAdCallbacks:"$latest_wx_ad_callbacks",LatestWxAdHashKey:"$latest_wx_ad_hash_key",IsChannelCallbackEvent:"$is_channel_callback_event",EventSessionId:"$event_session_id",Time:"$time",Event:"$event",Option:"$option",Project:"$project",Token:"$token",SignupMethod:"$signup_method"},_="event-tracker",w="1.1.0",b=function(){function t(){this.preset={}}return t.prototype.setPreset=function(t){this.preset=r({},t)},t.prototype.register=function(t){Object.assign(this.preset,t)},t.prototype.registerOnce=function(t){for(var e=0,n=Object.keys(t);e<n.length;e++){var r=n[e];r in this.preset||(this.preset[r]=t[r])}},t.prototype.clearRegister=function(){this.preset={}},t.prototype.unsetRegister=function(t){Object.prototype.hasOwnProperty.call(this.preset,t)&&delete this.preset[t]},t.prototype.getPreset=function(){return r({},this.preset)},t.prototype.build=function(t,e){void 0===e&&(e={});var n=r(r({},this.preset),e);if(n[m.Lib]=t.lib_name||"event-tracker",n[m.LibVersion]=t.lib_version||"0.1.0",t.app_id&&(n[m.AppId]=t.app_id),t.app_version&&(n[m.AppVersion]=t.app_version),a())try{n[m.URL]=location.href,n[m.URLPath]=location.pathname,n[m.Title]=document.title,document.referrer&&(n[m.Referrer]=document.referrer);var i=window.screen&&window.screen.width||0,o=window.screen&&window.screen.height||0;i&&(n[m.ScreenWidth]=i),o&&(n[m.ScreenHeight]=o);var s=window.innerWidth||document.documentElement&&document.documentElement.clientWidth||0,c=window.innerHeight||document.documentElement&&document.documentElement.clientHeight||0;s&&(n[m.ViewportWidth]=s),c&&(n[m.ViewportHeight]=c),navigator&&(n[m.Language]=navigator.language||"",n[m.UserAgent]=t.user_agent||navigator.userAgent||"",n[m.TimezoneOffset]=(new Date).getTimezoneOffset())}catch(t){}if(a()&&!1!==t.is_collect_utm){for(var u=function(t){var e={};if(!t)return e;for(var n=(t.startsWith("?")?t.substring(1):t).split("&"),r=0,i=n;r<i.length;r++){var o=i[r],s=o.indexOf("=");if(-1!==s){var a=decodeURIComponent(o.substring(0,s)),c=decodeURIComponent(o.substring(s+1));a.startsWith("utm_")&&(e[a]=c)}}return e}(location.search),l=0,d=Object.entries(u);l<d.length;l++){var f=d[l],h=f[0],p=f[1];n[m.LatestUtmSource.replace("Source",k(h.replace("utm_","")))]=p}n[m.LatestTrafficSourceType]=n[m.LatestUtmSource]?"付费广告流量":"直接流量"}return n},t}();function k(t){return t.charAt(0).toUpperCase()+t.slice(1)}var S=function(){function t(){this.backing=new Map}return t.prototype.get=function(t){return this.backing.has(t)?this.backing.get(t):null},t.prototype.set=function(t,e){this.backing.set(t,e)},t.prototype.remove=function(t){this.backing.delete(t)},t.prototype.keys=function(t){return void 0===t&&(t=""),Array.from(this.backing.keys()).filter(function(e){return e.startsWith(t)})},t}(),I=function(){function t(t,e,n){void 0===e&&(e=!0),void 0===n&&(n=!1),this.domain=t,this.crossSubdomain=e,this.secure=n}return t.prototype.get=function(t){for(var e=encodeURIComponent(t)+"=",n=document.cookie.split(";"),r=0;r<n.length;r++){for(var i=n[r];" "===i.charAt(0);)i=i.substring(1);if(0===i.indexOf(e))return decodeURIComponent(i.substring(e.length,i.length))}return null},t.prototype.set=function(t,e,n){void 0===n&&(n=365);var r="";if(n){var i=new Date;i.setTime(i.getTime()+24*n*60*60*1e3),r="; expires="+i.toUTCString()}var o=encodeURIComponent(t)+"="+encodeURIComponent(e)+r+"; path=/";this.domain&&this.crossSubdomain&&(o+="; domain="+this.domain),this.secure&&(o+="; Secure"),document.cookie=o},t.prototype.remove=function(t){this.set(t,"",-1)},t.prototype.keys=function(t){return void 0===t&&(t=""),document.cookie.split(";").map(function(t){var e=t.indexOf("=");return decodeURIComponent((e>-1?t.substring(0,e):t).trim())}).filter(function(e){return e.startsWith(t)})},t}(),E=function(){function t(){}return t.prototype.get=function(t){try{return window.localStorage.getItem(t)}catch(t){return null}},t.prototype.set=function(t,e){try{window.localStorage.setItem(t,e)}catch(t){}},t.prototype.remove=function(t){try{window.localStorage.removeItem(t)}catch(t){}},t.prototype.keys=function(t){void 0===t&&(t="");var e=[];try{for(var n=0;n<window.localStorage.length;n++){var r=window.localStorage.key(n);r&&r.startsWith(t)&&e.push(r)}}catch(t){}return e},t}();!function(){function t(){}t.prototype.get=function(t){try{return window.sessionStorage.getItem(t)}catch(t){return null}},t.prototype.set=function(t,e){try{window.sessionStorage.setItem(t,e)}catch(t){}},t.prototype.remove=function(t){try{window.sessionStorage.removeItem(t)}catch(t){}},t.prototype.keys=function(t){void 0===t&&(t="");var e=[];try{for(var n=0;n<window.sessionStorage.length;n++){var r=window.sessionStorage.key(n);r&&r.startsWith(t)&&e.push(r)}}catch(t){}return e}}();function A(t){return function(){if(!a()||!document.cookie)return!1;document.cookie="__et_test__=1";var t=-1!==document.cookie.indexOf("__et_test__");return document.cookie="__et_test__=; expires=Thu, 01 Jan 1970 00:00:00 GMT",t}()?new I(null==t?void 0:t.cookieDomain,null==t?void 0:t.cookieCrossSubdomain,null==t?void 0:t.secureCookie):c()?new E:new S}var T=null;var x=new Map;function C(t){var e=t.length;return e<=128?t:"".concat(e,"|").concat(t.slice(0,64),"|").concat(t.slice(-64))}function P(t){var e=x.get(t);if(e){if(!(Date.now()-e.ts>500))return x.delete(t),x.set(t,e),e.data;x.delete(t)}}function $(t,e){if(x.size>=64){var n=x.keys().next().value;void 0!==n&&x.delete(n)}x.set(t,{ts:Date.now(),data:e})}function D(t,e){var n=JSON.stringify(t),r=C(n);if(!e){var i=P(r);return void 0!==i?i:($(r,n),n)}return e(n)}function L(t,e){var n=JSON.stringify(t),r=C(n);if(!e){var i=P(r);return void 0!==i?i:($(r,n),n)}return e(n)}function O(t,e,n){void 0===n&&(n="form");var r=Array.isArray(t)?t[0]||"":t,i=r.indexOf("?")>=0;return"".concat(r).concat(i?"&":"?","data=").concat(encodeURIComponent(e))}function M(t){return(T||(T=new TextEncoder),T).encode(t)}function R(t){for(var e="",n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}new Map;var U=function(){function t(){this.name="image"}return t.prototype.canUse=function(){return u()},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,r,i;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,Promise.resolve(D(t,e.config.encryptor))];case 1:return n=o.sent(),r=O(e.config.server_url||"",n,"form"),[4,new Promise(function(t){var e,n="function"==typeof(e=((0,eval)("this")||globalThis).Image)?new e:{src:"",onload:void 0,onerror:void 0,onabort:void 0},i=function(){return t()};n.onload=i,n.onerror=i,n.onabort=i,n.src=r,setTimeout(i,3e3)})];case 2:return o.sent(),[3,4];case 3:return i=o.sent(),e.logger.error("ImageSender failed:",i),[3,4];case 4:return[2]}})})},t}(),j=function(){function t(){this.name="beacon"}return t.prototype.canUse=function(){return a()&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,r,i,s;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,Promise.resolve(D(t,e.config.encryptor))];case 1:return n=o.sent(),r=O(e.config.server_url||"",n,"form"),i=new Blob([n],{type:"application/x-www-form-urlencoded"}),navigator.sendBeacon(r,i)||e.logger.warn("BeaconSender returned false, URL:",r.slice(0,80)),[3,3];case 2:return s=o.sent(),e.logger.error("BeaconSender failed:",s),[3,3];case 3:return[2]}})})},t}(),N=new TextEncoder;function B(t,e){return i(this,void 0,void 0,function(){var n,r,i,s,a,c;return o(this,function(o){switch(o.label){case 0:return u=e.salt?"".concat(e.secret,":").concat(e.salt):e.secret,n=N.encode(u),[4,crypto.subtle.importKey("raw",n,{name:"HMAC",hash:"SHA-256"},!1,["sign"])];case 1:return r=o.sent(),[4,crypto.subtle.sign("HMAC",r,N.encode(t))];case 2:for(i=o.sent(),s=new Uint8Array(i),a="",c=0;c<s.length;c++)a+=String.fromCharCode(s[c]);return[2,btoa(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")]}var u})})}function W(t,e){if(t.length!==e.length)return!1;for(var n=0,r=0;r<t.length;r++)n|=t.charCodeAt(r)^e.charCodeAt(r);return 0===n}function F(t,e,n){return i(this,void 0,void 0,function(){var r,i,s,a;return o(this,function(o){switch(o.label){case 0:if(!(r=e.config.identity_secret))return[2,null];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,B(t,{secret:r,salt:n})];case 2:return[2,o.sent()];case 3:return i=o.sent(),null===(a=null===(s=e.logger)||void 0===s?void 0:s.warn)||void 0===a||a.call(s,"signPayload failed:",i),[2,null];case 4:return[2]}})})}function q(t,e){return i(this,void 0,void 0,function(){var n,r,i,s,a,c,u,l,d,f,h,p;return o(this,function(o){switch(o.label){case 0:if(!e||"function"!=typeof globalThis.CompressionStream)return[2,null];o.label=1;case 1:return o.trys.push([1,7,,8]),n=new globalThis.CompressionStream("gzip"),[4,(r=n.writable.getWriter()).write(M(t))];case 2:return o.sent(),[4,r.close()];case 3:o.sent(),i=n.readable.getReader(),s=[],a=0,o.label=4;case 4:return[4,i.read()];case 5:return c=o.sent(),u=c.value,c.done?[3,6]:(u&&(s.push(u),a+=u.byteLength),[3,4]);case 6:for(l=new Uint8Array(a),d=0,f=0,h=s;f<h.length;f++)p=h[f],l.set(p,d),d+=p.byteLength;return[2,{body:R(l),headers:{"Content-Type":"application/x-www-form-urlencoded","X-Content-Encoding":"gzip"}}];case 7:return o.sent(),[2,null];case 8:return[2]}})})}var H=function(){function t(){this.name="ajax"}return t.prototype.canUse=function(){return a()&&"function"==typeof fetch},t.prototype.getGzipEnabled=function(t){var e;return Boolean(null===(e=t.config.batch_send)||void 0===e?void 0:e.gzip)},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,r,i,s,a,c,u,l,d,f,h,p,g,v;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),[4,Promise.resolve(D(t,e.config.encryptor))];case 1:return n=o.sent(),r=Array.isArray(e.config.server_url)?e.config.server_url[0]:e.config.server_url,[4,q(n,this.getGzipEnabled(e))];case 2:return i=o.sent(),s=void 0,a=void 0,i?(s="data=".concat(i.body),a=i.headers):(s="data=".concat(encodeURIComponent(n)),a={"Content-Type":"application/x-www-form-urlencoded"}),[4,F(n,e,t.distinct_id)];case 3:return(c=o.sent())&&(a["X-Payload-Sig"]=c),[4,fetch(r,{method:"POST",mode:"cors",credentials:"omit",headers:a,body:s,keepalive:!0})];case 4:return(u=o.sent()).ok?null===(p=(h=e.config).callback)||void 0===p||p.call(h,t):(e.logger.warn("AjaxSender non-2xx:",u.status),null===(f=(d=e.config).on_error)||void 0===f||f.call(d,new Error("HTTP ".concat(u.status)),t)),[3,6];case 5:return l=o.sent(),e.logger.error("AjaxSender failed:",l),null===(v=(g=e.config).on_error)||void 0===v||v.call(g,l,t),[3,6];case 6:return[2]}})})},t.prototype.sendBatch=function(t,e){return i(this,void 0,void 0,function(){var n,r,i,s,a,c,u,l;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),[4,Promise.resolve(L(t,e.config.encryptor))];case 1:return n=o.sent(),r=Array.isArray(e.config.server_url)?e.config.server_url[0]:e.config.server_url,[4,q(n,this.getGzipEnabled(e))];case 2:return i=o.sent(),s=void 0,a=void 0,i?(s="data=".concat(i.body,"&batch=1"),a=i.headers):(s="data=".concat(encodeURIComponent(n),"&batch=1"),a={"Content-Type":"application/x-www-form-urlencoded"}),[4,F(n,e,null===(l=t[0])||void 0===l?void 0:l.distinct_id)];case 3:return(c=o.sent())&&(a["X-Payload-Sig"]=c),[4,fetch(r,{method:"POST",mode:"cors",credentials:"omit",headers:a,body:s,keepalive:!0})];case 4:return o.sent(),[3,6];case 5:return u=o.sent(),e.logger.error("AjaxSender.sendBatch failed:",u),[3,6];case 6:return[2]}})})},t}(),V=Object.freeze({__proto__:null,AjaxSender:H}),z="et_batch_queue",J=function(){function t(){this.name="batch",this.timer=null,this.running=!1}return t.prototype.canUse=function(){return"undefined"!=typeof window&&!!window.localStorage},t.prototype.start=function(t){this.canUse()&&(this.ctx=t,this.scheduleNext())},t.prototype.stop=function(){this.timer&&clearTimeout(this.timer),this.timer=null,this.ctx=void 0},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,r;return o(this,function(i){switch(i.label){case 0:return this.enqueue(t,e.config),n="object"==typeof e.config.batch_send&&(null===(r=e.config.batch_send)||void 0===r?void 0:r.max_length)||50,this.read(e.config).length>=n?[4,this.flush(e)]:[3,2];case 1:return i.sent(),[3,3];case 2:this.scheduleNext(),i.label=3;case 3:return[2]}})})},t.prototype.scheduleNext=function(){var t=this;if(!this.timer&&this.ctx){var e=this.ctx.config.batch_send,n=this.ctx.config.batch_send_predict,r=n?n():"object"==typeof e&&(null==e?void 0:e.send_interval)||this.ctx.config.datasend_timeout||6e3;this.timer=setTimeout(function(){t.timer=null,t.flush(t.ctx).then(function(){return t.scheduleNext()})},r)}},t.prototype.peekQueueSize=function(){return this.ctx?this.read(this.ctx.config).length:0},t.prototype.enqueue=function(t,e){var n=this.read(e);n.push(t),this.write(n,e)},t.prototype.read=function(t){try{var e=window.localStorage.getItem(z);if(!e)return[];var n=JSON.parse(e);return Array.isArray(n)?n:[]}catch(t){return[]}},t.prototype.write=function(t,e){try{var n=L(t,e.encryptor),r="string"==typeof n?n:JSON.stringify(t);window.localStorage.setItem(z,r)}catch(n){var i=t.slice(Math.floor(t.length/2));try{var o=L(i,e.encryptor),s="string"==typeof o?o:JSON.stringify(i);window.localStorage.setItem(z,s)}catch(t){}}},t.prototype.flush=function(t){return i(this,void 0,void 0,function(){var e,n,r,i,s,a;return o(this,function(o){switch(o.label){case 0:if(this.running)return[2];this.running=!0,o.label=1;case 1:if(o.trys.push([1,,9,10]),!(e=this.read(t.config)).length)return[2];try{window.localStorage.removeItem(z)}catch(t){}return[4,Promise.resolve().then(function(){return V})];case 2:return(n=new(o.sent().AjaxSender)).canUse()?[4,n.sendBatch(e,t)]:[3,4];case 3:return o.sent(),[3,8];case 4:r=new j,i=0,s=e,o.label=5;case 5:return i<s.length?(a=s[i],[4,r.send(a,t)]):[3,8];case 6:o.sent(),o.label=7;case 7:return i++,[3,5];case 8:return[3,10];case 9:return this.running=!1,[7];case 10:return[2]}})})},t}(),G=function(){function t(t){this.stage=t,this.list=[],this.stopped=!1,this.stopFlag=!1}return t.prototype.register=function(t){var e;this.unregister(t.name),this.list.push({priority:null!==(e=t.priority)&&void 0!==e?e:100,spec:t}),this.list.sort(function(t,e){return t.priority-e.priority})},t.prototype.unregister=function(t){this.list=this.list.filter(function(e){return e.spec.name!==t})},t.prototype.list2=function(){return this.list.map(function(t){return"".concat(t.spec.name,"@").concat(t.priority)})},t.prototype.reset=function(){this.stopFlag=!1},t.prototype.run=function(t,e){var n=this;this.stopFlag=!1;for(var r={data:t,meta:{stage:this.stage},cancellationToken:{stop:function(){n.stopFlag=!0}},owner:e},i=0,o=this.list;i<o.length;i++){var s=o[i].spec;if(this.stopFlag)break;var a=s.entry(r);void 0!==a&&(r.data=a)}return r.data},t}(),K=function(){function t(){this.hooks={sdkReady:new Set,sdkInitPara:new Set,sdkAfterInitPara:new Set,sdkInitAPI:new Set,sdkAfterInitAPI:new Set,changeDistinctId:new Set,switch:new Set}}return t.prototype.on=function(t,e){var n=this;if(!this.hooks[t])throw new Error("[Lifecycle] unknown hook: ".concat(t));return this.hooks[t].add(e),function(){return n.off(t,e)}},t.prototype.off=function(t,e){var n;null===(n=this.hooks[t])||void 0===n||n.delete(e)},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=this.hooks[t];if(r)for(var i=0,o=Array.from(r);i<o.length;i++){var s=o[i];try{s.apply(void 0,e)}catch(e){"undefined"!=typeof console&&console.error&&console.error("[EventTracker] hook ".concat(t," error:"),e)}}},t.prototype.clear=function(){for(var t=0,e=Object.keys(this.hooks);t<e.length;t++){var n=e[t];this.hooks[n].clear()}},t.prototype.inspect=function(){for(var t={},e=0,n=Object.keys(this.hooks);e<n.length;e++){var r=n[e];t[r]=this.hooks[r].size}return t},t}(),Q=function(){function t(){this.lifecycle=new K,this.plugins=[],this.commonWays={},this.stages={buildDataStage:new G("buildDataStage"),businessStage:new G("businessStage"),sendDataStage:new G("sendDataStage")}}return t.prototype.on=function(t,e){return this.lifecycle.on(t,e)},t.prototype.off=function(t,e){this.lifecycle.off(t,e)},t.prototype.emit=function(t){for(var e,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];(e=this.lifecycle).emit.apply(e,s([t],n,!1))},t.prototype.intercept=function(t,e){this.stages[t].register(e)},t.prototype.invoke=function(t){for(var e,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];(e=this.lifecycle).emit.apply(e,s([t],n,!1))},t.prototype.install=function(t,e){var n=this.plugins.findIndex(function(e){return e.name===t.name});if(n>=0&&(this.uninstall(this.plugins[n]),this.plugins.splice(n,1)),this.plugins.push(t),t.install){var i=r(r({},e),{registry:this,stages:this.stages});try{t.install(i)}catch(e){"undefined"!=typeof console&&console.error&&console.error("[EventTracker] plugin ".concat(t.name," install failed:"),e)}}},t.prototype.uninstall=function(t,e){var n;try{null===(n=t.uninstall)||void 0===n||n.call(t,e)}catch(e){"undefined"!=typeof console&&console.error&&console.error("[EventTracker] plugin ".concat(t.name," uninstall failed:"),e)}},t.prototype.list=function(){return this.plugins.map(function(t){return t.name})},t}(),Y="event-tracker",X=function(){function t(){this.bc=null,this.listeners=new Set,this.sourceId="".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,8)),this.localStorageKey="et_channel_".concat(Y),this.pollTimer=null,this.initBroadcastChannel(),this.bc||this.initLocalStoragePolling()}return t.prototype.initBroadcastChannel=function(){var t=this;if("undefined"!=typeof BroadcastChannel)try{this.bc=new BroadcastChannel(Y),this.bc.onmessage=function(e){var n;(null===(n=e.data)||void 0===n?void 0:n.source)!==t.sourceId&&t.listeners.forEach(function(t){return t(e.data)})}}catch(t){this.bc=null}},t.prototype.initLocalStoragePolling=function(){var t=this;"undefined"!=typeof window&&window.addEventListener("storage",function(e){if(e.key===t.localStorageKey&&e.newValue)try{var n=JSON.parse(e.newValue);if(n.source===t.sourceId)return;t.listeners.forEach(function(t){return t(n)})}catch(t){}})},t.prototype.post=function(t,e){var n={type:t,source:this.sourceId,payload:e};if(this.bc)try{this.bc.postMessage(n)}catch(t){}else try{localStorage.setItem(this.localStorageKey,JSON.stringify(n))}catch(t){}},t.prototype.on=function(t){var e=this;return this.listeners.add(t),function(){return e.listeners.delete(t)}},t.prototype.close=function(){if(this.bc){try{this.bc.close()}catch(t){}this.bc=null}this.listeners.clear(),this.pollTimer&&(clearInterval(this.pollTimer),this.pollTimer=null)},t.prototype.getSourceId=function(){return this.sourceId},t}(),Z=function(){function t(t,e,n){void 0===n&&(n="full"),this.config=t,this.logger=e,this.jitter=n}return t.prototype.backoff=function(t,e,n){void 0===e&&(e=1e3),void 0===n&&(n=3e4);var r=Math.min(e*Math.pow(2,t),n);switch(this.jitter){case"off":default:return r;case"equal":return r/2+Math.random()*(r/2);case"full":return Math.random()*r;case"decorrelated":var i=Math.min(e*Math.pow(2,Math.max(0,t-1))*3,n);return e+Math.random()*(i-e)}},t.prototype.execute=function(t){return i(this,arguments,void 0,function(t,e,n){var r,i,s,a,c,u,l,d,f,h;return void 0===e&&(e=function(){return!0}),o(this,function(o){switch(o.label){case 0:r=null!==(f=this.config.max_retry_count)&&void 0!==f?f:3,i=null!==(h=this.config.max_retry_duration)&&void 0!==h?h:6e4,s=Date.now(),a=null,c=0,u=0,o.label=1;case 1:if(!(u<=r))return[3,8];o.label=2;case 2:return o.trys.push([2,4,,7]),[4,t()];case 3:return o.sent(),[2,{ok:!0,attempts:u+1,finalErr:null}];case 4:return l=o.sent(),e(a=l)?(d=this.backoff(u),Date.now()-s+c+d>i?(this.logger.warn("[EventTracker] max_retry_duration reached, give up"),null==n||n(a,u+1),[2,{ok:!1,attempts:u+1,finalErr:a}]):u<r?(c+=d,[4,this.sleep(d)]):[3,6]):[2,{ok:!1,attempts:u+1,finalErr:a}];case 5:o.sent(),o.label=6;case 6:return[3,7];case 7:return u++,[3,1];case 8:return null==n||n(a,r+1),[2,{ok:!1,attempts:r+1,finalErr:a}]}})})},t.prototype.sleep=function(t){return new Promise(function(e){return setTimeout(e,t)})},t}(),tt="et_failed_queue",et=function(){function t(t){var e;void 0===t&&(t={}),this.draining=!1,this.drainPromise=null,this.drainAbort=null,this.config={max:null!==(e=t.max)&&void 0!==e?e:50,encryptor:t.encryptor}}return t.prototype.read=function(){if(!a()||!c())return[];try{var t=localStorage.getItem(tt);if(!t)return[];var e=JSON.parse(t);return Array.isArray(e)?e:[]}catch(t){return[]}},t.prototype.enqueue=function(t){if(a()&&c()){var e=this.read();e.push(t),e.length>this.config.max&&e.splice(0,e.length-this.config.max);try{this.config.encryptor;var n=JSON.stringify(e);localStorage.setItem(tt,n)}catch(t){var r=e.slice(Math.floor(e.length/2));try{localStorage.setItem(tt,JSON.stringify(r))}catch(t){}}}},t.prototype.clear=function(){if(a()&&c())try{localStorage.removeItem(tt)}catch(t){}},t.prototype.takeAll=function(){var t=this.read();return this.clear(),t},t.prototype.size=function(){return this.read().length},t.prototype.drain=function(t){return i(this,void 0,void 0,function(){return o(this,function(e){switch(e.label){case 0:return this.draining&&this.drainPromise?[4,this.drainPromise.catch(function(){})]:[3,2];case 1:return e.sent(),[2,0];case 2:this.draining=!0,this.drainAbort=new AbortController,this.drainPromise=this._drain(t),e.label=3;case 3:return e.trys.push([3,,5,6]),[4,this.drainPromise];case 4:return e.sent(),[2,0];case 5:return this.draining=!1,this.drainPromise=null,this.drainAbort=null,[7];case 6:return[2]}})})},t.prototype.abortDrain=function(t){var e;null===(e=this.drainAbort)||void 0===e||e.abort(t)},t.prototype._drain=function(t){return i(this,void 0,void 0,function(){var e,n,r,i,s,a,c,u,l;return o(this,function(o){switch(o.label){case 0:e=this.drainAbort.signal,o.label=1;case 1:if(e.aborted)return[3,6];if(!(n=this.takeAll()).length)return[2];o.label=2;case 2:return o.trys.push([2,4,,5]),[4,t(n)];case 3:if((r=o.sent())<n.length){for(i=n.slice(r),s=0,a=i;s<a.length;s++)l=a[s],this.enqueue(l);return[2]}return[3,5];case 4:for(o.sent(),c=0,u=n;c<u.length;c++)l=u[c],this.enqueue(l);return[2];case 5:return[3,1];case 6:return[2]}})})},t}(),nt=function(t){function e(e,n,r){void 0===r&&(r={});var i=t.call(this,n)||this;return i.name=i.constructor.name,i.code=e,i.cause=r.cause,i.context=r.context,i.timestamp=Date.now(),"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(i,i.constructor),i}return n(e,t),e.prototype.toJSON=function(){return{name:this.name,code:this.code,message:this.message,timestamp:this.timestamp,context:this.context,stack:this.stack}},e}(Error),rt=function(t){function e(e,n){return t.call(this,"INIT",e,n)||this}return n(e,t),e}(nt),it=function(t){function e(e,n,r){var i=t.call(this,"SEND",e,r)||this;return i.attempts=n,i}return n(e,t),e}(nt),ot=function(t){function e(e,n){return t.call(this,"ENCRYPT",e,n)||this}return n(e,t),e}(nt),st=function(t){function e(e,n){return t.call(this,"IDENTITY",e,n)||this}return n(e,t),e}(nt),at=function(t){function e(e,n){return t.call(this,"STORAGE",e,n)||this}return n(e,t),e}(nt),ct=function(t){function e(e,n,r){var i=t.call(this,"PLUGIN",n,r)||this;return i.plugin=e,i}return n(e,t),e}(nt),ut=function(t){function e(e,n){return t.call(this,"CONFIG",e,n)||this}return n(e,t),e}(nt);var lt=function(){if("undefined"!=typeof globalThis&&globalThis.TextEncoder)return new globalThis.TextEncoder;var t=require("util").TextEncoder;return globalThis.TextEncoder=t,new t}();function dt(t){if("undefined"!=typeof btoa){for(var e="",n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e)}return Buffer.from(t).toString("base64")}function ft(t,e){for(var n=2166136261,r=3421674724,i=0;i<t.length;i++)n^=t.charCodeAt(i),n=Math.imul(n,16777619)>>>0,r^=e.charCodeAt(i%e.length),r=Math.imul(r,1099511628211)>>>0;return(BigInt(n)<<32n|BigInt(r)).toString(36)}function ht(t,e){return i(this,void 0,void 0,function(){var n,r,i;return o(this,function(o){switch(o.label){case 0:return n=function(){var t;if("undefined"!=typeof globalThis&&(null===(t=globalThis.crypto)||void 0===t?void 0:t.subtle))return globalThis.crypto.subtle;var e=require("crypto").webcrypto;return globalThis.crypto=e,e.subtle}(),[4,n.importKey("raw",lt.encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign"])];case 1:return r=o.sent(),i=Uint8Array.bind,[4,n.sign("HMAC",r,lt.encode(t))];case 2:return[2,dt(new(i.apply(Uint8Array,[void 0,o.sent()])))]}})})}function pt(t,e,n){return i(this,void 0,void 0,function(){var r,i,s;return o(this,function(o){switch(o.label){case 0:return[4,ht(t,e)];case 1:if((r=o.sent()).length!==n.length)return[2,!1];for(i=0,s=0;s<r.length;s++)i|=r.charCodeAt(s)^n.charCodeAt(s);return[2,0===i]}})})}function gt(t){var e=this;if(!t)throw new nt("IDENTITY","createSignedIdentity: secret is required",{context:{hint:"set config.identity_secret to enable signed identity"}});return{sign:function(e){return ft(e,t)},signAsync:function(e){return ht(e,t)},verify:function(e,n){return ft(e,t)===n},verifyAsync:function(e,n){return pt(e,t,n)},encode:function(e){return"".concat(e,"|").concat(ft(e,t))},decode:function(e){var n=e.lastIndexOf("|");if(n<=0)return null;var r=e.slice(0,n),i=e.slice(n+1);return ft(r,t)!==i?null:r},encodeAsync:function(n){return i(e,void 0,void 0,function(){var e,r;return o(this,function(i){switch(i.label){case 0:return r=(e="".concat(n,"|")).concat,[4,ht(n,t)];case 1:return[2,r.apply(e,[i.sent()])]}})})},decodeAsync:function(n){return i(e,void 0,void 0,function(){var e,r,i;return o(this,function(o){switch(o.label){case 0:return(e=n.lastIndexOf("|"))<=0?[2,null]:(r=n.slice(0,e),i=n.slice(e+1),[4,pt(r,t,i)]);case 1:return o.sent()?[2,r]:[2,null]}})})}}}var vt=function(){function t(t,e,n,r,i,o,s,a){this.config=t,this.registry=e,this.identity=n,this.presetProps=r,this.retryPolicy=i,this.failedQueue=o,this.logger=s,this.stats=a,this.pending=[],this.senders=[],this.abortControllers=new Map}return t.prototype.setSenders=function(t){this.senders=t},t.prototype.setBatchSender=function(t){this.batchSender=t},t.prototype.makeCtx=function(){var t={config:this.config,logger:this.logger};return this.stats&&(t.stats=this.stats),t},t.prototype.buildEvent=function(t,e){var n,r;void 0===e&&(e={});var i=(null===(r=(n=this.config).get_client_timestamp)||void 0===r?void 0:r.call(n))||Date.now(),o=this.presetProps.build(this.config,e.properties||{}),s={type:t,time:i,distinct_id:this.identity.getDistinctId(),anonymous_id:this.identity.getAnonymousId(),first_id:this.identity.getFirstId(),login_id:this.identity.getLoginId()||void 0,original_id:this.identity.getOriginalId()||void 0,properties:o,lib:{$lib:this.config.lib_name||_,$lib_version:this.config.lib_version||w},token:this.config.app_id,project:this.config.app_id};return e.event&&(s.event=e.event),s},t.prototype.send=function(t,e){var n=this;if(this.config.disabled)null==e||e(null);else{this.registry.invoke("sdkInitAPI",t);var r=this.config.encryptEvent;if(r)try{var i=r(t);i&&"object"==typeof i&&(t=i)}catch(t){this.logger.error("encryptEvent hook failed:",t)}if(this.config.encryptor)try{var o=this.config.encryptor(JSON.stringify(t));"string"==typeof o?(t._encrypted=o,this.dispatchAfterEncrypt(t,e)):o.then(function(r){t._encrypted=r,n.dispatchAfterEncrypt(t,e)},function(r){n.logger.error(new ot("async encryptor failed",{cause:r})),n.dispatchAfterEncrypt(t,e)})}catch(n){this.logger.error(new ot("encryptor threw",{cause:n})),this.dispatchAfterEncrypt(t,e)}else this.dispatchAfterEncrypt(t,e)}},t.prototype.dispatchAfterEncrypt=function(t,e){var n=this;t.properties=this.registry.stages.sendDataStage.run(t.properties,this);var r=this.makeCtx();if("batch"===this.config.send_type&&this.batchSender){var s=Promise.resolve(this.batchSender.send(t,r)).then(function(){return null==e?void 0:e(null)}).catch(function(t){return null==e?void 0:e(t)});this.trackPending(s)}else{var a=this.pickSender(),c=this.retryPolicy.execute(function(){return function(t,e,n){return i(this,void 0,void 0,function(){var r,i,s,a,c;return o(this,function(o){switch(o.label){case 0:r=n.stats,i=t.name,s=r?r.recordStart(i):Date.now(),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,t.send(e,n)];case 2:if(o.sent(),null==r||r.recordSuccess(i,s),n.config.onSendSuccess)try{n.config.onSendSuccess(e,Date.now()-s)}catch(t){}return[3,4];case 3:if(a=o.sent(),c=a instanceof Error?a:new Error(String(a)),null==r||r.recordFailure(i,s,c),n.config.onSendError)try{n.config.onSendError(c,e)}catch(t){}throw c;case 4:return[2]}})})}(a,t,r)},function(){return!0},function(e,r){var i,o,s,a,c;n.failedQueue.enqueue(t),n.logger.warn("event send failed, queued:",e.message);try{null===(o=(i=n.config).onFailedEnqueue)||void 0===o||o.call(i,t,e.message)}catch(t){}try{null===(a=(s=n.config).onRetry)||void 0===a||a.call(s,t,r)}catch(t){}null===(c=n.stats)||void 0===c||c.recordRetry()}),u=c.then(function(t){null==e||e(t.ok?null:t.finalErr)});this.trackPending(u)}},t.prototype.pickSender=function(){var t=this.config.send_type;if(t&&"batch"!==t){var e=this.senders.find(function(e){return e.name===t&&e.canUse()});if(e)return e}return this.senders.find(function(t){return"beacon"===t.name&&t.canUse()})||this.senders.find(function(t){return"ajax"===t.name&&t.canUse()})||this.senders.find(function(t){return"image"===t.name&&t.canUse()})||this.senders[0]},t.prototype.trackPending=function(t){var e={promise:t,resolve:function(){},reject:function(){}};new Promise(function(t,n){e.resolve=t,e.reject=n});t.then(function(){return e.resolve()},function(t){return e.reject(t)}),this.pending.push(e)},t.prototype.flush=function(){return i(this,void 0,void 0,function(){var t,e,n,r,i,s,a,c,u,l;return o(this,function(o){switch(o.label){case 0:if(t=Date.now(),e=0,!this.batchSender)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),n=null!==(a=null===(s=(i=this.batchSender).peekQueueSize)||void 0===s?void 0:s.call(i))&&void 0!==a?a:0,[4,this.batchSender.flush({config:this.config,logger:this.logger})];case 2:return o.sent(),e+=n,[3,4];case 3:return r=o.sent(),this.logger.warn("batch flush failed:",r),[3,4];case 4:return[4,this.waitUntilIdle()];case 5:o.sent(),null===(c=this.stats)||void 0===c||c.recordFlush();try{null===(l=(u=this.config).onFlush)||void 0===l||l.call(u,e,Date.now()-t)}catch(t){}return[2]}})})},t.prototype.waitUntilIdle=function(){return i(this,void 0,void 0,function(){var t;return o(this,function(e){switch(e.label){case 0:return this.pending.length?(t=this.pending.splice(0),[4,Promise.allSettled(t.map(function(t){return t.promise}))]):[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}})})},t.prototype.abortAll=function(t){for(var e=0,n=this.abortControllers;e<n.length;e++){n[e][1].abort(t)}this.abortControllers.clear(),this.pending=[]},t.prototype.takeAbortController=function(t){var e=new AbortController;return this.abortControllers.set(t,e),e},t.prototype.releaseAbortController=function(t){this.abortControllers.delete(t)},t}(),yt=function(){function t(){this.total=0,this.success=0,this.failure=0,this.retry=0,this.in_flight=0,this.flushCount=0,this.bySender=new Map}return t.prototype.recordStart=function(t){return this.total++,this.in_flight++,this.getOrCreate(t).attempts++,Date.now()},t.prototype.recordSuccess=function(t,e){this.success++,this.in_flight=Math.max(0,this.in_flight-1);var n=this.getOrCreate(t),r=Date.now()-e;n.total_duration+=r,n.avg_duration=n.total_duration/n.attempts,r>n.max_duration&&(n.max_duration=r)},t.prototype.recordFailure=function(t,e,n){this.failure++,this.in_flight=Math.max(0,this.in_flight-1);var r=this.getOrCreate(t);r.failure++,r.last_error=n.message,r.last_error_at=Date.now()},t.prototype.recordRetry=function(){this.retry++},t.prototype.recordFlush=function(){this.flushCount++,this.lastFlushAt=Date.now()},t.prototype.snapshot=function(){for(var t={},e=0,n=this.bySender;e<n.length;e++){var i=n[e],o=i[0],s=i[1];t[o]=r({},s)}return{total:this.total,success:this.success,failure:this.failure,retry:this.retry,in_flight:this.in_flight,flush_count:this.flushCount,last_flush_at:this.lastFlushAt,by_sender:t,taken_at:Date.now()}},t.prototype.reset=function(){this.total=0,this.success=0,this.failure=0,this.retry=0,this.in_flight=0,this.flushCount=0,this.lastFlushAt=void 0,this.bySender.clear()},t.prototype.listSenders=function(){return Array.from(this.bySender.keys())},t.prototype.getOrCreate=function(t){var e=this.bySender.get(t);return e||(e={name:t,attempts:0,success:0,failure:0,total_duration:0,avg_duration:0,max_duration:0},this.bySender.set(t,e)),e},t}(),mt=new yt,_t={send_type:"image",max_retry_count:3,debug:0,storage_type:"memory",is_collect_utm:!0,send_timeout:5e3,max_retry_duration:3e4},wt=function(){function t(){this.lib_name=_,this.lib_version=w,this.DEFAULT_SEND_TYPE="image",this._senders=[],this._statsTimer=null,this._inited=!1,this.__noop=function(){},this.instanceId="".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,8))}return t.prototype.init=function(t){var e,n,i,o,s=this;if(this._inited)null===(e=this._logger)||void 0===e||e.warn("EventTracker already initialized, re-init ignored");else{if(this._config=r(r({},_t),t),this._config.lib_name=this._config.lib_name||_,this._config.lib_version=this._config.lib_version||w,!this._config.server_url)throw new rt("server_url is required");if(!this._config.app_id)throw new rt("app_id is required");var c,u;if(this._logger=new d({debug:this._config.debug,show_log:this._config.show_log}),this._store=A({cookieDomain:this._config.cookie_domain,cookieCrossSubdomain:this._config.cookie_cross_subdomain,secureCookie:this._config.secure_cookie}),this._config.identity_secret&&(this._signedIdentity=gt(this._config.identity_secret)),this._identity=new v(this._store,{getDistinctId:this._config.get_distinct_id,setDistinctId:this._config.set_distinct_id,getAnonymousId:this._config.get_anonymous_id,setAnonymousId:this._config.set_anonymous_id,getFirstId:this._config.get_first_id,setFirstId:this._config.set_first_id}),this._presetProps=new b,this._config.preset_properties&&this._presetProps.setPreset(this._config.preset_properties),this._registry=new Q,this._channel=new X,this._retryPolicy=new Z(this._config,this._logger),this._failedQueue=new et({max:200,encryptor:this._config.encryptor}),this._senders=[new U,new j,new H],this._batchSender=new J,this._stats=new yt,this._pipeline=new vt(this._config,this._registry,this._identity,this._presetProps,this._retryPolicy,this._failedQueue,this._logger,this._stats),this._pipeline.setSenders(this._senders),this._pipeline.setBatchSender(this._batchSender),(null!==(n=this._config.show_stats)&&void 0!==n?n:(null!==(i=this._config.debug)&&void 0!==i?i:0)>=1)&&"undefined"!=typeof window){var l=null!==(o=this._config.stats_interval)&&void 0!==o?o:6e4;this._statsTimer=setInterval(function(){var t=s._stats.snapshot();console.log("[EventTracker stats]",t)},l)}"batch"===this._config.send_type&&this._batchSender.start({config:this._config,logger:this._logger}),c=this,u=this._presetProps,Object.getPrototypeOf(c),c._registerAttached||(c._registerAttached=!0,c.register=function(t){return u.register(t),this},c.registerOnce=function(t){return u.registerOnce(t),this},c.clearAllRegister=function(){return u.clearRegister(),this},c.unsetRegister=function(t){return u.unsetRegister(t),this},c.registerPage=function(t){return u.registerOnce(t),this},c.registerSession=function(t){return u.register(t),this},c.registerSessionOnce=function(t){return u.registerOnce(t),this}),function(t,e){t._identityAttached||(t._identityAttached=!0,t.identify=function(n,r){return void 0===r&&(r=!0),e.identify(n,r),t.getRegistry().invoke("changeDistinctId",n),this},t.login=function(n){return e.login(n),t.getRegistry().invoke("changeDistinctId",n),this},t.logout=function(n){return e.resetAnonymousIdentity(n),t.getRegistry().invoke("changeDistinctId",e.getDistinctId()),this},t.resetAnonymousIdentity=t.logout,t.alias=function(n,r){(r||e.getDistinctId())!==n&&(e.identify(n,!0),t.track("$SignUp",{$signup_method:"alias"}),t.getRegistry().invoke("changeDistinctId",n))},t.getDistinctId=function(){return e.getDistinctId()},t.getAnonymousId=function(){return e.getAnonymousId()},t.getFirstId=function(){return e.getFirstId()},t.getLoginId=function(){return e.getLoginId()},t.getOriginalId=function(){return e.getOriginalId()})}(this,this._identity),function(t,e){if(!t._profileAttached){t._profileAttached=!0;var n=function(t,n,r){var i=e.buildEvent(t,{properties:n});e.send(i,r)};t.setProfile=function(t,e){return n("profile_set",t,e)},t.setOnceProfile=function(t,e){return n("profile_set_once",t,e)},t.incrementProfile=function(t,e){return n("profile_increment",t,e)},t.appendProfile=function(t,e){return n("profile_append",t,e)},t.unsetProfile=function(t,e){var r;return n("profile_unset",((r={})[t]=!0,r),e)},t.deleteProfile=function(t){return n("profile_delete",{},t)}}}(this,this._pipeline),function(t,e){t._trackAttached||(t._trackAttached=!0,t.track=function(t,n,r){void 0===n&&(n={});var i=e.buildEvent("track",{event:t,properties:n});e.send(i,r)},t.trackSignup=function(n,i,o){void 0===i&&(i={});var s=e.buildEvent("track_signup",{event:"$SignUp",properties:r(r({},i),{$signup_method:i.$signup_method||""})});s.original_id=t.getOriginalId(),t.identify(n,!0),s.distinct_id=n,s.login_id=n,e.send(s,o)},t.trackLinkage=function(e,n){t.track("$Linkage",e,n)},t.trackLink=function(e,n,i){if(void 0===n&&(n={}),a()){var o="string"==typeof e?document.querySelector(e):e;o&&o.addEventListener("click",function(){t.track("$WebClick",r(r({},n),{$element_selector:o.id?"#".concat(o.id):o.tagName.toLowerCase(),$element_target_url:o instanceof HTMLAnchorElement?o.href:void 0}),i)},{once:!0})}},t.trackLinks=function(e,n,r){if(void 0===n&&(n={}),a())for(var i=0,o=("string"==typeof e?Array.from(document.querySelectorAll(e)):e&&"length"in e&&!("click"in e)?Array.from(e):e);i<o.length;i++){var s=o[i];t.trackLink(s,n,r)}},t.trackHeatMap=function(e,n){return t.track("$heatmap_event",e,n)},t.trackWebClick=function(e,n){return t.track("$WebClick",e,n)},t.trackWebStay=function(e,n){return t.track("$WebStay",e,n)})}(this,this._pipeline),this._registry.invoke("sdkReady",this._config),this._registry.invoke("sdkInitPara",this._config),this._inited=!0,this._logger.log("EventTracker initialized:",{app_id:this._config.app_id,send_type:this._config.send_type}),this._registry.invoke("sdkAfterInitPara",this._config),this._registry.invoke("sdkInitAPI",this),this._registry.invoke("sdkAfterInitAPI",this)}},t.prototype.use=function(t){var e=this;if(!this._inited)return setTimeout(function(){return e.use(t)},0),this;var n={config:this._config,registry:this._registry,stages:this._registry.stages,sdk:this,kit:{},channel:this._channel,store:this._store,uninstall:function(){return e._registry.uninstall(t,n)}};return this._registry.install(t,n),this},t.prototype.track=function(t,e,n){},t.prototype.trackSignup=function(t,e,n){},t.prototype.trackLinkage=function(t,e){},t.prototype.trackLink=function(t,e,n){},t.prototype.trackLinks=function(t,e,n){},t.prototype.trackHeatMap=function(t,e){},t.prototype.trackWebClick=function(t,e){},t.prototype.trackWebStay=function(t,e){},t.prototype.identify=function(t,e){return this},t.prototype.login=function(t){return this},t.prototype.logout=function(t){return this},t.prototype.resetAnonymousIdentity=function(t){return this},t.prototype.alias=function(t,e){},t.prototype.getDistinctId=function(){return""},t.prototype.getAnonymousId=function(){return""},t.prototype.getFirstId=function(){return""},t.prototype.getLoginId=function(){return""},t.prototype.getOriginalId=function(){return""},t.prototype.register=function(t){return this},t.prototype.registerOnce=function(t){return this},t.prototype.clearAllRegister=function(){return this},t.prototype.unsetRegister=function(t){return this},t.prototype.registerPage=function(t){return this},t.prototype.registerSession=function(t){return this},t.prototype.registerSessionOnce=function(t){return this},t.prototype.setProfile=function(t,e){},t.prototype.setOnceProfile=function(t,e){},t.prototype.incrementProfile=function(t,e){},t.prototype.appendProfile=function(t,e){},t.prototype.unsetProfile=function(t,e){},t.prototype.deleteProfile=function(t){},t.prototype.disable=function(){return this._config.disabled=!0,this._logger.warn("EventTracker disabled"),this},t.prototype.enable=function(){return this._config.disabled=!1,this},t.prototype.setServerURL=function(t){return this.switchServer(t)},t.prototype.switchServer=function(t){return t?(this._config.server_url=t,this._registry.invoke("switch",t),this):this},t.prototype.flush=function(){return i(this,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:return this._inited?[4,this._pipeline.flush()]:[2];case 1:return t.sent(),[2]}})})},t.prototype.waitUntilIdle=function(){return i(this,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:return this._inited?[4,this._pipeline.waitUntilIdle()]:[2];case 1:return t.sent(),[2]}})})},t.prototype.abort=function(t){this._pipeline.abortAll(t)},t.prototype.close=function(){var t,e;null===(t=this._batchSender)||void 0===t||t.stop(),null===(e=this._channel)||void 0===e||e.close(),this._statsTimer&&(clearInterval(this._statsTimer),this._statsTimer=null),this.abort("closed")},t.prototype.uuid=function(){return l()},t.prototype.getPresetProperties=function(){return this._presetProps.build(this._config,{})},t.prototype.shutdown=function(){this.close()},t.prototype.getConfig=function(){return r({},this._config)},t.prototype.getLogger=function(){return this._logger},t.prototype.getRegistry=function(){return this._registry},t.prototype.getRetryPolicy=function(){return this._retryPolicy},t.prototype.getFailedQueue=function(){return this._failedQueue},t.prototype.getChannel=function(){return this._channel},t.prototype.getPipeline=function(){return this._pipeline},t.prototype.getSignedIdentity=function(){return this._signedIdentity},t.prototype.getStats=function(){var t;return null===(t=this._stats)||void 0===t?void 0:t.snapshot()},t.prototype.resetStats=function(){var t;null===(t=this._stats)||void 0===t||t.reset()},t.prototype.isBrowser=function(){return a()},t.prototype.isInitialized=function(){return this._inited},t}(),bt=new Map;function kt(){var t,e;if(a())return"web";var n=globalThis;return void 0!==n.navigator&&"ReactNative"===(null===(t=n.navigator)||void 0===t?void 0:t.product)||void 0!==n.__REACT_NATIVE__?"rn":"undefined"!=typeof process&&(null===(e=process.versions)||void 0===e?void 0:e.node)?"node":"unknown"}"undefined"!=typeof window&&(window.eventTracker=new wt);var St=null;function It(){return i(this,void 0,void 0,function(){return o(this,function(t){return[2,{available:!1,hmacSha256:function(t,e){return i(this,void 0,void 0,function(){var n,r;return o(this,function(i){switch(i.label){case 0:return[4,crypto.subtle.importKey("raw",t,{name:"HMAC",hash:"SHA-256"},!1,["sign"])];case 1:return n=i.sent(),[4,crypto.subtle.sign("HMAC",n,e)];case 2:return r=i.sent(),[2,new Uint8Array(r)]}})})},aesGcmEncrypt:function(t,e,n){return i(this,void 0,void 0,function(){var r,i;return o(this,function(o){switch(o.label){case 0:return[4,crypto.subtle.importKey("raw",t,"AES-GCM",!1,["encrypt"])];case 1:return r=o.sent(),[4,crypto.subtle.encrypt({name:"AES-GCM",iv:e},r,n)];case 2:return i=o.sent(),[2,new Uint8Array(i)]}})})},aesGcmDecrypt:function(t,e,n){return i(this,void 0,void 0,function(){var r,i;return o(this,function(o){switch(o.label){case 0:return[4,crypto.subtle.importKey("raw",t,"AES-GCM",!1,["decrypt"])];case 1:return r=o.sent(),[4,crypto.subtle.decrypt({name:"AES-GCM",iv:e},r,n)];case 2:return i=o.sent(),[2,new Uint8Array(i)]}})})}}]})})}var Et=[{name:"id_card_cn",re:/\b\d{17}[\dXx]\b/g,action:"mask"},{name:"phone_cn",re:/\b1[3-9]\d{9}\b/g,action:"mask"},{name:"email",re:/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,action:"hash"},{name:"bankcard",re:/\b\d{13,19}\b/g,action:"mask"},{name:"ipv4",re:/\b(?:\d{1,3}\.){3}\d{1,3}\b/g,action:"hash"}];function At(t){for(var e=2166136261,n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619)>>>0;return"h_"+e.toString(36)}function Tt(t){return t.length<=2?"*".repeat(t.length):t[0]+"*".repeat(t.length-2)+t[t.length-1]}var xt=function(){function t(t){void 0===t&&(t={}),this.patterns=s(s([],Et,!0),t.patterns||[],!0),this.exclude=new Set(t.excludeKeys||[])}return t.prototype.scan=function(t){if("string"!=typeof t)return{value:t,hits:[]};for(var e=t,n=[],r=function(t){if(!t.re.test(e))return t.re.lastIndex=0,"continue";t.re.lastIndex=0,n.push({name:t.name,action:t.action}),e=e.replace(t.re,function(e){var n=function(t,e){switch(t){case"drop":return;case"mask":return Tt(e);case"hash":return At(e);default:return e}}(t.action,e);return void 0===n?"":n})},i=0,o=this.patterns;i<o.length;i++){r(o[i])}return{value:e,hits:n}},t.prototype.scanProperties=function(t){for(var e=this,n={},r=0,i=0,o=Object.entries(t);i<o.length;i++){var s=o[i],a=s[0],c=s[1];if(this.exclude.has(a))n[a]=c;else if("string"==typeof c){var u=this.scan(c),l=u.value,d=u.hits;n[a]=l,r+=d.length}else if(c&&"object"==typeof c&&!Array.isArray(c)){var f=this.scanProperties(c),h=f.properties,p=f.hits;n[a]=h,r+=p}else Array.isArray(c)?n[a]=c.map(function(t){if("string"==typeof t){var n=e.scan(t),i=n.value,o=n.hits;return r+=o.length,i}return t}):n[a]=c}return{properties:n,hits:r}},t}(),Ct="__et_consent__",Pt=function(){function t(t){if(this.logger=t,this.state={mode:"off",scopes:new Set},this.storage=null,this.listeners=new Set,"undefined"!=typeof window){try{this.storage=window.localStorage}catch(t){}this.loadFromStorage()}}return t.prototype.setMode=function(t){var e,n;this.state.mode=t,null===(n=(e=this.logger).log)||void 0===n||n.call(e,"[Privacy] mode set to ".concat(t)),this.emit()},t.prototype.getMode=function(){return this.state.mode},t.prototype.grant=function(t){var e,n;"all"===t?(this.state.scopes.add("analytics"),this.state.scopes.add("personalization"),this.state.scopes.add("marketing")):this.state.scopes.add(t),this.persist(),null===(n=(e=this.logger).log)||void 0===n||n.call(e,"[Consent] granted ".concat(t)),this.emit()},t.prototype.revoke=function(t){var e,n;"all"===t?this.state.scopes.clear():this.state.scopes.delete(t),this.persist(),null===(n=(e=this.logger).warn)||void 0===n||n.call(e,"[Consent] revoked ".concat(t)),this.emit()},t.prototype.has=function(t){return!!this.state.scopes.has("all")||this.state.scopes.has(t)},t.prototype.shouldTrack=function(t){return void 0===t&&(t="analytics"),!!this.has(t)},t.prototype.subscribe=function(t){var e=this;return this.listeners.add(t),function(){return e.listeners.delete(t)}},t.prototype.applyPrivacy=function(t,e){if(void 0===e&&(e=this.state.mode),"off"===e)return t;var n=r({},t);if("strict"===e)for(var i=0,o=["$ip","$ip_addr","$user_agent","$device_id","$mac","$idfa"];i<o.length;i++){var s=o[i];s in n&&delete n[s]}return"balanced"!==e&&"strict"!==e||"$distinct_id"in n&&n.$distinct_id,n},t.prototype.loadFromStorage=function(){if(this.storage)try{var t=this.storage.getItem(Ct);if(!t)return;var e=JSON.parse(t);e.mode&&(this.state.mode=e.mode),Array.isArray(e.scopes)&&(this.state.scopes=new Set(e.scopes))}catch(t){}},t.prototype.persist=function(){if(this.storage)try{this.storage.setItem(Ct,JSON.stringify({mode:this.state.mode,scopes:Array.from(this.state.scopes)}))}catch(t){}},t.prototype.emit=function(){for(var t=0,e=Array.from(this.listeners);t<e.length;t++){var n=e[t];try{n(this.state)}catch(t){}}},t}();function $t(){if("function"==typeof globalThis.requestIdleCallback){var t=globalThis.requestIdleCallback.bind(globalThis),e=globalThis.cancelIdleCallback.bind(globalThis);return{schedule:function(e,n){return t(e,n||{})},cancel:function(t){e(t)}}}return{schedule:function(t){return setTimeout(function(){return t({didTimeout:!1,timeRemaining:function(){return 50}})},0)},cancel:function(t){clearTimeout(t)}}}var Dt=$t();function Lt(){return"function"==typeof globalThis.Worker}var Ot=function(){function t(){this.name="offscreen",this.worker=null,this.queue=[]}return t.prototype.canUse=function(){return Lt()},t.prototype.getWorker=function(){var t=this;if(this.worker)return this.worker;if(!Lt())return null;try{var e=new Blob(["\nself.onmessage = async function (e) {\n const msg = e.data;\n const start = Date.now();\n try {\n if (msg.kind === 'send') {\n const ev = msg.payload;\n const body = 'data=' + encodeURIComponent(JSON.stringify(ev)) + '&batch=0';\n const r = await fetch(msg.url, { method:'POST', mode:'cors', credentials:'omit',\n headers:{'Content-Type':'application/x-www-form-urlencoded'}, body, keepalive:true });\n self.postMessage({ kind: r.ok ? 'result' : 'error', ok: r.ok, durationMs: Date.now() - start });\n } else if (msg.kind === 'sendBatch') {\n const evs = msg.payload;\n const body = 'data=' + encodeURIComponent(JSON.stringify(evs)) + '&batch=1';\n const r = await fetch(msg.url, { method:'POST', mode:'cors', credentials:'omit',\n headers:{'Content-Type':'application/x-www-form-urlencoded'}, body, keepalive:true });\n self.postMessage({ kind: r.ok ? 'result' : 'error', ok: r.ok, durationMs: Date.now() - start });\n } else if (msg.kind === 'shutdown') {\n self.close();\n }\n } catch (err) {\n self.postMessage({ kind: 'error', ok: false, err: String(err), durationMs: Date.now() - start });\n }\n};\n"],{type:"application/javascript"}),n=URL.createObjectURL(e);this.worker=new Worker(n),this.worker.onmessage=function(e){var n=t.queue.shift();n&&("error"===e.data.kind?n.reject(new Error(e.data.err||"worker send failed")):n.resolve())},this.worker.onerror=function(e){for(var n=0,r=t.queue.splice(0);n<r.length;n++){r[n].reject(new Error(e.message||"worker error"))}}}catch(t){this.worker=null}return this.worker},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,r,i,s=this;return o(this,function(o){switch(o.label){case 0:return n=Array.isArray(e.config.server_url)?e.config.server_url[0]:e.config.server_url,(r=this.getWorker())?[3,2]:[4,Promise.resolve().then(function(){return V})];case 1:return i=o.sent().AjaxSender,this.fallback||(this.fallback=new i),[2,this.fallback.send(t,e)];case 2:return[2,new Promise(function(e,i){s.queue.push({resolve:e,reject:i}),r.postMessage({kind:"send",payload:t,url:n})})]}})})},t.prototype.sendBatch=function(t,e){return i(this,void 0,void 0,function(){var n,r,i,s,a,c=this;return o(this,function(o){switch(o.label){case 0:return n=Array.isArray(e.config.server_url)?e.config.server_url[0]:e.config.server_url,(r=this.getWorker())?[3,2]:[4,Promise.resolve().then(function(){return V})];case 1:return i=o.sent().AjaxSender,this.fallback||(this.fallback=new i),[2,null===(a=(s=this.fallback).sendBatch)||void 0===a?void 0:a.call(s,t,e)];case 2:return[2,new Promise(function(e,i){c.queue.push({resolve:e,reject:i}),r.postMessage({kind:"sendBatch",payload:t,url:n})})]}})})},t.prototype.destroy=function(){this.worker&&(this.worker.postMessage({kind:"shutdown"}),this.worker.terminate(),this.worker=null)},t}(),Mt=function(){function t(t){this.opts=t,this.name="ws",this.ws=null,this.buffer=[],this.reconnectDelay=1e3,this.reconnectTimer=null,this.configCb=null}return t.prototype.canUse=function(){return"function"==typeof globalThis.WebSocket},t.prototype.connect=function(){var t=this;if(!this.ws||this.ws.readyState!==WebSocket.OPEN&&this.ws.readyState!==WebSocket.CONNECTING){try{this.ws=new WebSocket(this.opts.url)}catch(t){return void this.scheduleReconnect()}this.ws.onopen=function(){t.reconnectDelay=1e3,t.opts.authToken&&t.safeSend({kind:"event",data:{_auth:t.opts.authToken}});for(var e=0,n=t.buffer.splice(0);e<n.length;e++){var r=n[e];t.safeSend({kind:"event",data:r})}},this.ws.onmessage=function(e){var n;try{var r=JSON.parse("string"==typeof e.data?e.data:"{}");"config"===r.kind&&r.data&&(null===(n=t.configCb)||void 0===n||n.call(t,r.data))}catch(t){}},this.ws.onerror=function(){t.scheduleReconnect()},this.ws.onclose=function(){t.scheduleReconnect()}}},t.prototype.onConfig=function(t){this.configCb=t},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var e;return o(this,function(n){return this.ws&&this.ws.readyState===WebSocket.OPEN?(this.safeSend({kind:"event",data:t}),[2]):(this.buffer.push(t),this.buffer.length>(null!==(e=this.opts.maxBuffer)&&void 0!==e?e:1e3)&&this.buffer.shift(),this.ws||this.connect(),[2])})})},t.prototype.sendBatch=function(t,e){return i(this,void 0,void 0,function(){var e;return o(this,function(n){return this.ws&&this.ws.readyState===WebSocket.OPEN?(this.safeSend({kind:"batch",data:t}),[2]):((e=this.buffer).push.apply(e,t),this.ws||this.connect(),[2])})})},t.prototype.close=function(){this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null)},t.prototype.safeSend=function(t){var e,n;try{null===(n=this.ws)||void 0===n||n.send(JSON.stringify(t))}catch(n){"event"===t.kind&&t.data&&this.buffer.unshift(t.data),"batch"===t.kind&&Array.isArray(t.data)&&(e=this.buffer).unshift.apply(e,t.data)}},t.prototype.scheduleReconnect=function(){var t,e=this;if(!this.reconnectTimer){var n=Math.min(this.reconnectDelay,null!==(t=this.opts.maxReconnectMs)&&void 0!==t?t:3e4);this.reconnectTimer=setTimeout(function(){var t;e.reconnectTimer=null,e.reconnectDelay=Math.min(2*e.reconnectDelay,null!==(t=e.opts.maxReconnectMs)&&void 0!==t?t:3e4),e.connect()},n)}},t}();var Rt="et_session_id",Ut="et_session_last_active";function jt(t){return function(e){return function(t,e){for(var n=e||"default",r="",i=0;i<t.length;i++)r+=String.fromCharCode(t.charCodeAt(i)^n.charCodeAt(i%n.length));return"undefined"!=typeof btoa?btoa(r):Buffer.from(r,"binary").toString("base64")}(e,t)}}function Nt(t){return function(e){for(var n="undefined"!=typeof atob?atob(e):Buffer.from(e,"base64").toString("binary"),r="",i=t||"default",o=0;o<n.length;o++)r+=String.fromCharCode(n.charCodeAt(o)^i.charCodeAt(o%i.length));return r}}var Bt=new TextEncoder,Wt=new TextDecoder;function Ft(t){if("undefined"!=typeof btoa){for(var e="",n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e)}return Buffer.from(t).toString("base64")}function qt(t){return i(this,void 0,void 0,function(){var e,n;return o(this,function(r){switch(r.label){case 0:return[4,(e=Ht()).digest("SHA-256",Bt.encode(t))];case 1:return n=r.sent(),[2,e.importKey("raw",n,{name:"AES-GCM"},!1,["encrypt","decrypt"])]}})})}function Ht(){var t;if("undefined"!=typeof globalThis&&(null===(t=globalThis.crypto)||void 0===t?void 0:t.subtle))return globalThis.crypto.subtle;try{var e=require("crypto").webcrypto;return globalThis.crypto=e,e.subtle}catch(t){throw new Error("[encrypt] Web Crypto API not available (need https/localhost or Node 18+)")}}function Vt(t){return{name:"encryptor",install:function(e){var n=e.sdk,r=e.config;r.encryptor=t.encrypt,r.decoder=t.decrypt;var i=r;i.encryptEvent=t.encryptEvent,i.decryptEvent=t.decryptEvent;var o=n;o.__encryptor=t.encrypt,o.__decoder=t.decrypt,o.__encryptEvent=t.encryptEvent,o.__decryptEvent=t.decryptEvent},uninstall:function(t){if(t){var e=t.config,n=t.sdk;delete e.encryptor,delete e.decoder;var r=e;delete r.encryptEvent,delete r.decryptEvent;var i=n;delete i.__encryptor,delete i.__decoder,delete i.__encryptEvent,delete i.__decryptEvent}}}}function zt(){return i(this,void 0,void 0,function(){var t;return o(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,Function('return import("@opentelemetry/api")')()];case 1:return(t=e.sent())&&t.trace&&t.context?[2,t]:[2,null];case 2:return e.sent(),[2,null];case 3:return[2]}})})}function Jt(){var t=new Uint8Array(8);crypto.getRandomValues(t);for(var e="",n=0,r=t;n<r.length;n++){e+=r[n].toString(16).padStart(2,"0")}return e}function Gt(t){return"string"==typeof t?{stringValue:t}:"number"==typeof t?{intValue:Number.isFinite(t)?t:0}:"boolean"==typeof t?{boolValue:t}:{stringValue:JSON.stringify(t)}}function Kt(t){var e=1e6*t.time,n=1e6*(t.time+1),r=Jt()+Jt(),i=Jt(),o=[{key:"et.event.name",value:{stringValue:t.name}},{key:"et.event.time",value:{intValue:t.time}}];t.distinctId&&o.push({key:"enduser.id",value:{stringValue:t.distinctId}});for(var s=0,a=Object.entries(t.properties||{});s<a.length;s++){var c=a[s],u=c[0],l=c[1];o.push({key:"et.".concat(u),value:Gt(l)})}return{name:t.name,startTimeUnixNano:e,endTimeUnixNano:n,attributes:o,traceId:r,spanId:i}}function Qt(t,e){return i(this,void 0,void 0,function(){var n,i,s,a,c,u;return o(this,function(o){switch(o.label){case 0:n=t.map(Kt),i={resourceSpans:[{resource:{attributes:[{key:"service.name",value:{stringValue:"event-tracker"}},{key:"service.version",value:{stringValue:"1.3.0"}}]},scopeSpans:[{scope:{name:"@macroui/event-tracker",version:"1.3.0"},spans:n.map(function(t){return r(r({},t),{startTimeUnixNano:String(t.startTimeUnixNano),endTimeUnixNano:String(t.endTimeUnixNano),traceId:t.traceId,spanId:t.spanId})})}]}]},s=new AbortController,a=setTimeout(function(){return s.abort()},null!==(u=e.timeoutMs)&&void 0!==u?u:5e3),o.label=1;case 1:return o.trys.push([1,,3,4]),[4,fetch(e.endpoint,{method:"POST",headers:r({"Content-Type":"application/json"},e.headers||{}),body:JSON.stringify(i),signal:s.signal})];case 2:if(!(c=o.sent()).ok)throw new Error("OTLP HTTP ".concat(c.status));return[3,4];case 3:return clearTimeout(a),[7];case 4:return[2]}})})}var Yt=new Map;function Xt(t){var e;try{if("undefined"!=typeof window&&window.localStorage)return window.localStorage.getItem(t)}catch(t){}return null!==(e=Yt.get(t))&&void 0!==e?e:null}function Zt(t,e){try{if("undefined"!=typeof window&&window.localStorage)return void window.localStorage.setItem(t,e)}catch(t){}Yt.set(t,e)}function te(t,e){void 0===e&&(e={});var n=e.storagePrefix||"__et_exp_",i=function(t){return"".concat(n,"var_").concat(t)};function o(e){var n,r=t[e];if(!r||!r.length)return null;var o=Xt(i(e));if(o&&(f=r.find(function(t){return t.id===o})))return f;for(var s=r.reduce(function(t,e){var n;return t+(null!==(n=e.weight)&&void 0!==n?n:1)},0),a=function(t){for(var e=2166136261,n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0)%1e6/1e6}("".concat(e,":").concat(Math.random()))*s,c=0,u=r[r.length-1],l=0,d=r;l<d.length;l++){var f;if(a<=(c+=null!==(n=(f=d[l]).weight)&&void 0!==n?n:1)){u=f;break}}return Zt(i(e),u.id),u}return{variantOf:o,variantIdOf:function(t){var e,n;return null!==(n=null===(e=o(t))||void 0===e?void 0:e.id)&&void 0!==n?n:null},exposure:function(t,e){var i;if("undefined"!=typeof window){var s=function(t){return"".concat(n,"exp_").concat(t)}(t);if(!Xt(s)){Zt(s,String(Date.now()));var a=o(t);try{var c=window.eventTracker;null===(i=null==c?void 0:c.track)||void 0===i||i.call(c,"$ExperimentExposure",r({$experiment_key:t,$variant_id:null==a?void 0:a.id,$is_first_exposure:!0},e||{}))}catch(t){}}}},forceSet:function(t,e){return Zt(i(t),e)},list:function(){for(var e={},n=0,r=Object.keys(t);n<r.length;n++){var i=r[n],s=o(i);s&&(e[i]=s.id)}return e}}}function ee(t){var e,n,r,i,o;void 0===t&&(t={});var s=null!==(e=t.minInterval)&&void 0!==e?e:1e3,a=null!==(n=t.maxInterval)&&void 0!==n?n:3e4,c=null!==(r=t.windowMs)&&void 0!==r?r:5e3,u=null!==(i=t.activityThreshold)&&void 0!==i?i:5,l=null!==(o=t.events)&&void 0!==o?o:["click","scroll","keypress"],d=[];if("undefined"!=typeof window)for(var f=function(){var t=Date.now();for(d.push(t);d.length&&t-d[0]>c;)d.shift()},h=0,p=l;h<p.length;h++){var g=p[h];window.addEventListener(g,f,{passive:!0})}return function(){return d.length>u?s:d.length>0?Math.round(s+(a-s)*(1-d.length/u)):a}}function ne(){return i(this,void 0,void 0,function(){var t,e;return o(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,Function('return import("ajv")')()];case 1:return(t=n.sent())&&t.default?(e=t.default,[2,new e({allErrors:!0,strict:!1})]):[2,null];case 2:return n.sent(),[2,null];case 3:return[2]}})})}var re=function(){function t(t){this.opts=t,this.ajv=null,this.entries=new Map,this.remoteCache=null}return t.prototype.init=function(){return i(this,void 0,void 0,function(){var t,e,n,r;return o(this,function(i){switch(i.label){case 0:return t=this,[4,ne()];case 1:if(t.ajv=i.sent(),!this.ajv)return[2];for(e=0,n=this.opts.schemas||[];e<n.length;e++)r=n[e],this.add(r);return this.opts.remoteUrl?[4,this.fetchRemote()]:[3,3];case 2:i.sent(),i.label=3;case 3:return[2]}})})},t.prototype.add=function(t){if(this.ajv){var e=this.ajv.compile(t.schema);this.entries.set(t.event,e)}},t.prototype.fetchRemote=function(){return i(this,void 0,void 0,function(){var t,e,n,r,i,s,a,c,u,l,d,f,h,p,g;return o(this,function(o){switch(o.label){case 0:if(!this.opts.remoteUrl)return[2];if(t=null!==(p=this.opts.remoteTtlMs)&&void 0!==p?p:36e5,this.remoteCache&&Date.now()-this.remoteCache.ts<t){for(e=0,n=this.remoteCache.schemas;e<n.length;e++)h=n[e],this.add(h);return[2]}o.label=1;case 1:return o.trys.push([1,4,,5]),r={},(null===(g=this.remoteCache)||void 0===g?void 0:g.etag)&&(r["If-None-Match"]=this.remoteCache.etag),[4,fetch(this.opts.remoteUrl,{headers:r})];case 2:if(304===(i=o.sent()).status&&this.remoteCache){for(this.remoteCache.ts=Date.now(),s=0,a=this.remoteCache.schemas;s<a.length;s++)h=a[s],this.add(h);return[2]}return i.ok?(c=i.headers.get("ETag")||void 0,[4,i.json()]):[2];case 3:for(u=o.sent(),l=Array.isArray(u)?u:u.schemas||[],this.remoteCache={url:this.opts.remoteUrl,etag:c,schemas:l,ts:Date.now()},d=0,f=l;d<f.length;d++)h=f[d],this.add(h);return[3,5];case 4:return o.sent(),[3,5];case 5:return[2]}})})},t.prototype.validate=function(t,e){var n,r=this.entries.get(t);if(!r)return{ok:!0};var i=r(e);return{ok:i,errors:i?void 0:(null===(n=this.ajv)||void 0===n?void 0:n.errors)||[]}},t}();var ie=function(){function t(t){this.opts=t,this.globalBuckets=[],this.userBuckets=new Map,this.eventBuckets=new Map}return t.prototype.allow=function(t,e){var n,r,i,o,s,a,c,u=Date.now();if(this.opts.global&&!this.checkBucket(this.globalBuckets,this.opts.global,u))return null===(r=(n=this.opts).onDrop)||void 0===r||r.call(n,{scope:"global"}),!1;if(this.opts.user&&e&&((c=this.userBuckets.get(e))||(c=[],this.userBuckets.set(e,c)),!this.checkBucket(c,this.opts.user,u)))return null===(o=(i=this.opts).onDrop)||void 0===o||o.call(i,{scope:"user",key:e}),!1;if(this.opts.perEvent&&((c=this.eventBuckets.get(t))||(c=[],this.eventBuckets.set(t,c)),!this.checkBucket(c,this.opts.perEvent,u)))return null===(a=(s=this.opts).onDrop)||void 0===a||a.call(s,{scope:"event",event:t}),!1;return!0},t.prototype.checkBucket=function(t,e,n){for(var r=n-e.windowMs;t.length&&t[0].ts<r;)t.shift();return!(t.reduce(function(t,e){return t+e.count},0)>=e.max)&&(t.push({ts:n,count:1}),!0)},t.prototype.reset=function(){this.globalBuckets=[],this.userBuckets.clear(),this.eventBuckets.clear()},t}();var oe=function(){function t(t){this.options=t,this.listeners=new Set,this.pending=[]}return t.prototype.subscribe=function(t){var e=this;return this.listeners.add(t),function(){return e.listeners.delete(t)}},t.prototype.emit=function(t){for(var e=0,n=this.listeners;e<n.length;e++){var r=n[e];try{r(t)}catch(t){}}},t.prototype.enqueue=function(t){this.pending.push(t)},t.prototype.queueSize=function(){return this.pending.length},t.prototype.flush=function(){return i(this,void 0,void 0,function(){var t,e,n,r,i,s,a;return o(this,function(o){switch(o.label){case 0:if(!this.pending.length)return[2];t=this.pending.splice(0),e=0,n=this.options.destinations,o.label=1;case 1:if(!(e<n.length))return[3,6];r=n[e],i=0,s=t,o.label=2;case 2:return i<s.length?(a=s[i],[4,this.send(r,a).catch(function(){})]):[3,5];case 3:o.sent(),o.label=4;case 4:return i++,[3,2];case 5:return e++,[3,1];case 6:return[2]}})})},t.prototype.send=function(t,e){return i(this,void 0,void 0,function(){var n,i,s,a;return o(this,function(o){switch(o.label){case 0:n=t.transform?t.transform(e):e,i=null!==(a=this.options.maxRetry)&&void 0!==a?a:2,s=0,o.label=1;case 1:if(!(s<=i))return[3,6];o.label=2;case 2:return o.trys.push([2,4,,5]),[4,fetch(t.endpoint,{method:t.method||"POST",headers:r({"Content-Type":"application/json"},t.headers||{}),body:JSON.stringify(n),keepalive:!0})];case 3:return o.sent().ok?[2]:[3,5];case 4:return o.sent(),[3,5];case 5:return s++,[3,1];case 6:return[2]}})})},t}();var se=new wt;"undefined"!=typeof window&&(window.eventTracker=se),t.AudienceSync=oe,t.ConfigError=ut,t.DEFAULT_PATTERNS=Et,t.EncryptError=ot,t.EventTracker=wt,t.FailedQueue=et,t.GLOBAL_STATS=mt,t.IdentityError=st,t.IdentityManager=v,t.InitError=rt,t.InstanceChannel=X,t.LIB_NAME=_,t.LIB_VERSION=w,t.Logger=d,t.OffscreenSender=Ot,t.PiiDetector=xt,t.PluginError=ct,t.PluginRegistry=Q,t.PresetEvent=y,t.PresetProperty=m,t.PresetPropertyBuilder=b,t.PrivacyManager=Pt,t.RateLimiter=ie,t.RetryPolicy=Z,t.SDKError=nt,t.SchemaRegistry=re,t.SendError=it,t.SendPipeline=vt,t.StatsCollector=yt,t.StorageError=at,t.WebSocketSender=Mt,t.aesGcmDecryptAsync=function(t){var e=this,n=null;return function(r){return i(e,void 0,void 0,function(){var e,i,s,a,c,u;return o(this,function(o){switch(o.label){case 0:return n||(n=qt(t)),[4,n];case 1:return e=o.sent(),i=Ht(),s=function(t){if("undefined"!=typeof atob){for(var e=atob(t),n=new Uint8Array(e.length),r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}return new Uint8Array(Buffer.from(t,"base64"))}(r),a=s.slice(0,12),c=s.slice(12),[4,i.decrypt({name:"AES-GCM",iv:a},e,c)];case 2:return u=o.sent(),[2,Wt.decode(u)]}})})}},t.aesGcmEncryptAsync=function(t){var e=this,n=null;return function(r){return i(e,void 0,void 0,function(){var e,i,s,a,c,u;return o(this,function(o){switch(o.label){case 0:return n||(n=qt(t)),[4,n];case 1:return e=o.sent(),i=Ht(),s=globalThis.crypto.getRandomValues(new Uint8Array(12)),c=Uint8Array.bind,[4,i.encrypt({name:"AES-GCM",iv:s},e,Bt.encode(r))];case 2:return a=new(c.apply(Uint8Array,[void 0,o.sent()])),(u=new Uint8Array(s.length+a.length)).set(s,0),u.set(a,s.length),[2,Ft(u)]}})})}},t.audienceSync=function(t){var e=null;return{name:"audience-sync",install:function(n){var r,i,o=n.sdk;e=new oe(t),o.audience=e;var s=null===(r=o.identify)||void 0===r?void 0:r.bind(o);"function"==typeof s&&(o.identify=function(t,n){var r=s(t,n);return e.emit({distinct_id:t,trigger:"identify"}),r});var a=null===(i=o.login)||void 0===i?void 0:i.bind(o);"function"==typeof a&&(o.login=function(t){var n=a(t);return e.emit({distinct_id:t,trigger:"login"}),n})},uninstall:function(){e=null}}},t.autoTrack=function(t){var e;void 0===t&&(t={});var n=null,r=Date.now(),i=new Set,o=null!==(e=t.scrollThresholds)&&void 0!==e?e:[25,50,75,100];function s(t,e){void 0===e&&(e={}),n&&n.track(t,e)}function c(){try{return location.pathname+location.search+location.hash}catch(t){return""}}function u(t,e){document.addEventListener("click",function(n){var r,i=n.target;if(i){var o=i.closest(t||"a, button, [data-track-click]");if(o){var a=((r={})[m.ElementSelector]=function(t){if(t.id)return"#".concat(t.id);var e=[],n=t,r=function(){var t=n,r=t.tagName.toLowerCase();t.classList&&t.classList.length&&(r+="."+Array.from(t.classList).slice(0,2).join("."));var i=t.parentElement;if(i){var o=Array.from(i.children).filter(function(e){return e instanceof Element&&e.tagName===t.tagName});o.length>1&&(r+=":nth-of-type(".concat(o.indexOf(t)+1,")"))}e.unshift(r),n=i};for(;n&&n!==document.body&&e.length<5;)r();return e.join(" > ")}(o),r[m.ElementType]=o.tagName.toLowerCase(),r[m.ElementContent]=(o.textContent||"").trim().slice(0,100),r[m.ElementId]=o.id||void 0,r[m.ElementClassName]=o.className||void 0,r);o instanceof HTMLAnchorElement&&(a.$element_href=o.href);for(var c=0,u=e;c<u.length;c++){var l=u[c],d=o.getAttribute(l);null!=d&&(a[l]=d)}s(y.WebClick,a)}}},!0)}function l(){var t=function(){var t,e=Date.now()-r;s(y.WebStay,((t={})[m.EventDuration]=e,t[m.URLPath]=c(),t))};window.addEventListener("beforeunload",t),document.addEventListener("visibilitychange",function(){"hidden"===document.visibilityState?t():r=Date.now()})}return{name:"auto-track",install:function(e){var r=e.sdk;a()&&(n=r,!1!==t.pageview&&function(){var t=function(){var t;s(y.PageView,((t={})[m.URLPath]=c(),t[m.Title]=document.title,t[m.Referrer]=document.referrer,t))};setTimeout(t,0);var e=function(e){var n=history[e];history[e]=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var i=n.apply(this,e);return setTimeout(t,0),i}};e("pushState"),e("replaceState"),window.addEventListener("popstate",function(){return setTimeout(t,0)}),window.addEventListener("hashchange",function(){return setTimeout(t,0)})}(),!1!==t.webclick&&u(t.webclickSelector,t.webclickAttrs||["data-track-id","data-sensors-click"]),!1!==t.webstay&&l(),t.scrolldepth&&(i=new Set,window.addEventListener("scroll",function(){var t,e=document.documentElement.scrollHeight-window.innerHeight;if(!(e<=0))for(var n=Math.min(100,Math.round(window.scrollY/e*100)),r=0,a=o;r<a.length;r++){var u=a[r];n>=u&&!i.has(u)&&(i.add(u),s("$scroll_depth",((t={percent:u})[m.URLPath]=c(),t)))}},{passive:!0})))}}},t.createExperiment=te,t.createIdleScheduler=$t,t.createReplay=function(t,e){var n,r,i,o,a;void 0===e&&(e={});var c=null!==(n=e.speed)&&void 0!==n?n:1,u=!1!==e.callRealTrack,l=null!==(r=e.startOffsetMs)&&void 0!==r?r:0,d=!1,f=!1,h=0,p=null,g=null,v=s([],t,!0).filter(function(t){return t.time>=l}).sort(function(t,e){return t.time-e.time});function y(){var t,n,r,i,o,s;if(!f&&!d)if(h>=v.length)null===(t=e.onEnd)||void 0===t||t.call(e);else{var a=v[h],l=Date.now(),m=a.time-(null!==(r=null===(n=v[0])||void 0===n?void 0:n.time)&&void 0!==r?r:0);if(null!==g){var _=m/c-(l-g);if(_>0)return void(p=setTimeout(y,_))}if(g=l,null===(i=e.onEvent)||void 0===i||i.call(e,a,h),null===(o=e.onProgress)||void 0===o||o.call(e,{current:h+1,total:v.length,percent:(h+1)/v.length*100}),u&&a.event){var w=function(){var t;return"undefined"==typeof window?null:null!==(t=window.eventTracker)&&void 0!==t?t:null}();try{null===(s=null==w?void 0:w.track)||void 0===s||s.call(w,a.event,a.properties)}catch(t){}}h++,queueMicrotask(y)}}if("undefined"!=typeof window)queueMicrotask(y);else if(v.length){for(var m=0;m<v.length;m++)null===(i=e.onEvent)||void 0===i||i.call(e,v[m],m),null===(o=e.onProgress)||void 0===o||o.call(e,{current:m+1,total:v.length,percent:(m+1)/v.length*100}),u&&v[m].event;null===(a=e.onEnd)||void 0===a||a.call(e)}return{pause:function(){d=!0,p&&(clearTimeout(p),p=null)},resume:function(){d=!1,g=null,y()},seek:function(t){h=Math.max(0,Math.min(t,v.length-1)),g=null,y()},stop:function(){f=!0,p&&(clearTimeout(p),p=null)}}},t.createSignedIdentity=gt,t.crossDomainStitching=function(t){var e,n;void 0===t&&(t={});var r=t.cookieName||"_sa_link_id",i=(null===(e=t.domain)||void 0===e?void 0:e.startsWith("."))?t.domain:t.domain?".".concat(t.domain):void 0,o=null!==(n=t.expiresDays)&&void 0!==n?n:365,s=!1!==t.injectProperty;return{name:"cross-domain-stitching",install:function(t){var e=t.sdk,n=t.config,a=function(t){if("undefined"==typeof document)return null;for(var e=encodeURIComponent(t)+"=",n=0,r=document.cookie.split(";");n<r.length;n++){for(var i=r[n];" "===i.charAt(0);)i=i.substring(1);if(0===i.indexOf(e))return decodeURIComponent(i.substring(e.length))}return null}(r);if(!a){var c=e.uuid;a="function"==typeof c?c():"link_".concat(Date.now(),"_").concat(Math.random().toString(36).slice(2)),function(t,e,n,r){if(void 0===r&&(r=365),"undefined"!=typeof document){var i=new Date;i.setTime(i.getTime()+24*r*60*60*1e3);var o="".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e),"; expires=").concat(i.toUTCString(),"; path=/");n&&(o+="; domain=".concat(n));try{document.cookie=o}catch(t){}}}(r,a,i,o)}e.getLinkId=function(){return a},n._sa_link_id=a,s&&e.register({_sa_link_id:a})}}},t.cspCompliant=function(t){return void 0===t&&(t={}),{name:"csp-compliant",install:function(e){var n=e.sdk,r=e.config,i=t.nonce||t.metaSelector&&function(t){if("undefined"==typeof document)return null;var e=document.querySelector(t);return(null==e?void 0:e.getAttribute("nonce"))||null}(t.metaSelector)||r.csp_nonce||null;i&&(r.csp_nonce=i,!1!==t.injectProperty&&n.register({$csp_nonce:i}),n.getCspNonce=function(){return i})}}},t.debugSender=function(t){return void 0===t&&(t={}),{name:"debug-sender",install:function(e){var n,r,i,o,s,a=e.config,c=e.stages,l=e.registry,d=e.sdk;if(null!==(n=t.enable)&&void 0!==n?n:!!a.debug_mode){var f,h,p=null!==(i=null!==(r=t.url)&&void 0!==r?r:a.debug_mode_url)&&void 0!==i?i:(f=a.server_url,(h=Array.isArray(f)?f[0]:f).includes("?")?h+"&debug":h+"?debug"),g=null!==(s=null!==(o=t.upload)&&void 0!==o?o:a.debug_mode_upload)&&void 0!==s?s:"true";c.sendDataStage.register({name:"debug-sender",priority:30,entry:function(e){var n=e.data;try{var r=D(n,a.encryptor);Promise.resolve(r).then(function(r){var i=O(p,r,"form");if(u()){var o=new Image(1,1);o.onload=function(){var e;try{null===(e=t.onSuccess)||void 0===e||e.call(t,n)}catch(t){}try{"undefined"!=typeof alert&&alert("debug数据发送成功"+(n.event||""))}catch(t){}},o.onerror=function(){var e,r=new Error("Image load failed");try{null===(e=t.onError)||void 0===e||e.call(t,r,n)}catch(t){}try{"undefined"!=typeof alert&&alert("debug失败 错误原因"+JSON.stringify({message:r.message}))}catch(t){}},o.src=i}else e.cancellationToken.stop()}).catch(function(t){d.getLogger().error("debug-sender error:",t)})}catch(t){d.getLogger().error("debug-sender error:",t)}return n}}),l.on("sdkAfterInitAPI",function(){Object.defineProperty(globalThis,"__et_debug_upload__",{value:g,writable:!0})})}},uninstall:function(){try{delete globalThis.__et_debug_upload__}catch(t){}}}},t.default=se,t.defaultDecryptor=Nt,t.defaultEncryptor=jt,t.detectPlatform=kt,t.encryptor=Vt,t.experiment=function(t,e){void 0===e&&(e={});var n=te(t,e);return{name:"experiment",install:function(e){var i=e.sdk,o=e.stages;i.experiment=n,o.sendDataStage.register({name:"experiment-inject",priority:80,entry:function(e){if("sendDataStage"!==e.meta.stage)return e.data;for(var i=e.data,o=r({},i.properties||{}),s=0,a=Object.entries(t);s<a.length;s++){var c=a[s],u=c[0],l=(c[1],n.variantOf(u));l&&(o["$exp__".concat(u)]=l.id,l.properties&&Object.assign(o,l.properties))}return r(r({},i),{properties:o})}})}}},t.exposure=function(t){void 0===t&&(t={});var e=null,n=null,r=new WeakSet;function i(){var i,o;if("IntersectionObserver"in window){var s=null!==(i=t.threshold)&&void 0!==i?i:.5,a=null!==(o=t.duration)&&void 0!==o?o:500;if(n=new IntersectionObserver(function(n){for(var i=function(n){if(n.intersectionRatio>=s){var i=n.target,o=setTimeout(function(){var o;if(!r.has(i)&&(r.add(i),e)){var s=((o={})[m.ElementSelector]=function(t){if(t.id)return"#".concat(t.id);for(var e=[],n=t;n&&n!==document.body&&e.length<5;){var r=n.tagName.toLowerCase();n.classList&&n.classList.length&&(r+="."+Array.from(n.classList).slice(0,2).join(".")),e.unshift(r),n=n.parentElement}return e.join(" > ")}(i),o[m.ElementType]=i.tagName.toLowerCase(),o.$intersection_ratio=n.intersectionRatio,o.$exposure_duration=a,o);if(i instanceof HTMLElement&&i.dataset)for(var c=t.attrPrefix||"data-exp-",u=0,l=Object.keys(i.dataset);u<l.length;u++){var d=l[u];d.startsWith(c)&&(s[d]=i.dataset[d])}e.track(y.ElementExposure,s)}},a),c=function(){clearTimeout(o),i.removeEventListener("mouseleave",c)};i.addEventListener("mouseleave",c)}},o=0,c=n;o<c.length;o++){i(c[o])}},{threshold:[s]}),t.selector)document.querySelectorAll(t.selector).forEach(function(t){return n.observe(t)})}}return{name:"exposure",install:function(t){var n=t.sdk;a()&&(e=n,"complete"===document.readyState?i():window.addEventListener("load",i,{once:!0}))},uninstall:function(){null==n||n.disconnect(),n=null,e=null}}},t.fastHash=function(t){for(var e=2166136261,n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0},t.fnv1a=At,t.getWasmCrypto=function(){return St||(St=i(this,void 0,void 0,function(){var t,e;return o(this,function(n){switch(n.label){case 0:if((t=globalThis).__ET_WASM_CRYPTO__)return[2,t.__ET_WASM_CRYPTO__];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,Function('return import("@macroui/crypto-wasm")')()];case 2:return(e=n.sent())&&e.default?[2,e.default]:[3,4];case 3:return n.sent(),[3,4];case 4:return[2,It()]}})}))},t.globalIdleScheduler=Dt,t.hmacSign=B,t.hmacSignAsync=ht,t.hmacSignSync=function(t,e){var n,r,i=(null===(r=null===(n=globalThis.process)||void 0===n?void 0:n.versions)||void 0===r?void 0:r.node)?require("crypto"):null;if(!i)throw new Error("hmacSignSync only available in Node");var o=i.createHmac("sha256",e.salt?"".concat(e.secret,":").concat(e.salt):e.secret);return o.update(t),o.digest("base64url")},t.hmacVerify=function(t,e,n){return i(this,void 0,void 0,function(){return o(this,function(r){switch(r.label){case 0:return[4,B(t,n)];case 1:return[2,W(r.sent(),e)]}})})},t.hmacVerifyAsync=pt,t.indexedDBSender=function(t){void 0===t&&(t={});var e=t.dbName||"event-tracker-outbox",n=t.storeName||"outbox",r=t.max||500,i=null,o={name:"indexeddb-sender",priority:60,entry:function(t){if("sendDataStage"===t.meta.stage){var o=t.data;return null!=i||(i=a()&&"undefined"!=typeof indexedDB?new Promise(function(t){try{var r=indexedDB.open(e,1);r.onupgradeneeded=function(){var t=r.result;t.objectStoreNames.contains(n)||t.createObjectStore(n,{autoIncrement:!0})},r.onsuccess=function(){return t(r.result)},r.onerror=function(){return t(null)}}catch(e){t(null)}}):Promise.resolve(null)),i.then(function(t){if(t)try{var e=t.transaction(n,"readwrite").objectStore(n),i=D(o),s=e.count();s.onsuccess=function(){s.result>=r&&e.delete(IDBKeyRange.lowerBound(0,!0)),e.add({time:Date.now(),payload:i})}}catch(t){}}).catch(function(){}),o}}};return{name:"indexeddb-sender",install:function(t){var e=t.stages;a()&&e.sendDataStage.register(o)},uninstall:function(){i=null}}},t.initEdge=function(t){var e,n;if(!t.server_url)throw new Error("server_url required");var r=(t.env||{}).fetch||globalThis.fetch,s=[],a=null!==(e=t.maxQueue)&&void 0!==e?e:500,c=null!==(n=t.flushIntervalMs)&&void 0!==n?n:3e3,u=null;function l(){return i(this,void 0,void 0,function(){var e,n,i,c;return o(this,function(o){switch(o.label){case 0:if(!s.length)return[2];e=s.splice(0),o.label=1;case 1:return o.trys.push([1,4,,5]),n=Array.isArray(t.server_url)?t.server_url[0]:t.server_url,[4,Promise.resolve(L(e,t.encryptor))];case 2:return i=o.sent(),[4,r(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"data=".concat(encodeURIComponent(i),"&batch=1")})];case 3:return o.sent(),[3,5];case 4:return o.sent(),(c=s.unshift.apply(s,e))>a&&s.splice(0,c-a),[3,5];case 5:return[2]}})})}return{track:function(e,n){return i(this,void 0,void 0,function(){var r;return o(this,function(i){switch(i.label){case 0:return r=function(e,n){return{type:"track",event:e,time:Date.now(),distinct_id:"edge-user",properties:n||{},lib:{$lib:"event-tracker-edge",$lib_version:"1.3.0"},token:t.app_id||"edge",project:t.app_id||"edge"}}(e,n),s.push(r),s.length>=a?[4,l()]:[3,2];case 1:return i.sent(),[3,3];case 2:u||(u=setInterval(l,c)),i.label=3;case 3:return[2]}})})},flush:function(){return i(this,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:return[4,l()];case 1:return t.sent(),[2]}})})},size:function(){return s.length},close:function(){u&&clearInterval(u),u=null,l()}}},t.initPara=function(t){var e=t.client_id||"instance-".concat(bt.size+1),n=bt.get(e);return n?(n.switchServer(t.server_url),t.app_id&&(n.getConfig().app_id=t.app_id),n):((n=new wt).init(t),bt.set(e,n),n)},t.isPlatformSenderEnabled=function(t){return"web"===kt()||"ajax"===t},t.isSDKError=function(t){return t instanceof nt},t.listInstances=function(){return Array.from(bt.values())},t.makeIntervalPredictor=ee,t.maskValue=Tt,t.otelBridge=function(t){return void 0===t&&(t={}),{name:"otel-bridge",install:function(e){return i(this,arguments,void 0,function(e){var n,r,i,s,a,c=e.stages;return o(this,function(e){switch(e.label){case 0:return!1===t.enabled?[2]:[4,zt()];case 1:return(n=e.sent())?(r=n.trace.getTracer(t.tracerName||"@macroui/event-tracker"),i=t.spanName||function(t){return t},s=t.filterAttr||function(){return!0},a={name:"otel-bridge",priority:40,entry:function(t){if("sendDataStage"!==t.meta.stage)return t.data;for(var e=t.data,n=e.event||e.type||"event",o=r.startSpan(i(n),{attributes:{"et.event.name":n,"et.event.type":e.type||"","et.event.time":Date.now()}}),a=e.properties||{},c=0,u=Object.entries(a);c<u.length;c++){var l=u[c],d=l[0],f=l[1];if(s(d,f))try{o.setAttribute("et.".concat(d),f)}catch(t){}}return o.end(),t.data}},c.sendDataStage.register(a),[2]):(console.warn("[otel-bridge] @opentelemetry/api not found, plugin noop"),[2])}})})}}},t.otelExporter=function(t){var e=[],n=null;function r(){return i(this,void 0,void 0,function(){var n,r;return o(this,function(i){switch(i.label){case 0:if(!e.length)return[2];n=e.splice(0,e.batchSize||100),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,Qt(n,t)];case 2:return i.sent(),[3,4];case 3:return r=i.sent(),console.warn("[otelExporter] export failed:",r),[3,4];case 4:return[2]}})})}return{name:"otel-exporter",install:function(i){var o=i.sdk,s=o.track;o.track=function(i,a){var c,u;try{var l={name:i,properties:a,time:Date.now(),distinctId:null===(u=(c=o).getDistinctId)||void 0===u?void 0:u.call(c)};t.filter&&!t.filter(l)||(e.push(l),e.length>=(t.batchSize||100)?r():function(){var e;n||(n=setTimeout(function(){n=null,r()},null!==(e=t.batchIntervalMs)&&void 0!==e?e:5e3))}())}catch(t){}return s.call(this,i,a)}},uninstall:function(){n&&clearTimeout(n),n=null,e=[]}}},t.pageLeave=function(t){void 0===t&&(t={});var e=null,n=Date.now();function r(t){var r;if(e){var i=Date.now()-n;e.track(y.WebPageLeave,((r={})[m.EventDuration]=i,r[m.URLPath]=location.pathname+location.search+location.hash,r[m.Title]=document.title,r[m.ViewportPosition]=window.scrollY||0,r.$page_leave_reason=t,r))}}return{name:"pageleave",install:function(t){var i=t.sdk;if(a()){e=i,n=Date.now();document.addEventListener("visibilitychange",function(){"visible"===document.visibilityState&&(n=Date.now())}),window.addEventListener("pagehide",function(){return r("pagehide")}),window.addEventListener("beforeunload",function(){return r("unload")}),document.addEventListener("visibilitychange",function(){"hidden"===document.visibilityState&&r("hidden")})}},uninstall:function(){e=null}}},t.pageLoad=function(t){void 0===t&&(t={});var e=null;function n(){var t;if(e){var n=((t={})[m.URLPath]=location.pathname+location.search+location.hash,t[m.Title]=document.title,t);try{var r="undefined"!=typeof performance?performance:null;if(r){var i=r.getEntriesByType("navigation")[0];i&&("number"==typeof i.domContentLoadedEventEnd&&(n.$dom_ready_time=Math.round(i.domContentLoadedEventEnd-i.startTime)),"number"==typeof i.domInteractive&&(n.$dom_interactive_time=Math.round(i.domInteractive-i.startTime)),"number"==typeof i.loadEventEnd&&"number"==typeof i.startTime&&(n.$load_time=Math.round(i.loadEventEnd-i.startTime)),"number"==typeof i.responseEnd&&"number"==typeof i.requestStart&&(n.$response_time=Math.round(i.responseEnd-i.requestStart)),"number"==typeof i.transferSize&&(n[m.PageResourceSize]=i.transferSize));var o=r.getEntriesByName("first-paint")[0],s=r.getEntriesByName("first-contentful-paint")[0];o&&(n.$first_paint=Math.round(o.startTime)),s&&(n.$first_contentful_paint=Math.round(s.startTime))}}catch(t){}try{document.documentElement&&(n[m.PageHeight]=document.documentElement.scrollHeight,n[m.ViewportPosition]=window.scrollY||0)}catch(t){}e.track(y.WebPageLoad,n)}}return{name:"pageload",install:function(r){var i=r.sdk;if(a()){e=i;var o=!1!==t.immediate;"complete"===document.readyState?o?n():window.addEventListener("load",n,{once:!0}):window.addEventListener("load",function(){o?n():setTimeout(n,0)},{once:!0})}}}},t.piiDetector=function(t){void 0===t&&(t={});var e=new xt(t),n=0,i={name:"pii-detector",priority:25,entry:function(i){if("sendDataStage"!==i.meta.stage)return i.data;if(!1===t.enabled)return i.data;var o=i.data,s=o.properties||{},a=e.scanProperties(s),c=a.properties,u=a.hits;return n+=u,r(r({},o),{properties:c})}};return{name:"pii-detector",install:function(t){t.stages.sendDataStage.register(i)},uninstall:function(){n=0},__getHits:function(){return n}}},t.platformStore=function(){return new S},t.predictiveBatcher=function(t){void 0===t&&(t={});var e=ee(t);return{name:"predictive-batcher",install:function(t){t.config.batch_send_predict=e}}},t.privacy=function(t){void 0===t&&(t={});var e=null,n=(t.requireScopes,0);return{name:"privacy",install:function(i){var o=i.sdk,s=i.stages,a=i.logger;e=new Pt(a),t.mode&&e.setMode(t.mode),o.privacy={setMode:function(t){return e.setMode(t)},getMode:function(){return e.getMode()},grant:function(t){return e.grant(t)},revoke:function(t){return e.revoke(t)},has:function(t){return e.has(t)},onChange:function(t){return e.subscribe(t)},dropped:function(){return n}},s.sendDataStage.register({name:"privacy-gate",priority:30,entry:function(t){var i;if("sendDataStage"!==t.meta.stage)return t.data;var o=t.data,s=(null===(i=o.properties)||void 0===i?void 0:i.$consent_scope)||"analytics";if(e.has(s)){var a=e.getMode();if("off"!==a&&o.properties){var c=e.applyPrivacy(o.properties,a);return r(r({},o),{properties:c})}return t.data}n++}})},uninstall:function(){e=null,n=0}}},t.rateLimiter=function(t){var e=null;return{name:"rate-limiter",install:function(n){var r=n.stages,i=n.sdk;e=new ie(t);var o={name:"rate-limiter",priority:15,entry:function(t){var n,r;if("sendDataStage"!==t.meta.stage)return t.data;var o=t.data,s=o.event||o.type||"",a=o.distinct_id||(null===(r=(n=i).getDistinctId)||void 0===r?void 0:r.call(n));return e.allow(s,a)?t.data:void 0}};r.sendDataStage.register(o)},uninstall:function(){null==e||e.reset(),e=null}}},t.registerAppid=function(t){return bt.get(t)},t.schemaRegistry=function(t){void 0===t&&(t={});var e=null;return{name:"schema-registry",install:function(n){return i(this,arguments,void 0,function(n){var r,i,s=n.stages,a=n.logger;return o(this,function(n){switch(n.label){case 0:return[4,(e=new re(t)).init()];case 1:return n.sent(),r=t.onInvalid||"warn",i={name:"schema-registry",priority:20,entry:function(t){var n;if("sendDataStage"!==t.meta.stage)return t.data;if(!e)return t.data;var i=t.data,o=i.event||i.type||"",s=e.validate(o,i.properties||{}),c=s.ok,u=s.errors;if(!c){if("drop"===r)return;"warn"===r&&(null===(n=a.warn)||void 0===n||n.call(a,"[Schema] invalid event '".concat(o,"':"),u))}return t.data}},s.sendDataStage.register(i),[2]}})})},uninstall:function(){e=null}}},t.sessionEvent=function(t){var e;void 0===t&&(t={});var n=null!==(e=t.timeout)&&void 0!==e?e:18e5,r=null,i=null,o="",s=0;function c(t){o=l(),s=Date.now(),i&&(i.set(Rt,o),i.set(Ut,String(s))),r&&"start"===t&&r.track("$session_start",{$event_session_id:o})}var u={name:"session-event",priority:10,entry:function(t){if("buildDataStage"===t.meta.stage){var e;e=Date.now(),(!o||s&&e-s>n)&&c(e-s>n?"timeout":"start"),s=e,i&&i.set(Ut,String(s));var r=t.data;r&&r.properties&&(r.properties[m.EventSessionId]=o)}}};return{name:"session-event",install:function(t){var e=t.sdk,l=t.stages,d=t.store;if(a()){r=e,i=d;var f=d.get(Rt),h=Number(d.get(Ut)||"0");f&&h&&Date.now()-h<n?(o=f,s=h):c("start"),l.buildDataStage.register(u),window.addEventListener("storage",function(t){t.key!==Rt||t.newValue||(o="")})}},uninstall:function(){r=null,i=null}}},t.setWasmCrypto=function(t){St=Promise.resolve(t)},t.signPayload=F,t.trackOnce=function(t,e,n){return i(this,void 0,void 0,function(){var r,i,s,a,c;return o(this,function(o){switch(o.label){case 0:if(r=(null===(c=n.env)||void 0===c?void 0:c.fetch)||globalThis.fetch,!n.server_url)throw new Error("server_url required");return i={type:"track",event:t,time:Date.now(),distinct_id:"edge-user",properties:e,lib:{$lib:"event-tracker-edge",$lib_version:"1.3.0"},token:n.app_id||"edge",project:n.app_id||"edge"},s=Array.isArray(n.server_url)?n.server_url[0]:n.server_url,[4,Promise.resolve(D(i,n.encryptor))];case 1:return a=o.sent(),[4,r(s,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"data=".concat(encodeURIComponent(a))})];case 2:return o.sent(),[2]}})})},t.tracker=se,t.webviewBridge=function(t){void 0===t&&(t={});var e=0,n=new Map;return{name:"webview-bridge",install:function(r){var i,o=r.sdk,c=r.config;if(a()){var u=window[t.defineName||"vapph5define"];if(u&&"function"==typeof u.call){var l=null!==(i=t.timeout)&&void 0!==i?i:5e3,d=function(t,r,i){return new Promise(function(o,s){if(u.rpc&&"function"==typeof u.rpc.call){var a="rpc_".concat(++e,"_").concat(Date.now()),c=setTimeout(function(){n.delete(a),s(new Error("[WebViewBridge] RPC '".concat(t,"' timeout after ").concat(null!=i?i:l,"ms")))},null!=i?i:l);n.set(a,{resolve:o,reject:s,timer:c});try{u.rpc.call(t,a,r)}catch(t){clearTimeout(c),n.delete(a),s(t)}}else try{o(u.call(t,r))}catch(t){s(t)}})};u.rpc&&"function"==typeof u.rpc.response&&u.handle("rpc.response",function(t,e,r){if("string"==typeof t){var i=n.get(t);i&&(n.delete(t),clearTimeout(i.timer),r?i.reject(new Error(String(r))):i.resolve(e))}});var f={call:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return u.call.apply(u,s([t],e,!1))},callAsync:d,on:function(t,e){return u.handle(t,e)},isInApp:function(){return!0===u.isInApp||!0===u.call("isInApp")}};if(o.bridge=f,c.is_webview=!0,!1!==t.fetchOnInit)d(t.protocolName||"getAppInfo").then(function(e){if(e&&"object"==typeof e){for(var n=t.fieldMap||{},r=0,i=Object.entries(n);r<i.length;r++){var s=i[r],a=s[0],u=e[s[1]];null!=u&&(c[a]=u)}o.register({$app_version:e.app_version||e.appVersion,$app_id:e.app_id||e.appId,$channel:e.channel,$lib:e.lib||e.lib_name||e.libName})}}).catch(function(){})}}}}},t.whenIdle=function(t,e){void 0===e&&(e=200);var n=Dt.schedule(t,{timeout:e});return function(){return Dt.cancel(n)}},t.xorEncryptor=function(t){return Vt({encrypt:jt(t),decrypt:Nt(t)})},Object.defineProperty(t,"__esModule",{value:!0})});
2
+ //# sourceMappingURL=event-tracker.min.js.map