@sensorswave/js-sdk 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -3
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/Api.d.ts +1 -0
- package/dist/types/core/src/utils/cookie.d.ts +1 -1
- package/dist/types/web/src/basic/session.d.ts +9 -0
- package/dist/types/web/src/index.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -351,9 +351,30 @@ const anonId = SensorsWave.getAnonId();
|
|
|
351
351
|
console.log('Anonymous user ID:', anonId);
|
|
352
352
|
```
|
|
353
353
|
|
|
354
|
+
#### getSessionId
|
|
355
|
+
|
|
356
|
+
Get the current session ID. Every event sent by the SDK automatically carries a `$session_id` property with the same value, so in most cases you don't need to call this — the SDK handles sessionization for you.
|
|
357
|
+
|
|
358
|
+
The session ID is a UUIDv7 generated by the SDK and shared across all tabs/windows of the site (stored in a cookie, `sensorswave2025jssdksession`). A new session ID is generated when:
|
|
359
|
+
|
|
360
|
+
- The user visits for the first time (no session cookie)
|
|
361
|
+
- No event has been sent for 30 minutes
|
|
362
|
+
- The current session has lasted 12 hours (even if the user stayed active)
|
|
363
|
+
- `reset()` is called (user logout)
|
|
364
|
+
|
|
365
|
+
This is a read-only view of the session: calling it does not extend session activity and does not trigger an idle rotation. Only sending an event refreshes session activity. If no session exists yet, one is created on the first call, so the returned value always matches what the next event will carry.
|
|
366
|
+
|
|
367
|
+
**Returns:** string (empty string if the SDK is not initialized or capturing is opted out)
|
|
368
|
+
|
|
369
|
+
**Example:**
|
|
370
|
+
```javascript
|
|
371
|
+
const sessionId = SensorsWave.getSessionId();
|
|
372
|
+
console.log('Current session ID:', sessionId);
|
|
373
|
+
```
|
|
374
|
+
|
|
354
375
|
#### reset
|
|
355
376
|
|
|
356
|
-
Call when the user logs out to unbind the login ID from the current device. After calling `reset()`, subsequent events are no longer associated with the logged-in user.
|
|
377
|
+
Call when the user logs out to unbind the login ID from the current device. After calling `reset()`, subsequent events are no longer associated with the logged-in user. The current session also ends — the next event starts a new session with a new `$session_id`.
|
|
357
378
|
|
|
358
379
|
By default the anonymous ID is preserved, so the device continues to be tracked as an anonymous user. Pass `true` to also reset the anonymous ID and generate a new one — useful for shared/public devices where the previous visitor's anonymous identity should not be reused.
|
|
359
380
|
|
|
@@ -389,7 +410,7 @@ SensorsWave.registerCommonProperties({
|
|
|
389
410
|
|
|
390
411
|
// Dynamic property (evaluated for each event)
|
|
391
412
|
current_time: () => new Date().toISOString(),
|
|
392
|
-
|
|
413
|
+
// 不需要手工拼 session:SDK 已在每个事件自动携带 $session_id(见 getSessionId)
|
|
393
414
|
|
|
394
415
|
// You can also include user-specific data
|
|
395
416
|
user_tier: () => getUserTier()
|
|
@@ -405,7 +426,7 @@ Remove specific registered common properties.
|
|
|
405
426
|
|
|
406
427
|
**Example:**
|
|
407
428
|
```javascript
|
|
408
|
-
SensorsWave.clearCommonProperties(['app_version'
|
|
429
|
+
SensorsWave.clearCommonProperties(['app_version']);
|
|
409
430
|
```
|
|
410
431
|
|
|
411
432
|
### A/B Testing
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";class e{constructor(){this.listeners={}}on(e,t,i=!1){if(e&&t){if(!s(t))throw new Error("listener must be a function");this.listeners[e]=this.listeners[e]||[],this.listeners[e].push({listener:t,once:i})}}off(e,t){const i=this.listeners[e];if(!i?.length)return;"number"==typeof t&&i.splice(t,1);const n=i.findIndex(e=>e.listener===t);-1!==n&&i.splice(n,1)}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((i,n)=>{i.listener.call(this,...t),i.listener.once&&this.off(e,n)})}once(e,t){this.on(e,t,!0)}removeAllListeners(e){e?this.listeners[e]=[]:this.listeners={}}}const t={get:function(e){const t=e+"=",i=document.cookie.split(";");for(let n=0,s=i.length;n<s;n++){let e=i[n];for(;" "==e.charAt(0);)e=e.substring(1,e.length);if(0==e.indexOf(t))return h(e.substring(t.length,e.length))}return null},set:function({name:e,value:t,expires:i,samesite:n,secure:s,domain:r}){let o="",a="",c="",u="";if(0!==(i=null==i||void 0===i?365:i)){const e=new Date;"s"===String(i).slice(-1)?e.setTime(e.getTime()+1e3*Number(String(i).slice(0,-1))):e.setTime(e.getTime()+24*i*60*60*1e3),o="; expires="+e.toUTCString()}function l(e){return e?e.replace(/\r\n/g,""):""}n&&(c="; SameSite="+n),s&&(a="; secure");const h=l(e),d=l(t),p=l(r);p&&(u="; domain="+p),h&&d&&(document.cookie=h+"="+encodeURIComponent(d)+o+"; path=/"+u+c+a)},remove:function(e){this.set({name:e,value:"",expires:-1})},isSupport:function({samesite:e,secure:t}={}){if(!navigator.cookieEnabled)return!1;const i="sensorswave_cookie_support_test";return this.set({name:i,value:"1",samesite:e,secure:t}),"1"===this.get(i)&&(this.remove(i),!0)}},i=Object.prototype.toString;function n(e){return"[object Object]"===i.call(e)}function s(e){const t=i.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t}function r(e){return"[object Array]"==i.call(e)}function o(e){return"[object String]"==i.call(e)}function a(e){return void 0===e}const c=Object.prototype.hasOwnProperty;function u(e){if(n(e)){for(let t in e)if(c.call(e,t))return!1;return!0}return!1}function l(e){return!(!e||1!==e.nodeType)}function h(e){let t=e;try{t=decodeURIComponent(e)}catch(i){t=e}return t}function d(e){try{return JSON.parse(e)}catch(t){return""}}const p=function(){let e=Date.now();return function(t){return Math.ceil((e=(9301*e+49297)%233280,e/233280*t))}}();function g(){if("function"==typeof Uint32Array){let e;if("undefined"!=typeof crypto&&(e=crypto),e&&n(e)&&e.getRandomValues)return e.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32)}return p(1e19)/1e19}const f=function(){function e(e){return("0".repeat(e)+Date.now().toString(16)).slice(-e)}return function(){let t=String(screen.height*screen.width);t=t&&/\d{4,}/.test(t)?t.slice(-4):String(31242*g()).replace(".","").slice(0,4);return e(8)+"-"+g().toString(16).replace(".","").slice(-4)+"-"+function(){const e=navigator.userAgent;let t,i=[],n=0;function s(e,t){let n=0;for(let s=0;s<t.length;s++)n|=i[s]<<8*s;return(e^n)>>>0}for(let r=0;r<e.length;r++)t=e.charCodeAt(r),i.unshift(255&t),i.length>=4&&(n=s(n,i),i=[]);return i.length>0&&(n=s(n,i)),("0000"+n.toString(16)).slice(-4)}()+"-"+t+"-"+e(12)||(String(g())+String(g())+String(g())).slice(2,15)}}();function m(e,t){t&&"string"==typeof t||(t="");let i=null;try{i=new URL(e).hostname}catch(n){}return i||t}function E(e){let t=[];try{t=atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})}catch(i){t=[]}try{return decodeURIComponent(t.join(""))}catch(i){return t.join("")}}function v(e){let t="";try{t=btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}))}catch(i){t=e}return t}const b={get:function(e){return window.localStorage.getItem(e)},parse:function(e){let t;try{t=JSON.parse(b.get(e))||null}catch(i){console.warn(i)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(i){console.warn(i)}},remove:function(e){window.localStorage.removeItem(e)},isSupport:function(){let e=!0;try{const t="__local_store_support__",i="testIsSupportStorage";b.set(t,i),b.get(t)!==i&&(e=!1),b.remove(t)}catch(t){e=!1}return e}};function _(e){return e.trim()}function I(e){if(!e||"string"!=typeof e)return"";try{return new URL(e,window.location.origin).pathname}catch(t){return""}}const S={},w="1.5.0",O="init-ready",y="spa-switch",A="ff-ready",R="$PageLeave",T="$Exception";var C=(e=>(e[e.FEATURE_GATE=1]="FEATURE_GATE",e[e.FEATURE_CONFIG=2]="FEATURE_CONFIG",e[e.EXPERIMENT=3]="EXPERIMENT",e))(C||{});const N={crossSubdomain:!1,requests:[],_sessionState:{},_abData:[],_trace_id:"",commonProps:{},_state:{anon_id:"",login_id:"",identities:{}},getIdentityCookieID(){return this._state.identities?.$identity_cookie_id||""},getCommonProps:function(){return this.commonProps||{}},setCommonProps:function(e){this.commonProps=e},getAnonId(){return this._state.anon_id||this.getIdentityCookieID()||f()},getLoginId(){return this._state.login_id},getTraceId(){return this._trace_id||f()},set:function(e,t){this._state[e]=t,this.save()},getCookieName:function(){return"sensorswave2025jssdkcross"},getABLSName:function(){return"sensorswave2025jssdkablatest"},save:function(){let e=JSON.parse(JSON.stringify(this._state));e.identities&&(e.identities=v(JSON.stringify(e.identities)));const i=JSON.stringify(e);t.set({name:this.getCookieName(),value:i,expires:365})},init:function(e){let i,s;this.crossSubdomain=e,t.isSupport()&&(i=t.get(this.getCookieName()),s=d(i)),N._state={...s||{}},N._state.identities&&(N._state.identities=d(E(N._state.identities))),N._state.identities&&n(N._state.identities)&&!u(N._state.identities)||(N._state.identities={$identity_cookie_id:f()}),N.save()},setLoginId(e){"number"==typeof e&&(e=String(e)),void 0!==e&&e&&(N.set("login_id",e),N.save())},clearLoginId(){this._state.login_id="",this.save()},resetAnonId(){this._state.anon_id="",this._state.identities={$identity_cookie_id:f()},this.save()},setAnonId(e){"number"==typeof e&&(e=String(e)),"string"==typeof e&&e?(N.set("anon_id",e),N.save()):console.warn("[SensorsWave store] Invalid anonId, ignored:",e)},saveABData(e){if(!e||u(e))return;this._abData=e;let t=JSON.parse(JSON.stringify(this._abData));t=v(JSON.stringify(t));try{localStorage.setItem(this.getABLSName(),JSON.stringify({time:Date.now(),data:t,anon_id:this.getAnonId(),login_id:this.getLoginId()}))}catch(i){console.warn("Failed to save abdata to localStorage",i)}},getABData(e=6e5){try{let t=localStorage.getItem(this.getABLSName());if(t){const{time:i,data:n,login_id:s,anon_id:r}=d(t)||{};if(i&&n&&Date.now()-i<e&&r===this.getAnonId()&&(!s||s===this.getLoginId())){const e=d(E(n));return this._abData=Array.isArray(e)?e:[],this._abData}localStorage.removeItem(this.getABLSName())}}catch(t){this._abData=[]}return this._abData||[]}};function P(e){return!(e>=400&&e<500)||408===e||429===e}function k(e){var t;if(e.data)return{contentType:"application/json",body:(t=e.data,JSON.stringify(t,(e,t)=>"bigint"==typeof t?t.toString():t,undefined))}}const x=[];function L(e){const t={...e};t.timeout=t.timeout||6e4;const i=t.transport??"fetch",n=x.find(e=>e.transport===i)?.method??x[0]?.method;if(!n)throw new Error("No available transport method for HTTP request");n(t)}function M(e){return o(e=e||document.referrer)&&(e=h(e=e.trim()))||""}function $(e){const t=m(e=e||M());if(!t)return"";const i={baidu:[/^.*\.baidu\.com$/],bing:[/^.*\.bing\.com$/],google:[/^www\.google\.com$/,/^www\.google\.com\.[a-z]{2}$/,/^www\.google\.[a-z]{2}$/],sm:[/^m\.sm\.cn$/],so:[/^.+\.so\.com$/],sogou:[/^.*\.sogou\.com$/],yahoo:[/^.*\.yahoo\.com$/],duckduckgo:[/^.*\.duckduckgo\.com$/]};for(let n of Object.keys(i)){let e=i[n];for(let i=0,s=e.length;i<s;i++)if(e[i].test(t))return n}return""}function F(e,t){return-1!==e.indexOf(t)}"function"==typeof fetch&&x.push({transport:"fetch",method:function(e){if("undefined"==typeof fetch)return void console.error("fetch API is not available");const t=k(e),i=new Headers;e.headers&&Object.keys(e.headers).forEach(t=>{i.append(t,e.headers[t])}),t?.contentType&&i.append("Content-Type",t.contentType),fetch(e.url,{method:e.method||"GET",headers:i,body:t?.body}).then(t=>t.text().then(i=>{const n={statusCode:t.status,text:i};if(200===t.status)try{n.json=JSON.parse(i)}catch(s){console.error("Failed to parse response:",s)}e.callback?.(n)})).catch(t=>{console.error("Request failed:",t),e.callback?.({statusCode:0,text:String(t)})})}}),"undefined"!=typeof XMLHttpRequest&&x.push({transport:"XHR",method:function(e){if("undefined"==typeof XMLHttpRequest)return void console.error("XMLHttpRequest is not available");const t=new XMLHttpRequest;t.open(e.method||"GET",e.url,!0);const i=k(e);e.headers&&Object.keys(e.headers).forEach(i=>{t.setRequestHeader(i,e.headers[i])}),i?.contentType&&t.setRequestHeader("Content-Type",i.contentType),t.timeout=e.timeout||6e4,t.withCredentials=!0,t.onreadystatechange=()=>{if(4===t.readyState){const n={statusCode:t.status,text:t.responseText};if(200===t.status)try{n.json=JSON.parse(t.responseText)}catch(i){console.error("Failed to parse JSON response:",i)}e.callback?.(n)}},t.send(i?.body)}});const D={FACEBOOK:"Facebook",MOBILE:"Mobile",IOS:"iOS",ANDROID:"Android",TABLET:"Tablet",ANDROID_TABLET:"Android Tablet",IPAD:"iPad",APPLE:"Apple",APPLE_WATCH:"Apple Watch",SAFARI:"Safari",BLACKBERRY:"BlackBerry",SAMSUNG_BROWSER:"SamsungBrowser",SAMSUNG_INTERNET:"Samsung Internet",CHROME:"Chrome",CHROME_OS:"Chrome OS",CHROME_IOS:"Chrome iOS",INTERNET_EXPLORER:"Internet Explorer",INTERNET_EXPLORER_MOBILE:"Internet Explorer Mobile",OPERA:"Opera",OPERA_MINI:"Opera Mini",EDGE:"Edge",MICROSOFT_EDGE:"Microsoft Edge",FIREFOX:"Firefox",FIREFOX_IOS:"Firefox iOS",NINTENDO:"Nintendo",PLAYSTATION:"PlayStation",XBOX:"Xbox",ANDROID_MOBILE:"Android Mobile",MOBILE_SAFARI:"Mobile Safari",WINDOWS:"Windows",WINDOWS_PHONE:"Windows Phone",NOKIA:"Nokia",OUYA:"Ouya",GENERIC_MOBILE:"Generic mobile",GENERIC_TABLET:"Generic tablet",KONQUEROR:"Konqueror",UC_BROWSER:"UC Browser",HUAWEI:"Huawei",XIAOMI:"Xiaomi",OPPO:"OPPO",VIVO:"vivo"},B="(\\d+(\\.\\d+)?)",H=new RegExp("Version/"+B),U=new RegExp(D.XBOX,"i"),W=new RegExp(D.PLAYSTATION+" \\w+","i"),X=new RegExp(D.NINTENDO+" \\w+","i"),j=new RegExp(D.BLACKBERRY+"|PlayBook|BB10","i"),q=new RegExp("(HUAWEI|honor|HONOR)","i"),G=new RegExp("(Xiaomi|Redmi)","i"),z=new RegExp("(OPPO|realme)","i"),V=new RegExp("(vivo|IQOO)","i"),Y={"NT3.51":"NT 3.11","NT4.0":"NT 4.0","5.0":"2000",5.1:"XP",5.2:"XP","6.0":"Vista",6.1:"7",6.2:"8",6.3:"8.1",6.4:"10","10.0":"10"};function K(e,t){return t=t||"",F(e," OPR/")&&F(e,"Mini")?D.OPERA_MINI:F(e," OPR/")?D.OPERA:j.test(e)?D.BLACKBERRY:F(e,"IE"+D.MOBILE)||F(e,"WPDesktop")?D.INTERNET_EXPLORER_MOBILE:F(e,D.SAMSUNG_BROWSER)?D.SAMSUNG_INTERNET:F(e,D.EDGE)||F(e,"Edg/")?D.MICROSOFT_EDGE:F(e,"FBIOS")?D.FACEBOOK+" "+D.MOBILE:F(e,"UCWEB")||F(e,"UCBrowser")?D.UC_BROWSER:F(e,"CriOS")?D.CHROME_IOS:F(e,"CrMo")||F(e,D.CHROME)?D.CHROME:F(e,D.ANDROID)&&F(e,D.SAFARI)?D.ANDROID_MOBILE:F(e,"FxiOS")?D.FIREFOX_IOS:F(e.toLowerCase(),D.KONQUEROR.toLowerCase())?D.KONQUEROR:function(e,t){return t&&F(t,D.APPLE)||F(i=e,D.SAFARI)&&!F(i,D.CHROME)&&!F(i,D.ANDROID);var i}(e,t)?F(e,D.MOBILE)?D.MOBILE_SAFARI:D.SAFARI:F(e,D.FIREFOX)?D.FIREFOX:F(e,"MSIE")||F(e,"Trident/")?D.INTERNET_EXPLORER:F(e,"Gecko")?D.FIREFOX:""}const J={[D.INTERNET_EXPLORER_MOBILE]:[new RegExp("rv:"+B)],[D.MICROSOFT_EDGE]:[new RegExp(D.EDGE+"?\\/"+B)],[D.CHROME]:[new RegExp("("+D.CHROME+"|CrMo)\\/"+B)],[D.CHROME_IOS]:[new RegExp("CriOS\\/"+B)],[D.UC_BROWSER]:[new RegExp("(UCBrowser|UCWEB)\\/"+B)],[D.SAFARI]:[H],[D.MOBILE_SAFARI]:[H],[D.OPERA]:[new RegExp("("+D.OPERA+"|OPR)\\/"+B)],[D.FIREFOX]:[new RegExp(D.FIREFOX+"\\/"+B)],[D.FIREFOX_IOS]:[new RegExp("FxiOS\\/"+B)],[D.KONQUEROR]:[new RegExp("Konqueror[:/]?"+B,"i")],[D.BLACKBERRY]:[new RegExp(D.BLACKBERRY+" "+B),H],[D.ANDROID_MOBILE]:[new RegExp("android\\s"+B,"i")],[D.SAMSUNG_INTERNET]:[new RegExp(D.SAMSUNG_BROWSER+"\\/"+B)],[D.INTERNET_EXPLORER]:[new RegExp("(rv:|MSIE )"+B)],Mozilla:[new RegExp("rv:"+B)]};function Z(e,t){const i=K(e,t),n=J[i];if(a(n))return null;for(let s=0;s<n.length;s++){const t=n[s],i=e.match(t);if(i)return parseFloat(i[i.length-2])}return null}const Q=[[new RegExp(D.XBOX+"; "+D.XBOX+" (.*?)[);]","i"),e=>[D.XBOX,e&&e[1]||""]],[new RegExp(D.NINTENDO,"i"),[D.NINTENDO,""]],[new RegExp(D.PLAYSTATION,"i"),[D.PLAYSTATION,""]],[j,[D.BLACKBERRY,""]],[new RegExp(D.WINDOWS,"i"),(e,t)=>{if(/Phone/.test(t)||/WPDesktop/.test(t))return[D.WINDOWS_PHONE,""];if(new RegExp(D.MOBILE).test(t)&&!/IEMobile\b/.test(t))return[D.WINDOWS+" "+D.MOBILE,""];const i=/Windows NT ([0-9.]+)/i.exec(t);if(i&&i[1]){const e=i[1];let n=Y[e]||"";return/arm/i.test(t)&&(n="RT"),[D.WINDOWS,n]}return[D.WINDOWS,""]}],[/((iPhone|iPad|iPod).*?OS (\d+)_(\d+)_?(\d+)?|iPhone)/,e=>{if(e&&e[3]){const t=[e[3],e[4],e[5]||"0"];return[D.IOS,t.join(".")]}return[D.IOS,""]}],[/(watch.*\/(\d+\.\d+\.\d+)|watch os,(\d+\.\d+),)/i,e=>{let t="";return e&&e.length>=3&&(t=a(e[2])?e[3]:e[2]),["watchOS",t]}],[new RegExp("("+D.ANDROID+" (\\d+)\\.(\\d+)\\.?(\\d+)?|"+D.ANDROID+")","i"),e=>{if(e&&e[2]){const t=[e[2],e[3],e[4]||"0"];return[D.ANDROID,t.join(".")]}return[D.ANDROID,""]}],[/Mac OS X (\d+)[_.](\d+)[_.]?(\d+)?/i,e=>{const t=["Mac OS X",""];if(e&&e[1]){const i=[e[1],e[2],e[3]||"0"];t[1]=i.join(".")}return t}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[D.CHROME_OS,""]],[/Linux|debian/i,["Linux",""]]];function ee(){const e=window.innerHeight||document.documentElement.clientHeight||document.body&&document.body.clientHeight||0,t=window.innerWidth||document.documentElement.clientWidth||document.body&&document.body.clientWidth||0,i=navigator.userAgent,n=function(e){for(let t=0;t<Q.length;t++){const[i,n]=Q[t],s=i.exec(e),r=s&&("function"==typeof n?n(s,e):n);if(r)return r}return["",""]}(i)||["",""];return{$browser:K(i),$browser_version:Z(i),$url:location?.href.substring(0,1e3),$host:location?.host,$viewport_height:e,$viewport_width:t,$lib:"webjs",$lib_version:w,$search_engine:$(),$referrer:M(),$referrer_host:m(r=r||M()),$title:document.title,$language:navigator.language,$model:(s=i,(X.test(s)?D.NINTENDO:W.test(s)?D.PLAYSTATION:U.test(s)?D.XBOX:new RegExp(D.OUYA,"i").test(s)?D.OUYA:new RegExp("("+D.WINDOWS_PHONE+"|WPDesktop)","i").test(s)?D.WINDOWS_PHONE:/iPad/.test(s)?D.IPAD:/iPod/.test(s)?"iPod Touch":/iPhone/.test(s)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(s)?D.APPLE_WATCH:j.test(s)?D.BLACKBERRY:/(kobo)\s(ereader|touch)/i.test(s)?"Kobo":new RegExp(D.NOKIA,"i").test(s)?D.NOKIA:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(s)||/(kf[a-z]+)( bui|\)).+silk\//i.test(s)?"Kindle Fire":q.test(s)?D.HUAWEI:G.test(s)?D.XIAOMI:z.test(s)?D.OPPO:V.test(s)?D.VIVO:/(Android|ZTE)/i.test(s)?!new RegExp(D.MOBILE).test(s)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(s)?/pixel[\daxl ]{1,6}/i.test(s)&&!/pixel c/i.test(s)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(s)||/lmy47v/i.test(s)&&!/QTAQZ3/i.test(s)?D.ANDROID:D.ANDROID_TABLET:D.ANDROID:new RegExp("(pda|"+D.MOBILE+")","i").test(s)?D.GENERIC_MOBILE:new RegExp(D.TABLET,"i").test(s)&&!new RegExp(D.TABLET+" pc","i").test(s)?D.GENERIC_TABLET:"")||""),$os:n?.[0]||"",$os_version:n?.[1]||"",$pathname:location?.pathname,$screen_height:Number(screen.height)||0,$screen_width:Number(screen.width)||0,$timezone_offset:60*-(new Date).getTimezoneOffset()};var s,r}const te=new class{constructor(){this.STORAGE_KEY="sensorswave_unsent_events",this.MAX_QUEUE_SIZE=200,this.MAX_RETRY_COUNT=1,this.MAX_AGE_MS=6048e5,this.queue=[],this.loadFromStorage(),this.cleanupExpiredItems()}loadFromStorage(){try{const e=localStorage.getItem(this.STORAGE_KEY);e&&(this.queue=d(e)||[])}catch(e){console.warn("Failed to load queue from localStorage:",e),this.queue=[]}}cleanupExpiredItems(){const e=Date.now(),t=this.queue.filter(t=>e-t.timestamp<this.MAX_AGE_MS);t.length!==this.queue.length&&(this.queue=t,this.saveToStorage())}saveToStorage(){try{this.cleanupExpiredItems(),this.queue.length>this.MAX_QUEUE_SIZE&&(this.queue=this.queue.slice(-this.MAX_QUEUE_SIZE)),localStorage.setItem(this.STORAGE_KEY,JSON.stringify(this.queue))}catch(e){console.warn("Failed to save queue to localStorage:",e)}}enqueue(e,t,i,n=this.MAX_RETRY_COUNT){try{const s={id:f(),url:e,data:t,headers:i,timestamp:Date.now(),retryCount:0,maxRetries:n};return this.queue.push(s),this.saveToStorage(),s.id}catch(s){return console.warn("Failed to enqueue request:",s),""}}dequeue(e){try{this.queue=this.queue.filter(t=>t.id!==e),this.saveToStorage()}catch(t){console.warn("Failed to dequeue request:",t)}}getAll(){try{return this.cleanupExpiredItems(),[...this.queue]}catch(e){return console.warn("Failed to get queue items:",e),[]}}incrementRetryCount(e){const t=this.queue.find(t=>t.id===e);return!(!t||t.retryCount>=t.maxRetries||(t.retryCount++,this.saveToStorage(),0))}clear(){this.queue=[];try{localStorage.removeItem(this.STORAGE_KEY)}catch(e){console.warn("Failed to clear queue from localStorage:",e)}}getItemById(e){return this.queue.find(t=>t.id===e)}};class ie{constructor(e={}){this.flushTimer=null,this.isFlushing=!1,this.paused=!1,this.destroyed=!1,this.config={maxBatchSize:e.maxBatchSize||20,flushInterval:e.flushInterval||5e3},this.startFlushTimer()}pause(){this.paused=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null)}resume(){this.paused&&(this.paused=!1,this.startFlushTimer())}isPaused(){return this.paused}add(){te.getAll().length>=this.config.maxBatchSize&&this.triggerFlush()}triggerFlush(){this.paused||this.isFlushing||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.isFlushing=!0,this.flush())}flush(){const e=te.getAll();if(0===e.length)return this.isFlushing=!1,void this.startFlushTimer();const t=e.slice(0,this.config.maxBatchSize),i=[],n=[];t.forEach(e=>{Array.isArray(e.data)?i.push(...e.data):i.push(e.data),n.push(e.id)});const s=t[t.length-1],r=s.url,o=s.headers;S.instance&&S.instance.config.debug&&console.log(JSON.stringify(i,null,2)),L({url:r,method:"POST",data:i,headers:o,callback:e=>{200===e.statusCode?n.forEach(e=>{te.dequeue(e)}):P(e.statusCode)?console.error("Failed to send batch events:",e):n.forEach(e=>{te.dequeue(e)}),this.isFlushing=!1,this.startFlushTimer()}})}startFlushTimer(){this.destroyed||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flushTimer=setInterval(()=>{te.getAll().length>0&&this.triggerFlush()},this.config.flushInterval))}destroy(){this.destroyed=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.paused||this.flush()}}let ne=null;function se(){const e=S.instance;return!(!e||!e.__innerInited)||(console.warn("[SensorsWave] SDK is not initialized. Please call init() first."),!1)}function re(){const e=S.instance;return!e||"function"!=typeof e.hasOptedOutCapturing||!e.hasOptedOutCapturing()}let oe=null;function ae(){return b.isSupport()?(oe||(ne||(ne=new ie({maxBatchSize:20,flushInterval:5e3})),oe=ne),oe):null}function ce(e,t,i){if(re())return L({url:e,method:"POST",data:t.data,headers:t.headers,callback:e=>{if(200!==e.statusCode){if(!P(e.statusCode))return void(i&&te.dequeue(i));if(i&&te.incrementRetryCount(i)){const e=te.getItemById(i);if(e){const t=Math.min(1e3*Math.pow(2,e.retryCount),3e4);setTimeout(()=>{ce(e.url,{data:e.data,headers:e.headers},e.id)},t)}}}else i&&te.dequeue(i),t.callback&&t.callback(e.json)}})}function ue(e){return`${e.apiHost}/in/track`}function le(e){return`${e.apiHost}/ab/evalall`}function he(e){return{"Content-Type":"application/json",SourceToken:e.sourceToken}}function de(e,t,i){S.instance&&S.instance.config.debug&&console.log(JSON.stringify(t.data,null,2));const n=te.enqueue(e,t.data,t.headers);return ce(e,{...t,callback:void 0},n)}function pe(){try{const e=sessionStorage.getItem("sensorswave_utm");if(!e)return{};const t=JSON.parse(e),i={};return Object.entries(t).forEach(([e,t])=>{null!=t&&""!==t&&(i[`$${e}`]=t)}),i}catch(e){return{}}}function ge(e){const t={};return Object.entries(e).forEach(([e,i])=>{if("function"==typeof i)try{const n=i();t[e]=n}catch(n){console.warn("[SensorsWave] Failed to resolve dynamic property:",e,n)}else t[e]=i}),t}function fe(e={},t=!0){const i={...t?ee():{},...ge(N.getCommonProps()),...e},n=pe();return Object.keys(n).length>0&&Object.assign(i,n),i}function me(e,t,i=!0){if(!se())return;if(!re())return;const n={time:Date.now(),trace_id:N.getTraceId(),event:e.event,properties:fe(e.properties,i)},s=pe();Object.keys(s).length>0&&(n.user_properties||(n.user_properties={}),n.user_properties.$set||(n.user_properties.$set={}),Object.assign(n.user_properties.$set,s)),e.user_properties&&(e.user_properties.$set&&(n.user_properties=n.user_properties||{},n.user_properties.$set={...n.user_properties.$set||{},...e.user_properties.$set},delete e.user_properties.$set),n.user_properties={...n.user_properties,...e.user_properties});const r=N.getLoginId(),o=N.getAnonId();r&&(n.login_id=r),o&&(n.anon_id=o);const a=ue(t),c=he(t),u=!1!==t.batchSend&&ae();u?(te.enqueue(a,[n],c),u.add()):de(a,{data:[n],headers:c})}function Ee({userProps:e,opts:t}){if(!se())return;if(!re())return;const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return;const s={time:Date.now(),trace_id:N.getTraceId(),event:"$UserSet",login_id:i,anon_id:n,user_properties:e,properties:fe()},r=ue(t),o=he(t),a=ae();if(!a)return de(r,{data:[s],headers:o});te.enqueue(r,[s],o),a.add()}function ve(e){return e.typ===C.FEATURE_GATE||e.typ===C.FEATURE_CONFIG?`$feature_${e.id}`:e.typ===C.EXPERIMENT?`$exp_${e.id}`:""}function be(e){const t=e.typ;return[C.FEATURE_GATE,C.EXPERIMENT,C.FEATURE_CONFIG].includes(t)?{[ve(e)]:e.vid}:{}}function _e(e){const t=e.typ;return t===C.FEATURE_GATE||t===C.FEATURE_CONFIG?{$feature_key:e.key,$feature_variant:e.vid}:t===C.EXPERIMENT?{$exp_key:e.key,$exp_variant:e.vid}:{}}function Ie({isUnset:e=!1,data:t,opts:i}){if(!se())return;if(!re())return;if(!t||u(t)||t.disable_impress)return;const n=N.getLoginId(),s=N.getAnonId();if(!n&&!s)return;const r=t.typ===C.EXPERIMENT?"$ExpImpress":"$FeatureImpress";let o={};return o=e?{$unset:{[ve(t)]:null}}:{$set:{...be(t)}},me({event:r,properties:_e(t),user_properties:o},i)}const Se="sensorswave_opt_out";class we{constructor(e){this.persist=e}read(){if(this.persist)try{const e=b.get(Se);return"0"===e||"1"!==e&&void 0}catch{return}}write(e){if(this.persist)try{b.set(Se,e?"0":"1")}catch{}}}class Oe{constructor({plugins:e,emitter:t,config:i,sdk:n}){this.plugins=[],this.pluginInsMap={},this.emitter=t,this.config=i,this.sdk=n,this.registerBuiltInPlugins(e),this.created(),this.emitter.on(O,()=>{this.init()})}registerBuiltInPlugins(e){for(let t=0,i=e.length;t<i;t++)this.registerPlugin(e[t])}registerPlugin(e){this.plugins.push(e)}getPlugins(){return this.plugins}getPlugin(e){return this.pluginInsMap[e]}created(){for(let e=0,t=this.plugins.length;e<t;e++){const t=this.plugins[e];if(!t.NAME)throw new Error('Plugin should be defined with "NAME"');const i=new t({emitter:this.emitter,config:this.config,sdk:this.sdk});this.pluginInsMap[t.NAME]=i}}init(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.init&&t.init()}}destroy(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.destroy&&"function"==typeof t.destroy&&t.destroy()}this.pluginInsMap={},this.plugins=[]}}const ye=class{constructor({emitter:e,config:t,sdk:i}){this.boundSend=null,this.hashEvent=null,this.spaSwitchHandler=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;this.boundSend=()=>{me({event:"$PageView",properties:{}},e)},this.sdk&&!0===this.sdk._postConsentInit||setTimeout(()=>{this.boundSend()},0),e.isSinglePageApp&&this.addSinglePageListener()}addSinglePageListener(){this.spaSwitchHandler=e=>{e!==location.href&&this.boundSend()},this.emitter.on(y,this.spaSwitchHandler)}destroy(){this.spaSwitchHandler&&(this.emitter.off(y,this.spaSwitchHandler),this.spaSwitchHandler=null),this.hashEvent&&this.boundSend&&(window.removeEventListener(this.hashEvent,this.boundSend),this.hashEvent=null),this.boundSend=null}};ye.NAME="pageview";let Ae=ye;const Re=class{constructor({emitter:e,config:t,sdk:i}){this.startTime=Date.now(),this.pageShowStatus=!0,this.pageHiddenStatus=!1,this.timer=null,this.currentPageUrl=document.referrer,this.url=location.href,this.title=document.title||"",this.heartbeatIntervalTime=5e3,this.heartbeatIntervalTimer=null,this.pageId=null,this.storageName="sensorswavewebjssdkpageleave",this.maxDuration=432e3,this.eventListeners=[],this._skipFirstPageEnd=!1,this.emitter=e,this.config=t,this.sdk=i}__canCapture(){return!this.sdk||"function"!=typeof this.sdk.hasOptedOutCapturing||!this.sdk.hasOptedOutCapturing()}init(){this.pageId=Number(String(g()).slice(2,5)+String(g()).slice(2,4)+String(Date.now()).slice(-4)),this.addEventListener(),this.sdk&&!0===this.sdk._postConsentInit&&(this._skipFirstPageEnd=!0),!0===document.hidden?this.pageShowStatus=!1:this.addHeartBeatInterval()}log(e){console.log(e)}refreshPageEndTimer(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.timer=setTimeout(()=>{this.pageHiddenStatus=!1},5e3)}hiddenStatusHandler(){this.timer&&clearTimeout(this.timer),this.timer=null,this.pageHiddenStatus=!1}pageStartHandler(){this.startTime=Date.now(),1==!document.hidden?this.pageShowStatus=!0:this.pageShowStatus=!1,this.url=location.href,this.title=document.title,this._skipFirstPageEnd=!1}pageEndHandler(){if(!0===this.pageHiddenStatus)return;if(!this.__canCapture())return;const e=this.getPageLeaveProperties();!1===this.pageShowStatus&&delete e.$event_duration,this.pageShowStatus=!1,this.pageHiddenStatus=!0,me({event:R,properties:e},this.config),this.refreshPageEndTimer(),this.delHeartBeatData()}addEventListener(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()}addPageStartListener(){if("onpageshow"in window){const e=()=>{this.pageStartHandler(),this.hiddenStatusHandler()};window.addEventListener("pageshow",e),this.eventListeners.push({target:window,event:"pageshow",handler:e})}}addSinglePageListener(){this.config.isSinglePageApp&&this.emitter.on(y,e=>{e!==location.href&&(this.url=e,this.pageEndHandler(),this.stopHeartBeatInterval(),this.currentPageUrl=this.url,this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval())})}addPageEndListener(){["pagehide","beforeunload"].forEach(e=>{if(`on${e}`in window){const t=()=>{if(this._skipFirstPageEnd)return this._skipFirstPageEnd=!1,void this.stopHeartBeatInterval();this.pageEndHandler(),this.stopHeartBeatInterval()};window.addEventListener(e,t),this.eventListeners.push({target:window,event:e,handler:t})}})}addPageSwitchListener(){const e=()=>{"visible"===document.visibilityState?(this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval()):(this.url=location.href,this.title=document.title,this.stopHeartBeatInterval())};document.addEventListener("visibilitychange",e),this.eventListeners.push({target:document,event:"visibilitychange",handler:e})}addHeartBeatInterval(){b.isSupport()&&this.startHeartBeatInterval()}startHeartBeatInterval(){this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),this.sdk&&!0===this.sdk._postConsentInit&&!0===this._skipFirstPageEnd||(this.heartbeatIntervalTimer=setInterval(()=>{this.saveHeartBeatData()},this.heartbeatIntervalTime),this.saveHeartBeatData("is_first_heartbeat"),this.reissueHeartBeatData())}stopHeartBeatInterval(){this.heartbeatIntervalTimer&&clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null}saveHeartBeatData(e){if(!this.__canCapture())return;const t=this.getPageLeaveProperties();t.$time=Date.now(),"is_first_heartbeat"===e&&(t.$event_duration=3);const i={type:"track",event:R,properties:t,time:t.$time};i.heartbeat_interval_time=this.heartbeatIntervalTime,b.isSupport()&&b.set(`${this.storageName}-${this.pageId}`,JSON.stringify(i))}delHeartBeatData(e){b.isSupport()&&b.remove(e||`${this.storageName}-${this.pageId}`)}reissueHeartBeatData(){if(this.__canCapture())for(let e=window.localStorage.length-1;e>=0;e--){const t=window.localStorage.key(e);if(t&&t!==`${this.storageName}-${this.pageId}`&&0===t.indexOf(`${this.storageName}-`)){const e=b.parse(t);n(e)&&Date.now()-e.time>e.heartbeat_interval_time+5e3&&(delete e.heartbeat_interval_time,e._flush_time=(new Date).getTime(),me({event:R,properties:e?.properties},this.config),this.delHeartBeatData(t))}}}getPageLeaveProperties(){let e=(Date.now()-this.startTime)/1e3;(isNaN(e)||e<0||e>this.maxDuration)&&(e=0),e=Number(e.toFixed(3));const t={$title:this.title,$url:this.url?.substring(0,1e3),$pathname:I(this.url)};return 0!==e&&(t.$event_duration=e),t}destroy(){this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}};Re.NAME="pageleave";let Te=Re;const Ce=class{constructor({emitter:e,config:t,sdk:i}){this.eventSended=!1,this.emitter=e,this.config=t,this.sdk=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit)return;const e=()=>{let t=0;const i={};if(window.performance){t=function(){let e=0;if("function"==typeof performance.getEntriesByType){const t=performance.getEntriesByType("navigation");t.length>0&&(e=t[0].domContentLoadedEventEnd||0)}return e}();const e=function(){if(performance.getEntries&&"function"==typeof performance.getEntries){const e=performance.getEntries();let t=0;for(const i of e)"transferSize"in i&&(t+=i.transferSize);if("number"==typeof t&&t>=0&&t<10737418240)return Number((t/1024).toFixed(3))}}();e&&(i.$page_resource_size=e)}else console.warn("Performance API is not supported.");t>0&&!Number.isFinite(t)&&(i.$event_duration=Number((t/1e3).toFixed(3))),this.eventSended||(this.eventSended=!0,me({event:"$PageLoad",properties:i},this.config)),window.removeEventListener("load",e)};"complete"===document.readyState?e():window.addEventListener&&window.addEventListener("load",e)}};Ce.NAME="pageload";let Ne=Ce;function Pe(e){if(!l(e))return!1;const t=o(e.tagName)?e.tagName.toLowerCase():"",i={};return i.$element_type=t,i.$element_name=e.getAttribute("name")||"",i.$element_id=e.getAttribute("id")||"",i.$element_class_name=o(e.className)?e.className:"",i.$element_target_url=e.getAttribute("href")||"",i.$element_content=function(e,t){return o(t)&&"input"===t.toLowerCase()?("button"===(i=e).type||"submit"===i.type)&&i.value||"":function(e,t){let i="",n="";return e.textContent?i=_(e.textContent):e.innerText&&(i=_(e.innerText)),i&&(i=i.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),n=i||"","input"!==t&&"INPUT"!==t||(n=e.value||""),n}(e,t);var i}(e,t)||"",i.$element_selector=ke(e)||"",i.$element_path=function(e){let t=[];for(;e.parentNode&&l(e);){if(!o(e.tagName))return"";if(e.id&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.id)){t.unshift(e.tagName.toLowerCase()+"#"+e.id);break}if(e===document.body){t.unshift("body");break}t.unshift(e.tagName.toLowerCase()),e=e.parentNode}return t.join(" > ")}(e)||"",i}function ke(e,t=[]){if(!(e&&e.parentNode&&e.parentNode.children&&o(e.tagName)))return"";t=Array.isArray(t)?t:[];const i=e.nodeName.toLowerCase();return e&&"body"!==i&&1==e.nodeType?(t.unshift(function(e){if(!e||!l(e)||!o(e.tagName))return"";let t=e.parentNode&&9==e.parentNode.nodeType?-1:function(e){if(!e.parentNode)return-1;let t=0;const i=e.tagName,n=e.parentNode.children;for(let s=0,r=n.length;s<r;s++)if(n[s].tagName===i){if(e===n[s])return t;t++}return-1}(e);return e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?"#"+e.getAttribute("id"):e.tagName.toLowerCase()+(~t?":nth-of-type("+(t+1)+")":"")}(e)),e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?t.join(" > "):ke(e.parentNode,t)):(t.unshift("body"),t.join(" > "))}function xe(){return{scrollLeft:document.body.scrollLeft||document.documentElement.scrollLeft||0,scrollTop:document.body.scrollTop||document.documentElement.scrollTop||0}}function Le(e){if(document.documentElement.getBoundingClientRect){const t=e.getBoundingClientRect();return{targetEleX:t.left+xe().scrollLeft||0,targetEleY:t.top+xe().scrollTop||0}}return{targetEleX:0,targetEleY:0}}function Me(e){return Number(Number(e).toFixed(3))}const $e=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleClick=null,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,!0),this.isInitialized=!0)}handleClick(e){const t=e.target;if(!t)return;if(!["A","INPUT","BUTTON","TEXTAREA"].includes(t.tagName))return;if("true"===t.getAttribute("sensorswave-disable"))return;const i=function(e,t){const i=Pe(e);if(!i)return!1;const n=function(e,t){const i=t.pageX||t.clientX+xe().scrollLeft||t.offsetX+Le(e).targetEleX,n=t.pageY||t.clientY+xe().scrollTop||t.offsetY+Le(e).targetEleY;return{$page_x:Me(i),$page_y:Me(n)}}(e,t);return i.$page_x=n.$page_x,i.$page_y=n.$page_y,i}(t,e);me({event:"$WebClick",properties:i||{}},this.config)}destroy(){this.boundHandleClick&&(document.removeEventListener("click",this.boundHandleClick,!0),this.boundHandleClick=null),this.isInitialized=!1}};$e.NAME="webclick";let Fe=$e;const De=class{constructor({emitter:e,config:t,sdk:i}){this.updateInterval=null,this.fetchingPromise=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;if(e.enableAB){if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;this.fastFetch().then(()=>{this.emitter.emit(A)}),e.abRefreshInterval<3e4&&(e.abRefreshInterval=3e4),this.updateInterval=setInterval(()=>{this.fetchNewData().catch(console.warn)},e.abRefreshInterval)}}async fastFetch(){const e=N.getABData(this.config.abRefreshInterval);return e&&e.length?(this.emitter.emit(A),Promise.resolve(e)):this.fetchNewData()}async fetchNewData(){return this.fetchingPromise||(this.fetchingPromise=new Promise(e=>{!function({opts:e,cb:t}){if(!se())return void(t&&t({}));if(!re())return void(t&&t({}));const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return void(t&&t({}));const s={user:{login_id:i||"",anon_id:n||"",props:{...ee(),...ge(N.getCommonProps())}},sdk:"webjs",sdk_version:w};L({url:le(e),method:"POST",data:s,headers:he(e),callback:e=>{200!==e.statusCode?(console.error("Failed to fetch feature flags"),t&&t({})):t&&t(e.json)}})}({opts:this.config,cb:t=>{N.saveABData(t?.data?.results||[]),e(t),this.fetchingPromise=null}})})),this.fetchingPromise}async getFeatureGate(e){return await this.fastFetch().catch(console.warn),N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_GATE&&t.key==e)}async checkFeatureGate(e){const t=await this.getFeatureGate(e);return!!t&&(!t.hasOwnProperty("vid")&&t.key?(Ie({isUnset:!0,data:t,opts:this.config}),!1):(Ie({data:t,opts:this.config}),"fail"!==t.vid))}async getExperiment(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.EXPERIMENT&&t.key===e);return t?!t.hasOwnProperty("vid")&&t.key?(Ie({isUnset:!0,data:t,opts:this.config}),{}):(Ie({data:t,opts:this.config}),t?.value||{}):{}}async getFeatureConfig(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_CONFIG&&t.key===e);if(!t)return{};if(!t.hasOwnProperty("vid")&&t.key)return Ie({isUnset:!0,data:t,opts:this.config}),{};Ie({data:t,opts:this.config});const i=t?.value;if(i){if(n(i))return i;try{return JSON.parse(i)}catch{return i}}return{}}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null),this.fetchingPromise=null}};De.NAME="abtest";let Be=De;const He=["utm_source","utm_medium","utm_campaign","utm_content","utm_term"],Ue="sensorswave_utm",We=class e{constructor({sdk:e,emitter:t,config:i}){this.sdk=e,this.emitter=t,this.config=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit){let t=e.readFromSessionStorage();return t&&0!==Object.keys(t).length||(t=e.captureAndStore(this.config?.debug)),void this.scheduleInitialUTM(t)}const t=e.getUTMFromURL();e.saveToSessionStorage(t,this.config?.debug),this.scheduleInitialUTM(t)}scheduleInitialUTM(e){setTimeout(()=>{this.sendInitialUTM(e)},0)}static getUTMFromURL(){try{const e=new URLSearchParams(window.location.search),t={};return He.forEach(i=>{const n=e.get(i);n&&(t[i]=n)}),t}catch(t){return e.getUTMFromURLFallback()}}static getUTMFromURLFallback(){const e={};return window.location.search.substring(1).split("&").forEach(t=>{const[i,n]=t.split("="),s=decodeURIComponent(i),r=n?decodeURIComponent(n):"";He.includes(s)&&(e[s]=r)}),e}static readFromSessionStorage(){try{const e=sessionStorage.getItem(Ue);if(!e)return{};const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch(e){return{}}}static saveToSessionStorage(e,t=!1){try{sessionStorage.setItem(Ue,JSON.stringify(e))}catch(i){t&&console.warn("[SensorsWave UTM] Failed to save to sessionStorage:",i)}}static captureAndStore(t=!1){const i=e.getUTMFromURL();return e.saveToSessionStorage(i,t),i}sendInitialUTM(e){const t={};He.forEach(i=>{t[`$initial_${i}`]=null!=e[i]?e[i]:""});try{this.sdk.profileSetOnce(t)}catch(i){this.config.debug&&console.warn("[SensorsWave UTM] Failed to send initial UTM:",i)}}destroy(){}};We.NAME="UTM";let Xe=We;const je=1e3,qe=/^\s*(?:async\s+)?at\s+(?:(.+)\s+\()?(.+?):(\d+):(\d+)\)?$/,Ge=/^(?:(.*)@)?(.+?):(\d+):(\d+)$/;function ze(e){let t=e;try{const e=location.origin;e&&0===t.indexOf(e)&&(t=t.substring(e.length))}catch(s){}const i=t.indexOf("?");i>-1&&(t=t.substring(0,i));const n=t.indexOf("#");return n>-1&&(t=t.substring(0,n)),t}function Ve(e){return e.map(e=>({platform:"web:javascript",filename:ze(e.file),function:e.fn||"?",lineno:Number(e.line),colno:Number(e.col),abs_path:Ye(e.file,1e3)}))}function Ye(e,t){return e.length>t?e.substring(0,t):e}function Ke(e){let t;if("string"==typeof e)t=e;else if(null!==e&&"object"==typeof e){try{t=JSON.stringify(e)}catch(i){t=Object.prototype.toString.call(e)}t||(t=Object.prototype.toString.call(e))}else t=String(e);return Ye(t,je)}function Je(e){const{frames:t,headerType:i}=function(e){const t=[];let i="";if(!e||"string"!=typeof e)return{frames:t,headerType:i};const n=e.split(/\r?\n/);for(let s=0;s<n.length;s++){const e=n[s];if(!e||e.length>1024)continue;const r=e.match(qe),o=r?null:e.match(Ge),a=r||o;if(a)t.push({fn:a[1]||"?",file:a[2],line:a[3],col:a[4]});else if(0===s){const t=e.indexOf(":");t>0&&(i=e.substring(0,t).trim())}if(t.length>=30)break}return{frames:t,headerType:i}}(e&&e.stack);let n=e&&e.name||i||"Error";return n=Ye(String(n),200),{$exception_level:"error",$exception_type:n,$exception_message:Ye(String(e&&e.message||""),je),$exception_frames:Ve(t)}}function Ze(e,t,i,n){let s=[];return t&&(s=[{platform:"web:javascript",filename:ze(t),function:"?",lineno:i||0,colno:n||0,abs_path:Ye(t,1e3)}]),{$exception_level:"error",$exception_type:"Error",$exception_message:Ye(String(e||""),je),$exception_frames:s}}class Qe{constructor(e=10,t=1,i=1e4){this.buckets=new Map,this.bucketSize=e,this.refillRate=t,this.refillInterval=i}allow(e){const t=Date.now();let i=this.buckets.get(e);if(i){if(t>i.lastRefill){const e=Math.floor((t-i.lastRefill)/this.refillInterval)*this.refillRate;e>0&&(i.tokens=Math.min(this.bucketSize,i.tokens+e),i.lastRefill+=e/this.refillRate*this.refillInterval)}}else i={tokens:this.bucketSize,lastRefill:t},this.buckets.set(e,i);return i.tokens>=1&&(i.tokens-=1,!0)}reset(){this.buckets.clear()}}const et=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleError=null,this.boundHandleRejection=null,this.rateLimiter=new Qe,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleError=this.handleError.bind(this),this.boundHandleRejection=this.handleRejection.bind(this),window.addEventListener("error",this.boundHandleError,!0),window.addEventListener("unhandledrejection",this.boundHandleRejection),this.isInitialized=!0)}handleError(e){try{const t=e.target;let i;if(t&&t!==window&&t.tagName)i=function(e){const t=e,i=(t.tagName||"").toLowerCase(),n=Ye(String(t.src||t.href||""),je);return{$exception_level:"error",$exception_type:"ResourceLoadError",$exception_message:`Failed to load <${i}>${n?` from ${n}`:""}`,$exception_frames:[]}}(t);else{const t=e;i=t.error instanceof Error?Je(t.error):Ze(String(t.message||""),t.filename,t.lineno,t.colno)}this.send(i)}catch(t){}}handleRejection(e){try{const t=e.reason;this.send(function(e){return e instanceof Error?Je(e):{$exception_level:"error",$exception_type:"UnhandledRejection",$exception_message:Ke(e),$exception_frames:[]}}(t))}catch(t){}}send(e){e.$exception_message&&this.rateLimiter.allow(e.$exception_type)&&me({event:T,properties:e},this.config)}destroy(){this.boundHandleError&&(window.removeEventListener("error",this.boundHandleError,!0),this.boundHandleError=null),this.boundHandleRejection&&(window.removeEventListener("unhandledrejection",this.boundHandleRejection),this.boundHandleRejection=null),this.rateLimiter.reset(),this.isInitialized=!1}};et.NAME="exception";let tt=et;const it="data-sw-exposure-event-name",nt="data-sw-exposure-config-",st=`[${it}]`,rt={visibleRatio:0,stayDuration:0,repeated:!0};function ot(e,t){const i={};if(!n(e))return i;const s=e;if(void 0!==s.visibleRatio){const e=Number(s.visibleRatio);!isNaN(e)&&e>=0&&e<=1?i.visibleRatio=e:t&&t("[exposure] parameter config.visibleRatio 非法(值域 0~1),已忽略:",s.visibleRatio)}if(void 0!==s.stayDuration){const e=Number(s.stayDuration);!isNaN(e)&&e>=0?i.stayDuration=e:t&&t("[exposure] parameter config.stayDuration 非法(须 >= 0),已忽略:",s.stayDuration)}if(void 0!==s.repeated){const e=s.repeated;!0===e||"true"===e?i.repeated=!0:!1===e||"false"===e?i.repeated=!1:t&&t("[exposure] parameter config.repeated 非法(须为布尔),已忽略:",e)}return i}function at(...e){const t={...rt};for(let i=0;i<e.length;i++){const s=e[i];if(!n(s))continue;const r=s;void 0!==r.visibleRatio&&(t.visibleRatio=r.visibleRatio),void 0!==r.stayDuration&&(t.stayDuration=r.stayDuration),void 0!==r.repeated&&(t.repeated=r.repeated)}return t}function ct(e){const t=(e.getAttribute(it)||"").trim();let i={},s={};const r=e.getAttribute("data-sw-exposure-option");if(r){const e=d(r);n(e)&&(n(e.config)&&(i=e.config),n(e.properties)&&(s=e.properties))}const a=e.getAttribute(nt+"visible-ratio");null!==a&&(i.visibleRatio=a);const c=e.getAttribute(nt+"stay-duration");null!==c&&(i.stayDuration=c);const u=e.getAttribute(nt+"repeated");null!==u&&(i.repeated=u);const l=e.attributes;for(let n=0;n<l.length;n++){const e=l[n],t=e.name;if(o(t)&&0===t.indexOf("data-sw-exposure-property-")){const i=t.substring(26);i&&(s[i]=e.value)}}return{eventName:t,config:ot(i),properties:s}}const ut=class{constructor({emitter:e,config:t,sdk:i}){this.isInitialized=!1,this.observers=new Map,this.records=new Map,this.mutationObserver=null,this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.boundHandleSpa=null,this.eventListeners=[],this.globalConfig={...rt},this.log=function(){},this.emitter=e,this.config=t,this.sdk=i}init(){this.isInitialized||(function(){try{return"undefined"!=typeof window&&"IntersectionObserver"in window&&"MutationObserver"in window}catch(e){return!1}}()?(this.log=!0==(!0===this.config.debug)&&"undefined"!=typeof console&&console.log?function(...e){console.log("[SensorsWave][exposure]",...e)}:function(){},this.globalConfig=at(this.globalConfig,ot(this.config.exposureConfig,this.log)),this.boundHandleIntersection=this.handleIntersection.bind(this),this.boundHandleMutation=this.handleMutation.bind(this),this.boundHandleVisibility=this.handleVisibility.bind(this),"loading"===document.readyState?(this.boundHandleReady=()=>{this.scanDocument(),this.observeMutations()},document.addEventListener("DOMContentLoaded",this.boundHandleReady),this.eventListeners.push({target:document,event:"DOMContentLoaded",handler:this.boundHandleReady})):(this.scanDocument(),this.observeMutations()),!0===this.config.isSinglePageApp&&(this.boundHandleSpa=e=>{this.handleSpaSwitch(e)},this.emitter.on(y,this.boundHandleSpa)),document.addEventListener("visibilitychange",this.boundHandleVisibility),this.eventListeners.push({target:document,event:"visibilitychange",handler:this.boundHandleVisibility}),!0===document.hidden&&this.stop(),this.isInitialized=!0):console.warn("[SensorsWave][exposure] 当前浏览器不支持 IntersectionObserver / MutationObserver,曝光采集未初始化"))}addExposureView(e,t){this.isInitialized?l(e)?n(t)&&o(t.eventName)&&t.eventName.trim()?this.addOrUpdateWatchEle(e,{eventName:t.eventName.trim(),config:n(t.config)?ot(t.config,this.log):void 0,properties:n(t.properties)?{...t.properties}:{},listener:n(t.listener)?{...t.listener}:{}},"api"):this.log("addExposureView parameter option.eventName 缺失:",t):this.log("addExposureView parameter element 非法:",e):this.log("曝光插件未初始化(enableExposureTrack 未开启或浏览器不支持)")}removeExposureView(e){this.isInitialized?l(e)?this.removeWatchEle(e):this.log("removeExposureView parameter element 非法:",e):this.log("曝光插件未初始化")}scanDocument(e){try{const t=e||document;if(!t.querySelectorAll)return;const i=t.querySelectorAll(st);for(let e=0;e<i.length;e++){const t=i[e];this.addOrUpdateWatchEle(t,ct(t),"attr")}}catch(t){}}addOrUpdateWatchEle(e,t,i){if(!e||!l(e))return void this.log("parameter element error:",e);if(!o(t.eventName)||!t.eventName.trim())return void this.log("parameter option.eventName error:",t);const n=this.records.get(e);if(n&&"api"===n.source&&"attr"===i)return void this.log("声明式属性变更被忽略:元素已由 addExposureView 注册",e);const s=at(this.globalConfig,n&&n.config,t.config);if(n&&n.config.visibleRatio===s.visibleRatio)return n.eventName=t.eventName,n.source=i,n.config=s,n.properties={...t.properties||{}},n.listener=t.listener||{},void(n.hasSent=!1);n&&this.removeWatchEle(e);const r={ele:e,eventName:t.eventName,source:i,config:s,properties:{...t.properties||{}},listener:t.listener||{},timer:null,hasSent:!1};this.records.set(e,r),this.getIntersection(s.visibleRatio).observe(e)}getIntersection(e){let t=this.observers.get(e);return!t&&this.boundHandleIntersection&&(t=new IntersectionObserver(this.boundHandleIntersection,{threshold:e}),this.observers.set(e,t)),t}removeWatchEle(e){const t=this.records.get(e);if(!t)return;const i=this.observers.get(t.config.visibleRatio);i&&l(e)&&i.unobserve(e),t.timer&&(clearTimeout(t.timer),t.timer=null),this.records.delete(e)}handleIntersection(e){try{for(const t of e){const e=t.target,i=this.records.get(e);i&&(!0===t.isIntersecting&&t.intersectionRatio>=i.config.visibleRatio?!0!==document.hidden&&(i.timer&&clearTimeout(i.timer),i.timer=setTimeout(()=>{this.fireExposure(e)},1e3*i.config.stayDuration)):i.timer&&(clearTimeout(i.timer),i.timer=null))}}catch(t){}}fireExposure(e){try{const i=this.records.get(e);if(i&&(i.timer=null),!i||i.hasSent)return;let n={width:0,height:0};try{n=e.getBoundingClientRect()}catch(t){}if(!n.width||!n.height)return;if(!e.isConnected)return void this.removeWatchEle(e);if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;const r={...Pe(e),...i.properties},{shouldExpose:o,didExpose:a}=i.listener||{};if(o&&s(o))try{if(!1===o(e,r))return}catch(t){return}if(me({event:i.eventName,properties:r},this.config),i.hasSent=!0,i.config.repeated&&(i.hasSent=!1),a&&s(a))try{a(e,r)}catch(t){}}catch(t){}}observeMutations(){!this.mutationObserver&&this.boundHandleMutation&&(this.mutationObserver=new MutationObserver(this.boundHandleMutation),this.mutationObserver.observe(document.body,{attributes:!0,childList:!0,subtree:!0}))}handleMutation(e){try{for(const t of e)if("childList"===t.type){if(t.removedNodes.length>0)for(const e of Array.from(t.removedNodes)){if(1!==e.nodeType)continue;this.removeWatchEle(e);const t=e.querySelectorAll(st);for(let e=0;e<t.length;e++)this.removeWatchEle(t[e])}if(t.addedNodes.length>0)for(const e of Array.from(t.addedNodes))1===e.nodeType&&(e.hasAttribute(it)&&this.addOrUpdateWatchEle(e,ct(e),"attr"),this.scanDocument(e))}else"attributes"===t.type&&this.handleAttrChange(t)}catch(t){}}handleAttrChange(e){const t=e.attributeName;if(!t||0!==t.indexOf("data-sw-exposure"))return;const i=e.target;t!==it||(i.getAttribute(t)||"").trim()?(i.getAttribute(it)||"").trim()&&this.addOrUpdateWatchEle(i,ct(i),"attr"):this.removeWatchEle(i)}handleSpaSwitch(e){try{if(e===location.href)return;this.stop();for(const[e,t]of Array.from(this.records))"attr"===t.source&&this.records.delete(e);this.start(),this.scanDocument()}catch(t){}}stop(){for(const e of Array.from(this.records.values())){const t=this.observers.get(e.config.visibleRatio);t&&t.unobserve(e.ele),e.timer&&(clearTimeout(e.timer),e.timer=null)}}start(){for(const e of Array.from(this.records.values())){if(!e.ele.isConnected){this.records.delete(e.ele);continue}const t=this.observers.get(e.config.visibleRatio);t&&t.observe(e.ele)}}handleVisibility(){try{"visible"===document.visibilityState?this.start():this.stop()}catch(e){}}destroy(){this.observers.forEach(e=>{try{e.disconnect()}catch(t){}}),this.observers.clear(),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null);for(const e of Array.from(this.records.values()))e.timer&&(clearTimeout(e.timer),e.timer=null);this.records.clear(),this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.boundHandleSpa&&(this.emitter.off(y,this.boundHandleSpa),this.boundHandleSpa=null),this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.globalConfig={...rt},this.log=function(){},this.isInitialized=!1}};ut.NAME="exposure";let lt=ut;const ht=[],dt={debug:!1,sourceToken:"",apiHost:"",autoCapture:!0,isSinglePageApp:!1,crossSubdomainCookie:!0,enableAB:!1,abRefreshInterval:6e5,enableClickTrack:!1,enableExposureTrack:!1,batchSend:!1,enableErrorTrack:!1,enableCrashTrack:!1,optOutCapturing:!1,persistOptOut:!1},pt=new class{constructor(){this.__innerInited=!1,this.inited=!1,this.config={},this.eventEmitter=new e,this.pluginCore={},this.commonProps={},this.spaCleanup=null,this._optOutCapturing=!1,this.consentStorage=new we(!1),this._setupAfterConsentDone=!1,this._postConsentInit=!1,S.instance=this}init(e,t={}){return this.inited?this:(S.instance=this,t.sourceToken=e,this.mergeConfig(t),this.consentStorage=new we(!0===this.config.persistOptOut),this._optOutCapturing?this.consentStorage.write(!0):!0===this.config.optOutCapturing?(this._optOutCapturing=!0,this.consentStorage.write(!0)):!0===this.consentStorage.read()&&(this._optOutCapturing=!0),this.eventEmitter.emit("init-param",this.config),this.__innerInited=!0,this._optOutCapturing?(Xe.captureAndStore(this.config.debug),this.eventEmitter.emit(O),this.inited=!0,this):(this.__setupAfterConsent(),this.eventEmitter.emit(O),this.inited=!0,this))}__setupAfterConsent(){if(this._setupAfterConsentDone)return;this._setupAfterConsentDone=!0;const e=this.config;ht.length=0,N.init(e.crossSubdomainCookie),e.anonId&&N.setAnonId(e.anonId),function(){if(window._swFailedRequestsInitialized)return;window._swFailedRequestsInitialized=!0;const e=S.instance;e&&"function"==typeof e.hasOptedOutCapturing&&e.hasOptedOutCapturing()||e&&!0===e._postConsentInit||function(){const e=te.getAll();if(0!==e.length)for(let t=0,i=e.length;t<i;t+=10){const i=e.slice(t,t+10),n=[],s=[];i.forEach(e=>{Array.isArray(e.data)?n.push(...e.data):n.push(e.data),s.push(e.id)});const r=i[i.length-1],o=r.url,a=r.headers;L({url:o,method:"POST",data:n,headers:a,callback:e=>{200!==e.statusCode?(console.error("Failed to send batch stored requests:",e),P(e.statusCode)||s.forEach(e=>{te.dequeue(e)})):s.forEach(e=>{te.dequeue(e)})}})}}()}(),ht.push(Xe),e.autoCapture&&this.autoTrack(),e.enableAB&&ht.push(Be),e.enableClickTrack&&ht.push(Fe),e.enableCrashTrack&&e.debug&&console.warn("[SensorsWave] enableCrashTrack 仅在 app 宿主环境生效,当前 Web 环境不采集 crash"),e.enableErrorTrack&&ht.push(tt),e.enableExposureTrack&&ht.push(lt),this.pluginCore=new Oe({plugins:ht,emitter:this.eventEmitter,config:e,sdk:this}),this.spaCleanup=function(e){let t=location.href;const i=window.history.pushState,n=window.history.replaceState,r=function(){e(t),t=location.href};return s(window.history.pushState)&&(window.history.pushState=function(...n){i.apply(window.history,n),e(t),t=location.href}),s(window.history.replaceState)&&(window.history.replaceState=function(...i){n.apply(window.history,i),e(t),t=location.href}),window.addEventListener("popstate",r),function(){s(window.history.pushState)&&(window.history.pushState=i),s(window.history.replaceState)&&(window.history.replaceState=n),window.removeEventListener("popstate",r)}}(e=>{this.eventEmitter.emit(y,e)})}mergeConfig(e){this.config={...dt,...e}}__canCapture(){return this.inited&&!this._optOutCapturing}track(e){this.__canCapture()&&function(e,t){if(!se())return;if(!re())return;const i={...e};i.time||(i.time=Date.now()),i.login_id||(i.login_id=N.getLoginId()),i.anon_id||(i.anon_id=N.getAnonId()),i.trace_id||(i.trace_id=N.getTraceId()),i.properties={...ee(),...ge(N.getCommonProps()),...i.properties};const n=ue(t),s=he(t),r=!1!==t.batchSend&&ae();if(!r)return de(n,{data:[i],headers:s});te.enqueue(n,[i],s),r.add()}(e,this.config)}trackEvent(e,t){this.__canCapture()&&me({event:e,properties:t},this.config)}trackException(e,t){if(!this.__canCapture())return;const i={...t||{},...e instanceof Error?Je(e):Ze(String(e))};me({event:T,properties:i},this.config)}addExposureView(e,t){if(!this.__canCapture())return;const i=this.pluginCore.getPlugin(lt.NAME);i?i.addExposureView(e,t):console.warn("[SensorsWave] addExposureView 需在 init 时配置 enableExposureTrack: true")}removeExposureView(e){if(!this.__canCapture())return;const t=this.pluginCore.getPlugin(lt.NAME);t&&t.removeExposureView(e)}autoTrack(){ht.push(Ae,Ne,Te)}profileSet(e){this.__canCapture()&&Ee({userProps:{$set:e},opts:this.config})}profileSetOnce(e){this.__canCapture()&&Ee({userProps:{$set_once:e},opts:this.config})}profileIncrement(e){this.__canCapture()&&Ee({userProps:{$increment:e},opts:this.config})}profileAppend(e){this.__canCapture()&&Ee({userProps:{$append:e},opts:this.config})}profileUnion(e){this.__canCapture()&&Ee({userProps:{$union:e},opts:this.config})}profileUnset(e){if(!this.__canCapture())return;const t={};r(e)?e.forEach(function(e){t[e]=null}):t[e]=null,Ee({userProps:{$unset:t},opts:this.config})}profileDelete(){this.__canCapture()&&Ee({userProps:{$delete:!0},opts:this.config})}registerCommonProperties(e){if(!n(e))return console.warn("Commmon Properties must be an object!");this.commonProps=e,N.setCommonProps(this.commonProps)}clearCommonProperties(e){if(!r(e))return console.warn("Commmon Properties to be cleared must be an array!");e.forEach(e=>{delete this.commonProps[e]}),N.setCommonProps(this.commonProps)}identify(e){this.__canCapture()&&(N.setLoginId(e),function(e){if(!se())return;if(!re())return;const t=N.getLoginId(),i=N.getAnonId();if(!t||!i)return;const n={time:Date.now(),trace_id:N.getTraceId(),event:"$Identify",login_id:t,anon_id:i,properties:fe()},s=ue(e),r=he(e),o=ae();if(!o)return de(s,{data:[n],headers:r});te.enqueue(s,[n],r),o.add()}(this.config))}setLoginId(e){this.__canCapture()&&N.setLoginId(e)}getAnonId(){return this.__canCapture()?N.getAnonId():""}setAnonId(e){this.__canCapture()&&N.setAnonId(e)}getLoginId(){return this.__canCapture()?N.getLoginId():""}reset(e=!1){this.__canCapture()&&(N.clearLoginId(),e&&N.resetAnonId())}checkFeatureGate(e){if(!this.__canCapture())return Promise.resolve(!1);const t=this.pluginCore.getPlugin(Be.NAME);return this.config.enableAB&&t?t.checkFeatureGate(e):Promise.reject("AB is disabled")}getExperiment(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Be.NAME);return this.config.enableAB&&t?t.getExperiment(e):Promise.reject("AB is disabled")}getFeatureConfig(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Be.NAME);return this.config.enableAB&&t?t.getFeatureConfig(e):Promise.reject("AB is disabled")}optOutCapturing(){this._optOutCapturing=!0,this.consentStorage.write(!0),oe&&oe.pause()}optInCapturing(){if(this._optOutCapturing=!1,this.consentStorage.write(!1),oe&&oe.resume(),this.inited&&!this._setupAfterConsentDone){this._postConsentInit=!0;try{this.__setupAfterConsent(),this.eventEmitter.emit(O)}finally{this._postConsentInit=!1}}}hasOptedOutCapturing(){return this._optOutCapturing}destroy(){oe&&(oe.destroy(),oe=null),"undefined"!=typeof window&&(window._swFailedRequestsInitialized=!1),this.inited=!1,this.__innerInited=!1,this.spaCleanup&&"function"==typeof this.spaCleanup&&(this.spaCleanup(),this.spaCleanup=null),this.pluginCore&&"function"==typeof this.pluginCore.destroy&&this.pluginCore.destroy(),this.pluginCore={},this.eventEmitter&&this.eventEmitter.removeAllListeners(),this.consentStorage=new we(!0===this.config?.persistOptOut),this._optOutCapturing=!1,this._setupAfterConsentDone=!1,this._postConsentInit=!1,S.instance===this&&(S.instance=null)}};module.exports=pt;
|
|
1
|
+
"use strict";class e{constructor(){this.listeners={}}on(e,t,i=!1){if(e&&t){if(!s(t))throw new Error("listener must be a function");this.listeners[e]=this.listeners[e]||[],this.listeners[e].push({listener:t,once:i})}}off(e,t){const i=this.listeners[e];if(!i?.length)return;"number"==typeof t&&i.splice(t,1);const n=i.findIndex(e=>e.listener===t);-1!==n&&i.splice(n,1)}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((i,n)=>{i.listener.call(this,...t),i.listener.once&&this.off(e,n)})}once(e,t){this.on(e,t,!0)}removeAllListeners(e){e?this.listeners[e]=[]:this.listeners={}}}const t={get:function(e){const t=e+"=",i=document.cookie.split(";");for(let n=0,s=i.length;n<s;n++){let e=i[n];for(;" "==e.charAt(0);)e=e.substring(1,e.length);if(0==e.indexOf(t))return h(e.substring(t.length,e.length))}return null},set:function({name:e,value:t,expires:i,samesite:n,secure:s,domain:r}){let o="",a="",c="",u="";if(0!==(i=null==i||void 0===i?365:i)){const e=new Date;"string"==typeof i?e.setTime(e.getTime()+1e3*Number(i.slice(0,-1))):e.setTime(e.getTime()+24*i*60*60*1e3),o="; expires="+e.toUTCString()}function l(e){return e?e.replace(/\r\n/g,""):""}n&&(c="; SameSite="+n),s&&(a="; secure");const h=l(e),d=l(t),p=l(r);p&&(u="; domain="+p),h&&d&&(document.cookie=h+"="+encodeURIComponent(d)+o+"; path=/"+u+c+a)},remove:function(e){const t=e?e.replace(/\r\n/g,""):"";t&&(document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")},isSupport:function({samesite:e,secure:t}={}){if(!navigator.cookieEnabled)return!1;const i="sensorswave_cookie_support_test";return this.set({name:i,value:"1",samesite:e,secure:t}),"1"===this.get(i)&&(this.remove(i),!0)}},i=Object.prototype.toString;function n(e){return"[object Object]"===i.call(e)}function s(e){const t=i.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t}function r(e){return"[object Array]"==i.call(e)}function o(e){return"[object String]"==i.call(e)}function a(e){return void 0===e}const c=Object.prototype.hasOwnProperty;function u(e){if(n(e)){for(let t in e)if(c.call(e,t))return!1;return!0}return!1}function l(e){return!(!e||1!==e.nodeType)}function h(e){let t=e;try{t=decodeURIComponent(e)}catch(i){t=e}return t}function d(e){try{return JSON.parse(e)}catch(t){return""}}const p=function(){let e=Date.now();return function(t){return Math.ceil((e=(9301*e+49297)%233280,e/233280*t))}}();function g(){if("function"==typeof Uint32Array){let e;if("undefined"!=typeof crypto&&(e=crypto),e&&n(e)&&e.getRandomValues)return e.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32)}return p(1e19)/1e19}const f=function(){function e(e){return("0".repeat(e)+Date.now().toString(16)).slice(-e)}return function(){let t=String(screen.height*screen.width);t=t&&/\d{4,}/.test(t)?t.slice(-4):String(31242*g()).replace(".","").slice(0,4);return e(8)+"-"+g().toString(16).replace(".","").slice(-4)+"-"+function(){const e=navigator.userAgent;let t,i=[],n=0;function s(e,t){let n=0;for(let s=0;s<t.length;s++)n|=i[s]<<8*s;return(e^n)>>>0}for(let r=0;r<e.length;r++)t=e.charCodeAt(r),i.unshift(255&t),i.length>=4&&(n=s(n,i),i=[]);return i.length>0&&(n=s(n,i)),("0000"+n.toString(16)).slice(-4)}()+"-"+t+"-"+e(12)||(String(g())+String(g())+String(g())).slice(2,15)}}();function m(e,t){t&&"string"==typeof t||(t="");let i=null;try{i=new URL(e).hostname}catch(n){}return i||t}function E(e){let t=[];try{t=atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})}catch(i){t=[]}try{return decodeURIComponent(t.join(""))}catch(i){return t.join("")}}function _(e){let t="";try{t=btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}))}catch(i){t=e}return t}const b={get:function(e){return window.localStorage.getItem(e)},parse:function(e){let t;try{t=JSON.parse(b.get(e))||null}catch(i){console.warn(i)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(i){console.warn(i)}},remove:function(e){window.localStorage.removeItem(e)},isSupport:function(){let e=!0;try{const t="__local_store_support__",i="testIsSupportStorage";b.set(t,i),b.get(t)!==i&&(e=!1),b.remove(t)}catch(t){e=!1}return e}};function v(e){return e.trim()}function I(e){if(!e||"string"!=typeof e)return"";try{return new URL(e,window.location.origin).pathname}catch(t){return""}}const w={},S="1.6.0",y="init-ready",O="spa-switch",A="ff-ready",R="$PageLeave",T="$Exception";var C=(e=>(e[e.FEATURE_GATE=1]="FEATURE_GATE",e[e.FEATURE_CONFIG=2]="FEATURE_CONFIG",e[e.EXPERIMENT=3]="EXPERIMENT",e))(C||{});const N={crossSubdomain:!1,requests:[],_sessionState:{},_abData:[],_trace_id:"",commonProps:{},_state:{anon_id:"",login_id:"",identities:{}},getIdentityCookieID(){return this._state.identities?.$identity_cookie_id||""},getCommonProps:function(){return this.commonProps||{}},setCommonProps:function(e){this.commonProps=e},getAnonId(){return this._state.anon_id||this.getIdentityCookieID()||f()},getLoginId(){return this._state.login_id},getTraceId(){return this._trace_id||f()},set:function(e,t){this._state[e]=t,this.save()},getCookieName:function(){return"sensorswave2025jssdkcross"},getABLSName:function(){return"sensorswave2025jssdkablatest"},save:function(){let e=JSON.parse(JSON.stringify(this._state));e.identities&&(e.identities=_(JSON.stringify(e.identities)));const i=JSON.stringify(e);t.set({name:this.getCookieName(),value:i,expires:365})},init:function(e){let i,s;this.crossSubdomain=e,t.isSupport()&&(i=t.get(this.getCookieName()),s=d(i)),N._state={...s||{}},N._state.identities&&(N._state.identities=d(E(N._state.identities))),N._state.identities&&n(N._state.identities)&&!u(N._state.identities)||(N._state.identities={$identity_cookie_id:f()}),N.save()},setLoginId(e){"number"==typeof e&&(e=String(e)),void 0!==e&&e&&(N.set("login_id",e),N.save())},clearLoginId(){this._state.login_id="",this.save()},resetAnonId(){this._state.anon_id="",this._state.identities={$identity_cookie_id:f()},this.save()},setAnonId(e){"number"==typeof e&&(e=String(e)),"string"==typeof e&&e?(N.set("anon_id",e),N.save()):console.warn("[SensorsWave store] Invalid anonId, ignored:",e)},saveABData(e){if(!e||u(e))return;this._abData=e;let t=JSON.parse(JSON.stringify(this._abData));t=_(JSON.stringify(t));try{localStorage.setItem(this.getABLSName(),JSON.stringify({time:Date.now(),data:t,anon_id:this.getAnonId(),login_id:this.getLoginId()}))}catch(i){console.warn("Failed to save abdata to localStorage",i)}},getABData(e=6e5){try{let t=localStorage.getItem(this.getABLSName());if(t){const{time:i,data:n,login_id:s,anon_id:r}=d(t)||{};if(i&&n&&Date.now()-i<e&&r===this.getAnonId()&&(!s||s===this.getLoginId())){const e=d(E(n));return this._abData=Array.isArray(e)?e:[],this._abData}localStorage.removeItem(this.getABLSName())}}catch(t){this._abData=[]}return this._abData||[]}};function P(e){return!(e>=400&&e<500)||408===e||429===e}function k(e){var t;if(e.data)return{contentType:"application/json",body:(t=e.data,JSON.stringify(t,(e,t)=>"bigint"==typeof t?t.toString():t,undefined))}}const x=[];function L(e){const t={...e};t.timeout=t.timeout||6e4;const i=t.transport??"fetch",n=x.find(e=>e.transport===i)?.method??x[0]?.method;if(!n)throw new Error("No available transport method for HTTP request");n(t)}function M(e){return o(e=e||document.referrer)&&(e=h(e=e.trim()))||""}function $(e){const t=m(e=e||M());if(!t)return"";const i={baidu:[/^.*\.baidu\.com$/],bing:[/^.*\.bing\.com$/],google:[/^www\.google\.com$/,/^www\.google\.com\.[a-z]{2}$/,/^www\.google\.[a-z]{2}$/],sm:[/^m\.sm\.cn$/],so:[/^.+\.so\.com$/],sogou:[/^.*\.sogou\.com$/],yahoo:[/^.*\.yahoo\.com$/],duckduckgo:[/^.*\.duckduckgo\.com$/]};for(let n of Object.keys(i)){let e=i[n];for(let i=0,s=e.length;i<s;i++)if(e[i].test(t))return n}return""}function D(e,t){return-1!==e.indexOf(t)}"function"==typeof fetch&&x.push({transport:"fetch",method:function(e){if("undefined"==typeof fetch)return void console.error("fetch API is not available");const t=k(e),i=new Headers;e.headers&&Object.keys(e.headers).forEach(t=>{i.append(t,e.headers[t])}),t?.contentType&&i.append("Content-Type",t.contentType),fetch(e.url,{method:e.method||"GET",headers:i,body:t?.body}).then(t=>t.text().then(i=>{const n={statusCode:t.status,text:i};if(200===t.status)try{n.json=JSON.parse(i)}catch(s){console.error("Failed to parse response:",s)}e.callback?.(n)})).catch(t=>{console.error("Request failed:",t),e.callback?.({statusCode:0,text:String(t)})})}}),"undefined"!=typeof XMLHttpRequest&&x.push({transport:"XHR",method:function(e){if("undefined"==typeof XMLHttpRequest)return void console.error("XMLHttpRequest is not available");const t=new XMLHttpRequest;t.open(e.method||"GET",e.url,!0);const i=k(e);e.headers&&Object.keys(e.headers).forEach(i=>{t.setRequestHeader(i,e.headers[i])}),i?.contentType&&t.setRequestHeader("Content-Type",i.contentType),t.timeout=e.timeout||6e4,t.withCredentials=!0,t.onreadystatechange=()=>{if(4===t.readyState){const n={statusCode:t.status,text:t.responseText};if(200===t.status)try{n.json=JSON.parse(t.responseText)}catch(i){console.error("Failed to parse JSON response:",i)}e.callback?.(n)}},t.send(i?.body)}});const F={FACEBOOK:"Facebook",MOBILE:"Mobile",IOS:"iOS",ANDROID:"Android",TABLET:"Tablet",ANDROID_TABLET:"Android Tablet",IPAD:"iPad",APPLE:"Apple",APPLE_WATCH:"Apple Watch",SAFARI:"Safari",BLACKBERRY:"BlackBerry",SAMSUNG_BROWSER:"SamsungBrowser",SAMSUNG_INTERNET:"Samsung Internet",CHROME:"Chrome",CHROME_OS:"Chrome OS",CHROME_IOS:"Chrome iOS",INTERNET_EXPLORER:"Internet Explorer",INTERNET_EXPLORER_MOBILE:"Internet Explorer Mobile",OPERA:"Opera",OPERA_MINI:"Opera Mini",EDGE:"Edge",MICROSOFT_EDGE:"Microsoft Edge",FIREFOX:"Firefox",FIREFOX_IOS:"Firefox iOS",NINTENDO:"Nintendo",PLAYSTATION:"PlayStation",XBOX:"Xbox",ANDROID_MOBILE:"Android Mobile",MOBILE_SAFARI:"Mobile Safari",WINDOWS:"Windows",WINDOWS_PHONE:"Windows Phone",NOKIA:"Nokia",OUYA:"Ouya",GENERIC_MOBILE:"Generic mobile",GENERIC_TABLET:"Generic tablet",KONQUEROR:"Konqueror",UC_BROWSER:"UC Browser",HUAWEI:"Huawei",XIAOMI:"Xiaomi",OPPO:"OPPO",VIVO:"vivo"},B="(\\d+(\\.\\d+)?)",H=new RegExp("Version/"+B),U=new RegExp(F.XBOX,"i"),W=new RegExp(F.PLAYSTATION+" \\w+","i"),X=new RegExp(F.NINTENDO+" \\w+","i"),j=new RegExp(F.BLACKBERRY+"|PlayBook|BB10","i"),q=new RegExp("(HUAWEI|honor|HONOR)","i"),G=new RegExp("(Xiaomi|Redmi)","i"),z=new RegExp("(OPPO|realme)","i"),V=new RegExp("(vivo|IQOO)","i"),Y={"NT3.51":"NT 3.11","NT4.0":"NT 4.0","5.0":"2000",5.1:"XP",5.2:"XP","6.0":"Vista",6.1:"7",6.2:"8",6.3:"8.1",6.4:"10","10.0":"10"};function J(e,t){return t=t||"",D(e," OPR/")&&D(e,"Mini")?F.OPERA_MINI:D(e," OPR/")?F.OPERA:j.test(e)?F.BLACKBERRY:D(e,"IE"+F.MOBILE)||D(e,"WPDesktop")?F.INTERNET_EXPLORER_MOBILE:D(e,F.SAMSUNG_BROWSER)?F.SAMSUNG_INTERNET:D(e,F.EDGE)||D(e,"Edg/")?F.MICROSOFT_EDGE:D(e,"FBIOS")?F.FACEBOOK+" "+F.MOBILE:D(e,"UCWEB")||D(e,"UCBrowser")?F.UC_BROWSER:D(e,"CriOS")?F.CHROME_IOS:D(e,"CrMo")||D(e,F.CHROME)?F.CHROME:D(e,F.ANDROID)&&D(e,F.SAFARI)?F.ANDROID_MOBILE:D(e,"FxiOS")?F.FIREFOX_IOS:D(e.toLowerCase(),F.KONQUEROR.toLowerCase())?F.KONQUEROR:function(e,t){return t&&D(t,F.APPLE)||D(i=e,F.SAFARI)&&!D(i,F.CHROME)&&!D(i,F.ANDROID);var i}(e,t)?D(e,F.MOBILE)?F.MOBILE_SAFARI:F.SAFARI:D(e,F.FIREFOX)?F.FIREFOX:D(e,"MSIE")||D(e,"Trident/")?F.INTERNET_EXPLORER:D(e,"Gecko")?F.FIREFOX:""}const K={[F.INTERNET_EXPLORER_MOBILE]:[new RegExp("rv:"+B)],[F.MICROSOFT_EDGE]:[new RegExp(F.EDGE+"?\\/"+B)],[F.CHROME]:[new RegExp("("+F.CHROME+"|CrMo)\\/"+B)],[F.CHROME_IOS]:[new RegExp("CriOS\\/"+B)],[F.UC_BROWSER]:[new RegExp("(UCBrowser|UCWEB)\\/"+B)],[F.SAFARI]:[H],[F.MOBILE_SAFARI]:[H],[F.OPERA]:[new RegExp("("+F.OPERA+"|OPR)\\/"+B)],[F.FIREFOX]:[new RegExp(F.FIREFOX+"\\/"+B)],[F.FIREFOX_IOS]:[new RegExp("FxiOS\\/"+B)],[F.KONQUEROR]:[new RegExp("Konqueror[:/]?"+B,"i")],[F.BLACKBERRY]:[new RegExp(F.BLACKBERRY+" "+B),H],[F.ANDROID_MOBILE]:[new RegExp("android\\s"+B,"i")],[F.SAMSUNG_INTERNET]:[new RegExp(F.SAMSUNG_BROWSER+"\\/"+B)],[F.INTERNET_EXPLORER]:[new RegExp("(rv:|MSIE )"+B)],Mozilla:[new RegExp("rv:"+B)]};function Z(e,t){const i=J(e,t),n=K[i];if(a(n))return null;for(let s=0;s<n.length;s++){const t=n[s],i=e.match(t);if(i)return parseFloat(i[i.length-2])}return null}const Q=[[new RegExp(F.XBOX+"; "+F.XBOX+" (.*?)[);]","i"),e=>[F.XBOX,e&&e[1]||""]],[new RegExp(F.NINTENDO,"i"),[F.NINTENDO,""]],[new RegExp(F.PLAYSTATION,"i"),[F.PLAYSTATION,""]],[j,[F.BLACKBERRY,""]],[new RegExp(F.WINDOWS,"i"),(e,t)=>{if(/Phone/.test(t)||/WPDesktop/.test(t))return[F.WINDOWS_PHONE,""];if(new RegExp(F.MOBILE).test(t)&&!/IEMobile\b/.test(t))return[F.WINDOWS+" "+F.MOBILE,""];const i=/Windows NT ([0-9.]+)/i.exec(t);if(i&&i[1]){const e=i[1];let n=Y[e]||"";return/arm/i.test(t)&&(n="RT"),[F.WINDOWS,n]}return[F.WINDOWS,""]}],[/((iPhone|iPad|iPod).*?OS (\d+)_(\d+)_?(\d+)?|iPhone)/,e=>{if(e&&e[3]){const t=[e[3],e[4],e[5]||"0"];return[F.IOS,t.join(".")]}return[F.IOS,""]}],[/(watch.*\/(\d+\.\d+\.\d+)|watch os,(\d+\.\d+),)/i,e=>{let t="";return e&&e.length>=3&&(t=a(e[2])?e[3]:e[2]),["watchOS",t]}],[new RegExp("("+F.ANDROID+" (\\d+)\\.(\\d+)\\.?(\\d+)?|"+F.ANDROID+")","i"),e=>{if(e&&e[2]){const t=[e[2],e[3],e[4]||"0"];return[F.ANDROID,t.join(".")]}return[F.ANDROID,""]}],[/Mac OS X (\d+)[_.](\d+)[_.]?(\d+)?/i,e=>{const t=["Mac OS X",""];if(e&&e[1]){const i=[e[1],e[2],e[3]||"0"];t[1]=i.join(".")}return t}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[F.CHROME_OS,""]],[/Linux|debian/i,["Linux",""]]];function ee(){const e=window.innerHeight||document.documentElement.clientHeight||document.body&&document.body.clientHeight||0,t=window.innerWidth||document.documentElement.clientWidth||document.body&&document.body.clientWidth||0,i=navigator.userAgent,n=function(e){for(let t=0;t<Q.length;t++){const[i,n]=Q[t],s=i.exec(e),r=s&&("function"==typeof n?n(s,e):n);if(r)return r}return["",""]}(i)||["",""];return{$browser:J(i),$browser_version:Z(i),$url:location?.href.substring(0,1e3),$host:location?.host,$viewport_height:e,$viewport_width:t,$lib:"webjs",$lib_version:S,$search_engine:$(),$referrer:M(),$referrer_host:m(r=r||M()),$title:document.title,$language:navigator.language,$model:(s=i,(X.test(s)?F.NINTENDO:W.test(s)?F.PLAYSTATION:U.test(s)?F.XBOX:new RegExp(F.OUYA,"i").test(s)?F.OUYA:new RegExp("("+F.WINDOWS_PHONE+"|WPDesktop)","i").test(s)?F.WINDOWS_PHONE:/iPad/.test(s)?F.IPAD:/iPod/.test(s)?"iPod Touch":/iPhone/.test(s)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(s)?F.APPLE_WATCH:j.test(s)?F.BLACKBERRY:/(kobo)\s(ereader|touch)/i.test(s)?"Kobo":new RegExp(F.NOKIA,"i").test(s)?F.NOKIA:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(s)||/(kf[a-z]+)( bui|\)).+silk\//i.test(s)?"Kindle Fire":q.test(s)?F.HUAWEI:G.test(s)?F.XIAOMI:z.test(s)?F.OPPO:V.test(s)?F.VIVO:/(Android|ZTE)/i.test(s)?!new RegExp(F.MOBILE).test(s)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(s)?/pixel[\daxl ]{1,6}/i.test(s)&&!/pixel c/i.test(s)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(s)||/lmy47v/i.test(s)&&!/QTAQZ3/i.test(s)?F.ANDROID:F.ANDROID_TABLET:F.ANDROID:new RegExp("(pda|"+F.MOBILE+")","i").test(s)?F.GENERIC_MOBILE:new RegExp(F.TABLET,"i").test(s)&&!new RegExp(F.TABLET+" pc","i").test(s)?F.GENERIC_TABLET:"")||""),$os:n?.[0]||"",$os_version:n?.[1]||"",$pathname:location?.pathname,$screen_height:Number(screen.height)||0,$screen_width:Number(screen.width)||0,$timezone_offset:60*-(new Date).getTimezoneOffset()};var s,r}const te=new class{constructor(){this.STORAGE_KEY="sensorswave_unsent_events",this.MAX_QUEUE_SIZE=200,this.MAX_RETRY_COUNT=1,this.MAX_AGE_MS=6048e5,this.queue=[],this.loadFromStorage(),this.cleanupExpiredItems()}loadFromStorage(){try{const e=localStorage.getItem(this.STORAGE_KEY);e&&(this.queue=d(e)||[])}catch(e){console.warn("Failed to load queue from localStorage:",e),this.queue=[]}}cleanupExpiredItems(){const e=Date.now(),t=this.queue.filter(t=>e-t.timestamp<this.MAX_AGE_MS);t.length!==this.queue.length&&(this.queue=t,this.saveToStorage())}saveToStorage(){try{this.cleanupExpiredItems(),this.queue.length>this.MAX_QUEUE_SIZE&&(this.queue=this.queue.slice(-this.MAX_QUEUE_SIZE)),localStorage.setItem(this.STORAGE_KEY,JSON.stringify(this.queue))}catch(e){console.warn("Failed to save queue to localStorage:",e)}}enqueue(e,t,i,n=this.MAX_RETRY_COUNT){try{const s={id:f(),url:e,data:t,headers:i,timestamp:Date.now(),retryCount:0,maxRetries:n};return this.queue.push(s),this.saveToStorage(),s.id}catch(s){return console.warn("Failed to enqueue request:",s),""}}dequeue(e){try{this.queue=this.queue.filter(t=>t.id!==e),this.saveToStorage()}catch(t){console.warn("Failed to dequeue request:",t)}}getAll(){try{return this.cleanupExpiredItems(),[...this.queue]}catch(e){return console.warn("Failed to get queue items:",e),[]}}incrementRetryCount(e){const t=this.queue.find(t=>t.id===e);return!(!t||t.retryCount>=t.maxRetries||(t.retryCount++,this.saveToStorage(),0))}clear(){this.queue=[];try{localStorage.removeItem(this.STORAGE_KEY)}catch(e){console.warn("Failed to clear queue from localStorage:",e)}}getItemById(e){return this.queue.find(t=>t.id===e)}};class ie{constructor(e={}){this.flushTimer=null,this.isFlushing=!1,this.paused=!1,this.destroyed=!1,this.config={maxBatchSize:e.maxBatchSize||20,flushInterval:e.flushInterval||5e3},this.startFlushTimer()}pause(){this.paused=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null)}resume(){this.paused&&(this.paused=!1,this.startFlushTimer())}isPaused(){return this.paused}add(){te.getAll().length>=this.config.maxBatchSize&&this.triggerFlush()}triggerFlush(){this.paused||this.isFlushing||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.isFlushing=!0,this.flush())}flush(){const e=te.getAll();if(0===e.length)return this.isFlushing=!1,void this.startFlushTimer();const t=e.slice(0,this.config.maxBatchSize),i=[],n=[];t.forEach(e=>{Array.isArray(e.data)?i.push(...e.data):i.push(e.data),n.push(e.id)});const s=t[t.length-1],r=s.url,o=s.headers;w.instance&&w.instance.config.debug&&console.log(JSON.stringify(i,null,2)),L({url:r,method:"POST",data:i,headers:o,callback:e=>{200===e.statusCode?n.forEach(e=>{te.dequeue(e)}):P(e.statusCode)?console.error("Failed to send batch events:",e):n.forEach(e=>{te.dequeue(e)}),this.isFlushing=!1,this.startFlushTimer()}})}startFlushTimer(){this.destroyed||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flushTimer=setInterval(()=>{te.getAll().length>0&&this.triggerFlush()},this.config.flushInterval))}destroy(){this.destroyed=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.paused||this.flush()}}let ne=null;const se="sensorswave2025jssdksession",re="$session_id";let oe=null;function ae(){const e=new Uint8Array(16);if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues)crypto.getRandomValues(e);else for(let r=6;r<16;r++)e[r]=Math.floor(256*Math.random());const t=new DataView(e.buffer),i=Date.now();t.setUint16(0,Math.floor(i/Math.pow(2,32))),t.setUint32(2,i%Math.pow(2,32)),e[6]=15&e[6]|112,e[8]=63&e[8]|128;const n=[];for(let r=0;r<16;r++)n.push(e[r].toString(16).padStart(2,"0"));const s=n.join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function ce(e){oe=e;try{t.set({name:se,value:JSON.stringify(e),expires:"1800s"})}catch(i){}}function ue(e=!1){const i=Date.now(),s=function(){let e=null;try{e=t.get(se)}catch(s){return oe}if(null==e)return oe;const i=d(e);return function(e){return!!(n(e)&&"string"==typeof e.session_id&&e.session_id&&"number"==typeof e.first_session_time&&Number.isFinite(e.first_session_time)&&"number"==typeof e.latest_session_time&&Number.isFinite(e.latest_session_time))}(i)?i:null}();if(!s||s.first_session_time>i||s.latest_session_time>i||i-s.first_session_time>432e5||i-s.latest_session_time>18e5){const e={session_id:ae(),first_session_time:i,latest_session_time:i};return ce(e),e.session_id}return e||ce({...s,latest_session_time:i}),s.session_id}function le(){const e=w.instance;return!(!e||!e.__innerInited)||(console.warn("[SensorsWave] SDK is not initialized. Please call init() first."),!1)}function he(){const e=w.instance;return!e||"function"!=typeof e.hasOptedOutCapturing||!e.hasOptedOutCapturing()}let de=null;function pe(){return b.isSupport()?(de||(ne||(ne=new ie({maxBatchSize:20,flushInterval:5e3})),de=ne),de):null}function ge(e,t,i){if(he())return L({url:e,method:"POST",data:t.data,headers:t.headers,callback:e=>{if(200!==e.statusCode){if(!P(e.statusCode))return void(i&&te.dequeue(i));if(i&&te.incrementRetryCount(i)){const e=te.getItemById(i);if(e){const t=Math.min(1e3*Math.pow(2,e.retryCount),3e4);setTimeout(()=>{ge(e.url,{data:e.data,headers:e.headers},e.id)},t)}}}else i&&te.dequeue(i),t.callback&&t.callback(e.json)}})}function fe(e){return`${e.apiHost}/in/track`}function me(e){return`${e.apiHost}/ab/evalall`}function Ee(e){return{"Content-Type":"application/json",SourceToken:e.sourceToken}}function _e(e,t,i){w.instance&&w.instance.config.debug&&console.log(JSON.stringify(t.data,null,2));const n=te.enqueue(e,t.data,t.headers);return ge(e,{...t,callback:void 0},n)}function be(){try{const e=sessionStorage.getItem("sensorswave_utm");if(!e)return{};const t=JSON.parse(e),i={};return Object.entries(t).forEach(([e,t])=>{null!=t&&""!==t&&(i[`$${e}`]=t)}),i}catch(e){return{}}}function ve(e){const t={};return Object.entries(e).forEach(([e,i])=>{if("function"==typeof i)try{const n=i();t[e]=n}catch(n){console.warn("[SensorsWave] Failed to resolve dynamic property:",e,n)}else t[e]=i}),t}function Ie(e={},t=!0){return{...t?ee():{},...ve(N.getCommonProps()),...e,[re]:ue()}}function we(e={},t=!0){const i=Ie(e,t),n=be();return Object.keys(n).length>0&&Object.assign(i,n),i}function Se(e,t,i=!0){if(!le())return;if(!he())return;const n={time:Date.now(),trace_id:N.getTraceId(),event:e.event,properties:we(e.properties,i)},s=be();Object.keys(s).length>0&&(n.user_properties||(n.user_properties={}),n.user_properties.$set||(n.user_properties.$set={}),Object.assign(n.user_properties.$set,s)),e.user_properties&&(e.user_properties.$set&&(n.user_properties=n.user_properties||{},n.user_properties.$set={...n.user_properties.$set||{},...e.user_properties.$set},delete e.user_properties.$set),n.user_properties={...n.user_properties,...e.user_properties});const r=N.getLoginId(),o=N.getAnonId();r&&(n.login_id=r),o&&(n.anon_id=o);const a=fe(t),c=Ee(t),u=!1!==t.batchSend&&pe();u?(te.enqueue(a,[n],c),u.add()):_e(a,{data:[n],headers:c})}function ye({userProps:e,opts:t}){if(!le())return;if(!he())return;const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return;const s={time:Date.now(),trace_id:N.getTraceId(),event:"$UserSet",login_id:i,anon_id:n,user_properties:e,properties:we()},r=fe(t),o=Ee(t),a=pe();if(!a)return _e(r,{data:[s],headers:o});te.enqueue(r,[s],o),a.add()}function Oe(e){return e.typ===C.FEATURE_GATE||e.typ===C.FEATURE_CONFIG?`$feature_${e.id}`:e.typ===C.EXPERIMENT?`$exp_${e.id}`:""}function Ae(e){const t=e.typ;return[C.FEATURE_GATE,C.EXPERIMENT,C.FEATURE_CONFIG].includes(t)?{[Oe(e)]:e.vid}:{}}function Re(e){const t=e.typ;return t===C.FEATURE_GATE||t===C.FEATURE_CONFIG?{$feature_key:e.key,$feature_variant:e.vid}:t===C.EXPERIMENT?{$exp_key:e.key,$exp_variant:e.vid}:{}}function Te({isUnset:e=!1,data:t,opts:i}){if(!le())return;if(!he())return;if(!t||u(t)||t.disable_impress)return;const n=N.getLoginId(),s=N.getAnonId();if(!n&&!s)return;const r=t.typ===C.EXPERIMENT?"$ExpImpress":"$FeatureImpress";let o={};return o=e?{$unset:{[Oe(t)]:null}}:{$set:{...Ae(t)}},Se({event:r,properties:Re(t),user_properties:o},i)}const Ce="sensorswave_opt_out";class Ne{constructor(e){this.persist=e}read(){if(this.persist)try{const e=b.get(Ce);return"0"===e||"1"!==e&&void 0}catch{return}}write(e){if(this.persist)try{b.set(Ce,e?"0":"1")}catch{}}}class Pe{constructor({plugins:e,emitter:t,config:i,sdk:n}){this.plugins=[],this.pluginInsMap={},this.emitter=t,this.config=i,this.sdk=n,this.registerBuiltInPlugins(e),this.created(),this.emitter.on(y,()=>{this.init()})}registerBuiltInPlugins(e){for(let t=0,i=e.length;t<i;t++)this.registerPlugin(e[t])}registerPlugin(e){this.plugins.push(e)}getPlugins(){return this.plugins}getPlugin(e){return this.pluginInsMap[e]}created(){for(let e=0,t=this.plugins.length;e<t;e++){const t=this.plugins[e];if(!t.NAME)throw new Error('Plugin should be defined with "NAME"');const i=new t({emitter:this.emitter,config:this.config,sdk:this.sdk});this.pluginInsMap[t.NAME]=i}}init(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.init&&t.init()}}destroy(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.destroy&&"function"==typeof t.destroy&&t.destroy()}this.pluginInsMap={},this.plugins=[]}}const ke=class{constructor({emitter:e,config:t,sdk:i}){this.boundSend=null,this.hashEvent=null,this.spaSwitchHandler=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;this.boundSend=()=>{Se({event:"$PageView",properties:{}},e)},this.sdk&&!0===this.sdk._postConsentInit||setTimeout(()=>{this.boundSend()},0),e.isSinglePageApp&&this.addSinglePageListener()}addSinglePageListener(){this.spaSwitchHandler=e=>{e!==location.href&&this.boundSend()},this.emitter.on(O,this.spaSwitchHandler)}destroy(){this.spaSwitchHandler&&(this.emitter.off(O,this.spaSwitchHandler),this.spaSwitchHandler=null),this.hashEvent&&this.boundSend&&(window.removeEventListener(this.hashEvent,this.boundSend),this.hashEvent=null),this.boundSend=null}};ke.NAME="pageview";let xe=ke;const Le=class{constructor({emitter:e,config:t,sdk:i}){this.startTime=Date.now(),this.pageShowStatus=!0,this.pageHiddenStatus=!1,this.timer=null,this.currentPageUrl=document.referrer,this.url=location.href,this.title=document.title||"",this.heartbeatIntervalTime=5e3,this.heartbeatIntervalTimer=null,this.pageId=null,this.storageName="sensorswavewebjssdkpageleave",this.maxDuration=432e3,this.eventListeners=[],this._skipFirstPageEnd=!1,this.emitter=e,this.config=t,this.sdk=i}__canCapture(){return!this.sdk||"function"!=typeof this.sdk.hasOptedOutCapturing||!this.sdk.hasOptedOutCapturing()}init(){this.pageId=Number(String(g()).slice(2,5)+String(g()).slice(2,4)+String(Date.now()).slice(-4)),this.addEventListener(),this.sdk&&!0===this.sdk._postConsentInit&&(this._skipFirstPageEnd=!0),!0===document.hidden?this.pageShowStatus=!1:this.addHeartBeatInterval()}log(e){console.log(e)}refreshPageEndTimer(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.timer=setTimeout(()=>{this.pageHiddenStatus=!1},5e3)}hiddenStatusHandler(){this.timer&&clearTimeout(this.timer),this.timer=null,this.pageHiddenStatus=!1}pageStartHandler(){this.startTime=Date.now(),1==!document.hidden?this.pageShowStatus=!0:this.pageShowStatus=!1,this.url=location.href,this.title=document.title,this._skipFirstPageEnd=!1}pageEndHandler(){if(!0===this.pageHiddenStatus)return;if(!this.__canCapture())return;const e=this.getPageLeaveProperties();!1===this.pageShowStatus&&delete e.$event_duration,this.pageShowStatus=!1,this.pageHiddenStatus=!0,Se({event:R,properties:e},this.config),this.refreshPageEndTimer(),this.delHeartBeatData()}addEventListener(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()}addPageStartListener(){if("onpageshow"in window){const e=()=>{this.pageStartHandler(),this.hiddenStatusHandler()};window.addEventListener("pageshow",e),this.eventListeners.push({target:window,event:"pageshow",handler:e})}}addSinglePageListener(){this.config.isSinglePageApp&&this.emitter.on(O,e=>{e!==location.href&&(this.url=e,this.pageEndHandler(),this.stopHeartBeatInterval(),this.currentPageUrl=this.url,this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval())})}addPageEndListener(){["pagehide","beforeunload"].forEach(e=>{if(`on${e}`in window){const t=()=>{if(this._skipFirstPageEnd)return this._skipFirstPageEnd=!1,void this.stopHeartBeatInterval();this.pageEndHandler(),this.stopHeartBeatInterval()};window.addEventListener(e,t),this.eventListeners.push({target:window,event:e,handler:t})}})}addPageSwitchListener(){const e=()=>{"visible"===document.visibilityState?(this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval()):(this.url=location.href,this.title=document.title,this.stopHeartBeatInterval(),this.delHeartBeatData())};document.addEventListener("visibilitychange",e),this.eventListeners.push({target:document,event:"visibilitychange",handler:e})}addHeartBeatInterval(){b.isSupport()&&this.startHeartBeatInterval()}startHeartBeatInterval(){this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),this.sdk&&!0===this.sdk._postConsentInit&&!0===this._skipFirstPageEnd||(this.heartbeatIntervalTimer=setInterval(()=>{this.saveHeartBeatData()},this.heartbeatIntervalTime),this.saveHeartBeatData("is_first_heartbeat"),this.reissueHeartBeatData())}stopHeartBeatInterval(){this.heartbeatIntervalTimer&&clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null}saveHeartBeatData(e){if(!this.__canCapture())return;const t=this.getPageLeaveProperties();t.$time=Date.now(),"is_first_heartbeat"===e&&(t.$event_duration=3);const i={type:"track",event:R,properties:t,time:t.$time};i.heartbeat_interval_time=this.heartbeatIntervalTime,b.isSupport()&&b.set(`${this.storageName}-${this.pageId}`,JSON.stringify(i))}delHeartBeatData(e){b.isSupport()&&b.remove(e||`${this.storageName}-${this.pageId}`)}reissueHeartBeatData(){if(this.__canCapture())for(let e=window.localStorage.length-1;e>=0;e--){const t=window.localStorage.key(e);if(t&&t!==`${this.storageName}-${this.pageId}`&&0===t.indexOf(`${this.storageName}-`)){const e=b.parse(t);n(e)&&Date.now()-e.time>e.heartbeat_interval_time+5e3&&(delete e.heartbeat_interval_time,e._flush_time=(new Date).getTime(),Se({event:R,properties:e?.properties},this.config),this.delHeartBeatData(t))}}}getPageLeaveProperties(){let e=(Date.now()-this.startTime)/1e3;(isNaN(e)||e<0||e>this.maxDuration)&&(e=0),e=Number(e.toFixed(3));const t={$title:this.title,$url:this.url?.substring(0,1e3),$pathname:I(this.url)};return 0!==e&&(t.$event_duration=e),t}destroy(){this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}};Le.NAME="pageleave";let Me=Le;const $e=class{constructor({emitter:e,config:t,sdk:i}){this.eventSended=!1,this.emitter=e,this.config=t,this.sdk=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit)return;const e=()=>{let t=0;const i={};if(window.performance){t=function(){let e=0;if("function"==typeof performance.getEntriesByType){const t=performance.getEntriesByType("navigation");t.length>0&&(e=t[0].domContentLoadedEventEnd||0)}return e}();const e=function(){if(performance.getEntries&&"function"==typeof performance.getEntries){const e=performance.getEntries();let t=0;for(const i of e)"transferSize"in i&&(t+=i.transferSize);if("number"==typeof t&&t>=0&&t<10737418240)return Number((t/1024).toFixed(3))}}();e&&(i.$page_resource_size=e)}else console.warn("Performance API is not supported.");t>0&&!Number.isFinite(t)&&(i.$event_duration=Number((t/1e3).toFixed(3))),this.eventSended||(this.eventSended=!0,Se({event:"$PageLoad",properties:i},this.config)),window.removeEventListener("load",e)};"complete"===document.readyState?e():window.addEventListener&&window.addEventListener("load",e)}};$e.NAME="pageload";let De=$e;function Fe(e){if(!l(e))return!1;const t=o(e.tagName)?e.tagName.toLowerCase():"",i={};return i.$element_type=t,i.$element_name=e.getAttribute("name")||"",i.$element_id=e.getAttribute("id")||"",i.$element_class_name=o(e.className)?e.className:"",i.$element_target_url=e.getAttribute("href")||"",i.$element_content=function(e,t){return o(t)&&"input"===t.toLowerCase()?("button"===(i=e).type||"submit"===i.type)&&i.value||"":function(e,t){let i="",n="";return e.textContent?i=v(e.textContent):e.innerText&&(i=v(e.innerText)),i&&(i=i.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),n=i||"","input"!==t&&"INPUT"!==t||(n=e.value||""),n}(e,t);var i}(e,t)||"",i.$element_selector=Be(e)||"",i.$element_path=function(e){let t=[];for(;e.parentNode&&l(e);){if(!o(e.tagName))return"";if(e.id&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.id)){t.unshift(e.tagName.toLowerCase()+"#"+e.id);break}if(e===document.body){t.unshift("body");break}t.unshift(e.tagName.toLowerCase()),e=e.parentNode}return t.join(" > ")}(e)||"",i}function Be(e,t=[]){if(!(e&&e.parentNode&&e.parentNode.children&&o(e.tagName)))return"";t=Array.isArray(t)?t:[];const i=e.nodeName.toLowerCase();return e&&"body"!==i&&1==e.nodeType?(t.unshift(function(e){if(!e||!l(e)||!o(e.tagName))return"";let t=e.parentNode&&9==e.parentNode.nodeType?-1:function(e){if(!e.parentNode)return-1;let t=0;const i=e.tagName,n=e.parentNode.children;for(let s=0,r=n.length;s<r;s++)if(n[s].tagName===i){if(e===n[s])return t;t++}return-1}(e);return e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?"#"+e.getAttribute("id"):e.tagName.toLowerCase()+(~t?":nth-of-type("+(t+1)+")":"")}(e)),e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?t.join(" > "):Be(e.parentNode,t)):(t.unshift("body"),t.join(" > "))}function He(){return{scrollLeft:document.body.scrollLeft||document.documentElement.scrollLeft||0,scrollTop:document.body.scrollTop||document.documentElement.scrollTop||0}}function Ue(e){if(document.documentElement.getBoundingClientRect){const t=e.getBoundingClientRect();return{targetEleX:t.left+He().scrollLeft||0,targetEleY:t.top+He().scrollTop||0}}return{targetEleX:0,targetEleY:0}}function We(e){return Number(Number(e).toFixed(3))}const Xe=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleClick=null,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,!0),this.isInitialized=!0)}handleClick(e){const t=e.target;if(!t)return;if(!["A","INPUT","BUTTON","TEXTAREA"].includes(t.tagName))return;if("true"===t.getAttribute("sensorswave-disable"))return;const i=function(e,t){const i=Fe(e);if(!i)return!1;const n=function(e,t){const i=t.pageX||t.clientX+He().scrollLeft||t.offsetX+Ue(e).targetEleX,n=t.pageY||t.clientY+He().scrollTop||t.offsetY+Ue(e).targetEleY;return{$page_x:We(i),$page_y:We(n)}}(e,t);return i.$page_x=n.$page_x,i.$page_y=n.$page_y,i}(t,e);Se({event:"$WebClick",properties:i||{}},this.config)}destroy(){this.boundHandleClick&&(document.removeEventListener("click",this.boundHandleClick,!0),this.boundHandleClick=null),this.isInitialized=!1}};Xe.NAME="webclick";let je=Xe;const qe=class{constructor({emitter:e,config:t,sdk:i}){this.updateInterval=null,this.fetchingPromise=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;if(e.enableAB){if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;this.fastFetch().then(()=>{this.emitter.emit(A)}),e.abRefreshInterval<3e4&&(e.abRefreshInterval=3e4),this.updateInterval=setInterval(()=>{this.fetchNewData().catch(console.warn)},e.abRefreshInterval)}}async fastFetch(){const e=N.getABData(this.config.abRefreshInterval);return e&&e.length?(this.emitter.emit(A),Promise.resolve(e)):this.fetchNewData()}async fetchNewData(){return this.fetchingPromise||(this.fetchingPromise=new Promise(e=>{!function({opts:e,cb:t}){if(!le())return void(t&&t({}));if(!he())return void(t&&t({}));const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return void(t&&t({}));const s={user:{login_id:i||"",anon_id:n||"",props:{...ee(),...ve(N.getCommonProps())}},sdk:"webjs",sdk_version:S};L({url:me(e),method:"POST",data:s,headers:Ee(e),callback:e=>{200!==e.statusCode?(console.error("Failed to fetch feature flags"),t&&t({})):t&&t(e.json)}})}({opts:this.config,cb:t=>{N.saveABData(t?.data?.results||[]),e(t),this.fetchingPromise=null}})})),this.fetchingPromise}async getFeatureGate(e){return await this.fastFetch().catch(console.warn),N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_GATE&&t.key==e)}async checkFeatureGate(e){const t=await this.getFeatureGate(e);return!!t&&(!t.hasOwnProperty("vid")&&t.key?(Te({isUnset:!0,data:t,opts:this.config}),!1):(Te({data:t,opts:this.config}),"fail"!==t.vid))}async getExperiment(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.EXPERIMENT&&t.key===e);return t?!t.hasOwnProperty("vid")&&t.key?(Te({isUnset:!0,data:t,opts:this.config}),{}):(Te({data:t,opts:this.config}),t?.value||{}):{}}async getFeatureConfig(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_CONFIG&&t.key===e);if(!t)return{};if(!t.hasOwnProperty("vid")&&t.key)return Te({isUnset:!0,data:t,opts:this.config}),{};Te({data:t,opts:this.config});const i=t?.value;if(i){if(n(i))return i;try{return JSON.parse(i)}catch{return i}}return{}}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null),this.fetchingPromise=null}};qe.NAME="abtest";let Ge=qe;const ze=["utm_source","utm_medium","utm_campaign","utm_content","utm_term"],Ve="sensorswave_utm",Ye=class e{constructor({sdk:e,emitter:t,config:i}){this.sdk=e,this.emitter=t,this.config=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit){let t=e.readFromSessionStorage();return t&&0!==Object.keys(t).length||(t=e.captureAndStore(this.config?.debug)),void this.scheduleInitialUTM(t)}const t=e.getUTMFromURL();e.saveToSessionStorage(t,this.config?.debug),this.scheduleInitialUTM(t)}scheduleInitialUTM(e){setTimeout(()=>{this.sendInitialUTM(e)},0)}static getUTMFromURL(){try{const e=new URLSearchParams(window.location.search),t={};return ze.forEach(i=>{const n=e.get(i);n&&(t[i]=n)}),t}catch(t){return e.getUTMFromURLFallback()}}static getUTMFromURLFallback(){const e={};return window.location.search.substring(1).split("&").forEach(t=>{const[i,n]=t.split("="),s=decodeURIComponent(i),r=n?decodeURIComponent(n):"";ze.includes(s)&&(e[s]=r)}),e}static readFromSessionStorage(){try{const e=sessionStorage.getItem(Ve);if(!e)return{};const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch(e){return{}}}static saveToSessionStorage(e,t=!1){try{sessionStorage.setItem(Ve,JSON.stringify(e))}catch(i){t&&console.warn("[SensorsWave UTM] Failed to save to sessionStorage:",i)}}static captureAndStore(t=!1){const i=e.getUTMFromURL();return e.saveToSessionStorage(i,t),i}sendInitialUTM(e){const t={};ze.forEach(i=>{t[`$initial_${i}`]=null!=e[i]?e[i]:""});try{this.sdk.profileSetOnce(t)}catch(i){this.config.debug&&console.warn("[SensorsWave UTM] Failed to send initial UTM:",i)}}destroy(){}};Ye.NAME="UTM";let Je=Ye;const Ke=1e3,Ze=/^\s*(?:async\s+)?at\s+(?:(.+)\s+\()?(.+?):(\d+):(\d+)\)?$/,Qe=/^(?:(.*)@)?(.+?):(\d+):(\d+)$/;function et(e){let t=e;try{const e=location.origin;e&&0===t.indexOf(e)&&(t=t.substring(e.length))}catch(s){}const i=t.indexOf("?");i>-1&&(t=t.substring(0,i));const n=t.indexOf("#");return n>-1&&(t=t.substring(0,n)),t}function tt(e){return e.map(e=>({platform:"web:javascript",filename:et(e.file),function:e.fn||"?",lineno:Number(e.line),colno:Number(e.col),abs_path:it(e.file,1e3)}))}function it(e,t){return e.length>t?e.substring(0,t):e}function nt(e){let t;if("string"==typeof e)t=e;else if(null!==e&&"object"==typeof e){try{t=JSON.stringify(e)}catch(i){t=Object.prototype.toString.call(e)}t||(t=Object.prototype.toString.call(e))}else t=String(e);return it(t,Ke)}function st(e){const{frames:t,headerType:i}=function(e){const t=[];let i="";if(!e||"string"!=typeof e)return{frames:t,headerType:i};const n=e.split(/\r?\n/);for(let s=0;s<n.length;s++){const e=n[s];if(!e||e.length>1024)continue;const r=e.match(Ze),o=r?null:e.match(Qe),a=r||o;if(a)t.push({fn:a[1]||"?",file:a[2],line:a[3],col:a[4]});else if(0===s){const t=e.indexOf(":");t>0&&(i=e.substring(0,t).trim())}if(t.length>=30)break}return{frames:t,headerType:i}}(e&&e.stack);let n=e&&e.name||i||"Error";return n=it(String(n),200),{$exception_level:"error",$exception_type:n,$exception_message:it(String(e&&e.message||""),Ke),$exception_frames:tt(t)}}function rt(e,t,i,n){let s=[];return t&&(s=[{platform:"web:javascript",filename:et(t),function:"?",lineno:i||0,colno:n||0,abs_path:it(t,1e3)}]),{$exception_level:"error",$exception_type:"Error",$exception_message:it(String(e||""),Ke),$exception_frames:s}}class ot{constructor(e=10,t=1,i=1e4){this.buckets=new Map,this.bucketSize=e,this.refillRate=t,this.refillInterval=i}allow(e){const t=Date.now();let i=this.buckets.get(e);if(i){if(t>i.lastRefill){const e=Math.floor((t-i.lastRefill)/this.refillInterval)*this.refillRate;e>0&&(i.tokens=Math.min(this.bucketSize,i.tokens+e),i.lastRefill+=e/this.refillRate*this.refillInterval)}}else i={tokens:this.bucketSize,lastRefill:t},this.buckets.set(e,i);return i.tokens>=1&&(i.tokens-=1,!0)}reset(){this.buckets.clear()}}const at=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleError=null,this.boundHandleRejection=null,this.rateLimiter=new ot,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleError=this.handleError.bind(this),this.boundHandleRejection=this.handleRejection.bind(this),window.addEventListener("error",this.boundHandleError,!0),window.addEventListener("unhandledrejection",this.boundHandleRejection),this.isInitialized=!0)}handleError(e){try{const t=e.target;let i;if(t&&t!==window&&t.tagName)i=function(e){const t=e,i=(t.tagName||"").toLowerCase(),n=it(String(t.src||t.href||""),Ke);return{$exception_level:"error",$exception_type:"ResourceLoadError",$exception_message:`Failed to load <${i}>${n?` from ${n}`:""}`,$exception_frames:[]}}(t);else{const t=e;i=t.error instanceof Error?st(t.error):rt(String(t.message||""),t.filename,t.lineno,t.colno)}this.send(i)}catch(t){}}handleRejection(e){try{const t=e.reason;this.send(function(e){return e instanceof Error?st(e):{$exception_level:"error",$exception_type:"UnhandledRejection",$exception_message:nt(e),$exception_frames:[]}}(t))}catch(t){}}send(e){e.$exception_message&&this.rateLimiter.allow(e.$exception_type)&&Se({event:T,properties:e},this.config)}destroy(){this.boundHandleError&&(window.removeEventListener("error",this.boundHandleError,!0),this.boundHandleError=null),this.boundHandleRejection&&(window.removeEventListener("unhandledrejection",this.boundHandleRejection),this.boundHandleRejection=null),this.rateLimiter.reset(),this.isInitialized=!1}};at.NAME="exception";let ct=at;const ut="data-sw-exposure-event-name",lt="data-sw-exposure-config-",ht=`[${ut}]`,dt={visibleRatio:0,stayDuration:0,repeated:!0};function pt(e,t){const i={};if(!n(e))return i;const s=e;if(void 0!==s.visibleRatio){const e=Number(s.visibleRatio);!isNaN(e)&&e>=0&&e<=1?i.visibleRatio=e:t&&t("[exposure] parameter config.visibleRatio 非法(值域 0~1),已忽略:",s.visibleRatio)}if(void 0!==s.stayDuration){const e=Number(s.stayDuration);!isNaN(e)&&e>=0?i.stayDuration=e:t&&t("[exposure] parameter config.stayDuration 非法(须 >= 0),已忽略:",s.stayDuration)}if(void 0!==s.repeated){const e=s.repeated;!0===e||"true"===e?i.repeated=!0:!1===e||"false"===e?i.repeated=!1:t&&t("[exposure] parameter config.repeated 非法(须为布尔),已忽略:",e)}return i}function gt(...e){const t={...dt};for(let i=0;i<e.length;i++){const s=e[i];if(!n(s))continue;const r=s;void 0!==r.visibleRatio&&(t.visibleRatio=r.visibleRatio),void 0!==r.stayDuration&&(t.stayDuration=r.stayDuration),void 0!==r.repeated&&(t.repeated=r.repeated)}return t}function ft(e){const t=(e.getAttribute(ut)||"").trim();let i={},s={};const r=e.getAttribute("data-sw-exposure-option");if(r){const e=d(r);n(e)&&(n(e.config)&&(i=e.config),n(e.properties)&&(s=e.properties))}const a=e.getAttribute(lt+"visible-ratio");null!==a&&(i.visibleRatio=a);const c=e.getAttribute(lt+"stay-duration");null!==c&&(i.stayDuration=c);const u=e.getAttribute(lt+"repeated");null!==u&&(i.repeated=u);const l=e.attributes;for(let n=0;n<l.length;n++){const e=l[n],t=e.name;if(o(t)&&0===t.indexOf("data-sw-exposure-property-")){const i=t.substring(26);i&&(s[i]=e.value)}}return{eventName:t,config:pt(i),properties:s}}const mt=class{constructor({emitter:e,config:t,sdk:i}){this.isInitialized=!1,this.observers=new Map,this.records=new Map,this.mutationObserver=null,this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.boundHandleSpa=null,this.eventListeners=[],this.globalConfig={...dt},this.log=function(){},this.emitter=e,this.config=t,this.sdk=i}init(){this.isInitialized||(function(){try{return"undefined"!=typeof window&&"IntersectionObserver"in window&&"MutationObserver"in window}catch(e){return!1}}()?(this.log=!0==(!0===this.config.debug)&&"undefined"!=typeof console&&console.log?function(...e){console.log("[SensorsWave][exposure]",...e)}:function(){},this.globalConfig=gt(this.globalConfig,pt(this.config.exposureConfig,this.log)),this.boundHandleIntersection=this.handleIntersection.bind(this),this.boundHandleMutation=this.handleMutation.bind(this),this.boundHandleVisibility=this.handleVisibility.bind(this),"loading"===document.readyState?(this.boundHandleReady=()=>{this.scanDocument(),this.observeMutations()},document.addEventListener("DOMContentLoaded",this.boundHandleReady),this.eventListeners.push({target:document,event:"DOMContentLoaded",handler:this.boundHandleReady})):(this.scanDocument(),this.observeMutations()),!0===this.config.isSinglePageApp&&(this.boundHandleSpa=e=>{this.handleSpaSwitch(e)},this.emitter.on(O,this.boundHandleSpa)),document.addEventListener("visibilitychange",this.boundHandleVisibility),this.eventListeners.push({target:document,event:"visibilitychange",handler:this.boundHandleVisibility}),!0===document.hidden&&this.stop(),this.isInitialized=!0):console.warn("[SensorsWave][exposure] 当前浏览器不支持 IntersectionObserver / MutationObserver,曝光采集未初始化"))}addExposureView(e,t){this.isInitialized?l(e)?n(t)&&o(t.eventName)&&t.eventName.trim()?this.addOrUpdateWatchEle(e,{eventName:t.eventName.trim(),config:n(t.config)?pt(t.config,this.log):void 0,properties:n(t.properties)?{...t.properties}:{},listener:n(t.listener)?{...t.listener}:{}},"api"):this.log("addExposureView parameter option.eventName 缺失:",t):this.log("addExposureView parameter element 非法:",e):this.log("曝光插件未初始化(enableExposureTrack 未开启或浏览器不支持)")}removeExposureView(e){this.isInitialized?l(e)?this.removeWatchEle(e):this.log("removeExposureView parameter element 非法:",e):this.log("曝光插件未初始化")}scanDocument(e){try{const t=e||document;if(!t.querySelectorAll)return;const i=t.querySelectorAll(ht);for(let e=0;e<i.length;e++){const t=i[e];this.addOrUpdateWatchEle(t,ft(t),"attr")}}catch(t){}}addOrUpdateWatchEle(e,t,i){if(!e||!l(e))return void this.log("parameter element error:",e);if(!o(t.eventName)||!t.eventName.trim())return void this.log("parameter option.eventName error:",t);const n=this.records.get(e);if(n&&"api"===n.source&&"attr"===i)return void this.log("声明式属性变更被忽略:元素已由 addExposureView 注册",e);const s=gt(this.globalConfig,n&&n.config,t.config);if(n&&n.config.visibleRatio===s.visibleRatio)return n.eventName=t.eventName,n.source=i,n.config=s,n.properties={...t.properties||{}},n.listener=t.listener||{},void(n.hasSent=!1);n&&this.removeWatchEle(e);const r={ele:e,eventName:t.eventName,source:i,config:s,properties:{...t.properties||{}},listener:t.listener||{},timer:null,hasSent:!1};this.records.set(e,r),this.getIntersection(s.visibleRatio).observe(e)}getIntersection(e){let t=this.observers.get(e);return!t&&this.boundHandleIntersection&&(t=new IntersectionObserver(this.boundHandleIntersection,{threshold:e}),this.observers.set(e,t)),t}removeWatchEle(e){const t=this.records.get(e);if(!t)return;const i=this.observers.get(t.config.visibleRatio);i&&l(e)&&i.unobserve(e),t.timer&&(clearTimeout(t.timer),t.timer=null),this.records.delete(e)}handleIntersection(e){try{for(const t of e){const e=t.target,i=this.records.get(e);i&&(!0===t.isIntersecting&&t.intersectionRatio>=i.config.visibleRatio?!0!==document.hidden&&(i.timer&&clearTimeout(i.timer),i.timer=setTimeout(()=>{this.fireExposure(e)},1e3*i.config.stayDuration)):i.timer&&(clearTimeout(i.timer),i.timer=null))}}catch(t){}}fireExposure(e){try{const i=this.records.get(e);if(i&&(i.timer=null),!i||i.hasSent)return;let n={width:0,height:0};try{n=e.getBoundingClientRect()}catch(t){}if(!n.width||!n.height)return;if(!e.isConnected)return void this.removeWatchEle(e);if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;const r={...Fe(e),...i.properties},{shouldExpose:o,didExpose:a}=i.listener||{};if(o&&s(o))try{if(!1===o(e,r))return}catch(t){return}if(Se({event:i.eventName,properties:r},this.config),i.hasSent=!0,i.config.repeated&&(i.hasSent=!1),a&&s(a))try{a(e,r)}catch(t){}}catch(t){}}observeMutations(){!this.mutationObserver&&this.boundHandleMutation&&(this.mutationObserver=new MutationObserver(this.boundHandleMutation),this.mutationObserver.observe(document.body,{attributes:!0,childList:!0,subtree:!0}))}handleMutation(e){try{for(const t of e)if("childList"===t.type){if(t.removedNodes.length>0)for(const e of Array.from(t.removedNodes)){if(1!==e.nodeType)continue;this.removeWatchEle(e);const t=e.querySelectorAll(ht);for(let e=0;e<t.length;e++)this.removeWatchEle(t[e])}if(t.addedNodes.length>0)for(const e of Array.from(t.addedNodes))1===e.nodeType&&(e.hasAttribute(ut)&&this.addOrUpdateWatchEle(e,ft(e),"attr"),this.scanDocument(e))}else"attributes"===t.type&&this.handleAttrChange(t)}catch(t){}}handleAttrChange(e){const t=e.attributeName;if(!t||0!==t.indexOf("data-sw-exposure"))return;const i=e.target;t!==ut||(i.getAttribute(t)||"").trim()?(i.getAttribute(ut)||"").trim()&&this.addOrUpdateWatchEle(i,ft(i),"attr"):this.removeWatchEle(i)}handleSpaSwitch(e){try{if(e===location.href)return;this.stop();for(const[e,t]of Array.from(this.records))"attr"===t.source&&this.records.delete(e);this.start(),this.scanDocument()}catch(t){}}stop(){for(const e of Array.from(this.records.values())){const t=this.observers.get(e.config.visibleRatio);t&&t.unobserve(e.ele),e.timer&&(clearTimeout(e.timer),e.timer=null)}}start(){for(const e of Array.from(this.records.values())){if(!e.ele.isConnected){this.records.delete(e.ele);continue}const t=this.observers.get(e.config.visibleRatio);t&&t.observe(e.ele)}}handleVisibility(){try{"visible"===document.visibilityState?this.start():this.stop()}catch(e){}}destroy(){this.observers.forEach(e=>{try{e.disconnect()}catch(t){}}),this.observers.clear(),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null);for(const e of Array.from(this.records.values()))e.timer&&(clearTimeout(e.timer),e.timer=null);this.records.clear(),this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.boundHandleSpa&&(this.emitter.off(O,this.boundHandleSpa),this.boundHandleSpa=null),this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.globalConfig={...dt},this.log=function(){},this.isInitialized=!1}};mt.NAME="exposure";let Et=mt;const _t=[],bt={debug:!1,sourceToken:"",apiHost:"",autoCapture:!0,isSinglePageApp:!1,crossSubdomainCookie:!0,enableAB:!1,abRefreshInterval:6e5,enableClickTrack:!1,enableExposureTrack:!1,batchSend:!1,enableErrorTrack:!1,enableCrashTrack:!1,optOutCapturing:!1,persistOptOut:!1},vt=new class{constructor(){this.__innerInited=!1,this.inited=!1,this.config={},this.eventEmitter=new e,this.pluginCore={},this.commonProps={},this.spaCleanup=null,this._optOutCapturing=!1,this.consentStorage=new Ne(!1),this._setupAfterConsentDone=!1,this._postConsentInit=!1,w.instance=this}init(e,t={}){return this.inited?this:(w.instance=this,t.sourceToken=e,this.mergeConfig(t),this.consentStorage=new Ne(!0===this.config.persistOptOut),this._optOutCapturing?this.consentStorage.write(!0):!0===this.config.optOutCapturing?(this._optOutCapturing=!0,this.consentStorage.write(!0)):!0===this.consentStorage.read()&&(this._optOutCapturing=!0),this.eventEmitter.emit("init-param",this.config),this.__innerInited=!0,this._optOutCapturing?(Je.captureAndStore(this.config.debug),this.eventEmitter.emit(y),this.inited=!0,this):(this.__setupAfterConsent(),this.eventEmitter.emit(y),this.inited=!0,this))}__setupAfterConsent(){if(this._setupAfterConsentDone)return;this._setupAfterConsentDone=!0;const e=this.config;_t.length=0,N.init(e.crossSubdomainCookie),e.anonId&&N.setAnonId(e.anonId),function(){if(window._swFailedRequestsInitialized)return;window._swFailedRequestsInitialized=!0;const e=w.instance;e&&"function"==typeof e.hasOptedOutCapturing&&e.hasOptedOutCapturing()||e&&!0===e._postConsentInit||function(){const e=te.getAll();if(0!==e.length)for(let t=0,i=e.length;t<i;t+=10){const i=e.slice(t,t+10),n=[],s=[];i.forEach(e=>{Array.isArray(e.data)?n.push(...e.data):n.push(e.data),s.push(e.id)});const r=i[i.length-1],o=r.url,a=r.headers;L({url:o,method:"POST",data:n,headers:a,callback:e=>{200!==e.statusCode?(console.error("Failed to send batch stored requests:",e),P(e.statusCode)||s.forEach(e=>{te.dequeue(e)})):s.forEach(e=>{te.dequeue(e)})}})}}()}(),_t.push(Je),e.autoCapture&&this.autoTrack(),e.enableAB&&_t.push(Ge),e.enableClickTrack&&_t.push(je),e.enableCrashTrack&&e.debug&&console.warn("[SensorsWave] enableCrashTrack 仅在 app 宿主环境生效,当前 Web 环境不采集 crash"),e.enableErrorTrack&&_t.push(ct),e.enableExposureTrack&&_t.push(Et),this.pluginCore=new Pe({plugins:_t,emitter:this.eventEmitter,config:e,sdk:this}),this.spaCleanup=function(e){let t=location.href;const i=window.history.pushState,n=window.history.replaceState,r=function(){e(t),t=location.href};return s(window.history.pushState)&&(window.history.pushState=function(...n){i.apply(window.history,n),e(t),t=location.href}),s(window.history.replaceState)&&(window.history.replaceState=function(...i){n.apply(window.history,i),e(t),t=location.href}),window.addEventListener("popstate",r),function(){s(window.history.pushState)&&(window.history.pushState=i),s(window.history.replaceState)&&(window.history.replaceState=n),window.removeEventListener("popstate",r)}}(e=>{this.eventEmitter.emit(O,e)})}mergeConfig(e){this.config={...bt,...e}}__canCapture(){return this.inited&&!this._optOutCapturing}track(e){this.__canCapture()&&function(e,t){if(!le())return;if(!he())return;const i={...e};i.time||(i.time=Date.now()),i.login_id||(i.login_id=N.getLoginId()),i.anon_id||(i.anon_id=N.getAnonId()),i.trace_id||(i.trace_id=N.getTraceId()),i.properties=Ie(i.properties);const n=fe(t),s=Ee(t),r=!1!==t.batchSend&&pe();if(!r)return _e(n,{data:[i],headers:s});te.enqueue(n,[i],s),r.add()}(e,this.config)}trackEvent(e,t){this.__canCapture()&&Se({event:e,properties:t},this.config)}trackException(e,t){if(!this.__canCapture())return;const i={...t||{},...e instanceof Error?st(e):rt(String(e))};Se({event:T,properties:i},this.config)}addExposureView(e,t){if(!this.__canCapture())return;const i=this.pluginCore.getPlugin(Et.NAME);i?i.addExposureView(e,t):console.warn("[SensorsWave] addExposureView 需在 init 时配置 enableExposureTrack: true")}removeExposureView(e){if(!this.__canCapture())return;const t=this.pluginCore.getPlugin(Et.NAME);t&&t.removeExposureView(e)}autoTrack(){_t.push(xe,De,Me)}profileSet(e){this.__canCapture()&&ye({userProps:{$set:e},opts:this.config})}profileSetOnce(e){this.__canCapture()&&ye({userProps:{$set_once:e},opts:this.config})}profileIncrement(e){this.__canCapture()&&ye({userProps:{$increment:e},opts:this.config})}profileAppend(e){this.__canCapture()&&ye({userProps:{$append:e},opts:this.config})}profileUnion(e){this.__canCapture()&&ye({userProps:{$union:e},opts:this.config})}profileUnset(e){if(!this.__canCapture())return;const t={};r(e)?e.forEach(function(e){t[e]=null}):t[e]=null,ye({userProps:{$unset:t},opts:this.config})}profileDelete(){this.__canCapture()&&ye({userProps:{$delete:!0},opts:this.config})}registerCommonProperties(e){if(!n(e))return console.warn("Commmon Properties must be an object!");this.commonProps=e,N.setCommonProps(this.commonProps)}clearCommonProperties(e){if(!r(e))return console.warn("Commmon Properties to be cleared must be an array!");e.forEach(e=>{delete this.commonProps[e]}),N.setCommonProps(this.commonProps)}identify(e){this.__canCapture()&&(N.setLoginId(e),function(e){if(!le())return;if(!he())return;const t=N.getLoginId(),i=N.getAnonId();if(!t||!i)return;const n={time:Date.now(),trace_id:N.getTraceId(),event:"$Identify",login_id:t,anon_id:i,properties:we()},s=fe(e),r=Ee(e),o=pe();if(!o)return _e(s,{data:[n],headers:r});te.enqueue(s,[n],r),o.add()}(this.config))}setLoginId(e){this.__canCapture()&&N.setLoginId(e)}getAnonId(){return this.__canCapture()?N.getAnonId():""}getSessionId(){return this.__canCapture()?ue(!0):""}setAnonId(e){this.__canCapture()&&N.setAnonId(e)}getLoginId(){return this.__canCapture()?N.getLoginId():""}reset(e=!1){this.__canCapture()&&(N.clearLoginId(),function(){oe=null;try{t.remove(se)}catch(e){}}(),e&&N.resetAnonId())}checkFeatureGate(e){if(!this.__canCapture())return Promise.resolve(!1);const t=this.pluginCore.getPlugin(Ge.NAME);return this.config.enableAB&&t?t.checkFeatureGate(e):Promise.reject("AB is disabled")}getExperiment(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Ge.NAME);return this.config.enableAB&&t?t.getExperiment(e):Promise.reject("AB is disabled")}getFeatureConfig(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Ge.NAME);return this.config.enableAB&&t?t.getFeatureConfig(e):Promise.reject("AB is disabled")}optOutCapturing(){this._optOutCapturing=!0,this.consentStorage.write(!0),de&&de.pause()}optInCapturing(){if(this._optOutCapturing=!1,this.consentStorage.write(!1),de&&de.resume(),this.inited&&!this._setupAfterConsentDone){this._postConsentInit=!0;try{this.__setupAfterConsent(),this.eventEmitter.emit(y)}finally{this._postConsentInit=!1}}}hasOptedOutCapturing(){return this._optOutCapturing}destroy(){de&&(de.destroy(),de=null),"undefined"!=typeof window&&(window._swFailedRequestsInitialized=!1),oe=null,this.inited=!1,this.__innerInited=!1,this.spaCleanup&&"function"==typeof this.spaCleanup&&(this.spaCleanup(),this.spaCleanup=null),this.pluginCore&&"function"==typeof this.pluginCore.destroy&&this.pluginCore.destroy(),this.pluginCore={},this.eventEmitter&&this.eventEmitter.removeAllListeners(),this.consentStorage=new Ne(!0===this.config?.persistOptOut),this._optOutCapturing=!1,this._setupAfterConsentDone=!1,this._postConsentInit=!1,w.instance===this&&(w.instance=null)}};module.exports=vt;
|
package/dist/index.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class e{constructor(){this.listeners={}}on(e,t,i=!1){if(e&&t){if(!s(t))throw new Error("listener must be a function");this.listeners[e]=this.listeners[e]||[],this.listeners[e].push({listener:t,once:i})}}off(e,t){const i=this.listeners[e];if(!i?.length)return;"number"==typeof t&&i.splice(t,1);const n=i.findIndex(e=>e.listener===t);-1!==n&&i.splice(n,1)}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((i,n)=>{i.listener.call(this,...t),i.listener.once&&this.off(e,n)})}once(e,t){this.on(e,t,!0)}removeAllListeners(e){e?this.listeners[e]=[]:this.listeners={}}}const t={get:function(e){const t=e+"=",i=document.cookie.split(";");for(let n=0,s=i.length;n<s;n++){let e=i[n];for(;" "==e.charAt(0);)e=e.substring(1,e.length);if(0==e.indexOf(t))return h(e.substring(t.length,e.length))}return null},set:function({name:e,value:t,expires:i,samesite:n,secure:s,domain:r}){let o="",a="",c="",u="";if(0!==(i=null==i||void 0===i?365:i)){const e=/* @__PURE__ */new Date;"s"===String(i).slice(-1)?e.setTime(e.getTime()+1e3*Number(String(i).slice(0,-1))):e.setTime(e.getTime()+24*i*60*60*1e3),o="; expires="+e.toUTCString()}function l(e){return e?e.replace(/\r\n/g,""):""}n&&(c="; SameSite="+n),s&&(a="; secure");const h=l(e),d=l(t),p=l(r);p&&(u="; domain="+p),h&&d&&(document.cookie=h+"="+encodeURIComponent(d)+o+"; path=/"+u+c+a)},remove:function(e){this.set({name:e,value:"",expires:-1})},isSupport:function({samesite:e,secure:t}={}){if(!navigator.cookieEnabled)return!1;const i="sensorswave_cookie_support_test";return this.set({name:i,value:"1",samesite:e,secure:t}),"1"===this.get(i)&&(this.remove(i),!0)}},i=Object.prototype.toString;function n(e){return"[object Object]"===i.call(e)}function s(e){const t=i.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t}function r(e){return"[object Array]"==i.call(e)}function o(e){return"[object String]"==i.call(e)}function a(e){return void 0===e}const c=Object.prototype.hasOwnProperty;function u(e){if(n(e)){for(let t in e)if(c.call(e,t))return!1;return!0}return!1}function l(e){return!(!e||1!==e.nodeType)}function h(e){let t=e;try{t=decodeURIComponent(e)}catch(i){t=e}return t}function d(e){try{return JSON.parse(e)}catch(t){return""}}const p=function(){let e=Date.now();return function(t){return Math.ceil((e=(9301*e+49297)%233280,e/233280*t))}}();function g(){if("function"==typeof Uint32Array){let e;if("undefined"!=typeof crypto&&(e=crypto),e&&n(e)&&e.getRandomValues)return e.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32)}return p(1e19)/1e19}const f=/* @__PURE__ */function(){function e(e){return("0".repeat(e)+Date.now().toString(16)).slice(-e)}return function(){let t=String(screen.height*screen.width);t=t&&/\d{4,}/.test(t)?t.slice(-4):String(31242*g()).replace(".","").slice(0,4);return e(8)+"-"+g().toString(16).replace(".","").slice(-4)+"-"+function(){const e=navigator.userAgent;let t,i=[],n=0;function s(e,t){let n=0;for(let s=0;s<t.length;s++)n|=i[s]<<8*s;return(e^n)>>>0}for(let r=0;r<e.length;r++)t=e.charCodeAt(r),i.unshift(255&t),i.length>=4&&(n=s(n,i),i=[]);return i.length>0&&(n=s(n,i)),("0000"+n.toString(16)).slice(-4)}()+"-"+t+"-"+e(12)||(String(g())+String(g())+String(g())).slice(2,15)}}();function m(e,t){t&&"string"==typeof t||(t="");let i=null;try{i=new URL(e).hostname}catch(n){}return i||t}function E(e){let t=[];try{t=atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})}catch(i){t=[]}try{return decodeURIComponent(t.join(""))}catch(i){return t.join("")}}function v(e){let t="";try{t=btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}))}catch(i){t=e}return t}const b={get:function(e){return window.localStorage.getItem(e)},parse:function(e){let t;try{t=JSON.parse(b.get(e))||null}catch(i){console.warn(i)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(i){console.warn(i)}},remove:function(e){window.localStorage.removeItem(e)},isSupport:function(){let e=!0;try{const t="__local_store_support__",i="testIsSupportStorage";b.set(t,i),b.get(t)!==i&&(e=!1),b.remove(t)}catch(t){e=!1}return e}};function _(e){return e.trim()}function I(e){if(!e||"string"!=typeof e)return"";try{return new URL(e,window.location.origin).pathname}catch(t){return""}}const S={},w="1.5.0",O="init-ready",y="spa-switch",A="ff-ready",R="$PageLeave",T="$Exception";var C=/* @__PURE__ */(e=>(e[e.FEATURE_GATE=1]="FEATURE_GATE",e[e.FEATURE_CONFIG=2]="FEATURE_CONFIG",e[e.EXPERIMENT=3]="EXPERIMENT",e))(C||{});const N={crossSubdomain:!1,requests:[],_sessionState:{},_abData:[],_trace_id:"",commonProps:{},_state:{anon_id:"",login_id:"",identities:{}},getIdentityCookieID(){return this._state.identities?.$identity_cookie_id||""},getCommonProps:function(){return this.commonProps||{}},setCommonProps:function(e){this.commonProps=e},getAnonId(){return this._state.anon_id||this.getIdentityCookieID()||f()},getLoginId(){return this._state.login_id},getTraceId(){return this._trace_id||f()},set:function(e,t){this._state[e]=t,this.save()},getCookieName:function(){return"sensorswave2025jssdkcross"},getABLSName:function(){return"sensorswave2025jssdkablatest"},save:function(){let e=JSON.parse(JSON.stringify(this._state));e.identities&&(e.identities=v(JSON.stringify(e.identities)));const i=JSON.stringify(e);t.set({name:this.getCookieName(),value:i,expires:365})},init:function(e){let i,s;this.crossSubdomain=e,t.isSupport()&&(i=t.get(this.getCookieName()),s=d(i)),N._state={...s||{}},N._state.identities&&(N._state.identities=d(E(N._state.identities))),N._state.identities&&n(N._state.identities)&&!u(N._state.identities)||(N._state.identities={$identity_cookie_id:f()}),N.save()},setLoginId(e){"number"==typeof e&&(e=String(e)),void 0!==e&&e&&(N.set("login_id",e),N.save())},clearLoginId(){this._state.login_id="",this.save()},resetAnonId(){this._state.anon_id="",this._state.identities={$identity_cookie_id:f()},this.save()},setAnonId(e){"number"==typeof e&&(e=String(e)),"string"==typeof e&&e?(N.set("anon_id",e),N.save()):console.warn("[SensorsWave store] Invalid anonId, ignored:",e)},saveABData(e){if(!e||u(e))return;this._abData=e;let t=JSON.parse(JSON.stringify(this._abData));t=v(JSON.stringify(t));try{localStorage.setItem(this.getABLSName(),JSON.stringify({time:Date.now(),data:t,anon_id:this.getAnonId(),login_id:this.getLoginId()}))}catch(i){console.warn("Failed to save abdata to localStorage",i)}},getABData(e=6e5){try{let t=localStorage.getItem(this.getABLSName());if(t){const{time:i,data:n,login_id:s,anon_id:r}=d(t)||{};if(i&&n&&Date.now()-i<e&&r===this.getAnonId()&&(!s||s===this.getLoginId())){const e=d(E(n));return this._abData=Array.isArray(e)?e:[],this._abData}localStorage.removeItem(this.getABLSName())}}catch(t){this._abData=[]}return this._abData||[]}};function P(e){return!(e>=400&&e<500)||408===e||429===e}function k(e){var t;if(e.data)return{contentType:"application/json",body:(t=e.data,JSON.stringify(t,(e,t)=>"bigint"==typeof t?t.toString():t,undefined))}}const x=[];function L(e){const t={...e};t.timeout=t.timeout||6e4;const i=t.transport??"fetch",n=x.find(e=>e.transport===i)?.method??x[0]?.method;if(!n)throw new Error("No available transport method for HTTP request");n(t)}function M(e){return o(e=e||document.referrer)&&(e=h(e=e.trim()))||""}function $(e){const t=m(e=e||M());if(!t)return"";const i={baidu:[/^.*\.baidu\.com$/],bing:[/^.*\.bing\.com$/],google:[/^www\.google\.com$/,/^www\.google\.com\.[a-z]{2}$/,/^www\.google\.[a-z]{2}$/],sm:[/^m\.sm\.cn$/],so:[/^.+\.so\.com$/],sogou:[/^.*\.sogou\.com$/],yahoo:[/^.*\.yahoo\.com$/],duckduckgo:[/^.*\.duckduckgo\.com$/]};for(let n of Object.keys(i)){let e=i[n];for(let i=0,s=e.length;i<s;i++)if(e[i].test(t))return n}return""}function F(e,t){return-1!==e.indexOf(t)}"function"==typeof fetch&&x.push({transport:"fetch",method:function(e){if("undefined"==typeof fetch)return void console.error("fetch API is not available");const t=k(e),i=new Headers;e.headers&&Object.keys(e.headers).forEach(t=>{i.append(t,e.headers[t])}),t?.contentType&&i.append("Content-Type",t.contentType),fetch(e.url,{method:e.method||"GET",headers:i,body:t?.body}).then(t=>t.text().then(i=>{const n={statusCode:t.status,text:i};if(200===t.status)try{n.json=JSON.parse(i)}catch(s){console.error("Failed to parse response:",s)}e.callback?.(n)})).catch(t=>{console.error("Request failed:",t),e.callback?.({statusCode:0,text:String(t)})})}}),"undefined"!=typeof XMLHttpRequest&&x.push({transport:"XHR",method:function(e){if("undefined"==typeof XMLHttpRequest)return void console.error("XMLHttpRequest is not available");const t=new XMLHttpRequest;t.open(e.method||"GET",e.url,!0);const i=k(e);e.headers&&Object.keys(e.headers).forEach(i=>{t.setRequestHeader(i,e.headers[i])}),i?.contentType&&t.setRequestHeader("Content-Type",i.contentType),t.timeout=e.timeout||6e4,t.withCredentials=!0,t.onreadystatechange=()=>{if(4===t.readyState){const n={statusCode:t.status,text:t.responseText};if(200===t.status)try{n.json=JSON.parse(t.responseText)}catch(i){console.error("Failed to parse JSON response:",i)}e.callback?.(n)}},t.send(i?.body)}});const D={FACEBOOK:"Facebook",MOBILE:"Mobile",IOS:"iOS",ANDROID:"Android",TABLET:"Tablet",ANDROID_TABLET:"Android Tablet",IPAD:"iPad",APPLE:"Apple",APPLE_WATCH:"Apple Watch",SAFARI:"Safari",BLACKBERRY:"BlackBerry",SAMSUNG_BROWSER:"SamsungBrowser",SAMSUNG_INTERNET:"Samsung Internet",CHROME:"Chrome",CHROME_OS:"Chrome OS",CHROME_IOS:"Chrome iOS",INTERNET_EXPLORER:"Internet Explorer",INTERNET_EXPLORER_MOBILE:"Internet Explorer Mobile",OPERA:"Opera",OPERA_MINI:"Opera Mini",EDGE:"Edge",MICROSOFT_EDGE:"Microsoft Edge",FIREFOX:"Firefox",FIREFOX_IOS:"Firefox iOS",NINTENDO:"Nintendo",PLAYSTATION:"PlayStation",XBOX:"Xbox",ANDROID_MOBILE:"Android Mobile",MOBILE_SAFARI:"Mobile Safari",WINDOWS:"Windows",WINDOWS_PHONE:"Windows Phone",NOKIA:"Nokia",OUYA:"Ouya",GENERIC_MOBILE:"Generic mobile",GENERIC_TABLET:"Generic tablet",KONQUEROR:"Konqueror",UC_BROWSER:"UC Browser",HUAWEI:"Huawei",XIAOMI:"Xiaomi",OPPO:"OPPO",VIVO:"vivo"},B="(\\d+(\\.\\d+)?)",H=new RegExp("Version/"+B),U=new RegExp(D.XBOX,"i"),W=new RegExp(D.PLAYSTATION+" \\w+","i"),X=new RegExp(D.NINTENDO+" \\w+","i"),j=new RegExp(D.BLACKBERRY+"|PlayBook|BB10","i"),q=new RegExp("(HUAWEI|honor|HONOR)","i"),G=new RegExp("(Xiaomi|Redmi)","i"),z=new RegExp("(OPPO|realme)","i"),V=new RegExp("(vivo|IQOO)","i"),Y={"NT3.51":"NT 3.11","NT4.0":"NT 4.0","5.0":"2000",5.1:"XP",5.2:"XP","6.0":"Vista",6.1:"7",6.2:"8",6.3:"8.1",6.4:"10","10.0":"10"};function K(e,t){return t=t||"",F(e," OPR/")&&F(e,"Mini")?D.OPERA_MINI:F(e," OPR/")?D.OPERA:j.test(e)?D.BLACKBERRY:F(e,"IE"+D.MOBILE)||F(e,"WPDesktop")?D.INTERNET_EXPLORER_MOBILE:F(e,D.SAMSUNG_BROWSER)?D.SAMSUNG_INTERNET:F(e,D.EDGE)||F(e,"Edg/")?D.MICROSOFT_EDGE:F(e,"FBIOS")?D.FACEBOOK+" "+D.MOBILE:F(e,"UCWEB")||F(e,"UCBrowser")?D.UC_BROWSER:F(e,"CriOS")?D.CHROME_IOS:F(e,"CrMo")||F(e,D.CHROME)?D.CHROME:F(e,D.ANDROID)&&F(e,D.SAFARI)?D.ANDROID_MOBILE:F(e,"FxiOS")?D.FIREFOX_IOS:F(e.toLowerCase(),D.KONQUEROR.toLowerCase())?D.KONQUEROR:function(e,t){return t&&F(t,D.APPLE)||F(i=e,D.SAFARI)&&!F(i,D.CHROME)&&!F(i,D.ANDROID);var i}(e,t)?F(e,D.MOBILE)?D.MOBILE_SAFARI:D.SAFARI:F(e,D.FIREFOX)?D.FIREFOX:F(e,"MSIE")||F(e,"Trident/")?D.INTERNET_EXPLORER:F(e,"Gecko")?D.FIREFOX:""}const J={[D.INTERNET_EXPLORER_MOBILE]:[new RegExp("rv:"+B)],[D.MICROSOFT_EDGE]:[new RegExp(D.EDGE+"?\\/"+B)],[D.CHROME]:[new RegExp("("+D.CHROME+"|CrMo)\\/"+B)],[D.CHROME_IOS]:[new RegExp("CriOS\\/"+B)],[D.UC_BROWSER]:[new RegExp("(UCBrowser|UCWEB)\\/"+B)],[D.SAFARI]:[H],[D.MOBILE_SAFARI]:[H],[D.OPERA]:[new RegExp("("+D.OPERA+"|OPR)\\/"+B)],[D.FIREFOX]:[new RegExp(D.FIREFOX+"\\/"+B)],[D.FIREFOX_IOS]:[new RegExp("FxiOS\\/"+B)],[D.KONQUEROR]:[new RegExp("Konqueror[:/]?"+B,"i")],[D.BLACKBERRY]:[new RegExp(D.BLACKBERRY+" "+B),H],[D.ANDROID_MOBILE]:[new RegExp("android\\s"+B,"i")],[D.SAMSUNG_INTERNET]:[new RegExp(D.SAMSUNG_BROWSER+"\\/"+B)],[D.INTERNET_EXPLORER]:[new RegExp("(rv:|MSIE )"+B)],Mozilla:[new RegExp("rv:"+B)]};function Z(e,t){const i=K(e,t),n=J[i];if(a(n))return null;for(let s=0;s<n.length;s++){const t=n[s],i=e.match(t);if(i)return parseFloat(i[i.length-2])}return null}const Q=[[new RegExp(D.XBOX+"; "+D.XBOX+" (.*?)[);]","i"),e=>[D.XBOX,e&&e[1]||""]],[new RegExp(D.NINTENDO,"i"),[D.NINTENDO,""]],[new RegExp(D.PLAYSTATION,"i"),[D.PLAYSTATION,""]],[j,[D.BLACKBERRY,""]],[new RegExp(D.WINDOWS,"i"),(e,t)=>{if(/Phone/.test(t)||/WPDesktop/.test(t))return[D.WINDOWS_PHONE,""];if(new RegExp(D.MOBILE).test(t)&&!/IEMobile\b/.test(t))return[D.WINDOWS+" "+D.MOBILE,""];const i=/Windows NT ([0-9.]+)/i.exec(t);if(i&&i[1]){const e=i[1];let n=Y[e]||"";return/arm/i.test(t)&&(n="RT"),[D.WINDOWS,n]}return[D.WINDOWS,""]}],[/((iPhone|iPad|iPod).*?OS (\d+)_(\d+)_?(\d+)?|iPhone)/,e=>{if(e&&e[3]){const t=[e[3],e[4],e[5]||"0"];return[D.IOS,t.join(".")]}return[D.IOS,""]}],[/(watch.*\/(\d+\.\d+\.\d+)|watch os,(\d+\.\d+),)/i,e=>{let t="";return e&&e.length>=3&&(t=a(e[2])?e[3]:e[2]),["watchOS",t]}],[new RegExp("("+D.ANDROID+" (\\d+)\\.(\\d+)\\.?(\\d+)?|"+D.ANDROID+")","i"),e=>{if(e&&e[2]){const t=[e[2],e[3],e[4]||"0"];return[D.ANDROID,t.join(".")]}return[D.ANDROID,""]}],[/Mac OS X (\d+)[_.](\d+)[_.]?(\d+)?/i,e=>{const t=["Mac OS X",""];if(e&&e[1]){const i=[e[1],e[2],e[3]||"0"];t[1]=i.join(".")}return t}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[D.CHROME_OS,""]],[/Linux|debian/i,["Linux",""]]];function ee(){const e=window.innerHeight||document.documentElement.clientHeight||document.body&&document.body.clientHeight||0,t=window.innerWidth||document.documentElement.clientWidth||document.body&&document.body.clientWidth||0,i=navigator.userAgent,n=function(e){for(let t=0;t<Q.length;t++){const[i,n]=Q[t],s=i.exec(e),r=s&&("function"==typeof n?n(s,e):n);if(r)return r}return["",""]}(i)||["",""];return{$browser:K(i),$browser_version:Z(i),$url:location?.href.substring(0,1e3),$host:location?.host,$viewport_height:e,$viewport_width:t,$lib:"webjs",$lib_version:w,$search_engine:$(),$referrer:M(),$referrer_host:m(r=r||M()),$title:document.title,$language:navigator.language,$model:(s=i,(X.test(s)?D.NINTENDO:W.test(s)?D.PLAYSTATION:U.test(s)?D.XBOX:new RegExp(D.OUYA,"i").test(s)?D.OUYA:new RegExp("("+D.WINDOWS_PHONE+"|WPDesktop)","i").test(s)?D.WINDOWS_PHONE:/iPad/.test(s)?D.IPAD:/iPod/.test(s)?"iPod Touch":/iPhone/.test(s)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(s)?D.APPLE_WATCH:j.test(s)?D.BLACKBERRY:/(kobo)\s(ereader|touch)/i.test(s)?"Kobo":new RegExp(D.NOKIA,"i").test(s)?D.NOKIA:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(s)||/(kf[a-z]+)( bui|\)).+silk\//i.test(s)?"Kindle Fire":q.test(s)?D.HUAWEI:G.test(s)?D.XIAOMI:z.test(s)?D.OPPO:V.test(s)?D.VIVO:/(Android|ZTE)/i.test(s)?!new RegExp(D.MOBILE).test(s)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(s)?/pixel[\daxl ]{1,6}/i.test(s)&&!/pixel c/i.test(s)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(s)||/lmy47v/i.test(s)&&!/QTAQZ3/i.test(s)?D.ANDROID:D.ANDROID_TABLET:D.ANDROID:new RegExp("(pda|"+D.MOBILE+")","i").test(s)?D.GENERIC_MOBILE:new RegExp(D.TABLET,"i").test(s)&&!new RegExp(D.TABLET+" pc","i").test(s)?D.GENERIC_TABLET:"")||""),$os:n?.[0]||"",$os_version:n?.[1]||"",$pathname:location?.pathname,$screen_height:Number(screen.height)||0,$screen_width:Number(screen.width)||0,$timezone_offset:60*-/* @__PURE__ */(new Date).getTimezoneOffset()};var s,r}const te=new class{constructor(){this.STORAGE_KEY="sensorswave_unsent_events",this.MAX_QUEUE_SIZE=200,this.MAX_RETRY_COUNT=1,this.MAX_AGE_MS=6048e5,this.queue=[],this.loadFromStorage(),this.cleanupExpiredItems()}loadFromStorage(){try{const e=localStorage.getItem(this.STORAGE_KEY);e&&(this.queue=d(e)||[])}catch(e){console.warn("Failed to load queue from localStorage:",e),this.queue=[]}}cleanupExpiredItems(){const e=Date.now(),t=this.queue.filter(t=>e-t.timestamp<this.MAX_AGE_MS);t.length!==this.queue.length&&(this.queue=t,this.saveToStorage())}saveToStorage(){try{this.cleanupExpiredItems(),this.queue.length>this.MAX_QUEUE_SIZE&&(this.queue=this.queue.slice(-this.MAX_QUEUE_SIZE)),localStorage.setItem(this.STORAGE_KEY,JSON.stringify(this.queue))}catch(e){console.warn("Failed to save queue to localStorage:",e)}}enqueue(e,t,i,n=this.MAX_RETRY_COUNT){try{const s={id:f(),url:e,data:t,headers:i,timestamp:Date.now(),retryCount:0,maxRetries:n};return this.queue.push(s),this.saveToStorage(),s.id}catch(s){return console.warn("Failed to enqueue request:",s),""}}dequeue(e){try{this.queue=this.queue.filter(t=>t.id!==e),this.saveToStorage()}catch(t){console.warn("Failed to dequeue request:",t)}}getAll(){try{return this.cleanupExpiredItems(),[...this.queue]}catch(e){return console.warn("Failed to get queue items:",e),[]}}incrementRetryCount(e){const t=this.queue.find(t=>t.id===e);return!(!t||t.retryCount>=t.maxRetries||(t.retryCount++,this.saveToStorage(),0))}clear(){this.queue=[];try{localStorage.removeItem(this.STORAGE_KEY)}catch(e){console.warn("Failed to clear queue from localStorage:",e)}}getItemById(e){return this.queue.find(t=>t.id===e)}};class ie{constructor(e={}){this.flushTimer=null,this.isFlushing=!1,this.paused=!1,this.destroyed=!1,this.config={maxBatchSize:e.maxBatchSize||20,flushInterval:e.flushInterval||5e3},this.startFlushTimer()}pause(){this.paused=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null)}resume(){this.paused&&(this.paused=!1,this.startFlushTimer())}isPaused(){return this.paused}add(){te.getAll().length>=this.config.maxBatchSize&&this.triggerFlush()}triggerFlush(){this.paused||this.isFlushing||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.isFlushing=!0,this.flush())}flush(){const e=te.getAll();if(0===e.length)return this.isFlushing=!1,void this.startFlushTimer();const t=e.slice(0,this.config.maxBatchSize),i=[],n=[];t.forEach(e=>{Array.isArray(e.data)?i.push(...e.data):i.push(e.data),n.push(e.id)});const s=t[t.length-1],r=s.url,o=s.headers;S.instance&&S.instance.config.debug&&console.log(JSON.stringify(i,null,2)),L({url:r,method:"POST",data:i,headers:o,callback:e=>{200===e.statusCode?n.forEach(e=>{te.dequeue(e)}):P(e.statusCode)?console.error("Failed to send batch events:",e):n.forEach(e=>{te.dequeue(e)}),this.isFlushing=!1,this.startFlushTimer()}})}startFlushTimer(){this.destroyed||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flushTimer=setInterval(()=>{te.getAll().length>0&&this.triggerFlush()},this.config.flushInterval))}destroy(){this.destroyed=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.paused||this.flush()}}let ne=null;function se(){const e=S.instance;return!(!e||!e.__innerInited)||(console.warn("[SensorsWave] SDK is not initialized. Please call init() first."),!1)}function re(){const e=S.instance;return!e||"function"!=typeof e.hasOptedOutCapturing||!e.hasOptedOutCapturing()}let oe=null;function ae(){return b.isSupport()?(oe||(ne||(ne=new ie({maxBatchSize:20,flushInterval:5e3})),oe=ne),oe):null}function ce(e,t,i){if(re())return L({url:e,method:"POST",data:t.data,headers:t.headers,callback:e=>{if(200!==e.statusCode){if(!P(e.statusCode))return void(i&&te.dequeue(i));if(i&&te.incrementRetryCount(i)){const e=te.getItemById(i);if(e){const t=Math.min(1e3*Math.pow(2,e.retryCount),3e4);setTimeout(()=>{ce(e.url,{data:e.data,headers:e.headers},e.id)},t)}}}else i&&te.dequeue(i),t.callback&&t.callback(e.json)}})}function ue(e){return`${e.apiHost}/in/track`}function le(e){return`${e.apiHost}/ab/evalall`}function he(e){return{"Content-Type":"application/json",SourceToken:e.sourceToken}}function de(e,t,i){S.instance&&S.instance.config.debug&&console.log(JSON.stringify(t.data,null,2));const n=te.enqueue(e,t.data,t.headers);return ce(e,{...t,callback:void 0},n)}function pe(){try{const e=sessionStorage.getItem("sensorswave_utm");if(!e)return{};const t=JSON.parse(e),i={};return Object.entries(t).forEach(([e,t])=>{null!=t&&""!==t&&(i[`$${e}`]=t)}),i}catch(e){return{}}}function ge(e){const t={};return Object.entries(e).forEach(([e,i])=>{if("function"==typeof i)try{const n=i();t[e]=n}catch(n){console.warn("[SensorsWave] Failed to resolve dynamic property:",e,n)}else t[e]=i}),t}function fe(e={},t=!0){const i={...t?ee():{},...ge(N.getCommonProps()),...e},n=pe();return Object.keys(n).length>0&&Object.assign(i,n),i}function me(e,t,i=!0){if(!se())return;if(!re())return;const n={time:Date.now(),trace_id:N.getTraceId(),event:e.event,properties:fe(e.properties,i)},s=pe();Object.keys(s).length>0&&(n.user_properties||(n.user_properties={}),n.user_properties.$set||(n.user_properties.$set={}),Object.assign(n.user_properties.$set,s)),e.user_properties&&(e.user_properties.$set&&(n.user_properties=n.user_properties||{},n.user_properties.$set={...n.user_properties.$set||{},...e.user_properties.$set},delete e.user_properties.$set),n.user_properties={...n.user_properties,...e.user_properties});const r=N.getLoginId(),o=N.getAnonId();r&&(n.login_id=r),o&&(n.anon_id=o);const a=ue(t),c=he(t),u=!1!==t.batchSend&&ae();u?(te.enqueue(a,[n],c),u.add()):de(a,{data:[n],headers:c})}function Ee({userProps:e,opts:t}){if(!se())return;if(!re())return;const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return;const s={time:Date.now(),trace_id:N.getTraceId(),event:"$UserSet",login_id:i,anon_id:n,user_properties:e,properties:fe()},r=ue(t),o=he(t),a=ae();if(!a)return de(r,{data:[s],headers:o});te.enqueue(r,[s],o),a.add()}function ve(e){return e.typ===C.FEATURE_GATE||e.typ===C.FEATURE_CONFIG?`$feature_${e.id}`:e.typ===C.EXPERIMENT?`$exp_${e.id}`:""}function be(e){const t=e.typ;return[C.FEATURE_GATE,C.EXPERIMENT,C.FEATURE_CONFIG].includes(t)?{[ve(e)]:e.vid}:{}}function _e(e){const t=e.typ;return t===C.FEATURE_GATE||t===C.FEATURE_CONFIG?{$feature_key:e.key,$feature_variant:e.vid}:t===C.EXPERIMENT?{$exp_key:e.key,$exp_variant:e.vid}:{}}function Ie({isUnset:e=!1,data:t,opts:i}){if(!se())return;if(!re())return;if(!t||u(t)||t.disable_impress)return;const n=N.getLoginId(),s=N.getAnonId();if(!n&&!s)return;const r=t.typ===C.EXPERIMENT?"$ExpImpress":"$FeatureImpress";let o={};return o=e?{$unset:{[ve(t)]:null}}:{$set:{...be(t)}},me({event:r,properties:_e(t),user_properties:o},i)}const Se="sensorswave_opt_out";class we{constructor(e){this.persist=e}read(){if(this.persist)try{const e=b.get(Se);return"0"===e||"1"!==e&&void 0}catch{return}}write(e){if(this.persist)try{b.set(Se,e?"0":"1")}catch{}}}class Oe{constructor({plugins:e,emitter:t,config:i,sdk:n}){this.plugins=[],this.pluginInsMap={},this.emitter=t,this.config=i,this.sdk=n,this.registerBuiltInPlugins(e),this.created(),this.emitter.on(O,()=>{this.init()})}registerBuiltInPlugins(e){for(let t=0,i=e.length;t<i;t++)this.registerPlugin(e[t])}registerPlugin(e){this.plugins.push(e)}getPlugins(){return this.plugins}getPlugin(e){return this.pluginInsMap[e]}created(){for(let e=0,t=this.plugins.length;e<t;e++){const t=this.plugins[e];if(!t.NAME)throw new Error('Plugin should be defined with "NAME"');const i=new t({emitter:this.emitter,config:this.config,sdk:this.sdk});this.pluginInsMap[t.NAME]=i}}init(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.init&&t.init()}}destroy(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.destroy&&"function"==typeof t.destroy&&t.destroy()}this.pluginInsMap={},this.plugins=[]}}const ye=class{constructor({emitter:e,config:t,sdk:i}){this.boundSend=null,this.hashEvent=null,this.spaSwitchHandler=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;this.boundSend=()=>{me({event:"$PageView",properties:{}},e)},this.sdk&&!0===this.sdk._postConsentInit||setTimeout(()=>{this.boundSend()},0),e.isSinglePageApp&&this.addSinglePageListener()}addSinglePageListener(){this.spaSwitchHandler=e=>{e!==location.href&&this.boundSend()},this.emitter.on(y,this.spaSwitchHandler)}destroy(){this.spaSwitchHandler&&(this.emitter.off(y,this.spaSwitchHandler),this.spaSwitchHandler=null),this.hashEvent&&this.boundSend&&(window.removeEventListener(this.hashEvent,this.boundSend),this.hashEvent=null),this.boundSend=null}};ye.NAME="pageview";let Ae=ye;const Re=class{constructor({emitter:e,config:t,sdk:i}){this.startTime=Date.now(),this.pageShowStatus=!0,this.pageHiddenStatus=!1,this.timer=null,this.currentPageUrl=document.referrer,this.url=location.href,this.title=document.title||"",this.heartbeatIntervalTime=5e3,this.heartbeatIntervalTimer=null,this.pageId=null,this.storageName="sensorswavewebjssdkpageleave",this.maxDuration=432e3,this.eventListeners=[],this._skipFirstPageEnd=!1,this.emitter=e,this.config=t,this.sdk=i}__canCapture(){return!this.sdk||"function"!=typeof this.sdk.hasOptedOutCapturing||!this.sdk.hasOptedOutCapturing()}init(){this.pageId=Number(String(g()).slice(2,5)+String(g()).slice(2,4)+String(Date.now()).slice(-4)),this.addEventListener(),this.sdk&&!0===this.sdk._postConsentInit&&(this._skipFirstPageEnd=!0),!0===document.hidden?this.pageShowStatus=!1:this.addHeartBeatInterval()}log(e){console.log(e)}refreshPageEndTimer(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.timer=setTimeout(()=>{this.pageHiddenStatus=!1},5e3)}hiddenStatusHandler(){this.timer&&clearTimeout(this.timer),this.timer=null,this.pageHiddenStatus=!1}pageStartHandler(){this.startTime=Date.now(),1==!document.hidden?this.pageShowStatus=!0:this.pageShowStatus=!1,this.url=location.href,this.title=document.title,this._skipFirstPageEnd=!1}pageEndHandler(){if(!0===this.pageHiddenStatus)return;if(!this.__canCapture())return;const e=this.getPageLeaveProperties();!1===this.pageShowStatus&&delete e.$event_duration,this.pageShowStatus=!1,this.pageHiddenStatus=!0,me({event:R,properties:e},this.config),this.refreshPageEndTimer(),this.delHeartBeatData()}addEventListener(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()}addPageStartListener(){if("onpageshow"in window){const e=()=>{this.pageStartHandler(),this.hiddenStatusHandler()};window.addEventListener("pageshow",e),this.eventListeners.push({target:window,event:"pageshow",handler:e})}}addSinglePageListener(){this.config.isSinglePageApp&&this.emitter.on(y,e=>{e!==location.href&&(this.url=e,this.pageEndHandler(),this.stopHeartBeatInterval(),this.currentPageUrl=this.url,this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval())})}addPageEndListener(){["pagehide","beforeunload"].forEach(e=>{if(`on${e}`in window){const t=()=>{if(this._skipFirstPageEnd)return this._skipFirstPageEnd=!1,void this.stopHeartBeatInterval();this.pageEndHandler(),this.stopHeartBeatInterval()};window.addEventListener(e,t),this.eventListeners.push({target:window,event:e,handler:t})}})}addPageSwitchListener(){const e=()=>{"visible"===document.visibilityState?(this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval()):(this.url=location.href,this.title=document.title,this.stopHeartBeatInterval())};document.addEventListener("visibilitychange",e),this.eventListeners.push({target:document,event:"visibilitychange",handler:e})}addHeartBeatInterval(){b.isSupport()&&this.startHeartBeatInterval()}startHeartBeatInterval(){this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),this.sdk&&!0===this.sdk._postConsentInit&&!0===this._skipFirstPageEnd||(this.heartbeatIntervalTimer=setInterval(()=>{this.saveHeartBeatData()},this.heartbeatIntervalTime),this.saveHeartBeatData("is_first_heartbeat"),this.reissueHeartBeatData())}stopHeartBeatInterval(){this.heartbeatIntervalTimer&&clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null}saveHeartBeatData(e){if(!this.__canCapture())return;const t=this.getPageLeaveProperties();t.$time=Date.now(),"is_first_heartbeat"===e&&(t.$event_duration=3);const i={type:"track",event:R,properties:t,time:t.$time};i.heartbeat_interval_time=this.heartbeatIntervalTime,b.isSupport()&&b.set(`${this.storageName}-${this.pageId}`,JSON.stringify(i))}delHeartBeatData(e){b.isSupport()&&b.remove(e||`${this.storageName}-${this.pageId}`)}reissueHeartBeatData(){if(this.__canCapture())for(let e=window.localStorage.length-1;e>=0;e--){const t=window.localStorage.key(e);if(t&&t!==`${this.storageName}-${this.pageId}`&&0===t.indexOf(`${this.storageName}-`)){const e=b.parse(t);n(e)&&Date.now()-e.time>e.heartbeat_interval_time+5e3&&(delete e.heartbeat_interval_time,e._flush_time=/* @__PURE__ */(new Date).getTime(),me({event:R,properties:e?.properties},this.config),this.delHeartBeatData(t))}}}getPageLeaveProperties(){let e=(Date.now()-this.startTime)/1e3;(isNaN(e)||e<0||e>this.maxDuration)&&(e=0),e=Number(e.toFixed(3));const t={$title:this.title,$url:this.url?.substring(0,1e3),$pathname:I(this.url)};return 0!==e&&(t.$event_duration=e),t}destroy(){this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}};Re.NAME="pageleave";let Te=Re;const Ce=class{constructor({emitter:e,config:t,sdk:i}){this.eventSended=!1,this.emitter=e,this.config=t,this.sdk=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit)return;const e=()=>{let t=0;const i={};if(window.performance){t=function(){let e=0;if("function"==typeof performance.getEntriesByType){const t=performance.getEntriesByType("navigation");t.length>0&&(e=t[0].domContentLoadedEventEnd||0)}return e}();const e=function(){if(performance.getEntries&&"function"==typeof performance.getEntries){const e=performance.getEntries();let t=0;for(const i of e)"transferSize"in i&&(t+=i.transferSize);if("number"==typeof t&&t>=0&&t<10737418240)return Number((t/1024).toFixed(3))}}();e&&(i.$page_resource_size=e)}else console.warn("Performance API is not supported.");t>0&&!Number.isFinite(t)&&(i.$event_duration=Number((t/1e3).toFixed(3))),this.eventSended||(this.eventSended=!0,me({event:"$PageLoad",properties:i},this.config)),window.removeEventListener("load",e)};"complete"===document.readyState?e():window.addEventListener&&window.addEventListener("load",e)}};Ce.NAME="pageload";let Ne=Ce;function Pe(e){if(!l(e))return!1;const t=o(e.tagName)?e.tagName.toLowerCase():"",i={};return i.$element_type=t,i.$element_name=e.getAttribute("name")||"",i.$element_id=e.getAttribute("id")||"",i.$element_class_name=o(e.className)?e.className:"",i.$element_target_url=e.getAttribute("href")||"",i.$element_content=function(e,t){return o(t)&&"input"===t.toLowerCase()?("button"===(i=e).type||"submit"===i.type)&&i.value||"":function(e,t){let i="",n="";return e.textContent?i=_(e.textContent):e.innerText&&(i=_(e.innerText)),i&&(i=i.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),n=i||"","input"!==t&&"INPUT"!==t||(n=e.value||""),n}(e,t);var i}(e,t)||"",i.$element_selector=ke(e)||"",i.$element_path=function(e){let t=[];for(;e.parentNode&&l(e);){if(!o(e.tagName))return"";if(e.id&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.id)){t.unshift(e.tagName.toLowerCase()+"#"+e.id);break}if(e===document.body){t.unshift("body");break}t.unshift(e.tagName.toLowerCase()),e=e.parentNode}return t.join(" > ")}(e)||"",i}function ke(e,t=[]){if(!(e&&e.parentNode&&e.parentNode.children&&o(e.tagName)))return"";t=Array.isArray(t)?t:[];const i=e.nodeName.toLowerCase();return e&&"body"!==i&&1==e.nodeType?(t.unshift(function(e){if(!e||!l(e)||!o(e.tagName))return"";let t=e.parentNode&&9==e.parentNode.nodeType?-1:function(e){if(!e.parentNode)return-1;let t=0;const i=e.tagName,n=e.parentNode.children;for(let s=0,r=n.length;s<r;s++)if(n[s].tagName===i){if(e===n[s])return t;t++}return-1}(e);return e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?"#"+e.getAttribute("id"):e.tagName.toLowerCase()+(~t?":nth-of-type("+(t+1)+")":"")}(e)),e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?t.join(" > "):ke(e.parentNode,t)):(t.unshift("body"),t.join(" > "))}function xe(){return{scrollLeft:document.body.scrollLeft||document.documentElement.scrollLeft||0,scrollTop:document.body.scrollTop||document.documentElement.scrollTop||0}}function Le(e){if(document.documentElement.getBoundingClientRect){const t=e.getBoundingClientRect();return{targetEleX:t.left+xe().scrollLeft||0,targetEleY:t.top+xe().scrollTop||0}}return{targetEleX:0,targetEleY:0}}function Me(e){return Number(Number(e).toFixed(3))}const $e=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleClick=null,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,!0),this.isInitialized=!0)}handleClick(e){const t=e.target;if(!t)return;if(!["A","INPUT","BUTTON","TEXTAREA"].includes(t.tagName))return;if("true"===t.getAttribute("sensorswave-disable"))return;const i=function(e,t){const i=Pe(e);if(!i)return!1;const n=function(e,t){const i=t.pageX||t.clientX+xe().scrollLeft||t.offsetX+Le(e).targetEleX,n=t.pageY||t.clientY+xe().scrollTop||t.offsetY+Le(e).targetEleY;return{$page_x:Me(i),$page_y:Me(n)}}(e,t);return i.$page_x=n.$page_x,i.$page_y=n.$page_y,i}(t,e);me({event:"$WebClick",properties:i||{}},this.config)}destroy(){this.boundHandleClick&&(document.removeEventListener("click",this.boundHandleClick,!0),this.boundHandleClick=null),this.isInitialized=!1}};$e.NAME="webclick";let Fe=$e;const De=class{constructor({emitter:e,config:t,sdk:i}){this.updateInterval=null,this.fetchingPromise=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;if(e.enableAB){if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;this.fastFetch().then(()=>{this.emitter.emit(A)}),e.abRefreshInterval<3e4&&(e.abRefreshInterval=3e4),this.updateInterval=setInterval(()=>{this.fetchNewData().catch(console.warn)},e.abRefreshInterval)}}async fastFetch(){const e=N.getABData(this.config.abRefreshInterval);return e&&e.length?(this.emitter.emit(A),Promise.resolve(e)):this.fetchNewData()}async fetchNewData(){return this.fetchingPromise||(this.fetchingPromise=new Promise(e=>{!function({opts:e,cb:t}){if(!se())return void(t&&t({}));if(!re())return void(t&&t({}));const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return void(t&&t({}));const s={user:{login_id:i||"",anon_id:n||"",props:{...ee(),...ge(N.getCommonProps())}},sdk:"webjs",sdk_version:w};L({url:le(e),method:"POST",data:s,headers:he(e),callback:e=>{200!==e.statusCode?(console.error("Failed to fetch feature flags"),t&&t({})):t&&t(e.json)}})}({opts:this.config,cb:t=>{N.saveABData(t?.data?.results||[]),e(t),this.fetchingPromise=null}})})),this.fetchingPromise}async getFeatureGate(e){return await this.fastFetch().catch(console.warn),N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_GATE&&t.key==e)}async checkFeatureGate(e){const t=await this.getFeatureGate(e);return!!t&&(!t.hasOwnProperty("vid")&&t.key?(Ie({isUnset:!0,data:t,opts:this.config}),!1):(Ie({data:t,opts:this.config}),"fail"!==t.vid))}async getExperiment(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.EXPERIMENT&&t.key===e);return t?!t.hasOwnProperty("vid")&&t.key?(Ie({isUnset:!0,data:t,opts:this.config}),{}):(Ie({data:t,opts:this.config}),t?.value||{}):{}}async getFeatureConfig(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_CONFIG&&t.key===e);if(!t)return{};if(!t.hasOwnProperty("vid")&&t.key)return Ie({isUnset:!0,data:t,opts:this.config}),{};Ie({data:t,opts:this.config});const i=t?.value;if(i){if(n(i))return i;try{return JSON.parse(i)}catch{return i}}return{}}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null),this.fetchingPromise=null}};De.NAME="abtest";let Be=De;const He=["utm_source","utm_medium","utm_campaign","utm_content","utm_term"],Ue="sensorswave_utm",We=class e{constructor({sdk:e,emitter:t,config:i}){this.sdk=e,this.emitter=t,this.config=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit){let t=e.readFromSessionStorage();return t&&0!==Object.keys(t).length||(t=e.captureAndStore(this.config?.debug)),void this.scheduleInitialUTM(t)}const t=e.getUTMFromURL();e.saveToSessionStorage(t,this.config?.debug),this.scheduleInitialUTM(t)}scheduleInitialUTM(e){setTimeout(()=>{this.sendInitialUTM(e)},0)}static getUTMFromURL(){try{const e=new URLSearchParams(window.location.search),t={};return He.forEach(i=>{const n=e.get(i);n&&(t[i]=n)}),t}catch(t){return e.getUTMFromURLFallback()}}static getUTMFromURLFallback(){const e={};return window.location.search.substring(1).split("&").forEach(t=>{const[i,n]=t.split("="),s=decodeURIComponent(i),r=n?decodeURIComponent(n):"";He.includes(s)&&(e[s]=r)}),e}static readFromSessionStorage(){try{const e=sessionStorage.getItem(Ue);if(!e)return{};const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch(e){return{}}}static saveToSessionStorage(e,t=!1){try{sessionStorage.setItem(Ue,JSON.stringify(e))}catch(i){t&&console.warn("[SensorsWave UTM] Failed to save to sessionStorage:",i)}}static captureAndStore(t=!1){const i=e.getUTMFromURL();return e.saveToSessionStorage(i,t),i}sendInitialUTM(e){const t={};He.forEach(i=>{t[`$initial_${i}`]=null!=e[i]?e[i]:""});try{this.sdk.profileSetOnce(t)}catch(i){this.config.debug&&console.warn("[SensorsWave UTM] Failed to send initial UTM:",i)}}destroy(){}};We.NAME="UTM";let Xe=We;const je=1e3,qe=/^\s*(?:async\s+)?at\s+(?:(.+)\s+\()?(.+?):(\d+):(\d+)\)?$/,Ge=/^(?:(.*)@)?(.+?):(\d+):(\d+)$/;function ze(e){let t=e;try{const e=location.origin;e&&0===t.indexOf(e)&&(t=t.substring(e.length))}catch(s){}const i=t.indexOf("?");i>-1&&(t=t.substring(0,i));const n=t.indexOf("#");return n>-1&&(t=t.substring(0,n)),t}function Ve(e){return e.map(e=>({platform:"web:javascript",filename:ze(e.file),function:e.fn||"?",lineno:Number(e.line),colno:Number(e.col),abs_path:Ye(e.file,1e3)}))}function Ye(e,t){return e.length>t?e.substring(0,t):e}function Ke(e){let t;if("string"==typeof e)t=e;else if(null!==e&&"object"==typeof e){try{t=JSON.stringify(e)}catch(i){t=Object.prototype.toString.call(e)}t||(t=Object.prototype.toString.call(e))}else t=String(e);return Ye(t,je)}function Je(e){const{frames:t,headerType:i}=function(e){const t=[];let i="";if(!e||"string"!=typeof e)return{frames:t,headerType:i};const n=e.split(/\r?\n/);for(let s=0;s<n.length;s++){const e=n[s];if(!e||e.length>1024)continue;const r=e.match(qe),o=r?null:e.match(Ge),a=r||o;if(a)t.push({fn:a[1]||"?",file:a[2],line:a[3],col:a[4]});else if(0===s){const t=e.indexOf(":");t>0&&(i=e.substring(0,t).trim())}if(t.length>=30)break}return{frames:t,headerType:i}}(e&&e.stack);let n=e&&e.name||i||"Error";return n=Ye(String(n),200),{$exception_level:"error",$exception_type:n,$exception_message:Ye(String(e&&e.message||""),je),$exception_frames:Ve(t)}}function Ze(e,t,i,n){let s=[];return t&&(s=[{platform:"web:javascript",filename:ze(t),function:"?",lineno:i||0,colno:n||0,abs_path:Ye(t,1e3)}]),{$exception_level:"error",$exception_type:"Error",$exception_message:Ye(String(e||""),je),$exception_frames:s}}class Qe{constructor(e=10,t=1,i=1e4){this.buckets=/* @__PURE__ */new Map,this.bucketSize=e,this.refillRate=t,this.refillInterval=i}allow(e){const t=Date.now();let i=this.buckets.get(e);if(i){if(t>i.lastRefill){const e=Math.floor((t-i.lastRefill)/this.refillInterval)*this.refillRate;e>0&&(i.tokens=Math.min(this.bucketSize,i.tokens+e),i.lastRefill+=e/this.refillRate*this.refillInterval)}}else i={tokens:this.bucketSize,lastRefill:t},this.buckets.set(e,i);return i.tokens>=1&&(i.tokens-=1,!0)}reset(){this.buckets.clear()}}const et=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleError=null,this.boundHandleRejection=null,this.rateLimiter=new Qe,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleError=this.handleError.bind(this),this.boundHandleRejection=this.handleRejection.bind(this),window.addEventListener("error",this.boundHandleError,!0),window.addEventListener("unhandledrejection",this.boundHandleRejection),this.isInitialized=!0)}handleError(e){try{const t=e.target;let i;if(t&&t!==window&&t.tagName)i=function(e){const t=e,i=(t.tagName||"").toLowerCase(),n=Ye(String(t.src||t.href||""),je);return{$exception_level:"error",$exception_type:"ResourceLoadError",$exception_message:`Failed to load <${i}>${n?` from ${n}`:""}`,$exception_frames:[]}}(t);else{const t=e;i=t.error instanceof Error?Je(t.error):Ze(String(t.message||""),t.filename,t.lineno,t.colno)}this.send(i)}catch(t){}}handleRejection(e){try{const t=e.reason;this.send(function(e){return e instanceof Error?Je(e):{$exception_level:"error",$exception_type:"UnhandledRejection",$exception_message:Ke(e),$exception_frames:[]}}(t))}catch(t){}}send(e){e.$exception_message&&this.rateLimiter.allow(e.$exception_type)&&me({event:T,properties:e},this.config)}destroy(){this.boundHandleError&&(window.removeEventListener("error",this.boundHandleError,!0),this.boundHandleError=null),this.boundHandleRejection&&(window.removeEventListener("unhandledrejection",this.boundHandleRejection),this.boundHandleRejection=null),this.rateLimiter.reset(),this.isInitialized=!1}};et.NAME="exception";let tt=et;const it="data-sw-exposure-event-name",nt="data-sw-exposure-config-",st=`[${it}]`,rt={visibleRatio:0,stayDuration:0,repeated:!0};function ot(e,t){const i={};if(!n(e))return i;const s=e;if(void 0!==s.visibleRatio){const e=Number(s.visibleRatio);!isNaN(e)&&e>=0&&e<=1?i.visibleRatio=e:t&&t("[exposure] parameter config.visibleRatio 非法(值域 0~1),已忽略:",s.visibleRatio)}if(void 0!==s.stayDuration){const e=Number(s.stayDuration);!isNaN(e)&&e>=0?i.stayDuration=e:t&&t("[exposure] parameter config.stayDuration 非法(须 >= 0),已忽略:",s.stayDuration)}if(void 0!==s.repeated){const e=s.repeated;!0===e||"true"===e?i.repeated=!0:!1===e||"false"===e?i.repeated=!1:t&&t("[exposure] parameter config.repeated 非法(须为布尔),已忽略:",e)}return i}function at(...e){const t={...rt};for(let i=0;i<e.length;i++){const s=e[i];if(!n(s))continue;const r=s;void 0!==r.visibleRatio&&(t.visibleRatio=r.visibleRatio),void 0!==r.stayDuration&&(t.stayDuration=r.stayDuration),void 0!==r.repeated&&(t.repeated=r.repeated)}return t}function ct(e){const t=(e.getAttribute(it)||"").trim();let i={},s={};const r=e.getAttribute("data-sw-exposure-option");if(r){const e=d(r);n(e)&&(n(e.config)&&(i=e.config),n(e.properties)&&(s=e.properties))}const a=e.getAttribute(nt+"visible-ratio");null!==a&&(i.visibleRatio=a);const c=e.getAttribute(nt+"stay-duration");null!==c&&(i.stayDuration=c);const u=e.getAttribute(nt+"repeated");null!==u&&(i.repeated=u);const l=e.attributes;for(let n=0;n<l.length;n++){const e=l[n],t=e.name;if(o(t)&&0===t.indexOf("data-sw-exposure-property-")){const i=t.substring(26);i&&(s[i]=e.value)}}return{eventName:t,config:ot(i),properties:s}}const ut=class{constructor({emitter:e,config:t,sdk:i}){this.isInitialized=!1,this.observers=/* @__PURE__ */new Map,this.records=/* @__PURE__ */new Map,this.mutationObserver=null,this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.boundHandleSpa=null,this.eventListeners=[],this.globalConfig={...rt},this.log=function(){},this.emitter=e,this.config=t,this.sdk=i}init(){this.isInitialized||(function(){try{return"undefined"!=typeof window&&"IntersectionObserver"in window&&"MutationObserver"in window}catch(e){return!1}}()?(this.log=!0==(!0===this.config.debug)&&"undefined"!=typeof console&&console.log?function(...e){console.log("[SensorsWave][exposure]",...e)}:function(){},this.globalConfig=at(this.globalConfig,ot(this.config.exposureConfig,this.log)),this.boundHandleIntersection=this.handleIntersection.bind(this),this.boundHandleMutation=this.handleMutation.bind(this),this.boundHandleVisibility=this.handleVisibility.bind(this),"loading"===document.readyState?(this.boundHandleReady=()=>{this.scanDocument(),this.observeMutations()},document.addEventListener("DOMContentLoaded",this.boundHandleReady),this.eventListeners.push({target:document,event:"DOMContentLoaded",handler:this.boundHandleReady})):(this.scanDocument(),this.observeMutations()),!0===this.config.isSinglePageApp&&(this.boundHandleSpa=e=>{this.handleSpaSwitch(e)},this.emitter.on(y,this.boundHandleSpa)),document.addEventListener("visibilitychange",this.boundHandleVisibility),this.eventListeners.push({target:document,event:"visibilitychange",handler:this.boundHandleVisibility}),!0===document.hidden&&this.stop(),this.isInitialized=!0):console.warn("[SensorsWave][exposure] 当前浏览器不支持 IntersectionObserver / MutationObserver,曝光采集未初始化"))}addExposureView(e,t){this.isInitialized?l(e)?n(t)&&o(t.eventName)&&t.eventName.trim()?this.addOrUpdateWatchEle(e,{eventName:t.eventName.trim(),config:n(t.config)?ot(t.config,this.log):void 0,properties:n(t.properties)?{...t.properties}:{},listener:n(t.listener)?{...t.listener}:{}},"api"):this.log("addExposureView parameter option.eventName 缺失:",t):this.log("addExposureView parameter element 非法:",e):this.log("曝光插件未初始化(enableExposureTrack 未开启或浏览器不支持)")}removeExposureView(e){this.isInitialized?l(e)?this.removeWatchEle(e):this.log("removeExposureView parameter element 非法:",e):this.log("曝光插件未初始化")}scanDocument(e){try{const t=e||document;if(!t.querySelectorAll)return;const i=t.querySelectorAll(st);for(let e=0;e<i.length;e++){const t=i[e];this.addOrUpdateWatchEle(t,ct(t),"attr")}}catch(t){}}addOrUpdateWatchEle(e,t,i){if(!e||!l(e))return void this.log("parameter element error:",e);if(!o(t.eventName)||!t.eventName.trim())return void this.log("parameter option.eventName error:",t);const n=this.records.get(e);if(n&&"api"===n.source&&"attr"===i)return void this.log("声明式属性变更被忽略:元素已由 addExposureView 注册",e);const s=at(this.globalConfig,n&&n.config,t.config);if(n&&n.config.visibleRatio===s.visibleRatio)return n.eventName=t.eventName,n.source=i,n.config=s,n.properties={...t.properties||{}},n.listener=t.listener||{},void(n.hasSent=!1);n&&this.removeWatchEle(e);const r={ele:e,eventName:t.eventName,source:i,config:s,properties:{...t.properties||{}},listener:t.listener||{},timer:null,hasSent:!1};this.records.set(e,r),this.getIntersection(s.visibleRatio).observe(e)}getIntersection(e){let t=this.observers.get(e);return!t&&this.boundHandleIntersection&&(t=new IntersectionObserver(this.boundHandleIntersection,{threshold:e}),this.observers.set(e,t)),t}removeWatchEle(e){const t=this.records.get(e);if(!t)return;const i=this.observers.get(t.config.visibleRatio);i&&l(e)&&i.unobserve(e),t.timer&&(clearTimeout(t.timer),t.timer=null),this.records.delete(e)}handleIntersection(e){try{for(const t of e){const e=t.target,i=this.records.get(e);i&&(!0===t.isIntersecting&&t.intersectionRatio>=i.config.visibleRatio?!0!==document.hidden&&(i.timer&&clearTimeout(i.timer),i.timer=setTimeout(()=>{this.fireExposure(e)},1e3*i.config.stayDuration)):i.timer&&(clearTimeout(i.timer),i.timer=null))}}catch(t){}}fireExposure(e){try{const i=this.records.get(e);if(i&&(i.timer=null),!i||i.hasSent)return;let n={width:0,height:0};try{n=e.getBoundingClientRect()}catch(t){}if(!n.width||!n.height)return;if(!e.isConnected)return void this.removeWatchEle(e);if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;const r={...Pe(e),...i.properties},{shouldExpose:o,didExpose:a}=i.listener||{};if(o&&s(o))try{if(!1===o(e,r))return}catch(t){return}if(me({event:i.eventName,properties:r},this.config),i.hasSent=!0,i.config.repeated&&(i.hasSent=!1),a&&s(a))try{a(e,r)}catch(t){}}catch(t){}}observeMutations(){!this.mutationObserver&&this.boundHandleMutation&&(this.mutationObserver=new MutationObserver(this.boundHandleMutation),this.mutationObserver.observe(document.body,{attributes:!0,childList:!0,subtree:!0}))}handleMutation(e){try{for(const t of e)if("childList"===t.type){if(t.removedNodes.length>0)for(const e of Array.from(t.removedNodes)){if(1!==e.nodeType)continue;this.removeWatchEle(e);const t=e.querySelectorAll(st);for(let e=0;e<t.length;e++)this.removeWatchEle(t[e])}if(t.addedNodes.length>0)for(const e of Array.from(t.addedNodes))1===e.nodeType&&(e.hasAttribute(it)&&this.addOrUpdateWatchEle(e,ct(e),"attr"),this.scanDocument(e))}else"attributes"===t.type&&this.handleAttrChange(t)}catch(t){}}handleAttrChange(e){const t=e.attributeName;if(!t||0!==t.indexOf("data-sw-exposure"))return;const i=e.target;t!==it||(i.getAttribute(t)||"").trim()?(i.getAttribute(it)||"").trim()&&this.addOrUpdateWatchEle(i,ct(i),"attr"):this.removeWatchEle(i)}handleSpaSwitch(e){try{if(e===location.href)return;this.stop();for(const[e,t]of Array.from(this.records))"attr"===t.source&&this.records.delete(e);this.start(),this.scanDocument()}catch(t){}}stop(){for(const e of Array.from(this.records.values())){const t=this.observers.get(e.config.visibleRatio);t&&t.unobserve(e.ele),e.timer&&(clearTimeout(e.timer),e.timer=null)}}start(){for(const e of Array.from(this.records.values())){if(!e.ele.isConnected){this.records.delete(e.ele);continue}const t=this.observers.get(e.config.visibleRatio);t&&t.observe(e.ele)}}handleVisibility(){try{"visible"===document.visibilityState?this.start():this.stop()}catch(e){}}destroy(){this.observers.forEach(e=>{try{e.disconnect()}catch(t){}}),this.observers.clear(),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null);for(const e of Array.from(this.records.values()))e.timer&&(clearTimeout(e.timer),e.timer=null);this.records.clear(),this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.boundHandleSpa&&(this.emitter.off(y,this.boundHandleSpa),this.boundHandleSpa=null),this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.globalConfig={...rt},this.log=function(){},this.isInitialized=!1}};ut.NAME="exposure";let lt=ut;const ht=[],dt={debug:!1,sourceToken:"",apiHost:"",autoCapture:!0,isSinglePageApp:!1,crossSubdomainCookie:!0,enableAB:!1,abRefreshInterval:6e5,enableClickTrack:!1,enableExposureTrack:!1,batchSend:!1,enableErrorTrack:!1,enableCrashTrack:!1,optOutCapturing:!1,persistOptOut:!1},pt=new class{constructor(){this.__innerInited=!1,this.inited=!1,this.config={},this.eventEmitter=new e,this.pluginCore={},this.commonProps={},this.spaCleanup=null,this._optOutCapturing=!1,this.consentStorage=new we(!1),this._setupAfterConsentDone=!1,this._postConsentInit=!1,S.instance=this}init(e,t={}){return this.inited?this:(S.instance=this,t.sourceToken=e,this.mergeConfig(t),this.consentStorage=new we(!0===this.config.persistOptOut),this._optOutCapturing?this.consentStorage.write(!0):!0===this.config.optOutCapturing?(this._optOutCapturing=!0,this.consentStorage.write(!0)):!0===this.consentStorage.read()&&(this._optOutCapturing=!0),this.eventEmitter.emit("init-param",this.config),this.__innerInited=!0,this._optOutCapturing?(Xe.captureAndStore(this.config.debug),this.eventEmitter.emit(O),this.inited=!0,this):(this.__setupAfterConsent(),this.eventEmitter.emit(O),this.inited=!0,this))}__setupAfterConsent(){if(this._setupAfterConsentDone)return;this._setupAfterConsentDone=!0;const e=this.config;ht.length=0,N.init(e.crossSubdomainCookie),e.anonId&&N.setAnonId(e.anonId),function(){if(window._swFailedRequestsInitialized)return;window._swFailedRequestsInitialized=!0;const e=S.instance;e&&"function"==typeof e.hasOptedOutCapturing&&e.hasOptedOutCapturing()||e&&!0===e._postConsentInit||function(){const e=te.getAll();if(0!==e.length)for(let t=0,i=e.length;t<i;t+=10){const i=e.slice(t,t+10),n=[],s=[];i.forEach(e=>{Array.isArray(e.data)?n.push(...e.data):n.push(e.data),s.push(e.id)});const r=i[i.length-1],o=r.url,a=r.headers;L({url:o,method:"POST",data:n,headers:a,callback:e=>{200!==e.statusCode?(console.error("Failed to send batch stored requests:",e),P(e.statusCode)||s.forEach(e=>{te.dequeue(e)})):s.forEach(e=>{te.dequeue(e)})}})}}()}(),ht.push(Xe),e.autoCapture&&this.autoTrack(),e.enableAB&&ht.push(Be),e.enableClickTrack&&ht.push(Fe),e.enableCrashTrack&&e.debug&&console.warn("[SensorsWave] enableCrashTrack 仅在 app 宿主环境生效,当前 Web 环境不采集 crash"),e.enableErrorTrack&&ht.push(tt),e.enableExposureTrack&&ht.push(lt),this.pluginCore=new Oe({plugins:ht,emitter:this.eventEmitter,config:e,sdk:this}),this.spaCleanup=function(e){let t=location.href;const i=window.history.pushState,n=window.history.replaceState,r=function(){e(t),t=location.href};return s(window.history.pushState)&&(window.history.pushState=function(...n){i.apply(window.history,n),e(t),t=location.href}),s(window.history.replaceState)&&(window.history.replaceState=function(...i){n.apply(window.history,i),e(t),t=location.href}),window.addEventListener("popstate",r),function(){s(window.history.pushState)&&(window.history.pushState=i),s(window.history.replaceState)&&(window.history.replaceState=n),window.removeEventListener("popstate",r)}}(e=>{this.eventEmitter.emit(y,e)})}mergeConfig(e){this.config={...dt,...e}}__canCapture(){return this.inited&&!this._optOutCapturing}track(e){this.__canCapture()&&function(e,t){if(!se())return;if(!re())return;const i={...e};i.time||(i.time=Date.now()),i.login_id||(i.login_id=N.getLoginId()),i.anon_id||(i.anon_id=N.getAnonId()),i.trace_id||(i.trace_id=N.getTraceId()),i.properties={...ee(),...ge(N.getCommonProps()),...i.properties};const n=ue(t),s=he(t),r=!1!==t.batchSend&&ae();if(!r)return de(n,{data:[i],headers:s});te.enqueue(n,[i],s),r.add()}(e,this.config)}trackEvent(e,t){this.__canCapture()&&me({event:e,properties:t},this.config)}trackException(e,t){if(!this.__canCapture())return;const i={...t||{},...e instanceof Error?Je(e):Ze(String(e))};me({event:T,properties:i},this.config)}addExposureView(e,t){if(!this.__canCapture())return;const i=this.pluginCore.getPlugin(lt.NAME);i?i.addExposureView(e,t):console.warn("[SensorsWave] addExposureView 需在 init 时配置 enableExposureTrack: true")}removeExposureView(e){if(!this.__canCapture())return;const t=this.pluginCore.getPlugin(lt.NAME);t&&t.removeExposureView(e)}autoTrack(){ht.push(Ae,Ne,Te)}profileSet(e){this.__canCapture()&&Ee({userProps:{$set:e},opts:this.config})}profileSetOnce(e){this.__canCapture()&&Ee({userProps:{$set_once:e},opts:this.config})}profileIncrement(e){this.__canCapture()&&Ee({userProps:{$increment:e},opts:this.config})}profileAppend(e){this.__canCapture()&&Ee({userProps:{$append:e},opts:this.config})}profileUnion(e){this.__canCapture()&&Ee({userProps:{$union:e},opts:this.config})}profileUnset(e){if(!this.__canCapture())return;const t={};r(e)?e.forEach(function(e){t[e]=null}):t[e]=null,Ee({userProps:{$unset:t},opts:this.config})}profileDelete(){this.__canCapture()&&Ee({userProps:{$delete:!0},opts:this.config})}registerCommonProperties(e){if(!n(e))return console.warn("Commmon Properties must be an object!");this.commonProps=e,N.setCommonProps(this.commonProps)}clearCommonProperties(e){if(!r(e))return console.warn("Commmon Properties to be cleared must be an array!");e.forEach(e=>{delete this.commonProps[e]}),N.setCommonProps(this.commonProps)}identify(e){this.__canCapture()&&(N.setLoginId(e),function(e){if(!se())return;if(!re())return;const t=N.getLoginId(),i=N.getAnonId();if(!t||!i)return;const n={time:Date.now(),trace_id:N.getTraceId(),event:"$Identify",login_id:t,anon_id:i,properties:fe()},s=ue(e),r=he(e),o=ae();if(!o)return de(s,{data:[n],headers:r});te.enqueue(s,[n],r),o.add()}(this.config))}setLoginId(e){this.__canCapture()&&N.setLoginId(e)}getAnonId(){return this.__canCapture()?N.getAnonId():""}setAnonId(e){this.__canCapture()&&N.setAnonId(e)}getLoginId(){return this.__canCapture()?N.getLoginId():""}reset(e=!1){this.__canCapture()&&(N.clearLoginId(),e&&N.resetAnonId())}checkFeatureGate(e){if(!this.__canCapture())return Promise.resolve(!1);const t=this.pluginCore.getPlugin(Be.NAME);return this.config.enableAB&&t?t.checkFeatureGate(e):Promise.reject("AB is disabled")}getExperiment(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Be.NAME);return this.config.enableAB&&t?t.getExperiment(e):Promise.reject("AB is disabled")}getFeatureConfig(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Be.NAME);return this.config.enableAB&&t?t.getFeatureConfig(e):Promise.reject("AB is disabled")}optOutCapturing(){this._optOutCapturing=!0,this.consentStorage.write(!0),oe&&oe.pause()}optInCapturing(){if(this._optOutCapturing=!1,this.consentStorage.write(!1),oe&&oe.resume(),this.inited&&!this._setupAfterConsentDone){this._postConsentInit=!0;try{this.__setupAfterConsent(),this.eventEmitter.emit(O)}finally{this._postConsentInit=!1}}}hasOptedOutCapturing(){return this._optOutCapturing}destroy(){oe&&(oe.destroy(),oe=null),"undefined"!=typeof window&&(window._swFailedRequestsInitialized=!1),this.inited=!1,this.__innerInited=!1,this.spaCleanup&&"function"==typeof this.spaCleanup&&(this.spaCleanup(),this.spaCleanup=null),this.pluginCore&&"function"==typeof this.pluginCore.destroy&&this.pluginCore.destroy(),this.pluginCore={},this.eventEmitter&&this.eventEmitter.removeAllListeners(),this.consentStorage=new we(!0===this.config?.persistOptOut),this._optOutCapturing=!1,this._setupAfterConsentDone=!1,this._postConsentInit=!1,S.instance===this&&(S.instance=null)}};export{pt as default};
|
|
1
|
+
class e{constructor(){this.listeners={}}on(e,t,i=!1){if(e&&t){if(!s(t))throw new Error("listener must be a function");this.listeners[e]=this.listeners[e]||[],this.listeners[e].push({listener:t,once:i})}}off(e,t){const i=this.listeners[e];if(!i?.length)return;"number"==typeof t&&i.splice(t,1);const n=i.findIndex(e=>e.listener===t);-1!==n&&i.splice(n,1)}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((i,n)=>{i.listener.call(this,...t),i.listener.once&&this.off(e,n)})}once(e,t){this.on(e,t,!0)}removeAllListeners(e){e?this.listeners[e]=[]:this.listeners={}}}const t={get:function(e){const t=e+"=",i=document.cookie.split(";");for(let n=0,s=i.length;n<s;n++){let e=i[n];for(;" "==e.charAt(0);)e=e.substring(1,e.length);if(0==e.indexOf(t))return h(e.substring(t.length,e.length))}return null},set:function({name:e,value:t,expires:i,samesite:n,secure:s,domain:r}){let o="",a="",c="",u="";if(0!==(i=null==i||void 0===i?365:i)){const e=/* @__PURE__ */new Date;"string"==typeof i?e.setTime(e.getTime()+1e3*Number(i.slice(0,-1))):e.setTime(e.getTime()+24*i*60*60*1e3),o="; expires="+e.toUTCString()}function l(e){return e?e.replace(/\r\n/g,""):""}n&&(c="; SameSite="+n),s&&(a="; secure");const h=l(e),d=l(t),p=l(r);p&&(u="; domain="+p),h&&d&&(document.cookie=h+"="+encodeURIComponent(d)+o+"; path=/"+u+c+a)},remove:function(e){const t=e?e.replace(/\r\n/g,""):"";t&&(document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")},isSupport:function({samesite:e,secure:t}={}){if(!navigator.cookieEnabled)return!1;const i="sensorswave_cookie_support_test";return this.set({name:i,value:"1",samesite:e,secure:t}),"1"===this.get(i)&&(this.remove(i),!0)}},i=Object.prototype.toString;function n(e){return"[object Object]"===i.call(e)}function s(e){const t=i.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t}function r(e){return"[object Array]"==i.call(e)}function o(e){return"[object String]"==i.call(e)}function a(e){return void 0===e}const c=Object.prototype.hasOwnProperty;function u(e){if(n(e)){for(let t in e)if(c.call(e,t))return!1;return!0}return!1}function l(e){return!(!e||1!==e.nodeType)}function h(e){let t=e;try{t=decodeURIComponent(e)}catch(i){t=e}return t}function d(e){try{return JSON.parse(e)}catch(t){return""}}const p=function(){let e=Date.now();return function(t){return Math.ceil((e=(9301*e+49297)%233280,e/233280*t))}}();function g(){if("function"==typeof Uint32Array){let e;if("undefined"!=typeof crypto&&(e=crypto),e&&n(e)&&e.getRandomValues)return e.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32)}return p(1e19)/1e19}const f=/* @__PURE__ */function(){function e(e){return("0".repeat(e)+Date.now().toString(16)).slice(-e)}return function(){let t=String(screen.height*screen.width);t=t&&/\d{4,}/.test(t)?t.slice(-4):String(31242*g()).replace(".","").slice(0,4);return e(8)+"-"+g().toString(16).replace(".","").slice(-4)+"-"+function(){const e=navigator.userAgent;let t,i=[],n=0;function s(e,t){let n=0;for(let s=0;s<t.length;s++)n|=i[s]<<8*s;return(e^n)>>>0}for(let r=0;r<e.length;r++)t=e.charCodeAt(r),i.unshift(255&t),i.length>=4&&(n=s(n,i),i=[]);return i.length>0&&(n=s(n,i)),("0000"+n.toString(16)).slice(-4)}()+"-"+t+"-"+e(12)||(String(g())+String(g())+String(g())).slice(2,15)}}();function m(e,t){t&&"string"==typeof t||(t="");let i=null;try{i=new URL(e).hostname}catch(n){}return i||t}function E(e){let t=[];try{t=atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})}catch(i){t=[]}try{return decodeURIComponent(t.join(""))}catch(i){return t.join("")}}function _(e){let t="";try{t=btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}))}catch(i){t=e}return t}const b={get:function(e){return window.localStorage.getItem(e)},parse:function(e){let t;try{t=JSON.parse(b.get(e))||null}catch(i){console.warn(i)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(i){console.warn(i)}},remove:function(e){window.localStorage.removeItem(e)},isSupport:function(){let e=!0;try{const t="__local_store_support__",i="testIsSupportStorage";b.set(t,i),b.get(t)!==i&&(e=!1),b.remove(t)}catch(t){e=!1}return e}};function v(e){return e.trim()}function I(e){if(!e||"string"!=typeof e)return"";try{return new URL(e,window.location.origin).pathname}catch(t){return""}}const w={},S="1.6.0",y="init-ready",O="spa-switch",A="ff-ready",R="$PageLeave",T="$Exception";var C=/* @__PURE__ */(e=>(e[e.FEATURE_GATE=1]="FEATURE_GATE",e[e.FEATURE_CONFIG=2]="FEATURE_CONFIG",e[e.EXPERIMENT=3]="EXPERIMENT",e))(C||{});const N={crossSubdomain:!1,requests:[],_sessionState:{},_abData:[],_trace_id:"",commonProps:{},_state:{anon_id:"",login_id:"",identities:{}},getIdentityCookieID(){return this._state.identities?.$identity_cookie_id||""},getCommonProps:function(){return this.commonProps||{}},setCommonProps:function(e){this.commonProps=e},getAnonId(){return this._state.anon_id||this.getIdentityCookieID()||f()},getLoginId(){return this._state.login_id},getTraceId(){return this._trace_id||f()},set:function(e,t){this._state[e]=t,this.save()},getCookieName:function(){return"sensorswave2025jssdkcross"},getABLSName:function(){return"sensorswave2025jssdkablatest"},save:function(){let e=JSON.parse(JSON.stringify(this._state));e.identities&&(e.identities=_(JSON.stringify(e.identities)));const i=JSON.stringify(e);t.set({name:this.getCookieName(),value:i,expires:365})},init:function(e){let i,s;this.crossSubdomain=e,t.isSupport()&&(i=t.get(this.getCookieName()),s=d(i)),N._state={...s||{}},N._state.identities&&(N._state.identities=d(E(N._state.identities))),N._state.identities&&n(N._state.identities)&&!u(N._state.identities)||(N._state.identities={$identity_cookie_id:f()}),N.save()},setLoginId(e){"number"==typeof e&&(e=String(e)),void 0!==e&&e&&(N.set("login_id",e),N.save())},clearLoginId(){this._state.login_id="",this.save()},resetAnonId(){this._state.anon_id="",this._state.identities={$identity_cookie_id:f()},this.save()},setAnonId(e){"number"==typeof e&&(e=String(e)),"string"==typeof e&&e?(N.set("anon_id",e),N.save()):console.warn("[SensorsWave store] Invalid anonId, ignored:",e)},saveABData(e){if(!e||u(e))return;this._abData=e;let t=JSON.parse(JSON.stringify(this._abData));t=_(JSON.stringify(t));try{localStorage.setItem(this.getABLSName(),JSON.stringify({time:Date.now(),data:t,anon_id:this.getAnonId(),login_id:this.getLoginId()}))}catch(i){console.warn("Failed to save abdata to localStorage",i)}},getABData(e=6e5){try{let t=localStorage.getItem(this.getABLSName());if(t){const{time:i,data:n,login_id:s,anon_id:r}=d(t)||{};if(i&&n&&Date.now()-i<e&&r===this.getAnonId()&&(!s||s===this.getLoginId())){const e=d(E(n));return this._abData=Array.isArray(e)?e:[],this._abData}localStorage.removeItem(this.getABLSName())}}catch(t){this._abData=[]}return this._abData||[]}};function P(e){return!(e>=400&&e<500)||408===e||429===e}function k(e){var t;if(e.data)return{contentType:"application/json",body:(t=e.data,JSON.stringify(t,(e,t)=>"bigint"==typeof t?t.toString():t,undefined))}}const x=[];function L(e){const t={...e};t.timeout=t.timeout||6e4;const i=t.transport??"fetch",n=x.find(e=>e.transport===i)?.method??x[0]?.method;if(!n)throw new Error("No available transport method for HTTP request");n(t)}function M(e){return o(e=e||document.referrer)&&(e=h(e=e.trim()))||""}function $(e){const t=m(e=e||M());if(!t)return"";const i={baidu:[/^.*\.baidu\.com$/],bing:[/^.*\.bing\.com$/],google:[/^www\.google\.com$/,/^www\.google\.com\.[a-z]{2}$/,/^www\.google\.[a-z]{2}$/],sm:[/^m\.sm\.cn$/],so:[/^.+\.so\.com$/],sogou:[/^.*\.sogou\.com$/],yahoo:[/^.*\.yahoo\.com$/],duckduckgo:[/^.*\.duckduckgo\.com$/]};for(let n of Object.keys(i)){let e=i[n];for(let i=0,s=e.length;i<s;i++)if(e[i].test(t))return n}return""}function D(e,t){return-1!==e.indexOf(t)}"function"==typeof fetch&&x.push({transport:"fetch",method:function(e){if("undefined"==typeof fetch)return void console.error("fetch API is not available");const t=k(e),i=new Headers;e.headers&&Object.keys(e.headers).forEach(t=>{i.append(t,e.headers[t])}),t?.contentType&&i.append("Content-Type",t.contentType),fetch(e.url,{method:e.method||"GET",headers:i,body:t?.body}).then(t=>t.text().then(i=>{const n={statusCode:t.status,text:i};if(200===t.status)try{n.json=JSON.parse(i)}catch(s){console.error("Failed to parse response:",s)}e.callback?.(n)})).catch(t=>{console.error("Request failed:",t),e.callback?.({statusCode:0,text:String(t)})})}}),"undefined"!=typeof XMLHttpRequest&&x.push({transport:"XHR",method:function(e){if("undefined"==typeof XMLHttpRequest)return void console.error("XMLHttpRequest is not available");const t=new XMLHttpRequest;t.open(e.method||"GET",e.url,!0);const i=k(e);e.headers&&Object.keys(e.headers).forEach(i=>{t.setRequestHeader(i,e.headers[i])}),i?.contentType&&t.setRequestHeader("Content-Type",i.contentType),t.timeout=e.timeout||6e4,t.withCredentials=!0,t.onreadystatechange=()=>{if(4===t.readyState){const n={statusCode:t.status,text:t.responseText};if(200===t.status)try{n.json=JSON.parse(t.responseText)}catch(i){console.error("Failed to parse JSON response:",i)}e.callback?.(n)}},t.send(i?.body)}});const F={FACEBOOK:"Facebook",MOBILE:"Mobile",IOS:"iOS",ANDROID:"Android",TABLET:"Tablet",ANDROID_TABLET:"Android Tablet",IPAD:"iPad",APPLE:"Apple",APPLE_WATCH:"Apple Watch",SAFARI:"Safari",BLACKBERRY:"BlackBerry",SAMSUNG_BROWSER:"SamsungBrowser",SAMSUNG_INTERNET:"Samsung Internet",CHROME:"Chrome",CHROME_OS:"Chrome OS",CHROME_IOS:"Chrome iOS",INTERNET_EXPLORER:"Internet Explorer",INTERNET_EXPLORER_MOBILE:"Internet Explorer Mobile",OPERA:"Opera",OPERA_MINI:"Opera Mini",EDGE:"Edge",MICROSOFT_EDGE:"Microsoft Edge",FIREFOX:"Firefox",FIREFOX_IOS:"Firefox iOS",NINTENDO:"Nintendo",PLAYSTATION:"PlayStation",XBOX:"Xbox",ANDROID_MOBILE:"Android Mobile",MOBILE_SAFARI:"Mobile Safari",WINDOWS:"Windows",WINDOWS_PHONE:"Windows Phone",NOKIA:"Nokia",OUYA:"Ouya",GENERIC_MOBILE:"Generic mobile",GENERIC_TABLET:"Generic tablet",KONQUEROR:"Konqueror",UC_BROWSER:"UC Browser",HUAWEI:"Huawei",XIAOMI:"Xiaomi",OPPO:"OPPO",VIVO:"vivo"},B="(\\d+(\\.\\d+)?)",H=new RegExp("Version/"+B),U=new RegExp(F.XBOX,"i"),W=new RegExp(F.PLAYSTATION+" \\w+","i"),X=new RegExp(F.NINTENDO+" \\w+","i"),j=new RegExp(F.BLACKBERRY+"|PlayBook|BB10","i"),q=new RegExp("(HUAWEI|honor|HONOR)","i"),G=new RegExp("(Xiaomi|Redmi)","i"),z=new RegExp("(OPPO|realme)","i"),V=new RegExp("(vivo|IQOO)","i"),Y={"NT3.51":"NT 3.11","NT4.0":"NT 4.0","5.0":"2000",5.1:"XP",5.2:"XP","6.0":"Vista",6.1:"7",6.2:"8",6.3:"8.1",6.4:"10","10.0":"10"};function J(e,t){return t=t||"",D(e," OPR/")&&D(e,"Mini")?F.OPERA_MINI:D(e," OPR/")?F.OPERA:j.test(e)?F.BLACKBERRY:D(e,"IE"+F.MOBILE)||D(e,"WPDesktop")?F.INTERNET_EXPLORER_MOBILE:D(e,F.SAMSUNG_BROWSER)?F.SAMSUNG_INTERNET:D(e,F.EDGE)||D(e,"Edg/")?F.MICROSOFT_EDGE:D(e,"FBIOS")?F.FACEBOOK+" "+F.MOBILE:D(e,"UCWEB")||D(e,"UCBrowser")?F.UC_BROWSER:D(e,"CriOS")?F.CHROME_IOS:D(e,"CrMo")||D(e,F.CHROME)?F.CHROME:D(e,F.ANDROID)&&D(e,F.SAFARI)?F.ANDROID_MOBILE:D(e,"FxiOS")?F.FIREFOX_IOS:D(e.toLowerCase(),F.KONQUEROR.toLowerCase())?F.KONQUEROR:function(e,t){return t&&D(t,F.APPLE)||D(i=e,F.SAFARI)&&!D(i,F.CHROME)&&!D(i,F.ANDROID);var i}(e,t)?D(e,F.MOBILE)?F.MOBILE_SAFARI:F.SAFARI:D(e,F.FIREFOX)?F.FIREFOX:D(e,"MSIE")||D(e,"Trident/")?F.INTERNET_EXPLORER:D(e,"Gecko")?F.FIREFOX:""}const K={[F.INTERNET_EXPLORER_MOBILE]:[new RegExp("rv:"+B)],[F.MICROSOFT_EDGE]:[new RegExp(F.EDGE+"?\\/"+B)],[F.CHROME]:[new RegExp("("+F.CHROME+"|CrMo)\\/"+B)],[F.CHROME_IOS]:[new RegExp("CriOS\\/"+B)],[F.UC_BROWSER]:[new RegExp("(UCBrowser|UCWEB)\\/"+B)],[F.SAFARI]:[H],[F.MOBILE_SAFARI]:[H],[F.OPERA]:[new RegExp("("+F.OPERA+"|OPR)\\/"+B)],[F.FIREFOX]:[new RegExp(F.FIREFOX+"\\/"+B)],[F.FIREFOX_IOS]:[new RegExp("FxiOS\\/"+B)],[F.KONQUEROR]:[new RegExp("Konqueror[:/]?"+B,"i")],[F.BLACKBERRY]:[new RegExp(F.BLACKBERRY+" "+B),H],[F.ANDROID_MOBILE]:[new RegExp("android\\s"+B,"i")],[F.SAMSUNG_INTERNET]:[new RegExp(F.SAMSUNG_BROWSER+"\\/"+B)],[F.INTERNET_EXPLORER]:[new RegExp("(rv:|MSIE )"+B)],Mozilla:[new RegExp("rv:"+B)]};function Z(e,t){const i=J(e,t),n=K[i];if(a(n))return null;for(let s=0;s<n.length;s++){const t=n[s],i=e.match(t);if(i)return parseFloat(i[i.length-2])}return null}const Q=[[new RegExp(F.XBOX+"; "+F.XBOX+" (.*?)[);]","i"),e=>[F.XBOX,e&&e[1]||""]],[new RegExp(F.NINTENDO,"i"),[F.NINTENDO,""]],[new RegExp(F.PLAYSTATION,"i"),[F.PLAYSTATION,""]],[j,[F.BLACKBERRY,""]],[new RegExp(F.WINDOWS,"i"),(e,t)=>{if(/Phone/.test(t)||/WPDesktop/.test(t))return[F.WINDOWS_PHONE,""];if(new RegExp(F.MOBILE).test(t)&&!/IEMobile\b/.test(t))return[F.WINDOWS+" "+F.MOBILE,""];const i=/Windows NT ([0-9.]+)/i.exec(t);if(i&&i[1]){const e=i[1];let n=Y[e]||"";return/arm/i.test(t)&&(n="RT"),[F.WINDOWS,n]}return[F.WINDOWS,""]}],[/((iPhone|iPad|iPod).*?OS (\d+)_(\d+)_?(\d+)?|iPhone)/,e=>{if(e&&e[3]){const t=[e[3],e[4],e[5]||"0"];return[F.IOS,t.join(".")]}return[F.IOS,""]}],[/(watch.*\/(\d+\.\d+\.\d+)|watch os,(\d+\.\d+),)/i,e=>{let t="";return e&&e.length>=3&&(t=a(e[2])?e[3]:e[2]),["watchOS",t]}],[new RegExp("("+F.ANDROID+" (\\d+)\\.(\\d+)\\.?(\\d+)?|"+F.ANDROID+")","i"),e=>{if(e&&e[2]){const t=[e[2],e[3],e[4]||"0"];return[F.ANDROID,t.join(".")]}return[F.ANDROID,""]}],[/Mac OS X (\d+)[_.](\d+)[_.]?(\d+)?/i,e=>{const t=["Mac OS X",""];if(e&&e[1]){const i=[e[1],e[2],e[3]||"0"];t[1]=i.join(".")}return t}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[F.CHROME_OS,""]],[/Linux|debian/i,["Linux",""]]];function ee(){const e=window.innerHeight||document.documentElement.clientHeight||document.body&&document.body.clientHeight||0,t=window.innerWidth||document.documentElement.clientWidth||document.body&&document.body.clientWidth||0,i=navigator.userAgent,n=function(e){for(let t=0;t<Q.length;t++){const[i,n]=Q[t],s=i.exec(e),r=s&&("function"==typeof n?n(s,e):n);if(r)return r}return["",""]}(i)||["",""];return{$browser:J(i),$browser_version:Z(i),$url:location?.href.substring(0,1e3),$host:location?.host,$viewport_height:e,$viewport_width:t,$lib:"webjs",$lib_version:S,$search_engine:$(),$referrer:M(),$referrer_host:m(r=r||M()),$title:document.title,$language:navigator.language,$model:(s=i,(X.test(s)?F.NINTENDO:W.test(s)?F.PLAYSTATION:U.test(s)?F.XBOX:new RegExp(F.OUYA,"i").test(s)?F.OUYA:new RegExp("("+F.WINDOWS_PHONE+"|WPDesktop)","i").test(s)?F.WINDOWS_PHONE:/iPad/.test(s)?F.IPAD:/iPod/.test(s)?"iPod Touch":/iPhone/.test(s)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(s)?F.APPLE_WATCH:j.test(s)?F.BLACKBERRY:/(kobo)\s(ereader|touch)/i.test(s)?"Kobo":new RegExp(F.NOKIA,"i").test(s)?F.NOKIA:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(s)||/(kf[a-z]+)( bui|\)).+silk\//i.test(s)?"Kindle Fire":q.test(s)?F.HUAWEI:G.test(s)?F.XIAOMI:z.test(s)?F.OPPO:V.test(s)?F.VIVO:/(Android|ZTE)/i.test(s)?!new RegExp(F.MOBILE).test(s)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(s)?/pixel[\daxl ]{1,6}/i.test(s)&&!/pixel c/i.test(s)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(s)||/lmy47v/i.test(s)&&!/QTAQZ3/i.test(s)?F.ANDROID:F.ANDROID_TABLET:F.ANDROID:new RegExp("(pda|"+F.MOBILE+")","i").test(s)?F.GENERIC_MOBILE:new RegExp(F.TABLET,"i").test(s)&&!new RegExp(F.TABLET+" pc","i").test(s)?F.GENERIC_TABLET:"")||""),$os:n?.[0]||"",$os_version:n?.[1]||"",$pathname:location?.pathname,$screen_height:Number(screen.height)||0,$screen_width:Number(screen.width)||0,$timezone_offset:60*-/* @__PURE__ */(new Date).getTimezoneOffset()};var s,r}const te=new class{constructor(){this.STORAGE_KEY="sensorswave_unsent_events",this.MAX_QUEUE_SIZE=200,this.MAX_RETRY_COUNT=1,this.MAX_AGE_MS=6048e5,this.queue=[],this.loadFromStorage(),this.cleanupExpiredItems()}loadFromStorage(){try{const e=localStorage.getItem(this.STORAGE_KEY);e&&(this.queue=d(e)||[])}catch(e){console.warn("Failed to load queue from localStorage:",e),this.queue=[]}}cleanupExpiredItems(){const e=Date.now(),t=this.queue.filter(t=>e-t.timestamp<this.MAX_AGE_MS);t.length!==this.queue.length&&(this.queue=t,this.saveToStorage())}saveToStorage(){try{this.cleanupExpiredItems(),this.queue.length>this.MAX_QUEUE_SIZE&&(this.queue=this.queue.slice(-this.MAX_QUEUE_SIZE)),localStorage.setItem(this.STORAGE_KEY,JSON.stringify(this.queue))}catch(e){console.warn("Failed to save queue to localStorage:",e)}}enqueue(e,t,i,n=this.MAX_RETRY_COUNT){try{const s={id:f(),url:e,data:t,headers:i,timestamp:Date.now(),retryCount:0,maxRetries:n};return this.queue.push(s),this.saveToStorage(),s.id}catch(s){return console.warn("Failed to enqueue request:",s),""}}dequeue(e){try{this.queue=this.queue.filter(t=>t.id!==e),this.saveToStorage()}catch(t){console.warn("Failed to dequeue request:",t)}}getAll(){try{return this.cleanupExpiredItems(),[...this.queue]}catch(e){return console.warn("Failed to get queue items:",e),[]}}incrementRetryCount(e){const t=this.queue.find(t=>t.id===e);return!(!t||t.retryCount>=t.maxRetries||(t.retryCount++,this.saveToStorage(),0))}clear(){this.queue=[];try{localStorage.removeItem(this.STORAGE_KEY)}catch(e){console.warn("Failed to clear queue from localStorage:",e)}}getItemById(e){return this.queue.find(t=>t.id===e)}};class ie{constructor(e={}){this.flushTimer=null,this.isFlushing=!1,this.paused=!1,this.destroyed=!1,this.config={maxBatchSize:e.maxBatchSize||20,flushInterval:e.flushInterval||5e3},this.startFlushTimer()}pause(){this.paused=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null)}resume(){this.paused&&(this.paused=!1,this.startFlushTimer())}isPaused(){return this.paused}add(){te.getAll().length>=this.config.maxBatchSize&&this.triggerFlush()}triggerFlush(){this.paused||this.isFlushing||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.isFlushing=!0,this.flush())}flush(){const e=te.getAll();if(0===e.length)return this.isFlushing=!1,void this.startFlushTimer();const t=e.slice(0,this.config.maxBatchSize),i=[],n=[];t.forEach(e=>{Array.isArray(e.data)?i.push(...e.data):i.push(e.data),n.push(e.id)});const s=t[t.length-1],r=s.url,o=s.headers;w.instance&&w.instance.config.debug&&console.log(JSON.stringify(i,null,2)),L({url:r,method:"POST",data:i,headers:o,callback:e=>{200===e.statusCode?n.forEach(e=>{te.dequeue(e)}):P(e.statusCode)?console.error("Failed to send batch events:",e):n.forEach(e=>{te.dequeue(e)}),this.isFlushing=!1,this.startFlushTimer()}})}startFlushTimer(){this.destroyed||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flushTimer=setInterval(()=>{te.getAll().length>0&&this.triggerFlush()},this.config.flushInterval))}destroy(){this.destroyed=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.paused||this.flush()}}let ne=null;const se="sensorswave2025jssdksession",re="$session_id";let oe=null;function ae(){const e=new Uint8Array(16);if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues)crypto.getRandomValues(e);else for(let r=6;r<16;r++)e[r]=Math.floor(256*Math.random());const t=new DataView(e.buffer),i=Date.now();t.setUint16(0,Math.floor(i/Math.pow(2,32))),t.setUint32(2,i%Math.pow(2,32)),e[6]=15&e[6]|112,e[8]=63&e[8]|128;const n=[];for(let r=0;r<16;r++)n.push(e[r].toString(16).padStart(2,"0"));const s=n.join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function ce(e){oe=e;try{t.set({name:se,value:JSON.stringify(e),expires:"1800s"})}catch(i){}}function ue(e=!1){const i=Date.now(),s=function(){let e=null;try{e=t.get(se)}catch(s){return oe}if(null==e)return oe;const i=d(e);return function(e){return!!(n(e)&&"string"==typeof e.session_id&&e.session_id&&"number"==typeof e.first_session_time&&Number.isFinite(e.first_session_time)&&"number"==typeof e.latest_session_time&&Number.isFinite(e.latest_session_time))}(i)?i:null}();if(!s||s.first_session_time>i||s.latest_session_time>i||i-s.first_session_time>432e5||i-s.latest_session_time>18e5){const e={session_id:ae(),first_session_time:i,latest_session_time:i};return ce(e),e.session_id}return e||ce({...s,latest_session_time:i}),s.session_id}function le(){const e=w.instance;return!(!e||!e.__innerInited)||(console.warn("[SensorsWave] SDK is not initialized. Please call init() first."),!1)}function he(){const e=w.instance;return!e||"function"!=typeof e.hasOptedOutCapturing||!e.hasOptedOutCapturing()}let de=null;function pe(){return b.isSupport()?(de||(ne||(ne=new ie({maxBatchSize:20,flushInterval:5e3})),de=ne),de):null}function ge(e,t,i){if(he())return L({url:e,method:"POST",data:t.data,headers:t.headers,callback:e=>{if(200!==e.statusCode){if(!P(e.statusCode))return void(i&&te.dequeue(i));if(i&&te.incrementRetryCount(i)){const e=te.getItemById(i);if(e){const t=Math.min(1e3*Math.pow(2,e.retryCount),3e4);setTimeout(()=>{ge(e.url,{data:e.data,headers:e.headers},e.id)},t)}}}else i&&te.dequeue(i),t.callback&&t.callback(e.json)}})}function fe(e){return`${e.apiHost}/in/track`}function me(e){return`${e.apiHost}/ab/evalall`}function Ee(e){return{"Content-Type":"application/json",SourceToken:e.sourceToken}}function _e(e,t,i){w.instance&&w.instance.config.debug&&console.log(JSON.stringify(t.data,null,2));const n=te.enqueue(e,t.data,t.headers);return ge(e,{...t,callback:void 0},n)}function be(){try{const e=sessionStorage.getItem("sensorswave_utm");if(!e)return{};const t=JSON.parse(e),i={};return Object.entries(t).forEach(([e,t])=>{null!=t&&""!==t&&(i[`$${e}`]=t)}),i}catch(e){return{}}}function ve(e){const t={};return Object.entries(e).forEach(([e,i])=>{if("function"==typeof i)try{const n=i();t[e]=n}catch(n){console.warn("[SensorsWave] Failed to resolve dynamic property:",e,n)}else t[e]=i}),t}function Ie(e={},t=!0){return{...t?ee():{},...ve(N.getCommonProps()),...e,[re]:ue()}}function we(e={},t=!0){const i=Ie(e,t),n=be();return Object.keys(n).length>0&&Object.assign(i,n),i}function Se(e,t,i=!0){if(!le())return;if(!he())return;const n={time:Date.now(),trace_id:N.getTraceId(),event:e.event,properties:we(e.properties,i)},s=be();Object.keys(s).length>0&&(n.user_properties||(n.user_properties={}),n.user_properties.$set||(n.user_properties.$set={}),Object.assign(n.user_properties.$set,s)),e.user_properties&&(e.user_properties.$set&&(n.user_properties=n.user_properties||{},n.user_properties.$set={...n.user_properties.$set||{},...e.user_properties.$set},delete e.user_properties.$set),n.user_properties={...n.user_properties,...e.user_properties});const r=N.getLoginId(),o=N.getAnonId();r&&(n.login_id=r),o&&(n.anon_id=o);const a=fe(t),c=Ee(t),u=!1!==t.batchSend&&pe();u?(te.enqueue(a,[n],c),u.add()):_e(a,{data:[n],headers:c})}function ye({userProps:e,opts:t}){if(!le())return;if(!he())return;const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return;const s={time:Date.now(),trace_id:N.getTraceId(),event:"$UserSet",login_id:i,anon_id:n,user_properties:e,properties:we()},r=fe(t),o=Ee(t),a=pe();if(!a)return _e(r,{data:[s],headers:o});te.enqueue(r,[s],o),a.add()}function Oe(e){return e.typ===C.FEATURE_GATE||e.typ===C.FEATURE_CONFIG?`$feature_${e.id}`:e.typ===C.EXPERIMENT?`$exp_${e.id}`:""}function Ae(e){const t=e.typ;return[C.FEATURE_GATE,C.EXPERIMENT,C.FEATURE_CONFIG].includes(t)?{[Oe(e)]:e.vid}:{}}function Re(e){const t=e.typ;return t===C.FEATURE_GATE||t===C.FEATURE_CONFIG?{$feature_key:e.key,$feature_variant:e.vid}:t===C.EXPERIMENT?{$exp_key:e.key,$exp_variant:e.vid}:{}}function Te({isUnset:e=!1,data:t,opts:i}){if(!le())return;if(!he())return;if(!t||u(t)||t.disable_impress)return;const n=N.getLoginId(),s=N.getAnonId();if(!n&&!s)return;const r=t.typ===C.EXPERIMENT?"$ExpImpress":"$FeatureImpress";let o={};return o=e?{$unset:{[Oe(t)]:null}}:{$set:{...Ae(t)}},Se({event:r,properties:Re(t),user_properties:o},i)}const Ce="sensorswave_opt_out";class Ne{constructor(e){this.persist=e}read(){if(this.persist)try{const e=b.get(Ce);return"0"===e||"1"!==e&&void 0}catch{return}}write(e){if(this.persist)try{b.set(Ce,e?"0":"1")}catch{}}}class Pe{constructor({plugins:e,emitter:t,config:i,sdk:n}){this.plugins=[],this.pluginInsMap={},this.emitter=t,this.config=i,this.sdk=n,this.registerBuiltInPlugins(e),this.created(),this.emitter.on(y,()=>{this.init()})}registerBuiltInPlugins(e){for(let t=0,i=e.length;t<i;t++)this.registerPlugin(e[t])}registerPlugin(e){this.plugins.push(e)}getPlugins(){return this.plugins}getPlugin(e){return this.pluginInsMap[e]}created(){for(let e=0,t=this.plugins.length;e<t;e++){const t=this.plugins[e];if(!t.NAME)throw new Error('Plugin should be defined with "NAME"');const i=new t({emitter:this.emitter,config:this.config,sdk:this.sdk});this.pluginInsMap[t.NAME]=i}}init(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.init&&t.init()}}destroy(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.destroy&&"function"==typeof t.destroy&&t.destroy()}this.pluginInsMap={},this.plugins=[]}}const ke=class{constructor({emitter:e,config:t,sdk:i}){this.boundSend=null,this.hashEvent=null,this.spaSwitchHandler=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;this.boundSend=()=>{Se({event:"$PageView",properties:{}},e)},this.sdk&&!0===this.sdk._postConsentInit||setTimeout(()=>{this.boundSend()},0),e.isSinglePageApp&&this.addSinglePageListener()}addSinglePageListener(){this.spaSwitchHandler=e=>{e!==location.href&&this.boundSend()},this.emitter.on(O,this.spaSwitchHandler)}destroy(){this.spaSwitchHandler&&(this.emitter.off(O,this.spaSwitchHandler),this.spaSwitchHandler=null),this.hashEvent&&this.boundSend&&(window.removeEventListener(this.hashEvent,this.boundSend),this.hashEvent=null),this.boundSend=null}};ke.NAME="pageview";let xe=ke;const Le=class{constructor({emitter:e,config:t,sdk:i}){this.startTime=Date.now(),this.pageShowStatus=!0,this.pageHiddenStatus=!1,this.timer=null,this.currentPageUrl=document.referrer,this.url=location.href,this.title=document.title||"",this.heartbeatIntervalTime=5e3,this.heartbeatIntervalTimer=null,this.pageId=null,this.storageName="sensorswavewebjssdkpageleave",this.maxDuration=432e3,this.eventListeners=[],this._skipFirstPageEnd=!1,this.emitter=e,this.config=t,this.sdk=i}__canCapture(){return!this.sdk||"function"!=typeof this.sdk.hasOptedOutCapturing||!this.sdk.hasOptedOutCapturing()}init(){this.pageId=Number(String(g()).slice(2,5)+String(g()).slice(2,4)+String(Date.now()).slice(-4)),this.addEventListener(),this.sdk&&!0===this.sdk._postConsentInit&&(this._skipFirstPageEnd=!0),!0===document.hidden?this.pageShowStatus=!1:this.addHeartBeatInterval()}log(e){console.log(e)}refreshPageEndTimer(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.timer=setTimeout(()=>{this.pageHiddenStatus=!1},5e3)}hiddenStatusHandler(){this.timer&&clearTimeout(this.timer),this.timer=null,this.pageHiddenStatus=!1}pageStartHandler(){this.startTime=Date.now(),1==!document.hidden?this.pageShowStatus=!0:this.pageShowStatus=!1,this.url=location.href,this.title=document.title,this._skipFirstPageEnd=!1}pageEndHandler(){if(!0===this.pageHiddenStatus)return;if(!this.__canCapture())return;const e=this.getPageLeaveProperties();!1===this.pageShowStatus&&delete e.$event_duration,this.pageShowStatus=!1,this.pageHiddenStatus=!0,Se({event:R,properties:e},this.config),this.refreshPageEndTimer(),this.delHeartBeatData()}addEventListener(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()}addPageStartListener(){if("onpageshow"in window){const e=()=>{this.pageStartHandler(),this.hiddenStatusHandler()};window.addEventListener("pageshow",e),this.eventListeners.push({target:window,event:"pageshow",handler:e})}}addSinglePageListener(){this.config.isSinglePageApp&&this.emitter.on(O,e=>{e!==location.href&&(this.url=e,this.pageEndHandler(),this.stopHeartBeatInterval(),this.currentPageUrl=this.url,this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval())})}addPageEndListener(){["pagehide","beforeunload"].forEach(e=>{if(`on${e}`in window){const t=()=>{if(this._skipFirstPageEnd)return this._skipFirstPageEnd=!1,void this.stopHeartBeatInterval();this.pageEndHandler(),this.stopHeartBeatInterval()};window.addEventListener(e,t),this.eventListeners.push({target:window,event:e,handler:t})}})}addPageSwitchListener(){const e=()=>{"visible"===document.visibilityState?(this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval()):(this.url=location.href,this.title=document.title,this.stopHeartBeatInterval(),this.delHeartBeatData())};document.addEventListener("visibilitychange",e),this.eventListeners.push({target:document,event:"visibilitychange",handler:e})}addHeartBeatInterval(){b.isSupport()&&this.startHeartBeatInterval()}startHeartBeatInterval(){this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),this.sdk&&!0===this.sdk._postConsentInit&&!0===this._skipFirstPageEnd||(this.heartbeatIntervalTimer=setInterval(()=>{this.saveHeartBeatData()},this.heartbeatIntervalTime),this.saveHeartBeatData("is_first_heartbeat"),this.reissueHeartBeatData())}stopHeartBeatInterval(){this.heartbeatIntervalTimer&&clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null}saveHeartBeatData(e){if(!this.__canCapture())return;const t=this.getPageLeaveProperties();t.$time=Date.now(),"is_first_heartbeat"===e&&(t.$event_duration=3);const i={type:"track",event:R,properties:t,time:t.$time};i.heartbeat_interval_time=this.heartbeatIntervalTime,b.isSupport()&&b.set(`${this.storageName}-${this.pageId}`,JSON.stringify(i))}delHeartBeatData(e){b.isSupport()&&b.remove(e||`${this.storageName}-${this.pageId}`)}reissueHeartBeatData(){if(this.__canCapture())for(let e=window.localStorage.length-1;e>=0;e--){const t=window.localStorage.key(e);if(t&&t!==`${this.storageName}-${this.pageId}`&&0===t.indexOf(`${this.storageName}-`)){const e=b.parse(t);n(e)&&Date.now()-e.time>e.heartbeat_interval_time+5e3&&(delete e.heartbeat_interval_time,e._flush_time=/* @__PURE__ */(new Date).getTime(),Se({event:R,properties:e?.properties},this.config),this.delHeartBeatData(t))}}}getPageLeaveProperties(){let e=(Date.now()-this.startTime)/1e3;(isNaN(e)||e<0||e>this.maxDuration)&&(e=0),e=Number(e.toFixed(3));const t={$title:this.title,$url:this.url?.substring(0,1e3),$pathname:I(this.url)};return 0!==e&&(t.$event_duration=e),t}destroy(){this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}};Le.NAME="pageleave";let Me=Le;const $e=class{constructor({emitter:e,config:t,sdk:i}){this.eventSended=!1,this.emitter=e,this.config=t,this.sdk=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit)return;const e=()=>{let t=0;const i={};if(window.performance){t=function(){let e=0;if("function"==typeof performance.getEntriesByType){const t=performance.getEntriesByType("navigation");t.length>0&&(e=t[0].domContentLoadedEventEnd||0)}return e}();const e=function(){if(performance.getEntries&&"function"==typeof performance.getEntries){const e=performance.getEntries();let t=0;for(const i of e)"transferSize"in i&&(t+=i.transferSize);if("number"==typeof t&&t>=0&&t<10737418240)return Number((t/1024).toFixed(3))}}();e&&(i.$page_resource_size=e)}else console.warn("Performance API is not supported.");t>0&&!Number.isFinite(t)&&(i.$event_duration=Number((t/1e3).toFixed(3))),this.eventSended||(this.eventSended=!0,Se({event:"$PageLoad",properties:i},this.config)),window.removeEventListener("load",e)};"complete"===document.readyState?e():window.addEventListener&&window.addEventListener("load",e)}};$e.NAME="pageload";let De=$e;function Fe(e){if(!l(e))return!1;const t=o(e.tagName)?e.tagName.toLowerCase():"",i={};return i.$element_type=t,i.$element_name=e.getAttribute("name")||"",i.$element_id=e.getAttribute("id")||"",i.$element_class_name=o(e.className)?e.className:"",i.$element_target_url=e.getAttribute("href")||"",i.$element_content=function(e,t){return o(t)&&"input"===t.toLowerCase()?("button"===(i=e).type||"submit"===i.type)&&i.value||"":function(e,t){let i="",n="";return e.textContent?i=v(e.textContent):e.innerText&&(i=v(e.innerText)),i&&(i=i.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),n=i||"","input"!==t&&"INPUT"!==t||(n=e.value||""),n}(e,t);var i}(e,t)||"",i.$element_selector=Be(e)||"",i.$element_path=function(e){let t=[];for(;e.parentNode&&l(e);){if(!o(e.tagName))return"";if(e.id&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.id)){t.unshift(e.tagName.toLowerCase()+"#"+e.id);break}if(e===document.body){t.unshift("body");break}t.unshift(e.tagName.toLowerCase()),e=e.parentNode}return t.join(" > ")}(e)||"",i}function Be(e,t=[]){if(!(e&&e.parentNode&&e.parentNode.children&&o(e.tagName)))return"";t=Array.isArray(t)?t:[];const i=e.nodeName.toLowerCase();return e&&"body"!==i&&1==e.nodeType?(t.unshift(function(e){if(!e||!l(e)||!o(e.tagName))return"";let t=e.parentNode&&9==e.parentNode.nodeType?-1:function(e){if(!e.parentNode)return-1;let t=0;const i=e.tagName,n=e.parentNode.children;for(let s=0,r=n.length;s<r;s++)if(n[s].tagName===i){if(e===n[s])return t;t++}return-1}(e);return e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?"#"+e.getAttribute("id"):e.tagName.toLowerCase()+(~t?":nth-of-type("+(t+1)+")":"")}(e)),e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?t.join(" > "):Be(e.parentNode,t)):(t.unshift("body"),t.join(" > "))}function He(){return{scrollLeft:document.body.scrollLeft||document.documentElement.scrollLeft||0,scrollTop:document.body.scrollTop||document.documentElement.scrollTop||0}}function Ue(e){if(document.documentElement.getBoundingClientRect){const t=e.getBoundingClientRect();return{targetEleX:t.left+He().scrollLeft||0,targetEleY:t.top+He().scrollTop||0}}return{targetEleX:0,targetEleY:0}}function We(e){return Number(Number(e).toFixed(3))}const Xe=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleClick=null,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,!0),this.isInitialized=!0)}handleClick(e){const t=e.target;if(!t)return;if(!["A","INPUT","BUTTON","TEXTAREA"].includes(t.tagName))return;if("true"===t.getAttribute("sensorswave-disable"))return;const i=function(e,t){const i=Fe(e);if(!i)return!1;const n=function(e,t){const i=t.pageX||t.clientX+He().scrollLeft||t.offsetX+Ue(e).targetEleX,n=t.pageY||t.clientY+He().scrollTop||t.offsetY+Ue(e).targetEleY;return{$page_x:We(i),$page_y:We(n)}}(e,t);return i.$page_x=n.$page_x,i.$page_y=n.$page_y,i}(t,e);Se({event:"$WebClick",properties:i||{}},this.config)}destroy(){this.boundHandleClick&&(document.removeEventListener("click",this.boundHandleClick,!0),this.boundHandleClick=null),this.isInitialized=!1}};Xe.NAME="webclick";let je=Xe;const qe=class{constructor({emitter:e,config:t,sdk:i}){this.updateInterval=null,this.fetchingPromise=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;if(e.enableAB){if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;this.fastFetch().then(()=>{this.emitter.emit(A)}),e.abRefreshInterval<3e4&&(e.abRefreshInterval=3e4),this.updateInterval=setInterval(()=>{this.fetchNewData().catch(console.warn)},e.abRefreshInterval)}}async fastFetch(){const e=N.getABData(this.config.abRefreshInterval);return e&&e.length?(this.emitter.emit(A),Promise.resolve(e)):this.fetchNewData()}async fetchNewData(){return this.fetchingPromise||(this.fetchingPromise=new Promise(e=>{!function({opts:e,cb:t}){if(!le())return void(t&&t({}));if(!he())return void(t&&t({}));const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return void(t&&t({}));const s={user:{login_id:i||"",anon_id:n||"",props:{...ee(),...ve(N.getCommonProps())}},sdk:"webjs",sdk_version:S};L({url:me(e),method:"POST",data:s,headers:Ee(e),callback:e=>{200!==e.statusCode?(console.error("Failed to fetch feature flags"),t&&t({})):t&&t(e.json)}})}({opts:this.config,cb:t=>{N.saveABData(t?.data?.results||[]),e(t),this.fetchingPromise=null}})})),this.fetchingPromise}async getFeatureGate(e){return await this.fastFetch().catch(console.warn),N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_GATE&&t.key==e)}async checkFeatureGate(e){const t=await this.getFeatureGate(e);return!!t&&(!t.hasOwnProperty("vid")&&t.key?(Te({isUnset:!0,data:t,opts:this.config}),!1):(Te({data:t,opts:this.config}),"fail"!==t.vid))}async getExperiment(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.EXPERIMENT&&t.key===e);return t?!t.hasOwnProperty("vid")&&t.key?(Te({isUnset:!0,data:t,opts:this.config}),{}):(Te({data:t,opts:this.config}),t?.value||{}):{}}async getFeatureConfig(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_CONFIG&&t.key===e);if(!t)return{};if(!t.hasOwnProperty("vid")&&t.key)return Te({isUnset:!0,data:t,opts:this.config}),{};Te({data:t,opts:this.config});const i=t?.value;if(i){if(n(i))return i;try{return JSON.parse(i)}catch{return i}}return{}}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null),this.fetchingPromise=null}};qe.NAME="abtest";let Ge=qe;const ze=["utm_source","utm_medium","utm_campaign","utm_content","utm_term"],Ve="sensorswave_utm",Ye=class e{constructor({sdk:e,emitter:t,config:i}){this.sdk=e,this.emitter=t,this.config=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit){let t=e.readFromSessionStorage();return t&&0!==Object.keys(t).length||(t=e.captureAndStore(this.config?.debug)),void this.scheduleInitialUTM(t)}const t=e.getUTMFromURL();e.saveToSessionStorage(t,this.config?.debug),this.scheduleInitialUTM(t)}scheduleInitialUTM(e){setTimeout(()=>{this.sendInitialUTM(e)},0)}static getUTMFromURL(){try{const e=new URLSearchParams(window.location.search),t={};return ze.forEach(i=>{const n=e.get(i);n&&(t[i]=n)}),t}catch(t){return e.getUTMFromURLFallback()}}static getUTMFromURLFallback(){const e={};return window.location.search.substring(1).split("&").forEach(t=>{const[i,n]=t.split("="),s=decodeURIComponent(i),r=n?decodeURIComponent(n):"";ze.includes(s)&&(e[s]=r)}),e}static readFromSessionStorage(){try{const e=sessionStorage.getItem(Ve);if(!e)return{};const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch(e){return{}}}static saveToSessionStorage(e,t=!1){try{sessionStorage.setItem(Ve,JSON.stringify(e))}catch(i){t&&console.warn("[SensorsWave UTM] Failed to save to sessionStorage:",i)}}static captureAndStore(t=!1){const i=e.getUTMFromURL();return e.saveToSessionStorage(i,t),i}sendInitialUTM(e){const t={};ze.forEach(i=>{t[`$initial_${i}`]=null!=e[i]?e[i]:""});try{this.sdk.profileSetOnce(t)}catch(i){this.config.debug&&console.warn("[SensorsWave UTM] Failed to send initial UTM:",i)}}destroy(){}};Ye.NAME="UTM";let Je=Ye;const Ke=1e3,Ze=/^\s*(?:async\s+)?at\s+(?:(.+)\s+\()?(.+?):(\d+):(\d+)\)?$/,Qe=/^(?:(.*)@)?(.+?):(\d+):(\d+)$/;function et(e){let t=e;try{const e=location.origin;e&&0===t.indexOf(e)&&(t=t.substring(e.length))}catch(s){}const i=t.indexOf("?");i>-1&&(t=t.substring(0,i));const n=t.indexOf("#");return n>-1&&(t=t.substring(0,n)),t}function tt(e){return e.map(e=>({platform:"web:javascript",filename:et(e.file),function:e.fn||"?",lineno:Number(e.line),colno:Number(e.col),abs_path:it(e.file,1e3)}))}function it(e,t){return e.length>t?e.substring(0,t):e}function nt(e){let t;if("string"==typeof e)t=e;else if(null!==e&&"object"==typeof e){try{t=JSON.stringify(e)}catch(i){t=Object.prototype.toString.call(e)}t||(t=Object.prototype.toString.call(e))}else t=String(e);return it(t,Ke)}function st(e){const{frames:t,headerType:i}=function(e){const t=[];let i="";if(!e||"string"!=typeof e)return{frames:t,headerType:i};const n=e.split(/\r?\n/);for(let s=0;s<n.length;s++){const e=n[s];if(!e||e.length>1024)continue;const r=e.match(Ze),o=r?null:e.match(Qe),a=r||o;if(a)t.push({fn:a[1]||"?",file:a[2],line:a[3],col:a[4]});else if(0===s){const t=e.indexOf(":");t>0&&(i=e.substring(0,t).trim())}if(t.length>=30)break}return{frames:t,headerType:i}}(e&&e.stack);let n=e&&e.name||i||"Error";return n=it(String(n),200),{$exception_level:"error",$exception_type:n,$exception_message:it(String(e&&e.message||""),Ke),$exception_frames:tt(t)}}function rt(e,t,i,n){let s=[];return t&&(s=[{platform:"web:javascript",filename:et(t),function:"?",lineno:i||0,colno:n||0,abs_path:it(t,1e3)}]),{$exception_level:"error",$exception_type:"Error",$exception_message:it(String(e||""),Ke),$exception_frames:s}}class ot{constructor(e=10,t=1,i=1e4){this.buckets=/* @__PURE__ */new Map,this.bucketSize=e,this.refillRate=t,this.refillInterval=i}allow(e){const t=Date.now();let i=this.buckets.get(e);if(i){if(t>i.lastRefill){const e=Math.floor((t-i.lastRefill)/this.refillInterval)*this.refillRate;e>0&&(i.tokens=Math.min(this.bucketSize,i.tokens+e),i.lastRefill+=e/this.refillRate*this.refillInterval)}}else i={tokens:this.bucketSize,lastRefill:t},this.buckets.set(e,i);return i.tokens>=1&&(i.tokens-=1,!0)}reset(){this.buckets.clear()}}const at=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleError=null,this.boundHandleRejection=null,this.rateLimiter=new ot,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleError=this.handleError.bind(this),this.boundHandleRejection=this.handleRejection.bind(this),window.addEventListener("error",this.boundHandleError,!0),window.addEventListener("unhandledrejection",this.boundHandleRejection),this.isInitialized=!0)}handleError(e){try{const t=e.target;let i;if(t&&t!==window&&t.tagName)i=function(e){const t=e,i=(t.tagName||"").toLowerCase(),n=it(String(t.src||t.href||""),Ke);return{$exception_level:"error",$exception_type:"ResourceLoadError",$exception_message:`Failed to load <${i}>${n?` from ${n}`:""}`,$exception_frames:[]}}(t);else{const t=e;i=t.error instanceof Error?st(t.error):rt(String(t.message||""),t.filename,t.lineno,t.colno)}this.send(i)}catch(t){}}handleRejection(e){try{const t=e.reason;this.send(function(e){return e instanceof Error?st(e):{$exception_level:"error",$exception_type:"UnhandledRejection",$exception_message:nt(e),$exception_frames:[]}}(t))}catch(t){}}send(e){e.$exception_message&&this.rateLimiter.allow(e.$exception_type)&&Se({event:T,properties:e},this.config)}destroy(){this.boundHandleError&&(window.removeEventListener("error",this.boundHandleError,!0),this.boundHandleError=null),this.boundHandleRejection&&(window.removeEventListener("unhandledrejection",this.boundHandleRejection),this.boundHandleRejection=null),this.rateLimiter.reset(),this.isInitialized=!1}};at.NAME="exception";let ct=at;const ut="data-sw-exposure-event-name",lt="data-sw-exposure-config-",ht=`[${ut}]`,dt={visibleRatio:0,stayDuration:0,repeated:!0};function pt(e,t){const i={};if(!n(e))return i;const s=e;if(void 0!==s.visibleRatio){const e=Number(s.visibleRatio);!isNaN(e)&&e>=0&&e<=1?i.visibleRatio=e:t&&t("[exposure] parameter config.visibleRatio 非法(值域 0~1),已忽略:",s.visibleRatio)}if(void 0!==s.stayDuration){const e=Number(s.stayDuration);!isNaN(e)&&e>=0?i.stayDuration=e:t&&t("[exposure] parameter config.stayDuration 非法(须 >= 0),已忽略:",s.stayDuration)}if(void 0!==s.repeated){const e=s.repeated;!0===e||"true"===e?i.repeated=!0:!1===e||"false"===e?i.repeated=!1:t&&t("[exposure] parameter config.repeated 非法(须为布尔),已忽略:",e)}return i}function gt(...e){const t={...dt};for(let i=0;i<e.length;i++){const s=e[i];if(!n(s))continue;const r=s;void 0!==r.visibleRatio&&(t.visibleRatio=r.visibleRatio),void 0!==r.stayDuration&&(t.stayDuration=r.stayDuration),void 0!==r.repeated&&(t.repeated=r.repeated)}return t}function ft(e){const t=(e.getAttribute(ut)||"").trim();let i={},s={};const r=e.getAttribute("data-sw-exposure-option");if(r){const e=d(r);n(e)&&(n(e.config)&&(i=e.config),n(e.properties)&&(s=e.properties))}const a=e.getAttribute(lt+"visible-ratio");null!==a&&(i.visibleRatio=a);const c=e.getAttribute(lt+"stay-duration");null!==c&&(i.stayDuration=c);const u=e.getAttribute(lt+"repeated");null!==u&&(i.repeated=u);const l=e.attributes;for(let n=0;n<l.length;n++){const e=l[n],t=e.name;if(o(t)&&0===t.indexOf("data-sw-exposure-property-")){const i=t.substring(26);i&&(s[i]=e.value)}}return{eventName:t,config:pt(i),properties:s}}const mt=class{constructor({emitter:e,config:t,sdk:i}){this.isInitialized=!1,this.observers=/* @__PURE__ */new Map,this.records=/* @__PURE__ */new Map,this.mutationObserver=null,this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.boundHandleSpa=null,this.eventListeners=[],this.globalConfig={...dt},this.log=function(){},this.emitter=e,this.config=t,this.sdk=i}init(){this.isInitialized||(function(){try{return"undefined"!=typeof window&&"IntersectionObserver"in window&&"MutationObserver"in window}catch(e){return!1}}()?(this.log=!0==(!0===this.config.debug)&&"undefined"!=typeof console&&console.log?function(...e){console.log("[SensorsWave][exposure]",...e)}:function(){},this.globalConfig=gt(this.globalConfig,pt(this.config.exposureConfig,this.log)),this.boundHandleIntersection=this.handleIntersection.bind(this),this.boundHandleMutation=this.handleMutation.bind(this),this.boundHandleVisibility=this.handleVisibility.bind(this),"loading"===document.readyState?(this.boundHandleReady=()=>{this.scanDocument(),this.observeMutations()},document.addEventListener("DOMContentLoaded",this.boundHandleReady),this.eventListeners.push({target:document,event:"DOMContentLoaded",handler:this.boundHandleReady})):(this.scanDocument(),this.observeMutations()),!0===this.config.isSinglePageApp&&(this.boundHandleSpa=e=>{this.handleSpaSwitch(e)},this.emitter.on(O,this.boundHandleSpa)),document.addEventListener("visibilitychange",this.boundHandleVisibility),this.eventListeners.push({target:document,event:"visibilitychange",handler:this.boundHandleVisibility}),!0===document.hidden&&this.stop(),this.isInitialized=!0):console.warn("[SensorsWave][exposure] 当前浏览器不支持 IntersectionObserver / MutationObserver,曝光采集未初始化"))}addExposureView(e,t){this.isInitialized?l(e)?n(t)&&o(t.eventName)&&t.eventName.trim()?this.addOrUpdateWatchEle(e,{eventName:t.eventName.trim(),config:n(t.config)?pt(t.config,this.log):void 0,properties:n(t.properties)?{...t.properties}:{},listener:n(t.listener)?{...t.listener}:{}},"api"):this.log("addExposureView parameter option.eventName 缺失:",t):this.log("addExposureView parameter element 非法:",e):this.log("曝光插件未初始化(enableExposureTrack 未开启或浏览器不支持)")}removeExposureView(e){this.isInitialized?l(e)?this.removeWatchEle(e):this.log("removeExposureView parameter element 非法:",e):this.log("曝光插件未初始化")}scanDocument(e){try{const t=e||document;if(!t.querySelectorAll)return;const i=t.querySelectorAll(ht);for(let e=0;e<i.length;e++){const t=i[e];this.addOrUpdateWatchEle(t,ft(t),"attr")}}catch(t){}}addOrUpdateWatchEle(e,t,i){if(!e||!l(e))return void this.log("parameter element error:",e);if(!o(t.eventName)||!t.eventName.trim())return void this.log("parameter option.eventName error:",t);const n=this.records.get(e);if(n&&"api"===n.source&&"attr"===i)return void this.log("声明式属性变更被忽略:元素已由 addExposureView 注册",e);const s=gt(this.globalConfig,n&&n.config,t.config);if(n&&n.config.visibleRatio===s.visibleRatio)return n.eventName=t.eventName,n.source=i,n.config=s,n.properties={...t.properties||{}},n.listener=t.listener||{},void(n.hasSent=!1);n&&this.removeWatchEle(e);const r={ele:e,eventName:t.eventName,source:i,config:s,properties:{...t.properties||{}},listener:t.listener||{},timer:null,hasSent:!1};this.records.set(e,r),this.getIntersection(s.visibleRatio).observe(e)}getIntersection(e){let t=this.observers.get(e);return!t&&this.boundHandleIntersection&&(t=new IntersectionObserver(this.boundHandleIntersection,{threshold:e}),this.observers.set(e,t)),t}removeWatchEle(e){const t=this.records.get(e);if(!t)return;const i=this.observers.get(t.config.visibleRatio);i&&l(e)&&i.unobserve(e),t.timer&&(clearTimeout(t.timer),t.timer=null),this.records.delete(e)}handleIntersection(e){try{for(const t of e){const e=t.target,i=this.records.get(e);i&&(!0===t.isIntersecting&&t.intersectionRatio>=i.config.visibleRatio?!0!==document.hidden&&(i.timer&&clearTimeout(i.timer),i.timer=setTimeout(()=>{this.fireExposure(e)},1e3*i.config.stayDuration)):i.timer&&(clearTimeout(i.timer),i.timer=null))}}catch(t){}}fireExposure(e){try{const i=this.records.get(e);if(i&&(i.timer=null),!i||i.hasSent)return;let n={width:0,height:0};try{n=e.getBoundingClientRect()}catch(t){}if(!n.width||!n.height)return;if(!e.isConnected)return void this.removeWatchEle(e);if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;const r={...Fe(e),...i.properties},{shouldExpose:o,didExpose:a}=i.listener||{};if(o&&s(o))try{if(!1===o(e,r))return}catch(t){return}if(Se({event:i.eventName,properties:r},this.config),i.hasSent=!0,i.config.repeated&&(i.hasSent=!1),a&&s(a))try{a(e,r)}catch(t){}}catch(t){}}observeMutations(){!this.mutationObserver&&this.boundHandleMutation&&(this.mutationObserver=new MutationObserver(this.boundHandleMutation),this.mutationObserver.observe(document.body,{attributes:!0,childList:!0,subtree:!0}))}handleMutation(e){try{for(const t of e)if("childList"===t.type){if(t.removedNodes.length>0)for(const e of Array.from(t.removedNodes)){if(1!==e.nodeType)continue;this.removeWatchEle(e);const t=e.querySelectorAll(ht);for(let e=0;e<t.length;e++)this.removeWatchEle(t[e])}if(t.addedNodes.length>0)for(const e of Array.from(t.addedNodes))1===e.nodeType&&(e.hasAttribute(ut)&&this.addOrUpdateWatchEle(e,ft(e),"attr"),this.scanDocument(e))}else"attributes"===t.type&&this.handleAttrChange(t)}catch(t){}}handleAttrChange(e){const t=e.attributeName;if(!t||0!==t.indexOf("data-sw-exposure"))return;const i=e.target;t!==ut||(i.getAttribute(t)||"").trim()?(i.getAttribute(ut)||"").trim()&&this.addOrUpdateWatchEle(i,ft(i),"attr"):this.removeWatchEle(i)}handleSpaSwitch(e){try{if(e===location.href)return;this.stop();for(const[e,t]of Array.from(this.records))"attr"===t.source&&this.records.delete(e);this.start(),this.scanDocument()}catch(t){}}stop(){for(const e of Array.from(this.records.values())){const t=this.observers.get(e.config.visibleRatio);t&&t.unobserve(e.ele),e.timer&&(clearTimeout(e.timer),e.timer=null)}}start(){for(const e of Array.from(this.records.values())){if(!e.ele.isConnected){this.records.delete(e.ele);continue}const t=this.observers.get(e.config.visibleRatio);t&&t.observe(e.ele)}}handleVisibility(){try{"visible"===document.visibilityState?this.start():this.stop()}catch(e){}}destroy(){this.observers.forEach(e=>{try{e.disconnect()}catch(t){}}),this.observers.clear(),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null);for(const e of Array.from(this.records.values()))e.timer&&(clearTimeout(e.timer),e.timer=null);this.records.clear(),this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.boundHandleSpa&&(this.emitter.off(O,this.boundHandleSpa),this.boundHandleSpa=null),this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.globalConfig={...dt},this.log=function(){},this.isInitialized=!1}};mt.NAME="exposure";let Et=mt;const _t=[],bt={debug:!1,sourceToken:"",apiHost:"",autoCapture:!0,isSinglePageApp:!1,crossSubdomainCookie:!0,enableAB:!1,abRefreshInterval:6e5,enableClickTrack:!1,enableExposureTrack:!1,batchSend:!1,enableErrorTrack:!1,enableCrashTrack:!1,optOutCapturing:!1,persistOptOut:!1},vt=new class{constructor(){this.__innerInited=!1,this.inited=!1,this.config={},this.eventEmitter=new e,this.pluginCore={},this.commonProps={},this.spaCleanup=null,this._optOutCapturing=!1,this.consentStorage=new Ne(!1),this._setupAfterConsentDone=!1,this._postConsentInit=!1,w.instance=this}init(e,t={}){return this.inited?this:(w.instance=this,t.sourceToken=e,this.mergeConfig(t),this.consentStorage=new Ne(!0===this.config.persistOptOut),this._optOutCapturing?this.consentStorage.write(!0):!0===this.config.optOutCapturing?(this._optOutCapturing=!0,this.consentStorage.write(!0)):!0===this.consentStorage.read()&&(this._optOutCapturing=!0),this.eventEmitter.emit("init-param",this.config),this.__innerInited=!0,this._optOutCapturing?(Je.captureAndStore(this.config.debug),this.eventEmitter.emit(y),this.inited=!0,this):(this.__setupAfterConsent(),this.eventEmitter.emit(y),this.inited=!0,this))}__setupAfterConsent(){if(this._setupAfterConsentDone)return;this._setupAfterConsentDone=!0;const e=this.config;_t.length=0,N.init(e.crossSubdomainCookie),e.anonId&&N.setAnonId(e.anonId),function(){if(window._swFailedRequestsInitialized)return;window._swFailedRequestsInitialized=!0;const e=w.instance;e&&"function"==typeof e.hasOptedOutCapturing&&e.hasOptedOutCapturing()||e&&!0===e._postConsentInit||function(){const e=te.getAll();if(0!==e.length)for(let t=0,i=e.length;t<i;t+=10){const i=e.slice(t,t+10),n=[],s=[];i.forEach(e=>{Array.isArray(e.data)?n.push(...e.data):n.push(e.data),s.push(e.id)});const r=i[i.length-1],o=r.url,a=r.headers;L({url:o,method:"POST",data:n,headers:a,callback:e=>{200!==e.statusCode?(console.error("Failed to send batch stored requests:",e),P(e.statusCode)||s.forEach(e=>{te.dequeue(e)})):s.forEach(e=>{te.dequeue(e)})}})}}()}(),_t.push(Je),e.autoCapture&&this.autoTrack(),e.enableAB&&_t.push(Ge),e.enableClickTrack&&_t.push(je),e.enableCrashTrack&&e.debug&&console.warn("[SensorsWave] enableCrashTrack 仅在 app 宿主环境生效,当前 Web 环境不采集 crash"),e.enableErrorTrack&&_t.push(ct),e.enableExposureTrack&&_t.push(Et),this.pluginCore=new Pe({plugins:_t,emitter:this.eventEmitter,config:e,sdk:this}),this.spaCleanup=function(e){let t=location.href;const i=window.history.pushState,n=window.history.replaceState,r=function(){e(t),t=location.href};return s(window.history.pushState)&&(window.history.pushState=function(...n){i.apply(window.history,n),e(t),t=location.href}),s(window.history.replaceState)&&(window.history.replaceState=function(...i){n.apply(window.history,i),e(t),t=location.href}),window.addEventListener("popstate",r),function(){s(window.history.pushState)&&(window.history.pushState=i),s(window.history.replaceState)&&(window.history.replaceState=n),window.removeEventListener("popstate",r)}}(e=>{this.eventEmitter.emit(O,e)})}mergeConfig(e){this.config={...bt,...e}}__canCapture(){return this.inited&&!this._optOutCapturing}track(e){this.__canCapture()&&function(e,t){if(!le())return;if(!he())return;const i={...e};i.time||(i.time=Date.now()),i.login_id||(i.login_id=N.getLoginId()),i.anon_id||(i.anon_id=N.getAnonId()),i.trace_id||(i.trace_id=N.getTraceId()),i.properties=Ie(i.properties);const n=fe(t),s=Ee(t),r=!1!==t.batchSend&&pe();if(!r)return _e(n,{data:[i],headers:s});te.enqueue(n,[i],s),r.add()}(e,this.config)}trackEvent(e,t){this.__canCapture()&&Se({event:e,properties:t},this.config)}trackException(e,t){if(!this.__canCapture())return;const i={...t||{},...e instanceof Error?st(e):rt(String(e))};Se({event:T,properties:i},this.config)}addExposureView(e,t){if(!this.__canCapture())return;const i=this.pluginCore.getPlugin(Et.NAME);i?i.addExposureView(e,t):console.warn("[SensorsWave] addExposureView 需在 init 时配置 enableExposureTrack: true")}removeExposureView(e){if(!this.__canCapture())return;const t=this.pluginCore.getPlugin(Et.NAME);t&&t.removeExposureView(e)}autoTrack(){_t.push(xe,De,Me)}profileSet(e){this.__canCapture()&&ye({userProps:{$set:e},opts:this.config})}profileSetOnce(e){this.__canCapture()&&ye({userProps:{$set_once:e},opts:this.config})}profileIncrement(e){this.__canCapture()&&ye({userProps:{$increment:e},opts:this.config})}profileAppend(e){this.__canCapture()&&ye({userProps:{$append:e},opts:this.config})}profileUnion(e){this.__canCapture()&&ye({userProps:{$union:e},opts:this.config})}profileUnset(e){if(!this.__canCapture())return;const t={};r(e)?e.forEach(function(e){t[e]=null}):t[e]=null,ye({userProps:{$unset:t},opts:this.config})}profileDelete(){this.__canCapture()&&ye({userProps:{$delete:!0},opts:this.config})}registerCommonProperties(e){if(!n(e))return console.warn("Commmon Properties must be an object!");this.commonProps=e,N.setCommonProps(this.commonProps)}clearCommonProperties(e){if(!r(e))return console.warn("Commmon Properties to be cleared must be an array!");e.forEach(e=>{delete this.commonProps[e]}),N.setCommonProps(this.commonProps)}identify(e){this.__canCapture()&&(N.setLoginId(e),function(e){if(!le())return;if(!he())return;const t=N.getLoginId(),i=N.getAnonId();if(!t||!i)return;const n={time:Date.now(),trace_id:N.getTraceId(),event:"$Identify",login_id:t,anon_id:i,properties:we()},s=fe(e),r=Ee(e),o=pe();if(!o)return _e(s,{data:[n],headers:r});te.enqueue(s,[n],r),o.add()}(this.config))}setLoginId(e){this.__canCapture()&&N.setLoginId(e)}getAnonId(){return this.__canCapture()?N.getAnonId():""}getSessionId(){return this.__canCapture()?ue(!0):""}setAnonId(e){this.__canCapture()&&N.setAnonId(e)}getLoginId(){return this.__canCapture()?N.getLoginId():""}reset(e=!1){this.__canCapture()&&(N.clearLoginId(),function(){oe=null;try{t.remove(se)}catch(e){}}(),e&&N.resetAnonId())}checkFeatureGate(e){if(!this.__canCapture())return Promise.resolve(!1);const t=this.pluginCore.getPlugin(Ge.NAME);return this.config.enableAB&&t?t.checkFeatureGate(e):Promise.reject("AB is disabled")}getExperiment(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Ge.NAME);return this.config.enableAB&&t?t.getExperiment(e):Promise.reject("AB is disabled")}getFeatureConfig(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Ge.NAME);return this.config.enableAB&&t?t.getFeatureConfig(e):Promise.reject("AB is disabled")}optOutCapturing(){this._optOutCapturing=!0,this.consentStorage.write(!0),de&&de.pause()}optInCapturing(){if(this._optOutCapturing=!1,this.consentStorage.write(!1),de&&de.resume(),this.inited&&!this._setupAfterConsentDone){this._postConsentInit=!0;try{this.__setupAfterConsent(),this.eventEmitter.emit(y)}finally{this._postConsentInit=!1}}}hasOptedOutCapturing(){return this._optOutCapturing}destroy(){de&&(de.destroy(),de=null),"undefined"!=typeof window&&(window._swFailedRequestsInitialized=!1),oe=null,this.inited=!1,this.__innerInited=!1,this.spaCleanup&&"function"==typeof this.spaCleanup&&(this.spaCleanup(),this.spaCleanup=null),this.pluginCore&&"function"==typeof this.pluginCore.destroy&&this.pluginCore.destroy(),this.pluginCore={},this.eventEmitter&&this.eventEmitter.removeAllListeners(),this.consentStorage=new Ne(!0===this.config?.persistOptOut),this._optOutCapturing=!1,this._setupAfterConsentDone=!1,this._postConsentInit=!1,w.instance===this&&(w.instance=null)}};export{vt as default};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SensorsWave=t()}(this,function(){"use strict";class e{constructor(){this.listeners={}}on(e,t,i=!1){if(e&&t){if(!s(t))throw new Error("listener must be a function");this.listeners[e]=this.listeners[e]||[],this.listeners[e].push({listener:t,once:i})}}off(e,t){const i=this.listeners[e];if(!i?.length)return;"number"==typeof t&&i.splice(t,1);const n=i.findIndex(e=>e.listener===t);-1!==n&&i.splice(n,1)}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((i,n)=>{i.listener.call(this,...t),i.listener.once&&this.off(e,n)})}once(e,t){this.on(e,t,!0)}removeAllListeners(e){e?this.listeners[e]=[]:this.listeners={}}}const t={get:function(e){const t=e+"=",i=document.cookie.split(";");for(let n=0,s=i.length;n<s;n++){let e=i[n];for(;" "==e.charAt(0);)e=e.substring(1,e.length);if(0==e.indexOf(t))return h(e.substring(t.length,e.length))}return null},set:function({name:e,value:t,expires:i,samesite:n,secure:s,domain:r}){let o="",a="",c="",u="";if(0!==(i=null==i||void 0===i?365:i)){const e=new Date;"s"===String(i).slice(-1)?e.setTime(e.getTime()+1e3*Number(String(i).slice(0,-1))):e.setTime(e.getTime()+24*i*60*60*1e3),o="; expires="+e.toUTCString()}function l(e){return e?e.replace(/\r\n/g,""):""}n&&(c="; SameSite="+n),s&&(a="; secure");const h=l(e),d=l(t),p=l(r);p&&(u="; domain="+p),h&&d&&(document.cookie=h+"="+encodeURIComponent(d)+o+"; path=/"+u+c+a)},remove:function(e){this.set({name:e,value:"",expires:-1})},isSupport:function({samesite:e,secure:t}={}){if(!navigator.cookieEnabled)return!1;const i="sensorswave_cookie_support_test";return this.set({name:i,value:"1",samesite:e,secure:t}),"1"===this.get(i)&&(this.remove(i),!0)}},i=Object.prototype.toString;function n(e){return"[object Object]"===i.call(e)}function s(e){const t=i.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t}function r(e){return"[object Array]"==i.call(e)}function o(e){return"[object String]"==i.call(e)}function a(e){return void 0===e}const c=Object.prototype.hasOwnProperty;function u(e){if(n(e)){for(let t in e)if(c.call(e,t))return!1;return!0}return!1}function l(e){return!(!e||1!==e.nodeType)}function h(e){let t=e;try{t=decodeURIComponent(e)}catch(i){t=e}return t}function d(e){try{return JSON.parse(e)}catch(t){return""}}const p=function(){let e=Date.now();return function(t){return Math.ceil((e=(9301*e+49297)%233280,e/233280*t))}}();function g(){if("function"==typeof Uint32Array){let e;if("undefined"!=typeof crypto&&(e=crypto),e&&n(e)&&e.getRandomValues)return e.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32)}return p(1e19)/1e19}const f=function(){function e(e){return("0".repeat(e)+Date.now().toString(16)).slice(-e)}return function(){let t=String(screen.height*screen.width);t=t&&/\d{4,}/.test(t)?t.slice(-4):String(31242*g()).replace(".","").slice(0,4);return e(8)+"-"+g().toString(16).replace(".","").slice(-4)+"-"+function(){const e=navigator.userAgent;let t,i=[],n=0;function s(e,t){let n=0;for(let s=0;s<t.length;s++)n|=i[s]<<8*s;return(e^n)>>>0}for(let r=0;r<e.length;r++)t=e.charCodeAt(r),i.unshift(255&t),i.length>=4&&(n=s(n,i),i=[]);return i.length>0&&(n=s(n,i)),("0000"+n.toString(16)).slice(-4)}()+"-"+t+"-"+e(12)||(String(g())+String(g())+String(g())).slice(2,15)}}();function m(e,t){t&&"string"==typeof t||(t="");let i=null;try{i=new URL(e).hostname}catch(n){}return i||t}function E(e){let t=[];try{t=atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})}catch(i){t=[]}try{return decodeURIComponent(t.join(""))}catch(i){return t.join("")}}function b(e){let t="";try{t=btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}))}catch(i){t=e}return t}const v={get:function(e){return window.localStorage.getItem(e)},parse:function(e){let t;try{t=JSON.parse(v.get(e))||null}catch(i){console.warn(i)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(i){console.warn(i)}},remove:function(e){window.localStorage.removeItem(e)},isSupport:function(){let e=!0;try{const t="__local_store_support__",i="testIsSupportStorage";v.set(t,i),v.get(t)!==i&&(e=!1),v.remove(t)}catch(t){e=!1}return e}};function _(e){return e.trim()}function I(e){if(!e||"string"!=typeof e)return"";try{return new URL(e,window.location.origin).pathname}catch(t){return""}}const S={},w="1.5.0",y="init-ready",O="spa-switch",A="ff-ready",R="$PageLeave",T="$Exception";var C=(e=>(e[e.FEATURE_GATE=1]="FEATURE_GATE",e[e.FEATURE_CONFIG=2]="FEATURE_CONFIG",e[e.EXPERIMENT=3]="EXPERIMENT",e))(C||{});const N={crossSubdomain:!1,requests:[],_sessionState:{},_abData:[],_trace_id:"",commonProps:{},_state:{anon_id:"",login_id:"",identities:{}},getIdentityCookieID(){return this._state.identities?.$identity_cookie_id||""},getCommonProps:function(){return this.commonProps||{}},setCommonProps:function(e){this.commonProps=e},getAnonId(){return this._state.anon_id||this.getIdentityCookieID()||f()},getLoginId(){return this._state.login_id},getTraceId(){return this._trace_id||f()},set:function(e,t){this._state[e]=t,this.save()},getCookieName:function(){return"sensorswave2025jssdkcross"},getABLSName:function(){return"sensorswave2025jssdkablatest"},save:function(){let e=JSON.parse(JSON.stringify(this._state));e.identities&&(e.identities=b(JSON.stringify(e.identities)));const i=JSON.stringify(e);t.set({name:this.getCookieName(),value:i,expires:365})},init:function(e){let i,s;this.crossSubdomain=e,t.isSupport()&&(i=t.get(this.getCookieName()),s=d(i)),N._state={...s||{}},N._state.identities&&(N._state.identities=d(E(N._state.identities))),N._state.identities&&n(N._state.identities)&&!u(N._state.identities)||(N._state.identities={$identity_cookie_id:f()}),N.save()},setLoginId(e){"number"==typeof e&&(e=String(e)),void 0!==e&&e&&(N.set("login_id",e),N.save())},clearLoginId(){this._state.login_id="",this.save()},resetAnonId(){this._state.anon_id="",this._state.identities={$identity_cookie_id:f()},this.save()},setAnonId(e){"number"==typeof e&&(e=String(e)),"string"==typeof e&&e?(N.set("anon_id",e),N.save()):console.warn("[SensorsWave store] Invalid anonId, ignored:",e)},saveABData(e){if(!e||u(e))return;this._abData=e;let t=JSON.parse(JSON.stringify(this._abData));t=b(JSON.stringify(t));try{localStorage.setItem(this.getABLSName(),JSON.stringify({time:Date.now(),data:t,anon_id:this.getAnonId(),login_id:this.getLoginId()}))}catch(i){console.warn("Failed to save abdata to localStorage",i)}},getABData(e=6e5){try{let t=localStorage.getItem(this.getABLSName());if(t){const{time:i,data:n,login_id:s,anon_id:r}=d(t)||{};if(i&&n&&Date.now()-i<e&&r===this.getAnonId()&&(!s||s===this.getLoginId())){const e=d(E(n));return this._abData=Array.isArray(e)?e:[],this._abData}localStorage.removeItem(this.getABLSName())}}catch(t){this._abData=[]}return this._abData||[]}};function P(e){return!(e>=400&&e<500)||408===e||429===e}function k(e){var t;if(e.data)return{contentType:"application/json",body:(t=e.data,JSON.stringify(t,(e,t)=>"bigint"==typeof t?t.toString():t,undefined))}}const x=[];function L(e){const t={...e};t.timeout=t.timeout||6e4;const i=t.transport??"fetch",n=x.find(e=>e.transport===i)?.method??x[0]?.method;if(!n)throw new Error("No available transport method for HTTP request");n(t)}function M(e){return o(e=e||document.referrer)&&(e=h(e=e.trim()))||""}function $(e){const t=m(e=e||M());if(!t)return"";const i={baidu:[/^.*\.baidu\.com$/],bing:[/^.*\.bing\.com$/],google:[/^www\.google\.com$/,/^www\.google\.com\.[a-z]{2}$/,/^www\.google\.[a-z]{2}$/],sm:[/^m\.sm\.cn$/],so:[/^.+\.so\.com$/],sogou:[/^.*\.sogou\.com$/],yahoo:[/^.*\.yahoo\.com$/],duckduckgo:[/^.*\.duckduckgo\.com$/]};for(let n of Object.keys(i)){let e=i[n];for(let i=0,s=e.length;i<s;i++)if(e[i].test(t))return n}return""}function F(e,t){return-1!==e.indexOf(t)}"function"==typeof fetch&&x.push({transport:"fetch",method:function(e){if("undefined"==typeof fetch)return void console.error("fetch API is not available");const t=k(e),i=new Headers;e.headers&&Object.keys(e.headers).forEach(t=>{i.append(t,e.headers[t])}),t?.contentType&&i.append("Content-Type",t.contentType),fetch(e.url,{method:e.method||"GET",headers:i,body:t?.body}).then(t=>t.text().then(i=>{const n={statusCode:t.status,text:i};if(200===t.status)try{n.json=JSON.parse(i)}catch(s){console.error("Failed to parse response:",s)}e.callback?.(n)})).catch(t=>{console.error("Request failed:",t),e.callback?.({statusCode:0,text:String(t)})})}}),"undefined"!=typeof XMLHttpRequest&&x.push({transport:"XHR",method:function(e){if("undefined"==typeof XMLHttpRequest)return void console.error("XMLHttpRequest is not available");const t=new XMLHttpRequest;t.open(e.method||"GET",e.url,!0);const i=k(e);e.headers&&Object.keys(e.headers).forEach(i=>{t.setRequestHeader(i,e.headers[i])}),i?.contentType&&t.setRequestHeader("Content-Type",i.contentType),t.timeout=e.timeout||6e4,t.withCredentials=!0,t.onreadystatechange=()=>{if(4===t.readyState){const n={statusCode:t.status,text:t.responseText};if(200===t.status)try{n.json=JSON.parse(t.responseText)}catch(i){console.error("Failed to parse JSON response:",i)}e.callback?.(n)}},t.send(i?.body)}});const D={FACEBOOK:"Facebook",MOBILE:"Mobile",IOS:"iOS",ANDROID:"Android",TABLET:"Tablet",ANDROID_TABLET:"Android Tablet",IPAD:"iPad",APPLE:"Apple",APPLE_WATCH:"Apple Watch",SAFARI:"Safari",BLACKBERRY:"BlackBerry",SAMSUNG_BROWSER:"SamsungBrowser",SAMSUNG_INTERNET:"Samsung Internet",CHROME:"Chrome",CHROME_OS:"Chrome OS",CHROME_IOS:"Chrome iOS",INTERNET_EXPLORER:"Internet Explorer",INTERNET_EXPLORER_MOBILE:"Internet Explorer Mobile",OPERA:"Opera",OPERA_MINI:"Opera Mini",EDGE:"Edge",MICROSOFT_EDGE:"Microsoft Edge",FIREFOX:"Firefox",FIREFOX_IOS:"Firefox iOS",NINTENDO:"Nintendo",PLAYSTATION:"PlayStation",XBOX:"Xbox",ANDROID_MOBILE:"Android Mobile",MOBILE_SAFARI:"Mobile Safari",WINDOWS:"Windows",WINDOWS_PHONE:"Windows Phone",NOKIA:"Nokia",OUYA:"Ouya",GENERIC_MOBILE:"Generic mobile",GENERIC_TABLET:"Generic tablet",KONQUEROR:"Konqueror",UC_BROWSER:"UC Browser",HUAWEI:"Huawei",XIAOMI:"Xiaomi",OPPO:"OPPO",VIVO:"vivo"},B="(\\d+(\\.\\d+)?)",H=new RegExp("Version/"+B),U=new RegExp(D.XBOX,"i"),W=new RegExp(D.PLAYSTATION+" \\w+","i"),X=new RegExp(D.NINTENDO+" \\w+","i"),j=new RegExp(D.BLACKBERRY+"|PlayBook|BB10","i"),q=new RegExp("(HUAWEI|honor|HONOR)","i"),G=new RegExp("(Xiaomi|Redmi)","i"),z=new RegExp("(OPPO|realme)","i"),V=new RegExp("(vivo|IQOO)","i"),Y={"NT3.51":"NT 3.11","NT4.0":"NT 4.0","5.0":"2000",5.1:"XP",5.2:"XP","6.0":"Vista",6.1:"7",6.2:"8",6.3:"8.1",6.4:"10","10.0":"10"};function K(e,t){return t=t||"",F(e," OPR/")&&F(e,"Mini")?D.OPERA_MINI:F(e," OPR/")?D.OPERA:j.test(e)?D.BLACKBERRY:F(e,"IE"+D.MOBILE)||F(e,"WPDesktop")?D.INTERNET_EXPLORER_MOBILE:F(e,D.SAMSUNG_BROWSER)?D.SAMSUNG_INTERNET:F(e,D.EDGE)||F(e,"Edg/")?D.MICROSOFT_EDGE:F(e,"FBIOS")?D.FACEBOOK+" "+D.MOBILE:F(e,"UCWEB")||F(e,"UCBrowser")?D.UC_BROWSER:F(e,"CriOS")?D.CHROME_IOS:F(e,"CrMo")||F(e,D.CHROME)?D.CHROME:F(e,D.ANDROID)&&F(e,D.SAFARI)?D.ANDROID_MOBILE:F(e,"FxiOS")?D.FIREFOX_IOS:F(e.toLowerCase(),D.KONQUEROR.toLowerCase())?D.KONQUEROR:function(e,t){return t&&F(t,D.APPLE)||F(i=e,D.SAFARI)&&!F(i,D.CHROME)&&!F(i,D.ANDROID);var i}(e,t)?F(e,D.MOBILE)?D.MOBILE_SAFARI:D.SAFARI:F(e,D.FIREFOX)?D.FIREFOX:F(e,"MSIE")||F(e,"Trident/")?D.INTERNET_EXPLORER:F(e,"Gecko")?D.FIREFOX:""}const J={[D.INTERNET_EXPLORER_MOBILE]:[new RegExp("rv:"+B)],[D.MICROSOFT_EDGE]:[new RegExp(D.EDGE+"?\\/"+B)],[D.CHROME]:[new RegExp("("+D.CHROME+"|CrMo)\\/"+B)],[D.CHROME_IOS]:[new RegExp("CriOS\\/"+B)],[D.UC_BROWSER]:[new RegExp("(UCBrowser|UCWEB)\\/"+B)],[D.SAFARI]:[H],[D.MOBILE_SAFARI]:[H],[D.OPERA]:[new RegExp("("+D.OPERA+"|OPR)\\/"+B)],[D.FIREFOX]:[new RegExp(D.FIREFOX+"\\/"+B)],[D.FIREFOX_IOS]:[new RegExp("FxiOS\\/"+B)],[D.KONQUEROR]:[new RegExp("Konqueror[:/]?"+B,"i")],[D.BLACKBERRY]:[new RegExp(D.BLACKBERRY+" "+B),H],[D.ANDROID_MOBILE]:[new RegExp("android\\s"+B,"i")],[D.SAMSUNG_INTERNET]:[new RegExp(D.SAMSUNG_BROWSER+"\\/"+B)],[D.INTERNET_EXPLORER]:[new RegExp("(rv:|MSIE )"+B)],Mozilla:[new RegExp("rv:"+B)]};function Z(e,t){const i=K(e,t),n=J[i];if(a(n))return null;for(let s=0;s<n.length;s++){const t=n[s],i=e.match(t);if(i)return parseFloat(i[i.length-2])}return null}const Q=[[new RegExp(D.XBOX+"; "+D.XBOX+" (.*?)[);]","i"),e=>[D.XBOX,e&&e[1]||""]],[new RegExp(D.NINTENDO,"i"),[D.NINTENDO,""]],[new RegExp(D.PLAYSTATION,"i"),[D.PLAYSTATION,""]],[j,[D.BLACKBERRY,""]],[new RegExp(D.WINDOWS,"i"),(e,t)=>{if(/Phone/.test(t)||/WPDesktop/.test(t))return[D.WINDOWS_PHONE,""];if(new RegExp(D.MOBILE).test(t)&&!/IEMobile\b/.test(t))return[D.WINDOWS+" "+D.MOBILE,""];const i=/Windows NT ([0-9.]+)/i.exec(t);if(i&&i[1]){const e=i[1];let n=Y[e]||"";return/arm/i.test(t)&&(n="RT"),[D.WINDOWS,n]}return[D.WINDOWS,""]}],[/((iPhone|iPad|iPod).*?OS (\d+)_(\d+)_?(\d+)?|iPhone)/,e=>{if(e&&e[3]){const t=[e[3],e[4],e[5]||"0"];return[D.IOS,t.join(".")]}return[D.IOS,""]}],[/(watch.*\/(\d+\.\d+\.\d+)|watch os,(\d+\.\d+),)/i,e=>{let t="";return e&&e.length>=3&&(t=a(e[2])?e[3]:e[2]),["watchOS",t]}],[new RegExp("("+D.ANDROID+" (\\d+)\\.(\\d+)\\.?(\\d+)?|"+D.ANDROID+")","i"),e=>{if(e&&e[2]){const t=[e[2],e[3],e[4]||"0"];return[D.ANDROID,t.join(".")]}return[D.ANDROID,""]}],[/Mac OS X (\d+)[_.](\d+)[_.]?(\d+)?/i,e=>{const t=["Mac OS X",""];if(e&&e[1]){const i=[e[1],e[2],e[3]||"0"];t[1]=i.join(".")}return t}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[D.CHROME_OS,""]],[/Linux|debian/i,["Linux",""]]];function ee(){const e=window.innerHeight||document.documentElement.clientHeight||document.body&&document.body.clientHeight||0,t=window.innerWidth||document.documentElement.clientWidth||document.body&&document.body.clientWidth||0,i=navigator.userAgent,n=function(e){for(let t=0;t<Q.length;t++){const[i,n]=Q[t],s=i.exec(e),r=s&&("function"==typeof n?n(s,e):n);if(r)return r}return["",""]}(i)||["",""];return{$browser:K(i),$browser_version:Z(i),$url:location?.href.substring(0,1e3),$host:location?.host,$viewport_height:e,$viewport_width:t,$lib:"webjs",$lib_version:w,$search_engine:$(),$referrer:M(),$referrer_host:m(r=r||M()),$title:document.title,$language:navigator.language,$model:(s=i,(X.test(s)?D.NINTENDO:W.test(s)?D.PLAYSTATION:U.test(s)?D.XBOX:new RegExp(D.OUYA,"i").test(s)?D.OUYA:new RegExp("("+D.WINDOWS_PHONE+"|WPDesktop)","i").test(s)?D.WINDOWS_PHONE:/iPad/.test(s)?D.IPAD:/iPod/.test(s)?"iPod Touch":/iPhone/.test(s)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(s)?D.APPLE_WATCH:j.test(s)?D.BLACKBERRY:/(kobo)\s(ereader|touch)/i.test(s)?"Kobo":new RegExp(D.NOKIA,"i").test(s)?D.NOKIA:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(s)||/(kf[a-z]+)( bui|\)).+silk\//i.test(s)?"Kindle Fire":q.test(s)?D.HUAWEI:G.test(s)?D.XIAOMI:z.test(s)?D.OPPO:V.test(s)?D.VIVO:/(Android|ZTE)/i.test(s)?!new RegExp(D.MOBILE).test(s)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(s)?/pixel[\daxl ]{1,6}/i.test(s)&&!/pixel c/i.test(s)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(s)||/lmy47v/i.test(s)&&!/QTAQZ3/i.test(s)?D.ANDROID:D.ANDROID_TABLET:D.ANDROID:new RegExp("(pda|"+D.MOBILE+")","i").test(s)?D.GENERIC_MOBILE:new RegExp(D.TABLET,"i").test(s)&&!new RegExp(D.TABLET+" pc","i").test(s)?D.GENERIC_TABLET:"")||""),$os:n?.[0]||"",$os_version:n?.[1]||"",$pathname:location?.pathname,$screen_height:Number(screen.height)||0,$screen_width:Number(screen.width)||0,$timezone_offset:60*-(new Date).getTimezoneOffset()};var s,r}const te=new class{constructor(){this.STORAGE_KEY="sensorswave_unsent_events",this.MAX_QUEUE_SIZE=200,this.MAX_RETRY_COUNT=1,this.MAX_AGE_MS=6048e5,this.queue=[],this.loadFromStorage(),this.cleanupExpiredItems()}loadFromStorage(){try{const e=localStorage.getItem(this.STORAGE_KEY);e&&(this.queue=d(e)||[])}catch(e){console.warn("Failed to load queue from localStorage:",e),this.queue=[]}}cleanupExpiredItems(){const e=Date.now(),t=this.queue.filter(t=>e-t.timestamp<this.MAX_AGE_MS);t.length!==this.queue.length&&(this.queue=t,this.saveToStorage())}saveToStorage(){try{this.cleanupExpiredItems(),this.queue.length>this.MAX_QUEUE_SIZE&&(this.queue=this.queue.slice(-this.MAX_QUEUE_SIZE)),localStorage.setItem(this.STORAGE_KEY,JSON.stringify(this.queue))}catch(e){console.warn("Failed to save queue to localStorage:",e)}}enqueue(e,t,i,n=this.MAX_RETRY_COUNT){try{const s={id:f(),url:e,data:t,headers:i,timestamp:Date.now(),retryCount:0,maxRetries:n};return this.queue.push(s),this.saveToStorage(),s.id}catch(s){return console.warn("Failed to enqueue request:",s),""}}dequeue(e){try{this.queue=this.queue.filter(t=>t.id!==e),this.saveToStorage()}catch(t){console.warn("Failed to dequeue request:",t)}}getAll(){try{return this.cleanupExpiredItems(),[...this.queue]}catch(e){return console.warn("Failed to get queue items:",e),[]}}incrementRetryCount(e){const t=this.queue.find(t=>t.id===e);return!(!t||t.retryCount>=t.maxRetries||(t.retryCount++,this.saveToStorage(),0))}clear(){this.queue=[];try{localStorage.removeItem(this.STORAGE_KEY)}catch(e){console.warn("Failed to clear queue from localStorage:",e)}}getItemById(e){return this.queue.find(t=>t.id===e)}};class ie{constructor(e={}){this.flushTimer=null,this.isFlushing=!1,this.paused=!1,this.destroyed=!1,this.config={maxBatchSize:e.maxBatchSize||20,flushInterval:e.flushInterval||5e3},this.startFlushTimer()}pause(){this.paused=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null)}resume(){this.paused&&(this.paused=!1,this.startFlushTimer())}isPaused(){return this.paused}add(){te.getAll().length>=this.config.maxBatchSize&&this.triggerFlush()}triggerFlush(){this.paused||this.isFlushing||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.isFlushing=!0,this.flush())}flush(){const e=te.getAll();if(0===e.length)return this.isFlushing=!1,void this.startFlushTimer();const t=e.slice(0,this.config.maxBatchSize),i=[],n=[];t.forEach(e=>{Array.isArray(e.data)?i.push(...e.data):i.push(e.data),n.push(e.id)});const s=t[t.length-1],r=s.url,o=s.headers;S.instance&&S.instance.config.debug&&console.log(JSON.stringify(i,null,2)),L({url:r,method:"POST",data:i,headers:o,callback:e=>{200===e.statusCode?n.forEach(e=>{te.dequeue(e)}):P(e.statusCode)?console.error("Failed to send batch events:",e):n.forEach(e=>{te.dequeue(e)}),this.isFlushing=!1,this.startFlushTimer()}})}startFlushTimer(){this.destroyed||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flushTimer=setInterval(()=>{te.getAll().length>0&&this.triggerFlush()},this.config.flushInterval))}destroy(){this.destroyed=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.paused||this.flush()}}let ne=null;function se(){const e=S.instance;return!(!e||!e.__innerInited)||(console.warn("[SensorsWave] SDK is not initialized. Please call init() first."),!1)}function re(){const e=S.instance;return!e||"function"!=typeof e.hasOptedOutCapturing||!e.hasOptedOutCapturing()}let oe=null;function ae(){return v.isSupport()?(oe||(ne||(ne=new ie({maxBatchSize:20,flushInterval:5e3})),oe=ne),oe):null}function ce(e,t,i){if(re())return L({url:e,method:"POST",data:t.data,headers:t.headers,callback:e=>{if(200!==e.statusCode){if(!P(e.statusCode))return void(i&&te.dequeue(i));if(i&&te.incrementRetryCount(i)){const e=te.getItemById(i);if(e){const t=Math.min(1e3*Math.pow(2,e.retryCount),3e4);setTimeout(()=>{ce(e.url,{data:e.data,headers:e.headers},e.id)},t)}}}else i&&te.dequeue(i),t.callback&&t.callback(e.json)}})}function ue(e){return`${e.apiHost}/in/track`}function le(e){return`${e.apiHost}/ab/evalall`}function he(e){return{"Content-Type":"application/json",SourceToken:e.sourceToken}}function de(e,t,i){S.instance&&S.instance.config.debug&&console.log(JSON.stringify(t.data,null,2));const n=te.enqueue(e,t.data,t.headers);return ce(e,{...t,callback:void 0},n)}function pe(){try{const e=sessionStorage.getItem("sensorswave_utm");if(!e)return{};const t=JSON.parse(e),i={};return Object.entries(t).forEach(([e,t])=>{null!=t&&""!==t&&(i[`$${e}`]=t)}),i}catch(e){return{}}}function ge(e){const t={};return Object.entries(e).forEach(([e,i])=>{if("function"==typeof i)try{const n=i();t[e]=n}catch(n){console.warn("[SensorsWave] Failed to resolve dynamic property:",e,n)}else t[e]=i}),t}function fe(e={},t=!0){const i={...t?ee():{},...ge(N.getCommonProps()),...e},n=pe();return Object.keys(n).length>0&&Object.assign(i,n),i}function me(e,t,i=!0){if(!se())return;if(!re())return;const n={time:Date.now(),trace_id:N.getTraceId(),event:e.event,properties:fe(e.properties,i)},s=pe();Object.keys(s).length>0&&(n.user_properties||(n.user_properties={}),n.user_properties.$set||(n.user_properties.$set={}),Object.assign(n.user_properties.$set,s)),e.user_properties&&(e.user_properties.$set&&(n.user_properties=n.user_properties||{},n.user_properties.$set={...n.user_properties.$set||{},...e.user_properties.$set},delete e.user_properties.$set),n.user_properties={...n.user_properties,...e.user_properties});const r=N.getLoginId(),o=N.getAnonId();r&&(n.login_id=r),o&&(n.anon_id=o);const a=ue(t),c=he(t),u=!1!==t.batchSend&&ae();u?(te.enqueue(a,[n],c),u.add()):de(a,{data:[n],headers:c})}function Ee({userProps:e,opts:t}){if(!se())return;if(!re())return;const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return;const s={time:Date.now(),trace_id:N.getTraceId(),event:"$UserSet",login_id:i,anon_id:n,user_properties:e,properties:fe()},r=ue(t),o=he(t),a=ae();if(!a)return de(r,{data:[s],headers:o});te.enqueue(r,[s],o),a.add()}function be(e){return e.typ===C.FEATURE_GATE||e.typ===C.FEATURE_CONFIG?`$feature_${e.id}`:e.typ===C.EXPERIMENT?`$exp_${e.id}`:""}function ve(e){const t=e.typ;return[C.FEATURE_GATE,C.EXPERIMENT,C.FEATURE_CONFIG].includes(t)?{[be(e)]:e.vid}:{}}function _e(e){const t=e.typ;return t===C.FEATURE_GATE||t===C.FEATURE_CONFIG?{$feature_key:e.key,$feature_variant:e.vid}:t===C.EXPERIMENT?{$exp_key:e.key,$exp_variant:e.vid}:{}}function Ie({isUnset:e=!1,data:t,opts:i}){if(!se())return;if(!re())return;if(!t||u(t)||t.disable_impress)return;const n=N.getLoginId(),s=N.getAnonId();if(!n&&!s)return;const r=t.typ===C.EXPERIMENT?"$ExpImpress":"$FeatureImpress";let o={};return o=e?{$unset:{[be(t)]:null}}:{$set:{...ve(t)}},me({event:r,properties:_e(t),user_properties:o},i)}const Se="sensorswave_opt_out";class we{constructor(e){this.persist=e}read(){if(this.persist)try{const e=v.get(Se);return"0"===e||"1"!==e&&void 0}catch{return}}write(e){if(this.persist)try{v.set(Se,e?"0":"1")}catch{}}}class ye{constructor({plugins:e,emitter:t,config:i,sdk:n}){this.plugins=[],this.pluginInsMap={},this.emitter=t,this.config=i,this.sdk=n,this.registerBuiltInPlugins(e),this.created(),this.emitter.on(y,()=>{this.init()})}registerBuiltInPlugins(e){for(let t=0,i=e.length;t<i;t++)this.registerPlugin(e[t])}registerPlugin(e){this.plugins.push(e)}getPlugins(){return this.plugins}getPlugin(e){return this.pluginInsMap[e]}created(){for(let e=0,t=this.plugins.length;e<t;e++){const t=this.plugins[e];if(!t.NAME)throw new Error('Plugin should be defined with "NAME"');const i=new t({emitter:this.emitter,config:this.config,sdk:this.sdk});this.pluginInsMap[t.NAME]=i}}init(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.init&&t.init()}}destroy(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.destroy&&"function"==typeof t.destroy&&t.destroy()}this.pluginInsMap={},this.plugins=[]}}const Oe=class{constructor({emitter:e,config:t,sdk:i}){this.boundSend=null,this.hashEvent=null,this.spaSwitchHandler=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;this.boundSend=()=>{me({event:"$PageView",properties:{}},e)},this.sdk&&!0===this.sdk._postConsentInit||setTimeout(()=>{this.boundSend()},0),e.isSinglePageApp&&this.addSinglePageListener()}addSinglePageListener(){this.spaSwitchHandler=e=>{e!==location.href&&this.boundSend()},this.emitter.on(O,this.spaSwitchHandler)}destroy(){this.spaSwitchHandler&&(this.emitter.off(O,this.spaSwitchHandler),this.spaSwitchHandler=null),this.hashEvent&&this.boundSend&&(window.removeEventListener(this.hashEvent,this.boundSend),this.hashEvent=null),this.boundSend=null}};Oe.NAME="pageview";let Ae=Oe;const Re=class{constructor({emitter:e,config:t,sdk:i}){this.startTime=Date.now(),this.pageShowStatus=!0,this.pageHiddenStatus=!1,this.timer=null,this.currentPageUrl=document.referrer,this.url=location.href,this.title=document.title||"",this.heartbeatIntervalTime=5e3,this.heartbeatIntervalTimer=null,this.pageId=null,this.storageName="sensorswavewebjssdkpageleave",this.maxDuration=432e3,this.eventListeners=[],this._skipFirstPageEnd=!1,this.emitter=e,this.config=t,this.sdk=i}__canCapture(){return!this.sdk||"function"!=typeof this.sdk.hasOptedOutCapturing||!this.sdk.hasOptedOutCapturing()}init(){this.pageId=Number(String(g()).slice(2,5)+String(g()).slice(2,4)+String(Date.now()).slice(-4)),this.addEventListener(),this.sdk&&!0===this.sdk._postConsentInit&&(this._skipFirstPageEnd=!0),!0===document.hidden?this.pageShowStatus=!1:this.addHeartBeatInterval()}log(e){console.log(e)}refreshPageEndTimer(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.timer=setTimeout(()=>{this.pageHiddenStatus=!1},5e3)}hiddenStatusHandler(){this.timer&&clearTimeout(this.timer),this.timer=null,this.pageHiddenStatus=!1}pageStartHandler(){this.startTime=Date.now(),1==!document.hidden?this.pageShowStatus=!0:this.pageShowStatus=!1,this.url=location.href,this.title=document.title,this._skipFirstPageEnd=!1}pageEndHandler(){if(!0===this.pageHiddenStatus)return;if(!this.__canCapture())return;const e=this.getPageLeaveProperties();!1===this.pageShowStatus&&delete e.$event_duration,this.pageShowStatus=!1,this.pageHiddenStatus=!0,me({event:R,properties:e},this.config),this.refreshPageEndTimer(),this.delHeartBeatData()}addEventListener(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()}addPageStartListener(){if("onpageshow"in window){const e=()=>{this.pageStartHandler(),this.hiddenStatusHandler()};window.addEventListener("pageshow",e),this.eventListeners.push({target:window,event:"pageshow",handler:e})}}addSinglePageListener(){this.config.isSinglePageApp&&this.emitter.on(O,e=>{e!==location.href&&(this.url=e,this.pageEndHandler(),this.stopHeartBeatInterval(),this.currentPageUrl=this.url,this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval())})}addPageEndListener(){["pagehide","beforeunload"].forEach(e=>{if(`on${e}`in window){const t=()=>{if(this._skipFirstPageEnd)return this._skipFirstPageEnd=!1,void this.stopHeartBeatInterval();this.pageEndHandler(),this.stopHeartBeatInterval()};window.addEventListener(e,t),this.eventListeners.push({target:window,event:e,handler:t})}})}addPageSwitchListener(){const e=()=>{"visible"===document.visibilityState?(this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval()):(this.url=location.href,this.title=document.title,this.stopHeartBeatInterval())};document.addEventListener("visibilitychange",e),this.eventListeners.push({target:document,event:"visibilitychange",handler:e})}addHeartBeatInterval(){v.isSupport()&&this.startHeartBeatInterval()}startHeartBeatInterval(){this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),this.sdk&&!0===this.sdk._postConsentInit&&!0===this._skipFirstPageEnd||(this.heartbeatIntervalTimer=setInterval(()=>{this.saveHeartBeatData()},this.heartbeatIntervalTime),this.saveHeartBeatData("is_first_heartbeat"),this.reissueHeartBeatData())}stopHeartBeatInterval(){this.heartbeatIntervalTimer&&clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null}saveHeartBeatData(e){if(!this.__canCapture())return;const t=this.getPageLeaveProperties();t.$time=Date.now(),"is_first_heartbeat"===e&&(t.$event_duration=3);const i={type:"track",event:R,properties:t,time:t.$time};i.heartbeat_interval_time=this.heartbeatIntervalTime,v.isSupport()&&v.set(`${this.storageName}-${this.pageId}`,JSON.stringify(i))}delHeartBeatData(e){v.isSupport()&&v.remove(e||`${this.storageName}-${this.pageId}`)}reissueHeartBeatData(){if(this.__canCapture())for(let e=window.localStorage.length-1;e>=0;e--){const t=window.localStorage.key(e);if(t&&t!==`${this.storageName}-${this.pageId}`&&0===t.indexOf(`${this.storageName}-`)){const e=v.parse(t);n(e)&&Date.now()-e.time>e.heartbeat_interval_time+5e3&&(delete e.heartbeat_interval_time,e._flush_time=(new Date).getTime(),me({event:R,properties:e?.properties},this.config),this.delHeartBeatData(t))}}}getPageLeaveProperties(){let e=(Date.now()-this.startTime)/1e3;(isNaN(e)||e<0||e>this.maxDuration)&&(e=0),e=Number(e.toFixed(3));const t={$title:this.title,$url:this.url?.substring(0,1e3),$pathname:I(this.url)};return 0!==e&&(t.$event_duration=e),t}destroy(){this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}};Re.NAME="pageleave";let Te=Re;const Ce=class{constructor({emitter:e,config:t,sdk:i}){this.eventSended=!1,this.emitter=e,this.config=t,this.sdk=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit)return;const e=()=>{let t=0;const i={};if(window.performance){t=function(){let e=0;if("function"==typeof performance.getEntriesByType){const t=performance.getEntriesByType("navigation");t.length>0&&(e=t[0].domContentLoadedEventEnd||0)}return e}();const e=function(){if(performance.getEntries&&"function"==typeof performance.getEntries){const e=performance.getEntries();let t=0;for(const i of e)"transferSize"in i&&(t+=i.transferSize);if("number"==typeof t&&t>=0&&t<10737418240)return Number((t/1024).toFixed(3))}}();e&&(i.$page_resource_size=e)}else console.warn("Performance API is not supported.");t>0&&!Number.isFinite(t)&&(i.$event_duration=Number((t/1e3).toFixed(3))),this.eventSended||(this.eventSended=!0,me({event:"$PageLoad",properties:i},this.config)),window.removeEventListener("load",e)};"complete"===document.readyState?e():window.addEventListener&&window.addEventListener("load",e)}};Ce.NAME="pageload";let Ne=Ce;function Pe(e){if(!l(e))return!1;const t=o(e.tagName)?e.tagName.toLowerCase():"",i={};return i.$element_type=t,i.$element_name=e.getAttribute("name")||"",i.$element_id=e.getAttribute("id")||"",i.$element_class_name=o(e.className)?e.className:"",i.$element_target_url=e.getAttribute("href")||"",i.$element_content=function(e,t){return o(t)&&"input"===t.toLowerCase()?("button"===(i=e).type||"submit"===i.type)&&i.value||"":function(e,t){let i="",n="";return e.textContent?i=_(e.textContent):e.innerText&&(i=_(e.innerText)),i&&(i=i.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),n=i||"","input"!==t&&"INPUT"!==t||(n=e.value||""),n}(e,t);var i}(e,t)||"",i.$element_selector=ke(e)||"",i.$element_path=function(e){let t=[];for(;e.parentNode&&l(e);){if(!o(e.tagName))return"";if(e.id&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.id)){t.unshift(e.tagName.toLowerCase()+"#"+e.id);break}if(e===document.body){t.unshift("body");break}t.unshift(e.tagName.toLowerCase()),e=e.parentNode}return t.join(" > ")}(e)||"",i}function ke(e,t=[]){if(!(e&&e.parentNode&&e.parentNode.children&&o(e.tagName)))return"";t=Array.isArray(t)?t:[];const i=e.nodeName.toLowerCase();return e&&"body"!==i&&1==e.nodeType?(t.unshift(function(e){if(!e||!l(e)||!o(e.tagName))return"";let t=e.parentNode&&9==e.parentNode.nodeType?-1:function(e){if(!e.parentNode)return-1;let t=0;const i=e.tagName,n=e.parentNode.children;for(let s=0,r=n.length;s<r;s++)if(n[s].tagName===i){if(e===n[s])return t;t++}return-1}(e);return e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?"#"+e.getAttribute("id"):e.tagName.toLowerCase()+(~t?":nth-of-type("+(t+1)+")":"")}(e)),e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?t.join(" > "):ke(e.parentNode,t)):(t.unshift("body"),t.join(" > "))}function xe(){return{scrollLeft:document.body.scrollLeft||document.documentElement.scrollLeft||0,scrollTop:document.body.scrollTop||document.documentElement.scrollTop||0}}function Le(e){if(document.documentElement.getBoundingClientRect){const t=e.getBoundingClientRect();return{targetEleX:t.left+xe().scrollLeft||0,targetEleY:t.top+xe().scrollTop||0}}return{targetEleX:0,targetEleY:0}}function Me(e){return Number(Number(e).toFixed(3))}const $e=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleClick=null,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,!0),this.isInitialized=!0)}handleClick(e){const t=e.target;if(!t)return;if(!["A","INPUT","BUTTON","TEXTAREA"].includes(t.tagName))return;if("true"===t.getAttribute("sensorswave-disable"))return;const i=function(e,t){const i=Pe(e);if(!i)return!1;const n=function(e,t){const i=t.pageX||t.clientX+xe().scrollLeft||t.offsetX+Le(e).targetEleX,n=t.pageY||t.clientY+xe().scrollTop||t.offsetY+Le(e).targetEleY;return{$page_x:Me(i),$page_y:Me(n)}}(e,t);return i.$page_x=n.$page_x,i.$page_y=n.$page_y,i}(t,e);me({event:"$WebClick",properties:i||{}},this.config)}destroy(){this.boundHandleClick&&(document.removeEventListener("click",this.boundHandleClick,!0),this.boundHandleClick=null),this.isInitialized=!1}};$e.NAME="webclick";let Fe=$e;const De=class{constructor({emitter:e,config:t,sdk:i}){this.updateInterval=null,this.fetchingPromise=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;if(e.enableAB){if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;this.fastFetch().then(()=>{this.emitter.emit(A)}),e.abRefreshInterval<3e4&&(e.abRefreshInterval=3e4),this.updateInterval=setInterval(()=>{this.fetchNewData().catch(console.warn)},e.abRefreshInterval)}}async fastFetch(){const e=N.getABData(this.config.abRefreshInterval);return e&&e.length?(this.emitter.emit(A),Promise.resolve(e)):this.fetchNewData()}async fetchNewData(){return this.fetchingPromise||(this.fetchingPromise=new Promise(e=>{!function({opts:e,cb:t}){if(!se())return void(t&&t({}));if(!re())return void(t&&t({}));const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return void(t&&t({}));const s={user:{login_id:i||"",anon_id:n||"",props:{...ee(),...ge(N.getCommonProps())}},sdk:"webjs",sdk_version:w};L({url:le(e),method:"POST",data:s,headers:he(e),callback:e=>{200!==e.statusCode?(console.error("Failed to fetch feature flags"),t&&t({})):t&&t(e.json)}})}({opts:this.config,cb:t=>{N.saveABData(t?.data?.results||[]),e(t),this.fetchingPromise=null}})})),this.fetchingPromise}async getFeatureGate(e){return await this.fastFetch().catch(console.warn),N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_GATE&&t.key==e)}async checkFeatureGate(e){const t=await this.getFeatureGate(e);return!!t&&(!t.hasOwnProperty("vid")&&t.key?(Ie({isUnset:!0,data:t,opts:this.config}),!1):(Ie({data:t,opts:this.config}),"fail"!==t.vid))}async getExperiment(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.EXPERIMENT&&t.key===e);return t?!t.hasOwnProperty("vid")&&t.key?(Ie({isUnset:!0,data:t,opts:this.config}),{}):(Ie({data:t,opts:this.config}),t?.value||{}):{}}async getFeatureConfig(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_CONFIG&&t.key===e);if(!t)return{};if(!t.hasOwnProperty("vid")&&t.key)return Ie({isUnset:!0,data:t,opts:this.config}),{};Ie({data:t,opts:this.config});const i=t?.value;if(i){if(n(i))return i;try{return JSON.parse(i)}catch{return i}}return{}}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null),this.fetchingPromise=null}};De.NAME="abtest";let Be=De;const He=["utm_source","utm_medium","utm_campaign","utm_content","utm_term"],Ue="sensorswave_utm",We=class e{constructor({sdk:e,emitter:t,config:i}){this.sdk=e,this.emitter=t,this.config=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit){let t=e.readFromSessionStorage();return t&&0!==Object.keys(t).length||(t=e.captureAndStore(this.config?.debug)),void this.scheduleInitialUTM(t)}const t=e.getUTMFromURL();e.saveToSessionStorage(t,this.config?.debug),this.scheduleInitialUTM(t)}scheduleInitialUTM(e){setTimeout(()=>{this.sendInitialUTM(e)},0)}static getUTMFromURL(){try{const e=new URLSearchParams(window.location.search),t={};return He.forEach(i=>{const n=e.get(i);n&&(t[i]=n)}),t}catch(t){return e.getUTMFromURLFallback()}}static getUTMFromURLFallback(){const e={};return window.location.search.substring(1).split("&").forEach(t=>{const[i,n]=t.split("="),s=decodeURIComponent(i),r=n?decodeURIComponent(n):"";He.includes(s)&&(e[s]=r)}),e}static readFromSessionStorage(){try{const e=sessionStorage.getItem(Ue);if(!e)return{};const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch(e){return{}}}static saveToSessionStorage(e,t=!1){try{sessionStorage.setItem(Ue,JSON.stringify(e))}catch(i){t&&console.warn("[SensorsWave UTM] Failed to save to sessionStorage:",i)}}static captureAndStore(t=!1){const i=e.getUTMFromURL();return e.saveToSessionStorage(i,t),i}sendInitialUTM(e){const t={};He.forEach(i=>{t[`$initial_${i}`]=null!=e[i]?e[i]:""});try{this.sdk.profileSetOnce(t)}catch(i){this.config.debug&&console.warn("[SensorsWave UTM] Failed to send initial UTM:",i)}}destroy(){}};We.NAME="UTM";let Xe=We;const je=1e3,qe=/^\s*(?:async\s+)?at\s+(?:(.+)\s+\()?(.+?):(\d+):(\d+)\)?$/,Ge=/^(?:(.*)@)?(.+?):(\d+):(\d+)$/;function ze(e){let t=e;try{const e=location.origin;e&&0===t.indexOf(e)&&(t=t.substring(e.length))}catch(s){}const i=t.indexOf("?");i>-1&&(t=t.substring(0,i));const n=t.indexOf("#");return n>-1&&(t=t.substring(0,n)),t}function Ve(e){return e.map(e=>({platform:"web:javascript",filename:ze(e.file),function:e.fn||"?",lineno:Number(e.line),colno:Number(e.col),abs_path:Ye(e.file,1e3)}))}function Ye(e,t){return e.length>t?e.substring(0,t):e}function Ke(e){let t;if("string"==typeof e)t=e;else if(null!==e&&"object"==typeof e){try{t=JSON.stringify(e)}catch(i){t=Object.prototype.toString.call(e)}t||(t=Object.prototype.toString.call(e))}else t=String(e);return Ye(t,je)}function Je(e){const{frames:t,headerType:i}=function(e){const t=[];let i="";if(!e||"string"!=typeof e)return{frames:t,headerType:i};const n=e.split(/\r?\n/);for(let s=0;s<n.length;s++){const e=n[s];if(!e||e.length>1024)continue;const r=e.match(qe),o=r?null:e.match(Ge),a=r||o;if(a)t.push({fn:a[1]||"?",file:a[2],line:a[3],col:a[4]});else if(0===s){const t=e.indexOf(":");t>0&&(i=e.substring(0,t).trim())}if(t.length>=30)break}return{frames:t,headerType:i}}(e&&e.stack);let n=e&&e.name||i||"Error";return n=Ye(String(n),200),{$exception_level:"error",$exception_type:n,$exception_message:Ye(String(e&&e.message||""),je),$exception_frames:Ve(t)}}function Ze(e,t,i,n){let s=[];return t&&(s=[{platform:"web:javascript",filename:ze(t),function:"?",lineno:i||0,colno:n||0,abs_path:Ye(t,1e3)}]),{$exception_level:"error",$exception_type:"Error",$exception_message:Ye(String(e||""),je),$exception_frames:s}}class Qe{constructor(e=10,t=1,i=1e4){this.buckets=new Map,this.bucketSize=e,this.refillRate=t,this.refillInterval=i}allow(e){const t=Date.now();let i=this.buckets.get(e);if(i){if(t>i.lastRefill){const e=Math.floor((t-i.lastRefill)/this.refillInterval)*this.refillRate;e>0&&(i.tokens=Math.min(this.bucketSize,i.tokens+e),i.lastRefill+=e/this.refillRate*this.refillInterval)}}else i={tokens:this.bucketSize,lastRefill:t},this.buckets.set(e,i);return i.tokens>=1&&(i.tokens-=1,!0)}reset(){this.buckets.clear()}}const et=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleError=null,this.boundHandleRejection=null,this.rateLimiter=new Qe,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleError=this.handleError.bind(this),this.boundHandleRejection=this.handleRejection.bind(this),window.addEventListener("error",this.boundHandleError,!0),window.addEventListener("unhandledrejection",this.boundHandleRejection),this.isInitialized=!0)}handleError(e){try{const t=e.target;let i;if(t&&t!==window&&t.tagName)i=function(e){const t=e,i=(t.tagName||"").toLowerCase(),n=Ye(String(t.src||t.href||""),je);return{$exception_level:"error",$exception_type:"ResourceLoadError",$exception_message:`Failed to load <${i}>${n?` from ${n}`:""}`,$exception_frames:[]}}(t);else{const t=e;i=t.error instanceof Error?Je(t.error):Ze(String(t.message||""),t.filename,t.lineno,t.colno)}this.send(i)}catch(t){}}handleRejection(e){try{const t=e.reason;this.send(function(e){return e instanceof Error?Je(e):{$exception_level:"error",$exception_type:"UnhandledRejection",$exception_message:Ke(e),$exception_frames:[]}}(t))}catch(t){}}send(e){e.$exception_message&&this.rateLimiter.allow(e.$exception_type)&&me({event:T,properties:e},this.config)}destroy(){this.boundHandleError&&(window.removeEventListener("error",this.boundHandleError,!0),this.boundHandleError=null),this.boundHandleRejection&&(window.removeEventListener("unhandledrejection",this.boundHandleRejection),this.boundHandleRejection=null),this.rateLimiter.reset(),this.isInitialized=!1}};et.NAME="exception";let tt=et;const it="data-sw-exposure-event-name",nt="data-sw-exposure-config-",st=`[${it}]`,rt={visibleRatio:0,stayDuration:0,repeated:!0};function ot(e,t){const i={};if(!n(e))return i;const s=e;if(void 0!==s.visibleRatio){const e=Number(s.visibleRatio);!isNaN(e)&&e>=0&&e<=1?i.visibleRatio=e:t&&t("[exposure] parameter config.visibleRatio 非法(值域 0~1),已忽略:",s.visibleRatio)}if(void 0!==s.stayDuration){const e=Number(s.stayDuration);!isNaN(e)&&e>=0?i.stayDuration=e:t&&t("[exposure] parameter config.stayDuration 非法(须 >= 0),已忽略:",s.stayDuration)}if(void 0!==s.repeated){const e=s.repeated;!0===e||"true"===e?i.repeated=!0:!1===e||"false"===e?i.repeated=!1:t&&t("[exposure] parameter config.repeated 非法(须为布尔),已忽略:",e)}return i}function at(...e){const t={...rt};for(let i=0;i<e.length;i++){const s=e[i];if(!n(s))continue;const r=s;void 0!==r.visibleRatio&&(t.visibleRatio=r.visibleRatio),void 0!==r.stayDuration&&(t.stayDuration=r.stayDuration),void 0!==r.repeated&&(t.repeated=r.repeated)}return t}function ct(e){const t=(e.getAttribute(it)||"").trim();let i={},s={};const r=e.getAttribute("data-sw-exposure-option");if(r){const e=d(r);n(e)&&(n(e.config)&&(i=e.config),n(e.properties)&&(s=e.properties))}const a=e.getAttribute(nt+"visible-ratio");null!==a&&(i.visibleRatio=a);const c=e.getAttribute(nt+"stay-duration");null!==c&&(i.stayDuration=c);const u=e.getAttribute(nt+"repeated");null!==u&&(i.repeated=u);const l=e.attributes;for(let n=0;n<l.length;n++){const e=l[n],t=e.name;if(o(t)&&0===t.indexOf("data-sw-exposure-property-")){const i=t.substring(26);i&&(s[i]=e.value)}}return{eventName:t,config:ot(i),properties:s}}const ut=class{constructor({emitter:e,config:t,sdk:i}){this.isInitialized=!1,this.observers=new Map,this.records=new Map,this.mutationObserver=null,this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.boundHandleSpa=null,this.eventListeners=[],this.globalConfig={...rt},this.log=function(){},this.emitter=e,this.config=t,this.sdk=i}init(){this.isInitialized||(function(){try{return"undefined"!=typeof window&&"IntersectionObserver"in window&&"MutationObserver"in window}catch(e){return!1}}()?(this.log=!0==(!0===this.config.debug)&&"undefined"!=typeof console&&console.log?function(...e){console.log("[SensorsWave][exposure]",...e)}:function(){},this.globalConfig=at(this.globalConfig,ot(this.config.exposureConfig,this.log)),this.boundHandleIntersection=this.handleIntersection.bind(this),this.boundHandleMutation=this.handleMutation.bind(this),this.boundHandleVisibility=this.handleVisibility.bind(this),"loading"===document.readyState?(this.boundHandleReady=()=>{this.scanDocument(),this.observeMutations()},document.addEventListener("DOMContentLoaded",this.boundHandleReady),this.eventListeners.push({target:document,event:"DOMContentLoaded",handler:this.boundHandleReady})):(this.scanDocument(),this.observeMutations()),!0===this.config.isSinglePageApp&&(this.boundHandleSpa=e=>{this.handleSpaSwitch(e)},this.emitter.on(O,this.boundHandleSpa)),document.addEventListener("visibilitychange",this.boundHandleVisibility),this.eventListeners.push({target:document,event:"visibilitychange",handler:this.boundHandleVisibility}),!0===document.hidden&&this.stop(),this.isInitialized=!0):console.warn("[SensorsWave][exposure] 当前浏览器不支持 IntersectionObserver / MutationObserver,曝光采集未初始化"))}addExposureView(e,t){this.isInitialized?l(e)?n(t)&&o(t.eventName)&&t.eventName.trim()?this.addOrUpdateWatchEle(e,{eventName:t.eventName.trim(),config:n(t.config)?ot(t.config,this.log):void 0,properties:n(t.properties)?{...t.properties}:{},listener:n(t.listener)?{...t.listener}:{}},"api"):this.log("addExposureView parameter option.eventName 缺失:",t):this.log("addExposureView parameter element 非法:",e):this.log("曝光插件未初始化(enableExposureTrack 未开启或浏览器不支持)")}removeExposureView(e){this.isInitialized?l(e)?this.removeWatchEle(e):this.log("removeExposureView parameter element 非法:",e):this.log("曝光插件未初始化")}scanDocument(e){try{const t=e||document;if(!t.querySelectorAll)return;const i=t.querySelectorAll(st);for(let e=0;e<i.length;e++){const t=i[e];this.addOrUpdateWatchEle(t,ct(t),"attr")}}catch(t){}}addOrUpdateWatchEle(e,t,i){if(!e||!l(e))return void this.log("parameter element error:",e);if(!o(t.eventName)||!t.eventName.trim())return void this.log("parameter option.eventName error:",t);const n=this.records.get(e);if(n&&"api"===n.source&&"attr"===i)return void this.log("声明式属性变更被忽略:元素已由 addExposureView 注册",e);const s=at(this.globalConfig,n&&n.config,t.config);if(n&&n.config.visibleRatio===s.visibleRatio)return n.eventName=t.eventName,n.source=i,n.config=s,n.properties={...t.properties||{}},n.listener=t.listener||{},void(n.hasSent=!1);n&&this.removeWatchEle(e);const r={ele:e,eventName:t.eventName,source:i,config:s,properties:{...t.properties||{}},listener:t.listener||{},timer:null,hasSent:!1};this.records.set(e,r),this.getIntersection(s.visibleRatio).observe(e)}getIntersection(e){let t=this.observers.get(e);return!t&&this.boundHandleIntersection&&(t=new IntersectionObserver(this.boundHandleIntersection,{threshold:e}),this.observers.set(e,t)),t}removeWatchEle(e){const t=this.records.get(e);if(!t)return;const i=this.observers.get(t.config.visibleRatio);i&&l(e)&&i.unobserve(e),t.timer&&(clearTimeout(t.timer),t.timer=null),this.records.delete(e)}handleIntersection(e){try{for(const t of e){const e=t.target,i=this.records.get(e);i&&(!0===t.isIntersecting&&t.intersectionRatio>=i.config.visibleRatio?!0!==document.hidden&&(i.timer&&clearTimeout(i.timer),i.timer=setTimeout(()=>{this.fireExposure(e)},1e3*i.config.stayDuration)):i.timer&&(clearTimeout(i.timer),i.timer=null))}}catch(t){}}fireExposure(e){try{const i=this.records.get(e);if(i&&(i.timer=null),!i||i.hasSent)return;let n={width:0,height:0};try{n=e.getBoundingClientRect()}catch(t){}if(!n.width||!n.height)return;if(!e.isConnected)return void this.removeWatchEle(e);if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;const r={...Pe(e),...i.properties},{shouldExpose:o,didExpose:a}=i.listener||{};if(o&&s(o))try{if(!1===o(e,r))return}catch(t){return}if(me({event:i.eventName,properties:r},this.config),i.hasSent=!0,i.config.repeated&&(i.hasSent=!1),a&&s(a))try{a(e,r)}catch(t){}}catch(t){}}observeMutations(){!this.mutationObserver&&this.boundHandleMutation&&(this.mutationObserver=new MutationObserver(this.boundHandleMutation),this.mutationObserver.observe(document.body,{attributes:!0,childList:!0,subtree:!0}))}handleMutation(e){try{for(const t of e)if("childList"===t.type){if(t.removedNodes.length>0)for(const e of Array.from(t.removedNodes)){if(1!==e.nodeType)continue;this.removeWatchEle(e);const t=e.querySelectorAll(st);for(let e=0;e<t.length;e++)this.removeWatchEle(t[e])}if(t.addedNodes.length>0)for(const e of Array.from(t.addedNodes))1===e.nodeType&&(e.hasAttribute(it)&&this.addOrUpdateWatchEle(e,ct(e),"attr"),this.scanDocument(e))}else"attributes"===t.type&&this.handleAttrChange(t)}catch(t){}}handleAttrChange(e){const t=e.attributeName;if(!t||0!==t.indexOf("data-sw-exposure"))return;const i=e.target;t!==it||(i.getAttribute(t)||"").trim()?(i.getAttribute(it)||"").trim()&&this.addOrUpdateWatchEle(i,ct(i),"attr"):this.removeWatchEle(i)}handleSpaSwitch(e){try{if(e===location.href)return;this.stop();for(const[e,t]of Array.from(this.records))"attr"===t.source&&this.records.delete(e);this.start(),this.scanDocument()}catch(t){}}stop(){for(const e of Array.from(this.records.values())){const t=this.observers.get(e.config.visibleRatio);t&&t.unobserve(e.ele),e.timer&&(clearTimeout(e.timer),e.timer=null)}}start(){for(const e of Array.from(this.records.values())){if(!e.ele.isConnected){this.records.delete(e.ele);continue}const t=this.observers.get(e.config.visibleRatio);t&&t.observe(e.ele)}}handleVisibility(){try{"visible"===document.visibilityState?this.start():this.stop()}catch(e){}}destroy(){this.observers.forEach(e=>{try{e.disconnect()}catch(t){}}),this.observers.clear(),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null);for(const e of Array.from(this.records.values()))e.timer&&(clearTimeout(e.timer),e.timer=null);this.records.clear(),this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.boundHandleSpa&&(this.emitter.off(O,this.boundHandleSpa),this.boundHandleSpa=null),this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.globalConfig={...rt},this.log=function(){},this.isInitialized=!1}};ut.NAME="exposure";let lt=ut;const ht=[],dt={debug:!1,sourceToken:"",apiHost:"",autoCapture:!0,isSinglePageApp:!1,crossSubdomainCookie:!0,enableAB:!1,abRefreshInterval:6e5,enableClickTrack:!1,enableExposureTrack:!1,batchSend:!1,enableErrorTrack:!1,enableCrashTrack:!1,optOutCapturing:!1,persistOptOut:!1};return new class{constructor(){this.__innerInited=!1,this.inited=!1,this.config={},this.eventEmitter=new e,this.pluginCore={},this.commonProps={},this.spaCleanup=null,this._optOutCapturing=!1,this.consentStorage=new we(!1),this._setupAfterConsentDone=!1,this._postConsentInit=!1,S.instance=this}init(e,t={}){return this.inited?this:(S.instance=this,t.sourceToken=e,this.mergeConfig(t),this.consentStorage=new we(!0===this.config.persistOptOut),this._optOutCapturing?this.consentStorage.write(!0):!0===this.config.optOutCapturing?(this._optOutCapturing=!0,this.consentStorage.write(!0)):!0===this.consentStorage.read()&&(this._optOutCapturing=!0),this.eventEmitter.emit("init-param",this.config),this.__innerInited=!0,this._optOutCapturing?(Xe.captureAndStore(this.config.debug),this.eventEmitter.emit(y),this.inited=!0,this):(this.__setupAfterConsent(),this.eventEmitter.emit(y),this.inited=!0,this))}__setupAfterConsent(){if(this._setupAfterConsentDone)return;this._setupAfterConsentDone=!0;const e=this.config;ht.length=0,N.init(e.crossSubdomainCookie),e.anonId&&N.setAnonId(e.anonId),function(){if(window._swFailedRequestsInitialized)return;window._swFailedRequestsInitialized=!0;const e=S.instance;e&&"function"==typeof e.hasOptedOutCapturing&&e.hasOptedOutCapturing()||e&&!0===e._postConsentInit||function(){const e=te.getAll();if(0!==e.length)for(let t=0,i=e.length;t<i;t+=10){const i=e.slice(t,t+10),n=[],s=[];i.forEach(e=>{Array.isArray(e.data)?n.push(...e.data):n.push(e.data),s.push(e.id)});const r=i[i.length-1],o=r.url,a=r.headers;L({url:o,method:"POST",data:n,headers:a,callback:e=>{200!==e.statusCode?(console.error("Failed to send batch stored requests:",e),P(e.statusCode)||s.forEach(e=>{te.dequeue(e)})):s.forEach(e=>{te.dequeue(e)})}})}}()}(),ht.push(Xe),e.autoCapture&&this.autoTrack(),e.enableAB&&ht.push(Be),e.enableClickTrack&&ht.push(Fe),e.enableCrashTrack&&e.debug&&console.warn("[SensorsWave] enableCrashTrack 仅在 app 宿主环境生效,当前 Web 环境不采集 crash"),e.enableErrorTrack&&ht.push(tt),e.enableExposureTrack&&ht.push(lt),this.pluginCore=new ye({plugins:ht,emitter:this.eventEmitter,config:e,sdk:this}),this.spaCleanup=function(e){let t=location.href;const i=window.history.pushState,n=window.history.replaceState,r=function(){e(t),t=location.href};return s(window.history.pushState)&&(window.history.pushState=function(...n){i.apply(window.history,n),e(t),t=location.href}),s(window.history.replaceState)&&(window.history.replaceState=function(...i){n.apply(window.history,i),e(t),t=location.href}),window.addEventListener("popstate",r),function(){s(window.history.pushState)&&(window.history.pushState=i),s(window.history.replaceState)&&(window.history.replaceState=n),window.removeEventListener("popstate",r)}}(e=>{this.eventEmitter.emit(O,e)})}mergeConfig(e){this.config={...dt,...e}}__canCapture(){return this.inited&&!this._optOutCapturing}track(e){this.__canCapture()&&function(e,t){if(!se())return;if(!re())return;const i={...e};i.time||(i.time=Date.now()),i.login_id||(i.login_id=N.getLoginId()),i.anon_id||(i.anon_id=N.getAnonId()),i.trace_id||(i.trace_id=N.getTraceId()),i.properties={...ee(),...ge(N.getCommonProps()),...i.properties};const n=ue(t),s=he(t),r=!1!==t.batchSend&&ae();if(!r)return de(n,{data:[i],headers:s});te.enqueue(n,[i],s),r.add()}(e,this.config)}trackEvent(e,t){this.__canCapture()&&me({event:e,properties:t},this.config)}trackException(e,t){if(!this.__canCapture())return;const i={...t||{},...e instanceof Error?Je(e):Ze(String(e))};me({event:T,properties:i},this.config)}addExposureView(e,t){if(!this.__canCapture())return;const i=this.pluginCore.getPlugin(lt.NAME);i?i.addExposureView(e,t):console.warn("[SensorsWave] addExposureView 需在 init 时配置 enableExposureTrack: true")}removeExposureView(e){if(!this.__canCapture())return;const t=this.pluginCore.getPlugin(lt.NAME);t&&t.removeExposureView(e)}autoTrack(){ht.push(Ae,Ne,Te)}profileSet(e){this.__canCapture()&&Ee({userProps:{$set:e},opts:this.config})}profileSetOnce(e){this.__canCapture()&&Ee({userProps:{$set_once:e},opts:this.config})}profileIncrement(e){this.__canCapture()&&Ee({userProps:{$increment:e},opts:this.config})}profileAppend(e){this.__canCapture()&&Ee({userProps:{$append:e},opts:this.config})}profileUnion(e){this.__canCapture()&&Ee({userProps:{$union:e},opts:this.config})}profileUnset(e){if(!this.__canCapture())return;const t={};r(e)?e.forEach(function(e){t[e]=null}):t[e]=null,Ee({userProps:{$unset:t},opts:this.config})}profileDelete(){this.__canCapture()&&Ee({userProps:{$delete:!0},opts:this.config})}registerCommonProperties(e){if(!n(e))return console.warn("Commmon Properties must be an object!");this.commonProps=e,N.setCommonProps(this.commonProps)}clearCommonProperties(e){if(!r(e))return console.warn("Commmon Properties to be cleared must be an array!");e.forEach(e=>{delete this.commonProps[e]}),N.setCommonProps(this.commonProps)}identify(e){this.__canCapture()&&(N.setLoginId(e),function(e){if(!se())return;if(!re())return;const t=N.getLoginId(),i=N.getAnonId();if(!t||!i)return;const n={time:Date.now(),trace_id:N.getTraceId(),event:"$Identify",login_id:t,anon_id:i,properties:fe()},s=ue(e),r=he(e),o=ae();if(!o)return de(s,{data:[n],headers:r});te.enqueue(s,[n],r),o.add()}(this.config))}setLoginId(e){this.__canCapture()&&N.setLoginId(e)}getAnonId(){return this.__canCapture()?N.getAnonId():""}setAnonId(e){this.__canCapture()&&N.setAnonId(e)}getLoginId(){return this.__canCapture()?N.getLoginId():""}reset(e=!1){this.__canCapture()&&(N.clearLoginId(),e&&N.resetAnonId())}checkFeatureGate(e){if(!this.__canCapture())return Promise.resolve(!1);const t=this.pluginCore.getPlugin(Be.NAME);return this.config.enableAB&&t?t.checkFeatureGate(e):Promise.reject("AB is disabled")}getExperiment(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Be.NAME);return this.config.enableAB&&t?t.getExperiment(e):Promise.reject("AB is disabled")}getFeatureConfig(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Be.NAME);return this.config.enableAB&&t?t.getFeatureConfig(e):Promise.reject("AB is disabled")}optOutCapturing(){this._optOutCapturing=!0,this.consentStorage.write(!0),oe&&oe.pause()}optInCapturing(){if(this._optOutCapturing=!1,this.consentStorage.write(!1),oe&&oe.resume(),this.inited&&!this._setupAfterConsentDone){this._postConsentInit=!0;try{this.__setupAfterConsent(),this.eventEmitter.emit(y)}finally{this._postConsentInit=!1}}}hasOptedOutCapturing(){return this._optOutCapturing}destroy(){oe&&(oe.destroy(),oe=null),"undefined"!=typeof window&&(window._swFailedRequestsInitialized=!1),this.inited=!1,this.__innerInited=!1,this.spaCleanup&&"function"==typeof this.spaCleanup&&(this.spaCleanup(),this.spaCleanup=null),this.pluginCore&&"function"==typeof this.pluginCore.destroy&&this.pluginCore.destroy(),this.pluginCore={},this.eventEmitter&&this.eventEmitter.removeAllListeners(),this.consentStorage=new we(!0===this.config?.persistOptOut),this._optOutCapturing=!1,this._setupAfterConsentDone=!1,this._postConsentInit=!1,S.instance===this&&(S.instance=null)}}});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SensorsWave=t()}(this,function(){"use strict";class e{constructor(){this.listeners={}}on(e,t,i=!1){if(e&&t){if(!s(t))throw new Error("listener must be a function");this.listeners[e]=this.listeners[e]||[],this.listeners[e].push({listener:t,once:i})}}off(e,t){const i=this.listeners[e];if(!i?.length)return;"number"==typeof t&&i.splice(t,1);const n=i.findIndex(e=>e.listener===t);-1!==n&&i.splice(n,1)}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((i,n)=>{i.listener.call(this,...t),i.listener.once&&this.off(e,n)})}once(e,t){this.on(e,t,!0)}removeAllListeners(e){e?this.listeners[e]=[]:this.listeners={}}}const t={get:function(e){const t=e+"=",i=document.cookie.split(";");for(let n=0,s=i.length;n<s;n++){let e=i[n];for(;" "==e.charAt(0);)e=e.substring(1,e.length);if(0==e.indexOf(t))return h(e.substring(t.length,e.length))}return null},set:function({name:e,value:t,expires:i,samesite:n,secure:s,domain:r}){let o="",a="",c="",u="";if(0!==(i=null==i||void 0===i?365:i)){const e=new Date;"string"==typeof i?e.setTime(e.getTime()+1e3*Number(i.slice(0,-1))):e.setTime(e.getTime()+24*i*60*60*1e3),o="; expires="+e.toUTCString()}function l(e){return e?e.replace(/\r\n/g,""):""}n&&(c="; SameSite="+n),s&&(a="; secure");const h=l(e),d=l(t),p=l(r);p&&(u="; domain="+p),h&&d&&(document.cookie=h+"="+encodeURIComponent(d)+o+"; path=/"+u+c+a)},remove:function(e){const t=e?e.replace(/\r\n/g,""):"";t&&(document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")},isSupport:function({samesite:e,secure:t}={}){if(!navigator.cookieEnabled)return!1;const i="sensorswave_cookie_support_test";return this.set({name:i,value:"1",samesite:e,secure:t}),"1"===this.get(i)&&(this.remove(i),!0)}},i=Object.prototype.toString;function n(e){return"[object Object]"===i.call(e)}function s(e){const t=i.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t}function r(e){return"[object Array]"==i.call(e)}function o(e){return"[object String]"==i.call(e)}function a(e){return void 0===e}const c=Object.prototype.hasOwnProperty;function u(e){if(n(e)){for(let t in e)if(c.call(e,t))return!1;return!0}return!1}function l(e){return!(!e||1!==e.nodeType)}function h(e){let t=e;try{t=decodeURIComponent(e)}catch(i){t=e}return t}function d(e){try{return JSON.parse(e)}catch(t){return""}}const p=function(){let e=Date.now();return function(t){return Math.ceil((e=(9301*e+49297)%233280,e/233280*t))}}();function g(){if("function"==typeof Uint32Array){let e;if("undefined"!=typeof crypto&&(e=crypto),e&&n(e)&&e.getRandomValues)return e.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32)}return p(1e19)/1e19}const f=function(){function e(e){return("0".repeat(e)+Date.now().toString(16)).slice(-e)}return function(){let t=String(screen.height*screen.width);t=t&&/\d{4,}/.test(t)?t.slice(-4):String(31242*g()).replace(".","").slice(0,4);return e(8)+"-"+g().toString(16).replace(".","").slice(-4)+"-"+function(){const e=navigator.userAgent;let t,i=[],n=0;function s(e,t){let n=0;for(let s=0;s<t.length;s++)n|=i[s]<<8*s;return(e^n)>>>0}for(let r=0;r<e.length;r++)t=e.charCodeAt(r),i.unshift(255&t),i.length>=4&&(n=s(n,i),i=[]);return i.length>0&&(n=s(n,i)),("0000"+n.toString(16)).slice(-4)}()+"-"+t+"-"+e(12)||(String(g())+String(g())+String(g())).slice(2,15)}}();function m(e,t){t&&"string"==typeof t||(t="");let i=null;try{i=new URL(e).hostname}catch(n){}return i||t}function E(e){let t=[];try{t=atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})}catch(i){t=[]}try{return decodeURIComponent(t.join(""))}catch(i){return t.join("")}}function _(e){let t="";try{t=btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}))}catch(i){t=e}return t}const b={get:function(e){return window.localStorage.getItem(e)},parse:function(e){let t;try{t=JSON.parse(b.get(e))||null}catch(i){console.warn(i)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(i){console.warn(i)}},remove:function(e){window.localStorage.removeItem(e)},isSupport:function(){let e=!0;try{const t="__local_store_support__",i="testIsSupportStorage";b.set(t,i),b.get(t)!==i&&(e=!1),b.remove(t)}catch(t){e=!1}return e}};function v(e){return e.trim()}function I(e){if(!e||"string"!=typeof e)return"";try{return new URL(e,window.location.origin).pathname}catch(t){return""}}const w={},S="1.6.0",y="init-ready",O="spa-switch",A="ff-ready",R="$PageLeave",T="$Exception";var C=(e=>(e[e.FEATURE_GATE=1]="FEATURE_GATE",e[e.FEATURE_CONFIG=2]="FEATURE_CONFIG",e[e.EXPERIMENT=3]="EXPERIMENT",e))(C||{});const N={crossSubdomain:!1,requests:[],_sessionState:{},_abData:[],_trace_id:"",commonProps:{},_state:{anon_id:"",login_id:"",identities:{}},getIdentityCookieID(){return this._state.identities?.$identity_cookie_id||""},getCommonProps:function(){return this.commonProps||{}},setCommonProps:function(e){this.commonProps=e},getAnonId(){return this._state.anon_id||this.getIdentityCookieID()||f()},getLoginId(){return this._state.login_id},getTraceId(){return this._trace_id||f()},set:function(e,t){this._state[e]=t,this.save()},getCookieName:function(){return"sensorswave2025jssdkcross"},getABLSName:function(){return"sensorswave2025jssdkablatest"},save:function(){let e=JSON.parse(JSON.stringify(this._state));e.identities&&(e.identities=_(JSON.stringify(e.identities)));const i=JSON.stringify(e);t.set({name:this.getCookieName(),value:i,expires:365})},init:function(e){let i,s;this.crossSubdomain=e,t.isSupport()&&(i=t.get(this.getCookieName()),s=d(i)),N._state={...s||{}},N._state.identities&&(N._state.identities=d(E(N._state.identities))),N._state.identities&&n(N._state.identities)&&!u(N._state.identities)||(N._state.identities={$identity_cookie_id:f()}),N.save()},setLoginId(e){"number"==typeof e&&(e=String(e)),void 0!==e&&e&&(N.set("login_id",e),N.save())},clearLoginId(){this._state.login_id="",this.save()},resetAnonId(){this._state.anon_id="",this._state.identities={$identity_cookie_id:f()},this.save()},setAnonId(e){"number"==typeof e&&(e=String(e)),"string"==typeof e&&e?(N.set("anon_id",e),N.save()):console.warn("[SensorsWave store] Invalid anonId, ignored:",e)},saveABData(e){if(!e||u(e))return;this._abData=e;let t=JSON.parse(JSON.stringify(this._abData));t=_(JSON.stringify(t));try{localStorage.setItem(this.getABLSName(),JSON.stringify({time:Date.now(),data:t,anon_id:this.getAnonId(),login_id:this.getLoginId()}))}catch(i){console.warn("Failed to save abdata to localStorage",i)}},getABData(e=6e5){try{let t=localStorage.getItem(this.getABLSName());if(t){const{time:i,data:n,login_id:s,anon_id:r}=d(t)||{};if(i&&n&&Date.now()-i<e&&r===this.getAnonId()&&(!s||s===this.getLoginId())){const e=d(E(n));return this._abData=Array.isArray(e)?e:[],this._abData}localStorage.removeItem(this.getABLSName())}}catch(t){this._abData=[]}return this._abData||[]}};function P(e){return!(e>=400&&e<500)||408===e||429===e}function k(e){var t;if(e.data)return{contentType:"application/json",body:(t=e.data,JSON.stringify(t,(e,t)=>"bigint"==typeof t?t.toString():t,undefined))}}const x=[];function L(e){const t={...e};t.timeout=t.timeout||6e4;const i=t.transport??"fetch",n=x.find(e=>e.transport===i)?.method??x[0]?.method;if(!n)throw new Error("No available transport method for HTTP request");n(t)}function M(e){return o(e=e||document.referrer)&&(e=h(e=e.trim()))||""}function $(e){const t=m(e=e||M());if(!t)return"";const i={baidu:[/^.*\.baidu\.com$/],bing:[/^.*\.bing\.com$/],google:[/^www\.google\.com$/,/^www\.google\.com\.[a-z]{2}$/,/^www\.google\.[a-z]{2}$/],sm:[/^m\.sm\.cn$/],so:[/^.+\.so\.com$/],sogou:[/^.*\.sogou\.com$/],yahoo:[/^.*\.yahoo\.com$/],duckduckgo:[/^.*\.duckduckgo\.com$/]};for(let n of Object.keys(i)){let e=i[n];for(let i=0,s=e.length;i<s;i++)if(e[i].test(t))return n}return""}function D(e,t){return-1!==e.indexOf(t)}"function"==typeof fetch&&x.push({transport:"fetch",method:function(e){if("undefined"==typeof fetch)return void console.error("fetch API is not available");const t=k(e),i=new Headers;e.headers&&Object.keys(e.headers).forEach(t=>{i.append(t,e.headers[t])}),t?.contentType&&i.append("Content-Type",t.contentType),fetch(e.url,{method:e.method||"GET",headers:i,body:t?.body}).then(t=>t.text().then(i=>{const n={statusCode:t.status,text:i};if(200===t.status)try{n.json=JSON.parse(i)}catch(s){console.error("Failed to parse response:",s)}e.callback?.(n)})).catch(t=>{console.error("Request failed:",t),e.callback?.({statusCode:0,text:String(t)})})}}),"undefined"!=typeof XMLHttpRequest&&x.push({transport:"XHR",method:function(e){if("undefined"==typeof XMLHttpRequest)return void console.error("XMLHttpRequest is not available");const t=new XMLHttpRequest;t.open(e.method||"GET",e.url,!0);const i=k(e);e.headers&&Object.keys(e.headers).forEach(i=>{t.setRequestHeader(i,e.headers[i])}),i?.contentType&&t.setRequestHeader("Content-Type",i.contentType),t.timeout=e.timeout||6e4,t.withCredentials=!0,t.onreadystatechange=()=>{if(4===t.readyState){const n={statusCode:t.status,text:t.responseText};if(200===t.status)try{n.json=JSON.parse(t.responseText)}catch(i){console.error("Failed to parse JSON response:",i)}e.callback?.(n)}},t.send(i?.body)}});const F={FACEBOOK:"Facebook",MOBILE:"Mobile",IOS:"iOS",ANDROID:"Android",TABLET:"Tablet",ANDROID_TABLET:"Android Tablet",IPAD:"iPad",APPLE:"Apple",APPLE_WATCH:"Apple Watch",SAFARI:"Safari",BLACKBERRY:"BlackBerry",SAMSUNG_BROWSER:"SamsungBrowser",SAMSUNG_INTERNET:"Samsung Internet",CHROME:"Chrome",CHROME_OS:"Chrome OS",CHROME_IOS:"Chrome iOS",INTERNET_EXPLORER:"Internet Explorer",INTERNET_EXPLORER_MOBILE:"Internet Explorer Mobile",OPERA:"Opera",OPERA_MINI:"Opera Mini",EDGE:"Edge",MICROSOFT_EDGE:"Microsoft Edge",FIREFOX:"Firefox",FIREFOX_IOS:"Firefox iOS",NINTENDO:"Nintendo",PLAYSTATION:"PlayStation",XBOX:"Xbox",ANDROID_MOBILE:"Android Mobile",MOBILE_SAFARI:"Mobile Safari",WINDOWS:"Windows",WINDOWS_PHONE:"Windows Phone",NOKIA:"Nokia",OUYA:"Ouya",GENERIC_MOBILE:"Generic mobile",GENERIC_TABLET:"Generic tablet",KONQUEROR:"Konqueror",UC_BROWSER:"UC Browser",HUAWEI:"Huawei",XIAOMI:"Xiaomi",OPPO:"OPPO",VIVO:"vivo"},B="(\\d+(\\.\\d+)?)",H=new RegExp("Version/"+B),U=new RegExp(F.XBOX,"i"),W=new RegExp(F.PLAYSTATION+" \\w+","i"),j=new RegExp(F.NINTENDO+" \\w+","i"),X=new RegExp(F.BLACKBERRY+"|PlayBook|BB10","i"),q=new RegExp("(HUAWEI|honor|HONOR)","i"),G=new RegExp("(Xiaomi|Redmi)","i"),z=new RegExp("(OPPO|realme)","i"),V=new RegExp("(vivo|IQOO)","i"),Y={"NT3.51":"NT 3.11","NT4.0":"NT 4.0","5.0":"2000",5.1:"XP",5.2:"XP","6.0":"Vista",6.1:"7",6.2:"8",6.3:"8.1",6.4:"10","10.0":"10"};function J(e,t){return t=t||"",D(e," OPR/")&&D(e,"Mini")?F.OPERA_MINI:D(e," OPR/")?F.OPERA:X.test(e)?F.BLACKBERRY:D(e,"IE"+F.MOBILE)||D(e,"WPDesktop")?F.INTERNET_EXPLORER_MOBILE:D(e,F.SAMSUNG_BROWSER)?F.SAMSUNG_INTERNET:D(e,F.EDGE)||D(e,"Edg/")?F.MICROSOFT_EDGE:D(e,"FBIOS")?F.FACEBOOK+" "+F.MOBILE:D(e,"UCWEB")||D(e,"UCBrowser")?F.UC_BROWSER:D(e,"CriOS")?F.CHROME_IOS:D(e,"CrMo")||D(e,F.CHROME)?F.CHROME:D(e,F.ANDROID)&&D(e,F.SAFARI)?F.ANDROID_MOBILE:D(e,"FxiOS")?F.FIREFOX_IOS:D(e.toLowerCase(),F.KONQUEROR.toLowerCase())?F.KONQUEROR:function(e,t){return t&&D(t,F.APPLE)||D(i=e,F.SAFARI)&&!D(i,F.CHROME)&&!D(i,F.ANDROID);var i}(e,t)?D(e,F.MOBILE)?F.MOBILE_SAFARI:F.SAFARI:D(e,F.FIREFOX)?F.FIREFOX:D(e,"MSIE")||D(e,"Trident/")?F.INTERNET_EXPLORER:D(e,"Gecko")?F.FIREFOX:""}const K={[F.INTERNET_EXPLORER_MOBILE]:[new RegExp("rv:"+B)],[F.MICROSOFT_EDGE]:[new RegExp(F.EDGE+"?\\/"+B)],[F.CHROME]:[new RegExp("("+F.CHROME+"|CrMo)\\/"+B)],[F.CHROME_IOS]:[new RegExp("CriOS\\/"+B)],[F.UC_BROWSER]:[new RegExp("(UCBrowser|UCWEB)\\/"+B)],[F.SAFARI]:[H],[F.MOBILE_SAFARI]:[H],[F.OPERA]:[new RegExp("("+F.OPERA+"|OPR)\\/"+B)],[F.FIREFOX]:[new RegExp(F.FIREFOX+"\\/"+B)],[F.FIREFOX_IOS]:[new RegExp("FxiOS\\/"+B)],[F.KONQUEROR]:[new RegExp("Konqueror[:/]?"+B,"i")],[F.BLACKBERRY]:[new RegExp(F.BLACKBERRY+" "+B),H],[F.ANDROID_MOBILE]:[new RegExp("android\\s"+B,"i")],[F.SAMSUNG_INTERNET]:[new RegExp(F.SAMSUNG_BROWSER+"\\/"+B)],[F.INTERNET_EXPLORER]:[new RegExp("(rv:|MSIE )"+B)],Mozilla:[new RegExp("rv:"+B)]};function Z(e,t){const i=J(e,t),n=K[i];if(a(n))return null;for(let s=0;s<n.length;s++){const t=n[s],i=e.match(t);if(i)return parseFloat(i[i.length-2])}return null}const Q=[[new RegExp(F.XBOX+"; "+F.XBOX+" (.*?)[);]","i"),e=>[F.XBOX,e&&e[1]||""]],[new RegExp(F.NINTENDO,"i"),[F.NINTENDO,""]],[new RegExp(F.PLAYSTATION,"i"),[F.PLAYSTATION,""]],[X,[F.BLACKBERRY,""]],[new RegExp(F.WINDOWS,"i"),(e,t)=>{if(/Phone/.test(t)||/WPDesktop/.test(t))return[F.WINDOWS_PHONE,""];if(new RegExp(F.MOBILE).test(t)&&!/IEMobile\b/.test(t))return[F.WINDOWS+" "+F.MOBILE,""];const i=/Windows NT ([0-9.]+)/i.exec(t);if(i&&i[1]){const e=i[1];let n=Y[e]||"";return/arm/i.test(t)&&(n="RT"),[F.WINDOWS,n]}return[F.WINDOWS,""]}],[/((iPhone|iPad|iPod).*?OS (\d+)_(\d+)_?(\d+)?|iPhone)/,e=>{if(e&&e[3]){const t=[e[3],e[4],e[5]||"0"];return[F.IOS,t.join(".")]}return[F.IOS,""]}],[/(watch.*\/(\d+\.\d+\.\d+)|watch os,(\d+\.\d+),)/i,e=>{let t="";return e&&e.length>=3&&(t=a(e[2])?e[3]:e[2]),["watchOS",t]}],[new RegExp("("+F.ANDROID+" (\\d+)\\.(\\d+)\\.?(\\d+)?|"+F.ANDROID+")","i"),e=>{if(e&&e[2]){const t=[e[2],e[3],e[4]||"0"];return[F.ANDROID,t.join(".")]}return[F.ANDROID,""]}],[/Mac OS X (\d+)[_.](\d+)[_.]?(\d+)?/i,e=>{const t=["Mac OS X",""];if(e&&e[1]){const i=[e[1],e[2],e[3]||"0"];t[1]=i.join(".")}return t}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[F.CHROME_OS,""]],[/Linux|debian/i,["Linux",""]]];function ee(){const e=window.innerHeight||document.documentElement.clientHeight||document.body&&document.body.clientHeight||0,t=window.innerWidth||document.documentElement.clientWidth||document.body&&document.body.clientWidth||0,i=navigator.userAgent,n=function(e){for(let t=0;t<Q.length;t++){const[i,n]=Q[t],s=i.exec(e),r=s&&("function"==typeof n?n(s,e):n);if(r)return r}return["",""]}(i)||["",""];return{$browser:J(i),$browser_version:Z(i),$url:location?.href.substring(0,1e3),$host:location?.host,$viewport_height:e,$viewport_width:t,$lib:"webjs",$lib_version:S,$search_engine:$(),$referrer:M(),$referrer_host:m(r=r||M()),$title:document.title,$language:navigator.language,$model:(s=i,(j.test(s)?F.NINTENDO:W.test(s)?F.PLAYSTATION:U.test(s)?F.XBOX:new RegExp(F.OUYA,"i").test(s)?F.OUYA:new RegExp("("+F.WINDOWS_PHONE+"|WPDesktop)","i").test(s)?F.WINDOWS_PHONE:/iPad/.test(s)?F.IPAD:/iPod/.test(s)?"iPod Touch":/iPhone/.test(s)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(s)?F.APPLE_WATCH:X.test(s)?F.BLACKBERRY:/(kobo)\s(ereader|touch)/i.test(s)?"Kobo":new RegExp(F.NOKIA,"i").test(s)?F.NOKIA:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(s)||/(kf[a-z]+)( bui|\)).+silk\//i.test(s)?"Kindle Fire":q.test(s)?F.HUAWEI:G.test(s)?F.XIAOMI:z.test(s)?F.OPPO:V.test(s)?F.VIVO:/(Android|ZTE)/i.test(s)?!new RegExp(F.MOBILE).test(s)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(s)?/pixel[\daxl ]{1,6}/i.test(s)&&!/pixel c/i.test(s)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(s)||/lmy47v/i.test(s)&&!/QTAQZ3/i.test(s)?F.ANDROID:F.ANDROID_TABLET:F.ANDROID:new RegExp("(pda|"+F.MOBILE+")","i").test(s)?F.GENERIC_MOBILE:new RegExp(F.TABLET,"i").test(s)&&!new RegExp(F.TABLET+" pc","i").test(s)?F.GENERIC_TABLET:"")||""),$os:n?.[0]||"",$os_version:n?.[1]||"",$pathname:location?.pathname,$screen_height:Number(screen.height)||0,$screen_width:Number(screen.width)||0,$timezone_offset:60*-(new Date).getTimezoneOffset()};var s,r}const te=new class{constructor(){this.STORAGE_KEY="sensorswave_unsent_events",this.MAX_QUEUE_SIZE=200,this.MAX_RETRY_COUNT=1,this.MAX_AGE_MS=6048e5,this.queue=[],this.loadFromStorage(),this.cleanupExpiredItems()}loadFromStorage(){try{const e=localStorage.getItem(this.STORAGE_KEY);e&&(this.queue=d(e)||[])}catch(e){console.warn("Failed to load queue from localStorage:",e),this.queue=[]}}cleanupExpiredItems(){const e=Date.now(),t=this.queue.filter(t=>e-t.timestamp<this.MAX_AGE_MS);t.length!==this.queue.length&&(this.queue=t,this.saveToStorage())}saveToStorage(){try{this.cleanupExpiredItems(),this.queue.length>this.MAX_QUEUE_SIZE&&(this.queue=this.queue.slice(-this.MAX_QUEUE_SIZE)),localStorage.setItem(this.STORAGE_KEY,JSON.stringify(this.queue))}catch(e){console.warn("Failed to save queue to localStorage:",e)}}enqueue(e,t,i,n=this.MAX_RETRY_COUNT){try{const s={id:f(),url:e,data:t,headers:i,timestamp:Date.now(),retryCount:0,maxRetries:n};return this.queue.push(s),this.saveToStorage(),s.id}catch(s){return console.warn("Failed to enqueue request:",s),""}}dequeue(e){try{this.queue=this.queue.filter(t=>t.id!==e),this.saveToStorage()}catch(t){console.warn("Failed to dequeue request:",t)}}getAll(){try{return this.cleanupExpiredItems(),[...this.queue]}catch(e){return console.warn("Failed to get queue items:",e),[]}}incrementRetryCount(e){const t=this.queue.find(t=>t.id===e);return!(!t||t.retryCount>=t.maxRetries||(t.retryCount++,this.saveToStorage(),0))}clear(){this.queue=[];try{localStorage.removeItem(this.STORAGE_KEY)}catch(e){console.warn("Failed to clear queue from localStorage:",e)}}getItemById(e){return this.queue.find(t=>t.id===e)}};class ie{constructor(e={}){this.flushTimer=null,this.isFlushing=!1,this.paused=!1,this.destroyed=!1,this.config={maxBatchSize:e.maxBatchSize||20,flushInterval:e.flushInterval||5e3},this.startFlushTimer()}pause(){this.paused=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null)}resume(){this.paused&&(this.paused=!1,this.startFlushTimer())}isPaused(){return this.paused}add(){te.getAll().length>=this.config.maxBatchSize&&this.triggerFlush()}triggerFlush(){this.paused||this.isFlushing||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.isFlushing=!0,this.flush())}flush(){const e=te.getAll();if(0===e.length)return this.isFlushing=!1,void this.startFlushTimer();const t=e.slice(0,this.config.maxBatchSize),i=[],n=[];t.forEach(e=>{Array.isArray(e.data)?i.push(...e.data):i.push(e.data),n.push(e.id)});const s=t[t.length-1],r=s.url,o=s.headers;w.instance&&w.instance.config.debug&&console.log(JSON.stringify(i,null,2)),L({url:r,method:"POST",data:i,headers:o,callback:e=>{200===e.statusCode?n.forEach(e=>{te.dequeue(e)}):P(e.statusCode)?console.error("Failed to send batch events:",e):n.forEach(e=>{te.dequeue(e)}),this.isFlushing=!1,this.startFlushTimer()}})}startFlushTimer(){this.destroyed||(this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flushTimer=setInterval(()=>{te.getAll().length>0&&this.triggerFlush()},this.config.flushInterval))}destroy(){this.destroyed=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.paused||this.flush()}}let ne=null;const se="sensorswave2025jssdksession",re="$session_id";let oe=null;function ae(){const e=new Uint8Array(16);if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues)crypto.getRandomValues(e);else for(let r=6;r<16;r++)e[r]=Math.floor(256*Math.random());const t=new DataView(e.buffer),i=Date.now();t.setUint16(0,Math.floor(i/Math.pow(2,32))),t.setUint32(2,i%Math.pow(2,32)),e[6]=15&e[6]|112,e[8]=63&e[8]|128;const n=[];for(let r=0;r<16;r++)n.push(e[r].toString(16).padStart(2,"0"));const s=n.join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function ce(e){oe=e;try{t.set({name:se,value:JSON.stringify(e),expires:"1800s"})}catch(i){}}function ue(e=!1){const i=Date.now(),s=function(){let e=null;try{e=t.get(se)}catch(s){return oe}if(null==e)return oe;const i=d(e);return function(e){return!!(n(e)&&"string"==typeof e.session_id&&e.session_id&&"number"==typeof e.first_session_time&&Number.isFinite(e.first_session_time)&&"number"==typeof e.latest_session_time&&Number.isFinite(e.latest_session_time))}(i)?i:null}();if(!s||s.first_session_time>i||s.latest_session_time>i||i-s.first_session_time>432e5||i-s.latest_session_time>18e5){const e={session_id:ae(),first_session_time:i,latest_session_time:i};return ce(e),e.session_id}return e||ce({...s,latest_session_time:i}),s.session_id}function le(){const e=w.instance;return!(!e||!e.__innerInited)||(console.warn("[SensorsWave] SDK is not initialized. Please call init() first."),!1)}function he(){const e=w.instance;return!e||"function"!=typeof e.hasOptedOutCapturing||!e.hasOptedOutCapturing()}let de=null;function pe(){return b.isSupport()?(de||(ne||(ne=new ie({maxBatchSize:20,flushInterval:5e3})),de=ne),de):null}function ge(e,t,i){if(he())return L({url:e,method:"POST",data:t.data,headers:t.headers,callback:e=>{if(200!==e.statusCode){if(!P(e.statusCode))return void(i&&te.dequeue(i));if(i&&te.incrementRetryCount(i)){const e=te.getItemById(i);if(e){const t=Math.min(1e3*Math.pow(2,e.retryCount),3e4);setTimeout(()=>{ge(e.url,{data:e.data,headers:e.headers},e.id)},t)}}}else i&&te.dequeue(i),t.callback&&t.callback(e.json)}})}function fe(e){return`${e.apiHost}/in/track`}function me(e){return`${e.apiHost}/ab/evalall`}function Ee(e){return{"Content-Type":"application/json",SourceToken:e.sourceToken}}function _e(e,t,i){w.instance&&w.instance.config.debug&&console.log(JSON.stringify(t.data,null,2));const n=te.enqueue(e,t.data,t.headers);return ge(e,{...t,callback:void 0},n)}function be(){try{const e=sessionStorage.getItem("sensorswave_utm");if(!e)return{};const t=JSON.parse(e),i={};return Object.entries(t).forEach(([e,t])=>{null!=t&&""!==t&&(i[`$${e}`]=t)}),i}catch(e){return{}}}function ve(e){const t={};return Object.entries(e).forEach(([e,i])=>{if("function"==typeof i)try{const n=i();t[e]=n}catch(n){console.warn("[SensorsWave] Failed to resolve dynamic property:",e,n)}else t[e]=i}),t}function Ie(e={},t=!0){return{...t?ee():{},...ve(N.getCommonProps()),...e,[re]:ue()}}function we(e={},t=!0){const i=Ie(e,t),n=be();return Object.keys(n).length>0&&Object.assign(i,n),i}function Se(e,t,i=!0){if(!le())return;if(!he())return;const n={time:Date.now(),trace_id:N.getTraceId(),event:e.event,properties:we(e.properties,i)},s=be();Object.keys(s).length>0&&(n.user_properties||(n.user_properties={}),n.user_properties.$set||(n.user_properties.$set={}),Object.assign(n.user_properties.$set,s)),e.user_properties&&(e.user_properties.$set&&(n.user_properties=n.user_properties||{},n.user_properties.$set={...n.user_properties.$set||{},...e.user_properties.$set},delete e.user_properties.$set),n.user_properties={...n.user_properties,...e.user_properties});const r=N.getLoginId(),o=N.getAnonId();r&&(n.login_id=r),o&&(n.anon_id=o);const a=fe(t),c=Ee(t),u=!1!==t.batchSend&&pe();u?(te.enqueue(a,[n],c),u.add()):_e(a,{data:[n],headers:c})}function ye({userProps:e,opts:t}){if(!le())return;if(!he())return;const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return;const s={time:Date.now(),trace_id:N.getTraceId(),event:"$UserSet",login_id:i,anon_id:n,user_properties:e,properties:we()},r=fe(t),o=Ee(t),a=pe();if(!a)return _e(r,{data:[s],headers:o});te.enqueue(r,[s],o),a.add()}function Oe(e){return e.typ===C.FEATURE_GATE||e.typ===C.FEATURE_CONFIG?`$feature_${e.id}`:e.typ===C.EXPERIMENT?`$exp_${e.id}`:""}function Ae(e){const t=e.typ;return[C.FEATURE_GATE,C.EXPERIMENT,C.FEATURE_CONFIG].includes(t)?{[Oe(e)]:e.vid}:{}}function Re(e){const t=e.typ;return t===C.FEATURE_GATE||t===C.FEATURE_CONFIG?{$feature_key:e.key,$feature_variant:e.vid}:t===C.EXPERIMENT?{$exp_key:e.key,$exp_variant:e.vid}:{}}function Te({isUnset:e=!1,data:t,opts:i}){if(!le())return;if(!he())return;if(!t||u(t)||t.disable_impress)return;const n=N.getLoginId(),s=N.getAnonId();if(!n&&!s)return;const r=t.typ===C.EXPERIMENT?"$ExpImpress":"$FeatureImpress";let o={};return o=e?{$unset:{[Oe(t)]:null}}:{$set:{...Ae(t)}},Se({event:r,properties:Re(t),user_properties:o},i)}const Ce="sensorswave_opt_out";class Ne{constructor(e){this.persist=e}read(){if(this.persist)try{const e=b.get(Ce);return"0"===e||"1"!==e&&void 0}catch{return}}write(e){if(this.persist)try{b.set(Ce,e?"0":"1")}catch{}}}class Pe{constructor({plugins:e,emitter:t,config:i,sdk:n}){this.plugins=[],this.pluginInsMap={},this.emitter=t,this.config=i,this.sdk=n,this.registerBuiltInPlugins(e),this.created(),this.emitter.on(y,()=>{this.init()})}registerBuiltInPlugins(e){for(let t=0,i=e.length;t<i;t++)this.registerPlugin(e[t])}registerPlugin(e){this.plugins.push(e)}getPlugins(){return this.plugins}getPlugin(e){return this.pluginInsMap[e]}created(){for(let e=0,t=this.plugins.length;e<t;e++){const t=this.plugins[e];if(!t.NAME)throw new Error('Plugin should be defined with "NAME"');const i=new t({emitter:this.emitter,config:this.config,sdk:this.sdk});this.pluginInsMap[t.NAME]=i}}init(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.init&&t.init()}}destroy(){for(const e of Object.keys(this.pluginInsMap)){const t=this.pluginInsMap[e];t.destroy&&"function"==typeof t.destroy&&t.destroy()}this.pluginInsMap={},this.plugins=[]}}const ke=class{constructor({emitter:e,config:t,sdk:i}){this.boundSend=null,this.hashEvent=null,this.spaSwitchHandler=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;this.boundSend=()=>{Se({event:"$PageView",properties:{}},e)},this.sdk&&!0===this.sdk._postConsentInit||setTimeout(()=>{this.boundSend()},0),e.isSinglePageApp&&this.addSinglePageListener()}addSinglePageListener(){this.spaSwitchHandler=e=>{e!==location.href&&this.boundSend()},this.emitter.on(O,this.spaSwitchHandler)}destroy(){this.spaSwitchHandler&&(this.emitter.off(O,this.spaSwitchHandler),this.spaSwitchHandler=null),this.hashEvent&&this.boundSend&&(window.removeEventListener(this.hashEvent,this.boundSend),this.hashEvent=null),this.boundSend=null}};ke.NAME="pageview";let xe=ke;const Le=class{constructor({emitter:e,config:t,sdk:i}){this.startTime=Date.now(),this.pageShowStatus=!0,this.pageHiddenStatus=!1,this.timer=null,this.currentPageUrl=document.referrer,this.url=location.href,this.title=document.title||"",this.heartbeatIntervalTime=5e3,this.heartbeatIntervalTimer=null,this.pageId=null,this.storageName="sensorswavewebjssdkpageleave",this.maxDuration=432e3,this.eventListeners=[],this._skipFirstPageEnd=!1,this.emitter=e,this.config=t,this.sdk=i}__canCapture(){return!this.sdk||"function"!=typeof this.sdk.hasOptedOutCapturing||!this.sdk.hasOptedOutCapturing()}init(){this.pageId=Number(String(g()).slice(2,5)+String(g()).slice(2,4)+String(Date.now()).slice(-4)),this.addEventListener(),this.sdk&&!0===this.sdk._postConsentInit&&(this._skipFirstPageEnd=!0),!0===document.hidden?this.pageShowStatus=!1:this.addHeartBeatInterval()}log(e){console.log(e)}refreshPageEndTimer(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.timer=setTimeout(()=>{this.pageHiddenStatus=!1},5e3)}hiddenStatusHandler(){this.timer&&clearTimeout(this.timer),this.timer=null,this.pageHiddenStatus=!1}pageStartHandler(){this.startTime=Date.now(),1==!document.hidden?this.pageShowStatus=!0:this.pageShowStatus=!1,this.url=location.href,this.title=document.title,this._skipFirstPageEnd=!1}pageEndHandler(){if(!0===this.pageHiddenStatus)return;if(!this.__canCapture())return;const e=this.getPageLeaveProperties();!1===this.pageShowStatus&&delete e.$event_duration,this.pageShowStatus=!1,this.pageHiddenStatus=!0,Se({event:R,properties:e},this.config),this.refreshPageEndTimer(),this.delHeartBeatData()}addEventListener(){this.addPageStartListener(),this.addPageSwitchListener(),this.addSinglePageListener(),this.addPageEndListener()}addPageStartListener(){if("onpageshow"in window){const e=()=>{this.pageStartHandler(),this.hiddenStatusHandler()};window.addEventListener("pageshow",e),this.eventListeners.push({target:window,event:"pageshow",handler:e})}}addSinglePageListener(){this.config.isSinglePageApp&&this.emitter.on(O,e=>{e!==location.href&&(this.url=e,this.pageEndHandler(),this.stopHeartBeatInterval(),this.currentPageUrl=this.url,this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval())})}addPageEndListener(){["pagehide","beforeunload"].forEach(e=>{if(`on${e}`in window){const t=()=>{if(this._skipFirstPageEnd)return this._skipFirstPageEnd=!1,void this.stopHeartBeatInterval();this.pageEndHandler(),this.stopHeartBeatInterval()};window.addEventListener(e,t),this.eventListeners.push({target:window,event:e,handler:t})}})}addPageSwitchListener(){const e=()=>{"visible"===document.visibilityState?(this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval()):(this.url=location.href,this.title=document.title,this.stopHeartBeatInterval(),this.delHeartBeatData())};document.addEventListener("visibilitychange",e),this.eventListeners.push({target:document,event:"visibilitychange",handler:e})}addHeartBeatInterval(){b.isSupport()&&this.startHeartBeatInterval()}startHeartBeatInterval(){this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),this.sdk&&!0===this.sdk._postConsentInit&&!0===this._skipFirstPageEnd||(this.heartbeatIntervalTimer=setInterval(()=>{this.saveHeartBeatData()},this.heartbeatIntervalTime),this.saveHeartBeatData("is_first_heartbeat"),this.reissueHeartBeatData())}stopHeartBeatInterval(){this.heartbeatIntervalTimer&&clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null}saveHeartBeatData(e){if(!this.__canCapture())return;const t=this.getPageLeaveProperties();t.$time=Date.now(),"is_first_heartbeat"===e&&(t.$event_duration=3);const i={type:"track",event:R,properties:t,time:t.$time};i.heartbeat_interval_time=this.heartbeatIntervalTime,b.isSupport()&&b.set(`${this.storageName}-${this.pageId}`,JSON.stringify(i))}delHeartBeatData(e){b.isSupport()&&b.remove(e||`${this.storageName}-${this.pageId}`)}reissueHeartBeatData(){if(this.__canCapture())for(let e=window.localStorage.length-1;e>=0;e--){const t=window.localStorage.key(e);if(t&&t!==`${this.storageName}-${this.pageId}`&&0===t.indexOf(`${this.storageName}-`)){const e=b.parse(t);n(e)&&Date.now()-e.time>e.heartbeat_interval_time+5e3&&(delete e.heartbeat_interval_time,e._flush_time=(new Date).getTime(),Se({event:R,properties:e?.properties},this.config),this.delHeartBeatData(t))}}}getPageLeaveProperties(){let e=(Date.now()-this.startTime)/1e3;(isNaN(e)||e<0||e>this.maxDuration)&&(e=0),e=Number(e.toFixed(3));const t={$title:this.title,$url:this.url?.substring(0,1e3),$pathname:I(this.url)};return 0!==e&&(t.$event_duration=e),t}destroy(){this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}};Le.NAME="pageleave";let Me=Le;const $e=class{constructor({emitter:e,config:t,sdk:i}){this.eventSended=!1,this.emitter=e,this.config=t,this.sdk=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit)return;const e=()=>{let t=0;const i={};if(window.performance){t=function(){let e=0;if("function"==typeof performance.getEntriesByType){const t=performance.getEntriesByType("navigation");t.length>0&&(e=t[0].domContentLoadedEventEnd||0)}return e}();const e=function(){if(performance.getEntries&&"function"==typeof performance.getEntries){const e=performance.getEntries();let t=0;for(const i of e)"transferSize"in i&&(t+=i.transferSize);if("number"==typeof t&&t>=0&&t<10737418240)return Number((t/1024).toFixed(3))}}();e&&(i.$page_resource_size=e)}else console.warn("Performance API is not supported.");t>0&&!Number.isFinite(t)&&(i.$event_duration=Number((t/1e3).toFixed(3))),this.eventSended||(this.eventSended=!0,Se({event:"$PageLoad",properties:i},this.config)),window.removeEventListener("load",e)};"complete"===document.readyState?e():window.addEventListener&&window.addEventListener("load",e)}};$e.NAME="pageload";let De=$e;function Fe(e){if(!l(e))return!1;const t=o(e.tagName)?e.tagName.toLowerCase():"",i={};return i.$element_type=t,i.$element_name=e.getAttribute("name")||"",i.$element_id=e.getAttribute("id")||"",i.$element_class_name=o(e.className)?e.className:"",i.$element_target_url=e.getAttribute("href")||"",i.$element_content=function(e,t){return o(t)&&"input"===t.toLowerCase()?("button"===(i=e).type||"submit"===i.type)&&i.value||"":function(e,t){let i="",n="";return e.textContent?i=v(e.textContent):e.innerText&&(i=v(e.innerText)),i&&(i=i.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),n=i||"","input"!==t&&"INPUT"!==t||(n=e.value||""),n}(e,t);var i}(e,t)||"",i.$element_selector=Be(e)||"",i.$element_path=function(e){let t=[];for(;e.parentNode&&l(e);){if(!o(e.tagName))return"";if(e.id&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.id)){t.unshift(e.tagName.toLowerCase()+"#"+e.id);break}if(e===document.body){t.unshift("body");break}t.unshift(e.tagName.toLowerCase()),e=e.parentNode}return t.join(" > ")}(e)||"",i}function Be(e,t=[]){if(!(e&&e.parentNode&&e.parentNode.children&&o(e.tagName)))return"";t=Array.isArray(t)?t:[];const i=e.nodeName.toLowerCase();return e&&"body"!==i&&1==e.nodeType?(t.unshift(function(e){if(!e||!l(e)||!o(e.tagName))return"";let t=e.parentNode&&9==e.parentNode.nodeType?-1:function(e){if(!e.parentNode)return-1;let t=0;const i=e.tagName,n=e.parentNode.children;for(let s=0,r=n.length;s<r;s++)if(n[s].tagName===i){if(e===n[s])return t;t++}return-1}(e);return e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?"#"+e.getAttribute("id"):e.tagName.toLowerCase()+(~t?":nth-of-type("+(t+1)+")":"")}(e)),e.getAttribute&&e.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(e.getAttribute("id"))?t.join(" > "):Be(e.parentNode,t)):(t.unshift("body"),t.join(" > "))}function He(){return{scrollLeft:document.body.scrollLeft||document.documentElement.scrollLeft||0,scrollTop:document.body.scrollTop||document.documentElement.scrollTop||0}}function Ue(e){if(document.documentElement.getBoundingClientRect){const t=e.getBoundingClientRect();return{targetEleX:t.left+He().scrollLeft||0,targetEleY:t.top+He().scrollTop||0}}return{targetEleX:0,targetEleY:0}}function We(e){return Number(Number(e).toFixed(3))}const je=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleClick=null,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,!0),this.isInitialized=!0)}handleClick(e){const t=e.target;if(!t)return;if(!["A","INPUT","BUTTON","TEXTAREA"].includes(t.tagName))return;if("true"===t.getAttribute("sensorswave-disable"))return;const i=function(e,t){const i=Fe(e);if(!i)return!1;const n=function(e,t){const i=t.pageX||t.clientX+He().scrollLeft||t.offsetX+Ue(e).targetEleX,n=t.pageY||t.clientY+He().scrollTop||t.offsetY+Ue(e).targetEleY;return{$page_x:We(i),$page_y:We(n)}}(e,t);return i.$page_x=n.$page_x,i.$page_y=n.$page_y,i}(t,e);Se({event:"$WebClick",properties:i||{}},this.config)}destroy(){this.boundHandleClick&&(document.removeEventListener("click",this.boundHandleClick,!0),this.boundHandleClick=null),this.isInitialized=!1}};je.NAME="webclick";let Xe=je;const qe=class{constructor({emitter:e,config:t,sdk:i}){this.updateInterval=null,this.fetchingPromise=null,this.emitter=e,this.config=t,this.sdk=i}init(){const e=this.config;if(e.enableAB){if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;this.fastFetch().then(()=>{this.emitter.emit(A)}),e.abRefreshInterval<3e4&&(e.abRefreshInterval=3e4),this.updateInterval=setInterval(()=>{this.fetchNewData().catch(console.warn)},e.abRefreshInterval)}}async fastFetch(){const e=N.getABData(this.config.abRefreshInterval);return e&&e.length?(this.emitter.emit(A),Promise.resolve(e)):this.fetchNewData()}async fetchNewData(){return this.fetchingPromise||(this.fetchingPromise=new Promise(e=>{!function({opts:e,cb:t}){if(!le())return void(t&&t({}));if(!he())return void(t&&t({}));const i=N.getLoginId(),n=N.getAnonId();if(!i&&!n)return void(t&&t({}));const s={user:{login_id:i||"",anon_id:n||"",props:{...ee(),...ve(N.getCommonProps())}},sdk:"webjs",sdk_version:S};L({url:me(e),method:"POST",data:s,headers:Ee(e),callback:e=>{200!==e.statusCode?(console.error("Failed to fetch feature flags"),t&&t({})):t&&t(e.json)}})}({opts:this.config,cb:t=>{N.saveABData(t?.data?.results||[]),e(t),this.fetchingPromise=null}})})),this.fetchingPromise}async getFeatureGate(e){return await this.fastFetch().catch(console.warn),N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_GATE&&t.key==e)}async checkFeatureGate(e){const t=await this.getFeatureGate(e);return!!t&&(!t.hasOwnProperty("vid")&&t.key?(Te({isUnset:!0,data:t,opts:this.config}),!1):(Te({data:t,opts:this.config}),"fail"!==t.vid))}async getExperiment(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.EXPERIMENT&&t.key===e);return t?!t.hasOwnProperty("vid")&&t.key?(Te({isUnset:!0,data:t,opts:this.config}),{}):(Te({data:t,opts:this.config}),t?.value||{}):{}}async getFeatureConfig(e){await this.fastFetch().catch(console.warn);const t=N.getABData(this.config.abRefreshInterval).find(t=>t.typ===C.FEATURE_CONFIG&&t.key===e);if(!t)return{};if(!t.hasOwnProperty("vid")&&t.key)return Te({isUnset:!0,data:t,opts:this.config}),{};Te({data:t,opts:this.config});const i=t?.value;if(i){if(n(i))return i;try{return JSON.parse(i)}catch{return i}}return{}}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null),this.fetchingPromise=null}};qe.NAME="abtest";let Ge=qe;const ze=["utm_source","utm_medium","utm_campaign","utm_content","utm_term"],Ve="sensorswave_utm",Ye=class e{constructor({sdk:e,emitter:t,config:i}){this.sdk=e,this.emitter=t,this.config=i}init(){if(this.sdk&&!0===this.sdk._postConsentInit){let t=e.readFromSessionStorage();return t&&0!==Object.keys(t).length||(t=e.captureAndStore(this.config?.debug)),void this.scheduleInitialUTM(t)}const t=e.getUTMFromURL();e.saveToSessionStorage(t,this.config?.debug),this.scheduleInitialUTM(t)}scheduleInitialUTM(e){setTimeout(()=>{this.sendInitialUTM(e)},0)}static getUTMFromURL(){try{const e=new URLSearchParams(window.location.search),t={};return ze.forEach(i=>{const n=e.get(i);n&&(t[i]=n)}),t}catch(t){return e.getUTMFromURLFallback()}}static getUTMFromURLFallback(){const e={};return window.location.search.substring(1).split("&").forEach(t=>{const[i,n]=t.split("="),s=decodeURIComponent(i),r=n?decodeURIComponent(n):"";ze.includes(s)&&(e[s]=r)}),e}static readFromSessionStorage(){try{const e=sessionStorage.getItem(Ve);if(!e)return{};const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch(e){return{}}}static saveToSessionStorage(e,t=!1){try{sessionStorage.setItem(Ve,JSON.stringify(e))}catch(i){t&&console.warn("[SensorsWave UTM] Failed to save to sessionStorage:",i)}}static captureAndStore(t=!1){const i=e.getUTMFromURL();return e.saveToSessionStorage(i,t),i}sendInitialUTM(e){const t={};ze.forEach(i=>{t[`$initial_${i}`]=null!=e[i]?e[i]:""});try{this.sdk.profileSetOnce(t)}catch(i){this.config.debug&&console.warn("[SensorsWave UTM] Failed to send initial UTM:",i)}}destroy(){}};Ye.NAME="UTM";let Je=Ye;const Ke=1e3,Ze=/^\s*(?:async\s+)?at\s+(?:(.+)\s+\()?(.+?):(\d+):(\d+)\)?$/,Qe=/^(?:(.*)@)?(.+?):(\d+):(\d+)$/;function et(e){let t=e;try{const e=location.origin;e&&0===t.indexOf(e)&&(t=t.substring(e.length))}catch(s){}const i=t.indexOf("?");i>-1&&(t=t.substring(0,i));const n=t.indexOf("#");return n>-1&&(t=t.substring(0,n)),t}function tt(e){return e.map(e=>({platform:"web:javascript",filename:et(e.file),function:e.fn||"?",lineno:Number(e.line),colno:Number(e.col),abs_path:it(e.file,1e3)}))}function it(e,t){return e.length>t?e.substring(0,t):e}function nt(e){let t;if("string"==typeof e)t=e;else if(null!==e&&"object"==typeof e){try{t=JSON.stringify(e)}catch(i){t=Object.prototype.toString.call(e)}t||(t=Object.prototype.toString.call(e))}else t=String(e);return it(t,Ke)}function st(e){const{frames:t,headerType:i}=function(e){const t=[];let i="";if(!e||"string"!=typeof e)return{frames:t,headerType:i};const n=e.split(/\r?\n/);for(let s=0;s<n.length;s++){const e=n[s];if(!e||e.length>1024)continue;const r=e.match(Ze),o=r?null:e.match(Qe),a=r||o;if(a)t.push({fn:a[1]||"?",file:a[2],line:a[3],col:a[4]});else if(0===s){const t=e.indexOf(":");t>0&&(i=e.substring(0,t).trim())}if(t.length>=30)break}return{frames:t,headerType:i}}(e&&e.stack);let n=e&&e.name||i||"Error";return n=it(String(n),200),{$exception_level:"error",$exception_type:n,$exception_message:it(String(e&&e.message||""),Ke),$exception_frames:tt(t)}}function rt(e,t,i,n){let s=[];return t&&(s=[{platform:"web:javascript",filename:et(t),function:"?",lineno:i||0,colno:n||0,abs_path:it(t,1e3)}]),{$exception_level:"error",$exception_type:"Error",$exception_message:it(String(e||""),Ke),$exception_frames:s}}class ot{constructor(e=10,t=1,i=1e4){this.buckets=new Map,this.bucketSize=e,this.refillRate=t,this.refillInterval=i}allow(e){const t=Date.now();let i=this.buckets.get(e);if(i){if(t>i.lastRefill){const e=Math.floor((t-i.lastRefill)/this.refillInterval)*this.refillRate;e>0&&(i.tokens=Math.min(this.bucketSize,i.tokens+e),i.lastRefill+=e/this.refillRate*this.refillInterval)}}else i={tokens:this.bucketSize,lastRefill:t},this.buckets.set(e,i);return i.tokens>=1&&(i.tokens-=1,!0)}reset(){this.buckets.clear()}}const at=class{constructor({emitter:e,config:t}){this.isInitialized=!1,this.boundHandleError=null,this.boundHandleRejection=null,this.rateLimiter=new ot,this.emitter=e,this.config=t}init(){this.isInitialized||(this.boundHandleError=this.handleError.bind(this),this.boundHandleRejection=this.handleRejection.bind(this),window.addEventListener("error",this.boundHandleError,!0),window.addEventListener("unhandledrejection",this.boundHandleRejection),this.isInitialized=!0)}handleError(e){try{const t=e.target;let i;if(t&&t!==window&&t.tagName)i=function(e){const t=e,i=(t.tagName||"").toLowerCase(),n=it(String(t.src||t.href||""),Ke);return{$exception_level:"error",$exception_type:"ResourceLoadError",$exception_message:`Failed to load <${i}>${n?` from ${n}`:""}`,$exception_frames:[]}}(t);else{const t=e;i=t.error instanceof Error?st(t.error):rt(String(t.message||""),t.filename,t.lineno,t.colno)}this.send(i)}catch(t){}}handleRejection(e){try{const t=e.reason;this.send(function(e){return e instanceof Error?st(e):{$exception_level:"error",$exception_type:"UnhandledRejection",$exception_message:nt(e),$exception_frames:[]}}(t))}catch(t){}}send(e){e.$exception_message&&this.rateLimiter.allow(e.$exception_type)&&Se({event:T,properties:e},this.config)}destroy(){this.boundHandleError&&(window.removeEventListener("error",this.boundHandleError,!0),this.boundHandleError=null),this.boundHandleRejection&&(window.removeEventListener("unhandledrejection",this.boundHandleRejection),this.boundHandleRejection=null),this.rateLimiter.reset(),this.isInitialized=!1}};at.NAME="exception";let ct=at;const ut="data-sw-exposure-event-name",lt="data-sw-exposure-config-",ht=`[${ut}]`,dt={visibleRatio:0,stayDuration:0,repeated:!0};function pt(e,t){const i={};if(!n(e))return i;const s=e;if(void 0!==s.visibleRatio){const e=Number(s.visibleRatio);!isNaN(e)&&e>=0&&e<=1?i.visibleRatio=e:t&&t("[exposure] parameter config.visibleRatio 非法(值域 0~1),已忽略:",s.visibleRatio)}if(void 0!==s.stayDuration){const e=Number(s.stayDuration);!isNaN(e)&&e>=0?i.stayDuration=e:t&&t("[exposure] parameter config.stayDuration 非法(须 >= 0),已忽略:",s.stayDuration)}if(void 0!==s.repeated){const e=s.repeated;!0===e||"true"===e?i.repeated=!0:!1===e||"false"===e?i.repeated=!1:t&&t("[exposure] parameter config.repeated 非法(须为布尔),已忽略:",e)}return i}function gt(...e){const t={...dt};for(let i=0;i<e.length;i++){const s=e[i];if(!n(s))continue;const r=s;void 0!==r.visibleRatio&&(t.visibleRatio=r.visibleRatio),void 0!==r.stayDuration&&(t.stayDuration=r.stayDuration),void 0!==r.repeated&&(t.repeated=r.repeated)}return t}function ft(e){const t=(e.getAttribute(ut)||"").trim();let i={},s={};const r=e.getAttribute("data-sw-exposure-option");if(r){const e=d(r);n(e)&&(n(e.config)&&(i=e.config),n(e.properties)&&(s=e.properties))}const a=e.getAttribute(lt+"visible-ratio");null!==a&&(i.visibleRatio=a);const c=e.getAttribute(lt+"stay-duration");null!==c&&(i.stayDuration=c);const u=e.getAttribute(lt+"repeated");null!==u&&(i.repeated=u);const l=e.attributes;for(let n=0;n<l.length;n++){const e=l[n],t=e.name;if(o(t)&&0===t.indexOf("data-sw-exposure-property-")){const i=t.substring(26);i&&(s[i]=e.value)}}return{eventName:t,config:pt(i),properties:s}}const mt=class{constructor({emitter:e,config:t,sdk:i}){this.isInitialized=!1,this.observers=new Map,this.records=new Map,this.mutationObserver=null,this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.boundHandleSpa=null,this.eventListeners=[],this.globalConfig={...dt},this.log=function(){},this.emitter=e,this.config=t,this.sdk=i}init(){this.isInitialized||(function(){try{return"undefined"!=typeof window&&"IntersectionObserver"in window&&"MutationObserver"in window}catch(e){return!1}}()?(this.log=!0==(!0===this.config.debug)&&"undefined"!=typeof console&&console.log?function(...e){console.log("[SensorsWave][exposure]",...e)}:function(){},this.globalConfig=gt(this.globalConfig,pt(this.config.exposureConfig,this.log)),this.boundHandleIntersection=this.handleIntersection.bind(this),this.boundHandleMutation=this.handleMutation.bind(this),this.boundHandleVisibility=this.handleVisibility.bind(this),"loading"===document.readyState?(this.boundHandleReady=()=>{this.scanDocument(),this.observeMutations()},document.addEventListener("DOMContentLoaded",this.boundHandleReady),this.eventListeners.push({target:document,event:"DOMContentLoaded",handler:this.boundHandleReady})):(this.scanDocument(),this.observeMutations()),!0===this.config.isSinglePageApp&&(this.boundHandleSpa=e=>{this.handleSpaSwitch(e)},this.emitter.on(O,this.boundHandleSpa)),document.addEventListener("visibilitychange",this.boundHandleVisibility),this.eventListeners.push({target:document,event:"visibilitychange",handler:this.boundHandleVisibility}),!0===document.hidden&&this.stop(),this.isInitialized=!0):console.warn("[SensorsWave][exposure] 当前浏览器不支持 IntersectionObserver / MutationObserver,曝光采集未初始化"))}addExposureView(e,t){this.isInitialized?l(e)?n(t)&&o(t.eventName)&&t.eventName.trim()?this.addOrUpdateWatchEle(e,{eventName:t.eventName.trim(),config:n(t.config)?pt(t.config,this.log):void 0,properties:n(t.properties)?{...t.properties}:{},listener:n(t.listener)?{...t.listener}:{}},"api"):this.log("addExposureView parameter option.eventName 缺失:",t):this.log("addExposureView parameter element 非法:",e):this.log("曝光插件未初始化(enableExposureTrack 未开启或浏览器不支持)")}removeExposureView(e){this.isInitialized?l(e)?this.removeWatchEle(e):this.log("removeExposureView parameter element 非法:",e):this.log("曝光插件未初始化")}scanDocument(e){try{const t=e||document;if(!t.querySelectorAll)return;const i=t.querySelectorAll(ht);for(let e=0;e<i.length;e++){const t=i[e];this.addOrUpdateWatchEle(t,ft(t),"attr")}}catch(t){}}addOrUpdateWatchEle(e,t,i){if(!e||!l(e))return void this.log("parameter element error:",e);if(!o(t.eventName)||!t.eventName.trim())return void this.log("parameter option.eventName error:",t);const n=this.records.get(e);if(n&&"api"===n.source&&"attr"===i)return void this.log("声明式属性变更被忽略:元素已由 addExposureView 注册",e);const s=gt(this.globalConfig,n&&n.config,t.config);if(n&&n.config.visibleRatio===s.visibleRatio)return n.eventName=t.eventName,n.source=i,n.config=s,n.properties={...t.properties||{}},n.listener=t.listener||{},void(n.hasSent=!1);n&&this.removeWatchEle(e);const r={ele:e,eventName:t.eventName,source:i,config:s,properties:{...t.properties||{}},listener:t.listener||{},timer:null,hasSent:!1};this.records.set(e,r),this.getIntersection(s.visibleRatio).observe(e)}getIntersection(e){let t=this.observers.get(e);return!t&&this.boundHandleIntersection&&(t=new IntersectionObserver(this.boundHandleIntersection,{threshold:e}),this.observers.set(e,t)),t}removeWatchEle(e){const t=this.records.get(e);if(!t)return;const i=this.observers.get(t.config.visibleRatio);i&&l(e)&&i.unobserve(e),t.timer&&(clearTimeout(t.timer),t.timer=null),this.records.delete(e)}handleIntersection(e){try{for(const t of e){const e=t.target,i=this.records.get(e);i&&(!0===t.isIntersecting&&t.intersectionRatio>=i.config.visibleRatio?!0!==document.hidden&&(i.timer&&clearTimeout(i.timer),i.timer=setTimeout(()=>{this.fireExposure(e)},1e3*i.config.stayDuration)):i.timer&&(clearTimeout(i.timer),i.timer=null))}}catch(t){}}fireExposure(e){try{const i=this.records.get(e);if(i&&(i.timer=null),!i||i.hasSent)return;let n={width:0,height:0};try{n=e.getBoundingClientRect()}catch(t){}if(!n.width||!n.height)return;if(!e.isConnected)return void this.removeWatchEle(e);if(this.sdk&&"function"==typeof this.sdk.hasOptedOutCapturing&&this.sdk.hasOptedOutCapturing())return;const r={...Fe(e),...i.properties},{shouldExpose:o,didExpose:a}=i.listener||{};if(o&&s(o))try{if(!1===o(e,r))return}catch(t){return}if(Se({event:i.eventName,properties:r},this.config),i.hasSent=!0,i.config.repeated&&(i.hasSent=!1),a&&s(a))try{a(e,r)}catch(t){}}catch(t){}}observeMutations(){!this.mutationObserver&&this.boundHandleMutation&&(this.mutationObserver=new MutationObserver(this.boundHandleMutation),this.mutationObserver.observe(document.body,{attributes:!0,childList:!0,subtree:!0}))}handleMutation(e){try{for(const t of e)if("childList"===t.type){if(t.removedNodes.length>0)for(const e of Array.from(t.removedNodes)){if(1!==e.nodeType)continue;this.removeWatchEle(e);const t=e.querySelectorAll(ht);for(let e=0;e<t.length;e++)this.removeWatchEle(t[e])}if(t.addedNodes.length>0)for(const e of Array.from(t.addedNodes))1===e.nodeType&&(e.hasAttribute(ut)&&this.addOrUpdateWatchEle(e,ft(e),"attr"),this.scanDocument(e))}else"attributes"===t.type&&this.handleAttrChange(t)}catch(t){}}handleAttrChange(e){const t=e.attributeName;if(!t||0!==t.indexOf("data-sw-exposure"))return;const i=e.target;t!==ut||(i.getAttribute(t)||"").trim()?(i.getAttribute(ut)||"").trim()&&this.addOrUpdateWatchEle(i,ft(i),"attr"):this.removeWatchEle(i)}handleSpaSwitch(e){try{if(e===location.href)return;this.stop();for(const[e,t]of Array.from(this.records))"attr"===t.source&&this.records.delete(e);this.start(),this.scanDocument()}catch(t){}}stop(){for(const e of Array.from(this.records.values())){const t=this.observers.get(e.config.visibleRatio);t&&t.unobserve(e.ele),e.timer&&(clearTimeout(e.timer),e.timer=null)}}start(){for(const e of Array.from(this.records.values())){if(!e.ele.isConnected){this.records.delete(e.ele);continue}const t=this.observers.get(e.config.visibleRatio);t&&t.observe(e.ele)}}handleVisibility(){try{"visible"===document.visibilityState?this.start():this.stop()}catch(e){}}destroy(){this.observers.forEach(e=>{try{e.disconnect()}catch(t){}}),this.observers.clear(),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null);for(const e of Array.from(this.records.values()))e.timer&&(clearTimeout(e.timer),e.timer=null);this.records.clear(),this.eventListeners.forEach(({target:e,event:t,handler:i})=>{e.removeEventListener(t,i)}),this.eventListeners=[],this.boundHandleSpa&&(this.emitter.off(O,this.boundHandleSpa),this.boundHandleSpa=null),this.boundHandleIntersection=null,this.boundHandleMutation=null,this.boundHandleVisibility=null,this.boundHandleReady=null,this.globalConfig={...dt},this.log=function(){},this.isInitialized=!1}};mt.NAME="exposure";let Et=mt;const _t=[],bt={debug:!1,sourceToken:"",apiHost:"",autoCapture:!0,isSinglePageApp:!1,crossSubdomainCookie:!0,enableAB:!1,abRefreshInterval:6e5,enableClickTrack:!1,enableExposureTrack:!1,batchSend:!1,enableErrorTrack:!1,enableCrashTrack:!1,optOutCapturing:!1,persistOptOut:!1};return new class{constructor(){this.__innerInited=!1,this.inited=!1,this.config={},this.eventEmitter=new e,this.pluginCore={},this.commonProps={},this.spaCleanup=null,this._optOutCapturing=!1,this.consentStorage=new Ne(!1),this._setupAfterConsentDone=!1,this._postConsentInit=!1,w.instance=this}init(e,t={}){return this.inited?this:(w.instance=this,t.sourceToken=e,this.mergeConfig(t),this.consentStorage=new Ne(!0===this.config.persistOptOut),this._optOutCapturing?this.consentStorage.write(!0):!0===this.config.optOutCapturing?(this._optOutCapturing=!0,this.consentStorage.write(!0)):!0===this.consentStorage.read()&&(this._optOutCapturing=!0),this.eventEmitter.emit("init-param",this.config),this.__innerInited=!0,this._optOutCapturing?(Je.captureAndStore(this.config.debug),this.eventEmitter.emit(y),this.inited=!0,this):(this.__setupAfterConsent(),this.eventEmitter.emit(y),this.inited=!0,this))}__setupAfterConsent(){if(this._setupAfterConsentDone)return;this._setupAfterConsentDone=!0;const e=this.config;_t.length=0,N.init(e.crossSubdomainCookie),e.anonId&&N.setAnonId(e.anonId),function(){if(window._swFailedRequestsInitialized)return;window._swFailedRequestsInitialized=!0;const e=w.instance;e&&"function"==typeof e.hasOptedOutCapturing&&e.hasOptedOutCapturing()||e&&!0===e._postConsentInit||function(){const e=te.getAll();if(0!==e.length)for(let t=0,i=e.length;t<i;t+=10){const i=e.slice(t,t+10),n=[],s=[];i.forEach(e=>{Array.isArray(e.data)?n.push(...e.data):n.push(e.data),s.push(e.id)});const r=i[i.length-1],o=r.url,a=r.headers;L({url:o,method:"POST",data:n,headers:a,callback:e=>{200!==e.statusCode?(console.error("Failed to send batch stored requests:",e),P(e.statusCode)||s.forEach(e=>{te.dequeue(e)})):s.forEach(e=>{te.dequeue(e)})}})}}()}(),_t.push(Je),e.autoCapture&&this.autoTrack(),e.enableAB&&_t.push(Ge),e.enableClickTrack&&_t.push(Xe),e.enableCrashTrack&&e.debug&&console.warn("[SensorsWave] enableCrashTrack 仅在 app 宿主环境生效,当前 Web 环境不采集 crash"),e.enableErrorTrack&&_t.push(ct),e.enableExposureTrack&&_t.push(Et),this.pluginCore=new Pe({plugins:_t,emitter:this.eventEmitter,config:e,sdk:this}),this.spaCleanup=function(e){let t=location.href;const i=window.history.pushState,n=window.history.replaceState,r=function(){e(t),t=location.href};return s(window.history.pushState)&&(window.history.pushState=function(...n){i.apply(window.history,n),e(t),t=location.href}),s(window.history.replaceState)&&(window.history.replaceState=function(...i){n.apply(window.history,i),e(t),t=location.href}),window.addEventListener("popstate",r),function(){s(window.history.pushState)&&(window.history.pushState=i),s(window.history.replaceState)&&(window.history.replaceState=n),window.removeEventListener("popstate",r)}}(e=>{this.eventEmitter.emit(O,e)})}mergeConfig(e){this.config={...bt,...e}}__canCapture(){return this.inited&&!this._optOutCapturing}track(e){this.__canCapture()&&function(e,t){if(!le())return;if(!he())return;const i={...e};i.time||(i.time=Date.now()),i.login_id||(i.login_id=N.getLoginId()),i.anon_id||(i.anon_id=N.getAnonId()),i.trace_id||(i.trace_id=N.getTraceId()),i.properties=Ie(i.properties);const n=fe(t),s=Ee(t),r=!1!==t.batchSend&&pe();if(!r)return _e(n,{data:[i],headers:s});te.enqueue(n,[i],s),r.add()}(e,this.config)}trackEvent(e,t){this.__canCapture()&&Se({event:e,properties:t},this.config)}trackException(e,t){if(!this.__canCapture())return;const i={...t||{},...e instanceof Error?st(e):rt(String(e))};Se({event:T,properties:i},this.config)}addExposureView(e,t){if(!this.__canCapture())return;const i=this.pluginCore.getPlugin(Et.NAME);i?i.addExposureView(e,t):console.warn("[SensorsWave] addExposureView 需在 init 时配置 enableExposureTrack: true")}removeExposureView(e){if(!this.__canCapture())return;const t=this.pluginCore.getPlugin(Et.NAME);t&&t.removeExposureView(e)}autoTrack(){_t.push(xe,De,Me)}profileSet(e){this.__canCapture()&&ye({userProps:{$set:e},opts:this.config})}profileSetOnce(e){this.__canCapture()&&ye({userProps:{$set_once:e},opts:this.config})}profileIncrement(e){this.__canCapture()&&ye({userProps:{$increment:e},opts:this.config})}profileAppend(e){this.__canCapture()&&ye({userProps:{$append:e},opts:this.config})}profileUnion(e){this.__canCapture()&&ye({userProps:{$union:e},opts:this.config})}profileUnset(e){if(!this.__canCapture())return;const t={};r(e)?e.forEach(function(e){t[e]=null}):t[e]=null,ye({userProps:{$unset:t},opts:this.config})}profileDelete(){this.__canCapture()&&ye({userProps:{$delete:!0},opts:this.config})}registerCommonProperties(e){if(!n(e))return console.warn("Commmon Properties must be an object!");this.commonProps=e,N.setCommonProps(this.commonProps)}clearCommonProperties(e){if(!r(e))return console.warn("Commmon Properties to be cleared must be an array!");e.forEach(e=>{delete this.commonProps[e]}),N.setCommonProps(this.commonProps)}identify(e){this.__canCapture()&&(N.setLoginId(e),function(e){if(!le())return;if(!he())return;const t=N.getLoginId(),i=N.getAnonId();if(!t||!i)return;const n={time:Date.now(),trace_id:N.getTraceId(),event:"$Identify",login_id:t,anon_id:i,properties:we()},s=fe(e),r=Ee(e),o=pe();if(!o)return _e(s,{data:[n],headers:r});te.enqueue(s,[n],r),o.add()}(this.config))}setLoginId(e){this.__canCapture()&&N.setLoginId(e)}getAnonId(){return this.__canCapture()?N.getAnonId():""}getSessionId(){return this.__canCapture()?ue(!0):""}setAnonId(e){this.__canCapture()&&N.setAnonId(e)}getLoginId(){return this.__canCapture()?N.getLoginId():""}reset(e=!1){this.__canCapture()&&(N.clearLoginId(),function(){oe=null;try{t.remove(se)}catch(e){}}(),e&&N.resetAnonId())}checkFeatureGate(e){if(!this.__canCapture())return Promise.resolve(!1);const t=this.pluginCore.getPlugin(Ge.NAME);return this.config.enableAB&&t?t.checkFeatureGate(e):Promise.reject("AB is disabled")}getExperiment(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Ge.NAME);return this.config.enableAB&&t?t.getExperiment(e):Promise.reject("AB is disabled")}getFeatureConfig(e){if(!this.__canCapture())return Promise.resolve({});const t=this.pluginCore.getPlugin(Ge.NAME);return this.config.enableAB&&t?t.getFeatureConfig(e):Promise.reject("AB is disabled")}optOutCapturing(){this._optOutCapturing=!0,this.consentStorage.write(!0),de&&de.pause()}optInCapturing(){if(this._optOutCapturing=!1,this.consentStorage.write(!1),de&&de.resume(),this.inited&&!this._setupAfterConsentDone){this._postConsentInit=!0;try{this.__setupAfterConsent(),this.eventEmitter.emit(y)}finally{this._postConsentInit=!1}}}hasOptedOutCapturing(){return this._optOutCapturing}destroy(){de&&(de.destroy(),de=null),"undefined"!=typeof window&&(window._swFailedRequestsInitialized=!1),oe=null,this.inited=!1,this.__innerInited=!1,this.spaCleanup&&"function"==typeof this.spaCleanup&&(this.spaCleanup(),this.spaCleanup=null),this.pluginCore&&"function"==typeof this.pluginCore.destroy&&this.pluginCore.destroy(),this.pluginCore={},this.eventEmitter&&this.eventEmitter.removeAllListeners(),this.consentStorage=new Ne(!0===this.config?.persistOptOut),this._optOutCapturing=!1,this._setupAfterConsentDone=!1,this._postConsentInit=!1,w.instance===this&&(w.instance=null)}}});
|
package/dist/types/Api.d.ts
CHANGED
|
@@ -88,6 +88,7 @@ interface SensorsWaveInterface {
|
|
|
88
88
|
identify(u: string | number): void;
|
|
89
89
|
setLoginId(u: string | number): void;
|
|
90
90
|
setAnonId(u: string | number): void;
|
|
91
|
+
getSessionId(): string;
|
|
91
92
|
reset(resetAnonymousId?: boolean): void;
|
|
92
93
|
checkFeatureGate(key: string): Promise<boolean>;
|
|
93
94
|
getExperiment(key: string): Promise<Object>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const SESSION_COOKIE_NAME = "sensorswave2025jssdksession";
|
|
2
|
+
export declare const SESSION_ID_PROP = "$session_id";
|
|
3
|
+
export declare const SESSION_IDLE_TIMEOUT: number;
|
|
4
|
+
export declare const SESSION_MAX_DURATION: number;
|
|
5
|
+
export declare function generateSessionId(): string;
|
|
6
|
+
export declare function checkAndGetSessionId(readOnly?: boolean): string;
|
|
7
|
+
export declare function getSessionId(): string;
|
|
8
|
+
export declare function resetSessionId(): void;
|
|
9
|
+
export declare function clearSessionCache(): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sensorswave/js-sdk",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.6.0",
|
|
5
5
|
"description": "Sensors Wave JS SDK for web analytics",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
7
7
|
"module": "dist/index.es.js",
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
"sdk"
|
|
20
20
|
],
|
|
21
21
|
"author": "liulangyu",
|
|
22
|
-
"license": "
|
|
22
|
+
"license": "Apache-2.0"
|
|
23
23
|
}
|