@sensorswave/js-sdk 0.1.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/dist/index.cjs.js +1 -0
- package/dist/index.es.js +1 -0
- package/dist/index.umd.js +1 -0
- package/dist/types/Api.d.ts +62 -0
- package/dist/types/core/src/index.d.ts +1 -0
- package/dist/types/core/src/utils/cookie.d.ts +17 -0
- package/dist/types/core/src/utils/event-emitter.d.ts +8 -0
- package/dist/types/core/src/utils/index.d.ts +36 -0
- package/dist/types/web/src/basic/batch-sender.d.ts +18 -0
- package/dist/types/web/src/basic/domain-name.d.ts +1 -0
- package/dist/types/web/src/basic/element-info.d.ts +1 -0
- package/dist/types/web/src/basic/persistent-queue.d.ts +28 -0
- package/dist/types/web/src/basic/props.d.ts +19 -0
- package/dist/types/web/src/basic/send.d.ts +16 -0
- package/dist/types/web/src/basic/store.d.ts +27 -0
- package/dist/types/web/src/constants/index.d.ts +17 -0
- package/dist/types/web/src/global.d.ts +2 -0
- package/dist/types/web/src/index.d.ts +34 -0
- package/dist/types/web/src/plugins/abtest.d.ts +17 -0
- package/dist/types/web/src/plugins/index.d.ts +19 -0
- package/dist/types/web/src/plugins/pageleave.d.ts +42 -0
- package/dist/types/web/src/plugins/pageload.d.ts +12 -0
- package/dist/types/web/src/plugins/pageview.d.ts +14 -0
- package/dist/types/web/src/plugins/webclick.d.ts +15 -0
- package/dist/types/web/src/utils/referrer.d.ts +3 -0
- package/dist/types/web/src/utils/request.d.ts +26 -0
- package/dist/types/web/src/utils/spa.d.ts +1 -0
- package/dist/types/web/src/utils/user-agent.d.ts +9 -0
- package/package.json +24 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";class e{constructor(){this.listeners={}}on(e,t,n=!1){if(e&&t){if(!r(t))throw new Error("listener must be a function");this.listeners[e]=this.listeners[e]||[],this.listeners[e].push({listener:t,once:n})}}off(e,t){const n=this.listeners[e];if(!n?.length)return;"number"==typeof t&&n.splice(t,1);const i=n.findIndex(e=>e.listener===t);-1!==i&&n.splice(i,1)}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((n,i)=>{n.listener.call(this,...t),n.listener.once&&this.off(e,i)})}once(e,t){this.on(e,t,!0)}removeAllListeners(e){e?this.listeners[e]=[]:this.listeners={}}}const t={get:function(e){const t=e+"=",n=document.cookie.split(";");for(let i=0,r=n.length;i<r;i++){let e=n[i];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:n,samesite:i,secure:r,domain:s}){let o="",a="",l="",c="";if(0!==(n=null==n||void 0===n?365:n)){const e=new Date;"s"===String(n).slice(-1)?e.setTime(e.getTime()+1e3*Number(String(n).slice(0,-1))):e.setTime(e.getTime()+24*n*60*60*1e3),o="; expires="+e.toUTCString()}function u(e){return e?e.replace(/\r\n/g,""):""}i&&(l="; SameSite="+i),r&&(a="; secure");const h=u(e),d=u(t),g=u(s);g&&(c="; domain="+g),h&&d&&(document.cookie=h+"="+encodeURIComponent(d)+o+"; path=/"+c+l+a)},remove:function(e){this.set({name:e,value:"",expires:-1})},isSupport:function({samesite:e,secure:t}={}){if(!navigator.cookieEnabled)return!1;const n="sol_cookie_support_test";return this.set({name:n,value:"1",samesite:e,secure:t}),"1"===this.get(n)&&(this.remove(n),!0)}},n=Object.prototype.toString;function i(e){return"[object Object]"===n.call(e)}function r(e){const t=n.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t}function s(e){return"[object Array]"==n.call(e)}function o(e){return"[object String]"==n.call(e)}function a(e){return void 0===e}const l=Object.prototype.hasOwnProperty;function c(e){if(i(e)){for(let t in e)if(l.call(e,t))return!1;return!0}return!1}function u(e){return!(!e||1!==e.nodeType)}function h(e){let t=e;try{t=decodeURIComponent(e)}catch(n){t=e}return t}function d(e){try{return JSON.parse(e)}catch(t){return""}}const g=function(){let e=Date.now();return function(t){return Math.ceil((e=(9301*e+49297)%233280,e/233280*t))}}();function p(){if("function"==typeof Uint32Array){let e;if("undefined"!=typeof crypto&&(e=crypto),e&&i(e)&&e.getRandomValues)return e.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32)}return g(1e19)/1e19}const f=function(){function e(){let e=Date.now(),t=0;for(;e==Date.now();)t++;return e.toString(16)+t.toString(16)}return function(){let t=String(screen.height*screen.width);t=t&&/\d{5,}/.test(t)?t.toString():String(31242*p()).replace(".","").slice(0,8);return e()+"-"+p().toString(16).replace(".","")+"-"+function(){const e=navigator.userAgent;let t,n=[],i=0;function r(e,t){let i=0;for(let r=0;r<t.length;r++)i|=n[r]<<8*r;return e^i}for(let s=0;s<e.length;s++)t=e.charCodeAt(s),n.unshift(255&t),n.length>=4&&(i=r(i,n),n=[]);return n.length>0&&(i=r(i,n)),i.toString(16)}()+"-"+t+"-"+e()||(String(p())+String(p())+String(p())).slice(2,15)}}();function m(e,t){t&&"string"==typeof t||(t="");let n=null;try{n=new URL(e).hostname}catch(i){}return n||t}function E(e){let t=[];try{t=atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})}catch(n){t=[]}try{return decodeURIComponent(t.join(""))}catch(n){return t.join("")}}function I(e){let t="";try{t=btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}))}catch(n){t=e}return t}const S={get:function(e){return window.localStorage.getItem(e)},parse:function(e){let t;try{t=JSON.parse(S.get(e))||null}catch(n){console.warn(n)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(n){console.warn(n)}},remove:function(e){window.localStorage.removeItem(e)},isSupport:function(){let e=!0;try{const t="__local_store_support__",n="testIsSupportStorage";S.set(t,n),S.get(t)!==n&&(e=!1),S.remove(t)}catch(t){e=!1}return e}};function w(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}const O={},_="init-ready",v="spa-switch",A="ff-ready",R="$PageLeave",b=6e5,N={crossSubdomain:!1,requests:[],_sessionState:{},_abData:[],_trace_id:"",_state:{props:{},anon_id:"",login_id:"",identities:{}},getIdentityCookieID(){return this._state.identities?.$identity_cookie_id||""},getProps:function(){return this._state.props||{}},getAnonId(){return this.getIdentityCookieID()||this._state.anon_id||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"sol2025jssdkcross"},getABLSName:function(){return"sol2025jssdkablatest"},save:function(){let e=JSON.parse(JSON.stringify(this._state));e.identities&&(e.identities=I(JSON.stringify(e.identities)));const n=JSON.stringify(e);t.set({name:this.getCookieName(),value:n,expires:365})},init:function(e){let n,r;this.crossSubdomain=e,t.isSupport()&&(n=t.get(this.getCookieName()),r=d(n)),N._state={...r||{}},N._state.identities&&(N._state.identities=d(E(N._state.identities))),N._state.identities&&i(N._state.identities)&&!c(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())},saveABData(e){if(!e||c(e))return;this._abData=e;let t=JSON.parse(JSON.stringify(this._abData));t=I(JSON.stringify(t));try{localStorage.setItem(this.getABLSName(),JSON.stringify({time:Date.now(),data:t,anon_id:this.getAnonId(),login_id:this.getLoginId()}))}catch(n){console.warn("Failed to save abdata to localStorage",n)}},getABData(){try{let e=localStorage.getItem(this.getABLSName());if(e){const{time:t,data:n,login_id:i,anon_id:r}=d(e)||{};if(t&&n&&Date.now()-t<b&&r===this.getAnonId()&&(!i||i===this.getLoginId()))return d(E(n));localStorage.removeItem(this.getABLSName())}}catch(e){console.warn("Failed to load abdata from localStorage",e),this._abData=[]}return this._abData||[]}};function y(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 T=[];function P(e){const t={...e};t.timeout=t.timeout||6e4;const n=t.transport??"fetch",i=T.find(e=>e.transport===n)?.method??T[0]?.method;if(!i)throw new Error("No available transport method for HTTP request");i(t)}function C(e){return o(e=e||document.referrer)&&(e=h(e=e.trim()))||""}function L(e){const t=m(e=e||C());if(!t)return"";const n={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 i of Object.keys(n)){let e=n[i];for(let n=0,r=e.length;n<r;n++)if(e[n].test(t))return i}return"Unknown Search Engine"}function B(e,t){return-1!==e.indexOf(t)}"function"==typeof fetch&&T.push({transport:"fetch",method:function(e){if("undefined"==typeof fetch)return void console.error("fetch API is not available");const t=y(e),n=new Headers;e.headers&&Object.keys(e.headers).forEach(t=>{n.append(t,e.headers[t])}),t?.contentType&&n.append("Content-Type",t.contentType),fetch(e.url,{method:e.method||"GET",headers:n,body:t?.body}).then(t=>t.text().then(n=>{const i={statusCode:t.status,text:n};if(200===t.status)try{i.json=JSON.parse(n)}catch(r){console.error("Failed to parse response:",r)}e.callback?.(i)})).catch(t=>{console.error("Request failed:",t),e.callback?.({statusCode:0,text:String(t)})})}}),"undefined"!=typeof XMLHttpRequest&&T.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 n=y(e);e.headers&&Object.keys(e.headers).forEach(n=>{t.setRequestHeader(n,e.headers[n])}),n?.contentType&&t.setRequestHeader("Content-Type",n.contentType),t.timeout=e.timeout||6e4,t.withCredentials=!0,t.onreadystatechange=()=>{if(4===t.readyState){const i={statusCode:t.status,text:t.responseText};if(200===t.status)try{i.json=JSON.parse(t.responseText)}catch(n){console.error("Failed to parse JSON response:",n)}e.callback?.(i)}},t.send(n?.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"},D="(\\d+(\\.\\d+)?)",M=new RegExp("Version/"+D),x=new RegExp(F.XBOX,"i"),k=new RegExp(F.PLAYSTATION+" \\w+","i"),H=new RegExp(F.NINTENDO+" \\w+","i"),$=new RegExp(F.BLACKBERRY+"|PlayBook|BB10","i"),X=new RegExp("(HUAWEI|honor|HONOR)","i"),U=new RegExp("(Xiaomi|Redmi)","i"),q=new RegExp("(OPPO|realme)","i"),W=new RegExp("(vivo|IQOO)","i"),j={"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 G(e,t){return t=t||"",B(e," OPR/")&&B(e,"Mini")?F.OPERA_MINI:B(e," OPR/")?F.OPERA:$.test(e)?F.BLACKBERRY:B(e,"IE"+F.MOBILE)||B(e,"WPDesktop")?F.INTERNET_EXPLORER_MOBILE:B(e,F.SAMSUNG_BROWSER)?F.SAMSUNG_INTERNET:B(e,F.EDGE)||B(e,"Edg/")?F.MICROSOFT_EDGE:B(e,"FBIOS")?F.FACEBOOK+" "+F.MOBILE:B(e,"UCWEB")||B(e,"UCBrowser")?F.UC_BROWSER:B(e,"CriOS")?F.CHROME_IOS:B(e,"CrMo")||B(e,F.CHROME)?F.CHROME:B(e,F.ANDROID)&&B(e,F.SAFARI)?F.ANDROID_MOBILE:B(e,"FxiOS")?F.FIREFOX_IOS:B(e.toLowerCase(),F.KONQUEROR.toLowerCase())?F.KONQUEROR:function(e,t){return t&&B(t,F.APPLE)||B(n=e,F.SAFARI)&&!B(n,F.CHROME)&&!B(n,F.ANDROID);var n}(e,t)?B(e,F.MOBILE)?F.MOBILE_SAFARI:F.SAFARI:B(e,F.FIREFOX)?F.FIREFOX:B(e,"MSIE")||B(e,"Trident/")?F.INTERNET_EXPLORER:B(e,"Gecko")?F.FIREFOX:""}const Y={[F.INTERNET_EXPLORER_MOBILE]:[new RegExp("rv:"+D)],[F.MICROSOFT_EDGE]:[new RegExp(F.EDGE+"?\\/"+D)],[F.CHROME]:[new RegExp("("+F.CHROME+"|CrMo)\\/"+D)],[F.CHROME_IOS]:[new RegExp("CriOS\\/"+D)],[F.UC_BROWSER]:[new RegExp("(UCBrowser|UCWEB)\\/"+D)],[F.SAFARI]:[M],[F.MOBILE_SAFARI]:[M],[F.OPERA]:[new RegExp("("+F.OPERA+"|OPR)\\/"+D)],[F.FIREFOX]:[new RegExp(F.FIREFOX+"\\/"+D)],[F.FIREFOX_IOS]:[new RegExp("FxiOS\\/"+D)],[F.KONQUEROR]:[new RegExp("Konqueror[:/]?"+D,"i")],[F.BLACKBERRY]:[new RegExp(F.BLACKBERRY+" "+D),M],[F.ANDROID_MOBILE]:[new RegExp("android\\s"+D,"i")],[F.SAMSUNG_INTERNET]:[new RegExp(F.SAMSUNG_BROWSER+"\\/"+D)],[F.INTERNET_EXPLORER]:[new RegExp("(rv:|MSIE )"+D)],Mozilla:[new RegExp("rv:"+D)]};function z(e,t){const n=G(e,t),i=Y[n];if(a(i))return null;for(let r=0;r<i.length;r++){const t=i[r],n=e.match(t);if(n)return parseFloat(n[n.length-2])}return null}const K=[[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,""]],[$,[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 n=/Windows NT ([0-9.]+)/i.exec(t);if(n&&n[1]){const e=n[1];let i=j[e]||"";return/arm/i.test(t)&&(i="RT"),[F.WINDOWS,i]}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 n=[e[1],e[2],e[3]||"0"];t[1]=n.join(".")}return t}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[F.CHROME_OS,""]],[/Linux|debian/i,["Linux",""]]];function J(){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,n=navigator.userAgent,i=function(e){for(let t=0;t<K.length;t++){const[n,i]=K[t],r=n.exec(e),s=r&&("function"==typeof i?i(r,e):i);if(s)return s}return["",""]}(n)||["",""];return{$browser:G(n),$browser_version:z(n),$url:location?.href.substring(0,1e3),$host:location?.host,$viewport_height:e,$viewport_width:t,$lib:"webjs",$lib_version:"0.1.0",$search_engine:L(),$referrer:C(),$referrer_domain:m(s=s||C()),$model:(r=n,(H.test(r)?F.NINTENDO:k.test(r)?F.PLAYSTATION:x.test(r)?F.XBOX:new RegExp(F.OUYA,"i").test(r)?F.OUYA:new RegExp("("+F.WINDOWS_PHONE+"|WPDesktop)","i").test(r)?F.WINDOWS_PHONE:/iPad/.test(r)?F.IPAD:/iPod/.test(r)?"iPod Touch":/iPhone/.test(r)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(r)?F.APPLE_WATCH:$.test(r)?F.BLACKBERRY:/(kobo)\s(ereader|touch)/i.test(r)?"Kobo":new RegExp(F.NOKIA,"i").test(r)?F.NOKIA:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(r)||/(kf[a-z]+)( bui|\)).+silk\//i.test(r)?"Kindle Fire":X.test(r)?F.HUAWEI:U.test(r)?F.XIAOMI:q.test(r)?F.OPPO:W.test(r)?F.VIVO:/(Android|ZTE)/i.test(r)?!new RegExp(F.MOBILE).test(r)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(r)?/pixel[\daxl ]{1,6}/i.test(r)&&!/pixel c/i.test(r)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(r)||/lmy47v/i.test(r)&&!/QTAQZ3/i.test(r)?F.ANDROID:F.ANDROID_TABLET:F.ANDROID:new RegExp("(pda|"+F.MOBILE+")","i").test(r)?F.GENERIC_MOBILE:new RegExp(F.TABLET,"i").test(r)&&!new RegExp(F.TABLET+" pc","i").test(r)?F.GENERIC_TABLET:"")||""),$os:i?.[0]||"",$os_version:i?.[1]||"",$pathname:location?.pathname,$screen_height:Number(screen.height)||0,$screen_width:Number(screen.width)||0};var r,s}const Z=new class{constructor(){this.STORAGE_KEY="sol_unsent_events",this.MAX_QUEUE_SIZE=100,this.MAX_RETRY_COUNT=3,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.retryCount<t.maxRetries);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,n,i=this.MAX_RETRY_COUNT){try{const r={id:f(),url:e,data:t,headers:n,timestamp:Date.now(),retryCount:0,maxRetries:i};return this.queue.push(r),this.saveToStorage(),r.id}catch(r){return console.warn("Failed to enqueue request:",r),""}}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.retryCount>=t.maxRetries?(this.dequeue(e),!1):(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 Q{constructor(e={}){this.flushTimer=null,this.isFlushing=!1,this.pendingFlush=!1,this.config={maxBatchSize:e.maxBatchSize||10,flushInterval:e.flushInterval||5e3},this.startFlushTimer()}add(){Z.getAll().length>=this.config.maxBatchSize&&this.triggerFlush()}triggerFlush(){this.isFlushing?this.pendingFlush=!0:(this.isFlushing=!0,this.flush())}flush(){const e=Z.getAll();if(0===e.length)return this.isFlushing=!1,void(this.pendingFlush&&(this.pendingFlush=!1,this.triggerFlush()));const t=[],n=[];e.forEach(e=>{Array.isArray(e.data)?t.push(...e.data):t.push(e.data),n.push(e.id)});const i=t.slice(0,this.config.maxBatchSize),r=e[0],s=r.url,o=r.headers;O.instance.config.debug&&console.log(JSON.stringify(i,null,2)),P({url:s,method:"POST",data:i,headers:o,callback:e=>{200!==e.statusCode?console.error("Failed to send batch events:",e):n.forEach(e=>{Z.dequeue(e)}),this.isFlushing=!1;const t=Z.getAll();(this.pendingFlush||t.length>=this.config.maxBatchSize)&&(this.pendingFlush=!1,this.triggerFlush())}})}startFlushTimer(){this.flushTimer&&clearInterval(this.flushTimer),this.flushTimer=setInterval(()=>{this.flush()},this.config.flushInterval)}destroy(){this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flush()}}let V=null,ee=null;function te(e,t,n){return P({url:e,method:"POST",data:t.data,headers:t.headers,callback:e=>{if(200!==e.statusCode){if(n)if(Z.incrementRetryCount(n)){const e=Z.getItemById(n);if(e){const t=Math.min(1e3*Math.pow(2,e.retryCount),3e4);setTimeout(()=>{te(e.url,{data:e.data,headers:e.headers},e.id)},t)}}else console.warn("Max retries reached for request:",n)}else n&&Z.dequeue(n),t.callback&&t.callback(e.json)}})}function ne(e){return`${e.apiHost}/in/track`}function ie(e){return`${e.apiHost}/ff/evalall`}function re(e){return{"Content-Type":"application/json",ProjectToken:e.apiToken}}function se(e,t,n){O.instance.config.debug&&console.log(JSON.stringify(t.data,null,2));const i=Z.enqueue(e,t.data,t.headers);return te(e,{...t,callback:void 0},i)}function oe(e,t,n=!0){const i={time:Date.now(),trace_id:N.getTraceId(),event:e.event,properties:{...e.properties,...n?J():{}}},r=N.getLoginId(),s=N.getAnonId();r&&(i.login_id=r),s&&(i.anon_id=s);const o=ne(t),a=re(t),l=S.isSupport()?(ee||(V||(V=new Q({maxBatchSize:10,flushInterval:5e3})),ee=V),ee):null;!1!==t.batchSend&&l?(Z.enqueue(o,[i],a),l.add()):se(o,{data:[i],headers:a})}function ae({userProps:e,opts:t}){const n=N.getLoginId(),i=N.getAnonId();if(!n||!i)return;const r={time:Date.now(),trace_id:N.getTraceId(),event:"$user_set",login_id:n,anon_id:i,user_properties:e};return se(ne(t),{data:r,headers:re(t)})}class le{constructor({plugins:e,emitter:t,config:n}){this.plugins=[],this.pluginInsMap={},this.emitter=t,this.config=n,this.registerBuiltInPlugins(e),this.created(),this.emitter.on(_,()=>{this.init()})}registerBuiltInPlugins(e){for(let t=0,n=e.length;t<n;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 n=new t({emitter:this.emitter,config:this.config});this.pluginInsMap[t.NAME]=n}}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 ce=class{constructor({emitter:e,config:t}){this.boundSend=null,this.hashEvent=null,this.emitter=e,this.config=t}init(){const e=this.config;this.boundSend=()=>{oe({event:"$PageView",properties:{$title:document.title}},e)},e.isSinglePageApp?(this.hashEvent="pushState"in window.history?"popstate":"hashchange",window.addEventListener(this.hashEvent,this.boundSend)):this.boundSend()}destroy(){this.hashEvent&&this.boundSend&&(window.removeEventListener(this.hashEvent,this.boundSend),this.hashEvent=null,this.boundSend=null)}};ce.NAME="pageview";let ue=ce;const he=class{constructor({emitter:e,config:t}){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="solwebjssdkpageleave",this.maxDuration=432e3,this.eventListeners=[],this.emitter=e,this.config=t}init(){this.pageId=Number(String(p()).slice(2,5)+String(p()).slice(2,4)+String(Date.now()).slice(-4)),this.addEventListener(),!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}pageEndHandler(){if(!0===this.pageHiddenStatus)return;const e=this.getPageLeaveProperties();!1===this.pageShowStatus&&delete e.event_duration,this.pageShowStatus=!1,this.pageHiddenStatus=!0,oe({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(v,e=>{e!==location.href&&(this.url=e,this.pageEndHandler(),this.stopHeartBeatInterval(),this.currentPageUrl=this.url,this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval())})}addPageEndListener(){["pagehide","beforeunload","unload"].forEach(e=>{if(`on${e}`in window){const t=()=>{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.pageEndHandler(),this.stopHeartBeatInterval())};document.addEventListener("visibilitychange",e),this.eventListeners.push({target:document,event:"visibilitychange",handler:e})}addHeartBeatInterval(){S.isSupport()&&this.startHeartBeatInterval()}startHeartBeatInterval(){this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),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){const t=this.getPageLeaveProperties();t.$time=Date.now(),"is_first_heartbeat"===e&&(t.event_duration=3);const n={type:"track",event:R,properties:t};n.heartbeat_interval_time=this.heartbeatIntervalTime,S.isSupport()&&S.set(`${this.storageName}-${this.pageId}`,JSON.stringify(n))}delHeartBeatData(e){S.isSupport()&&S.remove(e||`${this.storageName}-${this.pageId}`)}reissueHeartBeatData(){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=S.parse(t);i(e)&&Date.now()-e.time>e.heartbeat_interval_time+5e3&&(delete e.heartbeat_interval_time,e._flush_time=(new Date).getTime(),oe({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=document.documentElement&&document.documentElement.scrollTop||window.pageYOffset||document.body&&document.body.scrollTop||0,n=Math.round(t)||0,i={$title:this.title,$viewport_position:n};return 0!==e&&(i.event_duration=e),i}destroy(){this.eventListeners.forEach(({target:e,event:t,handler:n})=>{e.removeEventListener(t,n)}),this.eventListeners=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}};he.NAME="pageleave";let de=he;const ge=class{constructor({emitter:e,config:t}){this.eventSended=!1,this.emitter=e,this.config=t}init(){const e=()=>{let t=0;const n=window.performance,i={$title:document.title};if(n){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 n of e)"transferSize"in n&&(t+=n.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,oe({event:"$PageLoad",properties:i},this.config)),window.removeEventListener("load",e)};"complete"===document.readyState?e():window.addEventListener&&window.addEventListener("load",e)}};ge.NAME="pageload";let pe=ge;function fe(e,t){if(!u(e))return!1;const n=o(e.tagName)?e.tagName.toLowerCase():"unknown",i={};i.$element_type=n,i.$element_name=e.getAttribute("name"),i.$element_id=e.getAttribute("id"),i.$element_class_name=o(e.className)?e.className:null,i.$element_target_url=e.getAttribute("href"),i.$element_content=function(e,t){return o(t)&&"input"===t.toLowerCase()?("button"===(n=e).type||"submit"===n.type)&&n.value||"":function(e,t){let n="",i="";return e.textContent?n=w(e.textContent):e.innerText&&(n=w(e.innerText)),n&&(n=n.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),i=n||"","input"!==t&&"INPUT"!==t||(i=e.value||""),i}(e,t);var n}(e,n),i.$element_selector=me(e),i.$element_path=function(e){let t=[];for(;e.parentNode&&u(e);){if(!o(e.tagName))return"unknown";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.$url_path=location.pathname,i.$title=document.title;const r=function(e,t){const n=t.pageX||t.clientX+Ee().scrollLeft||t.offsetX+Ie(e).targetEleX,i=t.pageY||t.clientY+Ee().scrollTop||t.offsetY+Ie(e).targetEleY;return{$page_x:Se(n),$page_y:Se(i)}}(e,t);return i.$page_x=r.$page_x,i.$page_y=r.$page_y,i}function me(e,t=[]){if(!(e&&e.parentNode&&e.parentNode.children&&o(e.tagName)))return"unknown";t=Array.isArray(t)?t:[];const n=e.nodeName.toLowerCase();return e&&"body"!==n&&1==e.nodeType?(t.unshift(function(e){if(!e||!u(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 n=e.tagName,i=e.parentNode.children;for(let r=0,s=i.length;r<s;r++)if(i[r].tagName===n){if(e===i[r])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(" > "):me(e.parentNode,t)):(t.unshift("body"),t.join(" > "))}function Ee(){return{scrollLeft:document.body.scrollLeft||document.documentElement.scrollLeft||0,scrollTop:document.body.scrollTop||document.documentElement.scrollTop||0}}function Ie(e){if(document.documentElement.getBoundingClientRect){const t=e.getBoundingClientRect();return{targetEleX:t.left+Ee().scrollLeft||0,targetEleY:t.top+Ee().scrollTop||0}}return{targetEleX:0,targetEleY:0}}function Se(e){return Number(Number(e).toFixed(3))}const we=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("sol-disable"))return;oe({event:"$WebClick",properties:fe(t,e)||{}},this.config)}destroy(){this.boundHandleClick&&(document.removeEventListener("click",this.boundHandleClick,!0),this.boundHandleClick=null),this.isInitialized=!1}};we.NAME="webclick";let Oe=we;const _e=class{constructor({emitter:e,config:t}){this.updateInterval=null,this.fetchingPromise=null,this.emitter=e,this.config=t}init(){const e=this.config;e.enableFeatureFlag&&(this.fastFetch().then(()=>{this.emitter.emit(A)}),e.featureFlagRefreshInterval<3e4&&(e.featureFlagRefreshInterval=3e4),this.updateInterval=setInterval(()=>{this.fetchNewData().catch(console.warn)},e.featureFlagRefreshInterval))}async fastFetch(){const e=N.getABData();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}){const n=N.getLoginId(),i=N.getAnonId();if(!n||!i)return;const r={ffuser:{login_id:n,anon_id:i,props:J()||{}}};P({url:ie(e),method:"POST",data:r,headers:re(e),callback:e=>{200!==e.statusCode?console.error("Failed to fetch feature flags"):t&&t(e.json)}})}({opts:this.config,cb:t=>{N.saveABData(t.data),e(t),this.fetchingPromise=null}})})),this.fetchingPromise}async getFeatureFlag(e){return await this.fastFetch().catch(console.warn),N.getABData().find(t=>t.ffkey===e)}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null),this.fetchingPromise=null}};_e.NAME="abtest";let ve=_e;const Ae=[],Re={debug:!1,apiToken:"",apiHost:"",autoCapture:!0,beforeSend:e=>e,isSinglePageApp:!1,crossSubdomainCookie:!0,enableFeatureFlag:!1,featureFlagRefreshInterval:b,enableClickTrack:!1,batchSend:!0},be=new class{constructor(){this.__loaded=!1,this.config={},this.eventEmitter=new e,this.pluginCore={},this.commonProps={},this.spaCleanup=null,O.instance=this}init(e,t={}){t.apiToken=e,this.mergeConfig(t),this.eventEmitter.emit("init-param",this.config);const n=this.config;return N.init(n.crossSubdomainCookie),this.__loaded=!0,window._solFailedRequestsInitialized||(window._solFailedRequestsInitialized=!0,function(){const e=Z.getAll();0!==e.length&&e.forEach(e=>{te(e.url,{data:e.data,headers:e.headers},e.id)})}()),n.autoCapture&&this.autoTrack(),n.enableFeatureFlag&&Ae.push(ve),n.enableClickTrack&&Ae.push(Oe),this.pluginCore=new le({plugins:Ae,emitter:this.eventEmitter,config:n}),this.spaCleanup=function(e){let t=location.href;const n=window.history.pushState,i=window.history.replaceState,s=function(){e(t),t=location.href};return r(window.history.pushState)&&(window.history.pushState=function(...i){n.apply(window.history,i),e(t),t=location.href}),r(window.history.replaceState)&&(window.history.replaceState=function(...n){i.apply(window.history,n),e(t),t=location.href}),window.addEventListener("popstate",s),function(){r(window.history.pushState)&&(window.history.pushState=n),r(window.history.replaceState)&&(window.history.replaceState=i),window.removeEventListener("popstate",s)}}(e=>{this.eventEmitter.emit(v,e)}),this.eventEmitter.emit(_),this}mergeConfig(e){this.config={...Re,...e}}track(e){!function(e,t){const n={...e};n.time||(n.time=Date.now()),n.login_id||(n.login_id=N.getLoginId()),n.anon_id||(n.anon_id=N.getAnonId()),n.properties={...J(),...n.properties},se(ne(t),{data:n,headers:re(t)})}(e,this.config)}trackEvent(e,t){oe({event:e,properties:{...t,...this.commonProps}},this.config)}autoTrack(){Ae.push(ue,pe,de)}profileSet(e){ae({userProps:{$set:e},opts:this.config})}profileSetOnce(e){ae({userProps:{$set_once:e},opts:this.config})}profileIncrement(e){ae({userProps:{$increment:e},opts:this.config})}profileAppend(e){ae({userProps:{$append:e},opts:this.config})}profileUnion(e){ae({userProps:{$union:e},opts:this.config})}profileUnset(e){const t={};s(e)?e.forEach(function(e){t[e]=null}):t[e]=null,ae({userProps:{$unset:t},opts:this.config})}profileDelete(){ae({userProps:{$delete:!0},opts:this.config})}registerCommonProperties(e){if(!i(e))return console.warn("Commmon Properties must be an object!");this.commonProps=e}clearCommonProperties(e){if(!s(e))return console.warn("Commmon Properties to be cleared must be an array!");e.forEach(e=>{delete this.commonProps[e]})}identify(e){N.setLoginId(e),function(e){const t=N.getLoginId(),n=N.getAnonId();if(!t||!n)return;const i={time:Date.now(),trace_id:N.getTraceId(),event:"$identify",login_id:t,anon_id:n};se(ne(e),{data:i,headers:re(e)})}(this.config)}setLoginId(e){N.setLoginId(e)}getAnonId(){return N.getAnonId()}getLoginId(){return N.getLoginId()}getFeatureFlag(e){const t=this.pluginCore.getPlugin(ve.NAME);return this.config.enableFeatureFlag&&t?t.getFeatureFlag(e):Promise.reject("Feature flag is disabled")}destroy(){ee&&(ee.destroy(),ee=null),this.spaCleanup&&"function"==typeof this.spaCleanup&&(this.spaCleanup(),this.spaCleanup=null),this.pluginCore&&"function"==typeof this.pluginCore.destroy&&this.pluginCore.destroy(),this.eventEmitter&&this.eventEmitter.removeAllListeners(),O.instance===this&&(O.instance=null)}};module.exports=be;
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class e{constructor(){this.listeners={}}on(e,t,n=!1){if(e&&t){if(!r(t))throw new Error("listener must be a function");this.listeners[e]=this.listeners[e]||[],this.listeners[e].push({listener:t,once:n})}}off(e,t){const n=this.listeners[e];if(!n?.length)return;"number"==typeof t&&n.splice(t,1);const i=n.findIndex(e=>e.listener===t);-1!==i&&n.splice(i,1)}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((n,i)=>{n.listener.call(this,...t),n.listener.once&&this.off(e,i)})}once(e,t){this.on(e,t,!0)}removeAllListeners(e){e?this.listeners[e]=[]:this.listeners={}}}const t={get:function(e){const t=e+"=",n=document.cookie.split(";");for(let i=0,r=n.length;i<r;i++){let e=n[i];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:n,samesite:i,secure:r,domain:s}){let o="",a="",l="",c="";if(0!==(n=null==n||void 0===n?365:n)){const e=/* @__PURE__ */new Date;"s"===String(n).slice(-1)?e.setTime(e.getTime()+1e3*Number(String(n).slice(0,-1))):e.setTime(e.getTime()+24*n*60*60*1e3),o="; expires="+e.toUTCString()}function u(e){return e?e.replace(/\r\n/g,""):""}i&&(l="; SameSite="+i),r&&(a="; secure");const h=u(e),d=u(t),g=u(s);g&&(c="; domain="+g),h&&d&&(document.cookie=h+"="+encodeURIComponent(d)+o+"; path=/"+c+l+a)},remove:function(e){this.set({name:e,value:"",expires:-1})},isSupport:function({samesite:e,secure:t}={}){if(!navigator.cookieEnabled)return!1;const n="sol_cookie_support_test";return this.set({name:n,value:"1",samesite:e,secure:t}),"1"===this.get(n)&&(this.remove(n),!0)}},n=Object.prototype.toString;function i(e){return"[object Object]"===n.call(e)}function r(e){const t=n.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t}function s(e){return"[object Array]"==n.call(e)}function o(e){return"[object String]"==n.call(e)}function a(e){return void 0===e}const l=Object.prototype.hasOwnProperty;function c(e){if(i(e)){for(let t in e)if(l.call(e,t))return!1;return!0}return!1}function u(e){return!(!e||1!==e.nodeType)}function h(e){let t=e;try{t=decodeURIComponent(e)}catch(n){t=e}return t}function d(e){try{return JSON.parse(e)}catch(t){return""}}const g=function(){let e=Date.now();return function(t){return Math.ceil((e=(9301*e+49297)%233280,e/233280*t))}}();function p(){if("function"==typeof Uint32Array){let e;if("undefined"!=typeof crypto&&(e=crypto),e&&i(e)&&e.getRandomValues)return e.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32)}return g(1e19)/1e19}const f=/* @__PURE__ */function(){function e(){let e=Date.now(),t=0;for(;e==Date.now();)t++;return e.toString(16)+t.toString(16)}return function(){let t=String(screen.height*screen.width);t=t&&/\d{5,}/.test(t)?t.toString():String(31242*p()).replace(".","").slice(0,8);return e()+"-"+p().toString(16).replace(".","")+"-"+function(){const e=navigator.userAgent;let t,n=[],i=0;function r(e,t){let i=0;for(let r=0;r<t.length;r++)i|=n[r]<<8*r;return e^i}for(let s=0;s<e.length;s++)t=e.charCodeAt(s),n.unshift(255&t),n.length>=4&&(i=r(i,n),n=[]);return n.length>0&&(i=r(i,n)),i.toString(16)}()+"-"+t+"-"+e()||(String(p())+String(p())+String(p())).slice(2,15)}}();function m(e,t){t&&"string"==typeof t||(t="");let n=null;try{n=new URL(e).hostname}catch(i){}return n||t}function E(e){let t=[];try{t=atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})}catch(n){t=[]}try{return decodeURIComponent(t.join(""))}catch(n){return t.join("")}}function I(e){let t="";try{t=btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}))}catch(n){t=e}return t}const S={get:function(e){return window.localStorage.getItem(e)},parse:function(e){let t;try{t=JSON.parse(S.get(e))||null}catch(n){console.warn(n)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(n){console.warn(n)}},remove:function(e){window.localStorage.removeItem(e)},isSupport:function(){let e=!0;try{const t="__local_store_support__",n="testIsSupportStorage";S.set(t,n),S.get(t)!==n&&(e=!1),S.remove(t)}catch(t){e=!1}return e}};function w(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}const O={},_="init-ready",v="spa-switch",A="ff-ready",R="$PageLeave",b=6e5,N={crossSubdomain:!1,requests:[],_sessionState:{},_abData:[],_trace_id:"",_state:{props:{},anon_id:"",login_id:"",identities:{}},getIdentityCookieID(){return this._state.identities?.$identity_cookie_id||""},getProps:function(){return this._state.props||{}},getAnonId(){return this.getIdentityCookieID()||this._state.anon_id||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"sol2025jssdkcross"},getABLSName:function(){return"sol2025jssdkablatest"},save:function(){let e=JSON.parse(JSON.stringify(this._state));e.identities&&(e.identities=I(JSON.stringify(e.identities)));const n=JSON.stringify(e);t.set({name:this.getCookieName(),value:n,expires:365})},init:function(e){let n,r;this.crossSubdomain=e,t.isSupport()&&(n=t.get(this.getCookieName()),r=d(n)),N._state={...r||{}},N._state.identities&&(N._state.identities=d(E(N._state.identities))),N._state.identities&&i(N._state.identities)&&!c(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())},saveABData(e){if(!e||c(e))return;this._abData=e;let t=JSON.parse(JSON.stringify(this._abData));t=I(JSON.stringify(t));try{localStorage.setItem(this.getABLSName(),JSON.stringify({time:Date.now(),data:t,anon_id:this.getAnonId(),login_id:this.getLoginId()}))}catch(n){console.warn("Failed to save abdata to localStorage",n)}},getABData(){try{let e=localStorage.getItem(this.getABLSName());if(e){const{time:t,data:n,login_id:i,anon_id:r}=d(e)||{};if(t&&n&&Date.now()-t<b&&r===this.getAnonId()&&(!i||i===this.getLoginId()))return d(E(n));localStorage.removeItem(this.getABLSName())}}catch(e){console.warn("Failed to load abdata from localStorage",e),this._abData=[]}return this._abData||[]}};function y(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 T=[];function P(e){const t={...e};t.timeout=t.timeout||6e4;const n=t.transport??"fetch",i=T.find(e=>e.transport===n)?.method??T[0]?.method;if(!i)throw new Error("No available transport method for HTTP request");i(t)}function C(e){return o(e=e||document.referrer)&&(e=h(e=e.trim()))||""}function L(e){const t=m(e=e||C());if(!t)return"";const n={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 i of Object.keys(n)){let e=n[i];for(let n=0,r=e.length;n<r;n++)if(e[n].test(t))return i}return"Unknown Search Engine"}function B(e,t){return-1!==e.indexOf(t)}"function"==typeof fetch&&T.push({transport:"fetch",method:function(e){if("undefined"==typeof fetch)return void console.error("fetch API is not available");const t=y(e),n=new Headers;e.headers&&Object.keys(e.headers).forEach(t=>{n.append(t,e.headers[t])}),t?.contentType&&n.append("Content-Type",t.contentType),fetch(e.url,{method:e.method||"GET",headers:n,body:t?.body}).then(t=>t.text().then(n=>{const i={statusCode:t.status,text:n};if(200===t.status)try{i.json=JSON.parse(n)}catch(r){console.error("Failed to parse response:",r)}e.callback?.(i)})).catch(t=>{console.error("Request failed:",t),e.callback?.({statusCode:0,text:String(t)})})}}),"undefined"!=typeof XMLHttpRequest&&T.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 n=y(e);e.headers&&Object.keys(e.headers).forEach(n=>{t.setRequestHeader(n,e.headers[n])}),n?.contentType&&t.setRequestHeader("Content-Type",n.contentType),t.timeout=e.timeout||6e4,t.withCredentials=!0,t.onreadystatechange=()=>{if(4===t.readyState){const i={statusCode:t.status,text:t.responseText};if(200===t.status)try{i.json=JSON.parse(t.responseText)}catch(n){console.error("Failed to parse JSON response:",n)}e.callback?.(i)}},t.send(n?.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"},D="(\\d+(\\.\\d+)?)",M=new RegExp("Version/"+D),x=new RegExp(F.XBOX,"i"),k=new RegExp(F.PLAYSTATION+" \\w+","i"),H=new RegExp(F.NINTENDO+" \\w+","i"),$=new RegExp(F.BLACKBERRY+"|PlayBook|BB10","i"),X=new RegExp("(HUAWEI|honor|HONOR)","i"),U=new RegExp("(Xiaomi|Redmi)","i"),q=new RegExp("(OPPO|realme)","i"),W=new RegExp("(vivo|IQOO)","i"),j={"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 G(e,t){return t=t||"",B(e," OPR/")&&B(e,"Mini")?F.OPERA_MINI:B(e," OPR/")?F.OPERA:$.test(e)?F.BLACKBERRY:B(e,"IE"+F.MOBILE)||B(e,"WPDesktop")?F.INTERNET_EXPLORER_MOBILE:B(e,F.SAMSUNG_BROWSER)?F.SAMSUNG_INTERNET:B(e,F.EDGE)||B(e,"Edg/")?F.MICROSOFT_EDGE:B(e,"FBIOS")?F.FACEBOOK+" "+F.MOBILE:B(e,"UCWEB")||B(e,"UCBrowser")?F.UC_BROWSER:B(e,"CriOS")?F.CHROME_IOS:B(e,"CrMo")||B(e,F.CHROME)?F.CHROME:B(e,F.ANDROID)&&B(e,F.SAFARI)?F.ANDROID_MOBILE:B(e,"FxiOS")?F.FIREFOX_IOS:B(e.toLowerCase(),F.KONQUEROR.toLowerCase())?F.KONQUEROR:function(e,t){return t&&B(t,F.APPLE)||B(n=e,F.SAFARI)&&!B(n,F.CHROME)&&!B(n,F.ANDROID);var n}(e,t)?B(e,F.MOBILE)?F.MOBILE_SAFARI:F.SAFARI:B(e,F.FIREFOX)?F.FIREFOX:B(e,"MSIE")||B(e,"Trident/")?F.INTERNET_EXPLORER:B(e,"Gecko")?F.FIREFOX:""}const Y={[F.INTERNET_EXPLORER_MOBILE]:[new RegExp("rv:"+D)],[F.MICROSOFT_EDGE]:[new RegExp(F.EDGE+"?\\/"+D)],[F.CHROME]:[new RegExp("("+F.CHROME+"|CrMo)\\/"+D)],[F.CHROME_IOS]:[new RegExp("CriOS\\/"+D)],[F.UC_BROWSER]:[new RegExp("(UCBrowser|UCWEB)\\/"+D)],[F.SAFARI]:[M],[F.MOBILE_SAFARI]:[M],[F.OPERA]:[new RegExp("("+F.OPERA+"|OPR)\\/"+D)],[F.FIREFOX]:[new RegExp(F.FIREFOX+"\\/"+D)],[F.FIREFOX_IOS]:[new RegExp("FxiOS\\/"+D)],[F.KONQUEROR]:[new RegExp("Konqueror[:/]?"+D,"i")],[F.BLACKBERRY]:[new RegExp(F.BLACKBERRY+" "+D),M],[F.ANDROID_MOBILE]:[new RegExp("android\\s"+D,"i")],[F.SAMSUNG_INTERNET]:[new RegExp(F.SAMSUNG_BROWSER+"\\/"+D)],[F.INTERNET_EXPLORER]:[new RegExp("(rv:|MSIE )"+D)],Mozilla:[new RegExp("rv:"+D)]};function z(e,t){const n=G(e,t),i=Y[n];if(a(i))return null;for(let r=0;r<i.length;r++){const t=i[r],n=e.match(t);if(n)return parseFloat(n[n.length-2])}return null}const K=[[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,""]],[$,[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 n=/Windows NT ([0-9.]+)/i.exec(t);if(n&&n[1]){const e=n[1];let i=j[e]||"";return/arm/i.test(t)&&(i="RT"),[F.WINDOWS,i]}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 n=[e[1],e[2],e[3]||"0"];t[1]=n.join(".")}return t}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[F.CHROME_OS,""]],[/Linux|debian/i,["Linux",""]]];function J(){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,n=navigator.userAgent,i=function(e){for(let t=0;t<K.length;t++){const[n,i]=K[t],r=n.exec(e),s=r&&("function"==typeof i?i(r,e):i);if(s)return s}return["",""]}(n)||["",""];return{$browser:G(n),$browser_version:z(n),$url:location?.href.substring(0,1e3),$host:location?.host,$viewport_height:e,$viewport_width:t,$lib:"webjs",$lib_version:"0.1.0",$search_engine:L(),$referrer:C(),$referrer_domain:m(s=s||C()),$model:(r=n,(H.test(r)?F.NINTENDO:k.test(r)?F.PLAYSTATION:x.test(r)?F.XBOX:new RegExp(F.OUYA,"i").test(r)?F.OUYA:new RegExp("("+F.WINDOWS_PHONE+"|WPDesktop)","i").test(r)?F.WINDOWS_PHONE:/iPad/.test(r)?F.IPAD:/iPod/.test(r)?"iPod Touch":/iPhone/.test(r)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(r)?F.APPLE_WATCH:$.test(r)?F.BLACKBERRY:/(kobo)\s(ereader|touch)/i.test(r)?"Kobo":new RegExp(F.NOKIA,"i").test(r)?F.NOKIA:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(r)||/(kf[a-z]+)( bui|\)).+silk\//i.test(r)?"Kindle Fire":X.test(r)?F.HUAWEI:U.test(r)?F.XIAOMI:q.test(r)?F.OPPO:W.test(r)?F.VIVO:/(Android|ZTE)/i.test(r)?!new RegExp(F.MOBILE).test(r)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(r)?/pixel[\daxl ]{1,6}/i.test(r)&&!/pixel c/i.test(r)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(r)||/lmy47v/i.test(r)&&!/QTAQZ3/i.test(r)?F.ANDROID:F.ANDROID_TABLET:F.ANDROID:new RegExp("(pda|"+F.MOBILE+")","i").test(r)?F.GENERIC_MOBILE:new RegExp(F.TABLET,"i").test(r)&&!new RegExp(F.TABLET+" pc","i").test(r)?F.GENERIC_TABLET:"")||""),$os:i?.[0]||"",$os_version:i?.[1]||"",$pathname:location?.pathname,$screen_height:Number(screen.height)||0,$screen_width:Number(screen.width)||0};var r,s}const Z=new class{constructor(){this.STORAGE_KEY="sol_unsent_events",this.MAX_QUEUE_SIZE=100,this.MAX_RETRY_COUNT=3,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.retryCount<t.maxRetries);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,n,i=this.MAX_RETRY_COUNT){try{const r={id:f(),url:e,data:t,headers:n,timestamp:Date.now(),retryCount:0,maxRetries:i};return this.queue.push(r),this.saveToStorage(),r.id}catch(r){return console.warn("Failed to enqueue request:",r),""}}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.retryCount>=t.maxRetries?(this.dequeue(e),!1):(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 Q{constructor(e={}){this.flushTimer=null,this.isFlushing=!1,this.pendingFlush=!1,this.config={maxBatchSize:e.maxBatchSize||10,flushInterval:e.flushInterval||5e3},this.startFlushTimer()}add(){Z.getAll().length>=this.config.maxBatchSize&&this.triggerFlush()}triggerFlush(){this.isFlushing?this.pendingFlush=!0:(this.isFlushing=!0,this.flush())}flush(){const e=Z.getAll();if(0===e.length)return this.isFlushing=!1,void(this.pendingFlush&&(this.pendingFlush=!1,this.triggerFlush()));const t=[],n=[];e.forEach(e=>{Array.isArray(e.data)?t.push(...e.data):t.push(e.data),n.push(e.id)});const i=t.slice(0,this.config.maxBatchSize),r=e[0],s=r.url,o=r.headers;O.instance.config.debug&&console.log(JSON.stringify(i,null,2)),P({url:s,method:"POST",data:i,headers:o,callback:e=>{200!==e.statusCode?console.error("Failed to send batch events:",e):n.forEach(e=>{Z.dequeue(e)}),this.isFlushing=!1;const t=Z.getAll();(this.pendingFlush||t.length>=this.config.maxBatchSize)&&(this.pendingFlush=!1,this.triggerFlush())}})}startFlushTimer(){this.flushTimer&&clearInterval(this.flushTimer),this.flushTimer=setInterval(()=>{this.flush()},this.config.flushInterval)}destroy(){this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flush()}}let V=null,ee=null;function te(e,t,n){return P({url:e,method:"POST",data:t.data,headers:t.headers,callback:e=>{if(200!==e.statusCode){if(n)if(Z.incrementRetryCount(n)){const e=Z.getItemById(n);if(e){const t=Math.min(1e3*Math.pow(2,e.retryCount),3e4);setTimeout(()=>{te(e.url,{data:e.data,headers:e.headers},e.id)},t)}}else console.warn("Max retries reached for request:",n)}else n&&Z.dequeue(n),t.callback&&t.callback(e.json)}})}function ne(e){return`${e.apiHost}/in/track`}function ie(e){return`${e.apiHost}/ff/evalall`}function re(e){return{"Content-Type":"application/json",ProjectToken:e.apiToken}}function se(e,t,n){O.instance.config.debug&&console.log(JSON.stringify(t.data,null,2));const i=Z.enqueue(e,t.data,t.headers);return te(e,{...t,callback:void 0},i)}function oe(e,t,n=!0){const i={time:Date.now(),trace_id:N.getTraceId(),event:e.event,properties:{...e.properties,...n?J():{}}},r=N.getLoginId(),s=N.getAnonId();r&&(i.login_id=r),s&&(i.anon_id=s);const o=ne(t),a=re(t),l=S.isSupport()?(ee||(V||(V=new Q({maxBatchSize:10,flushInterval:5e3})),ee=V),ee):null;!1!==t.batchSend&&l?(Z.enqueue(o,[i],a),l.add()):se(o,{data:[i],headers:a})}function ae({userProps:e,opts:t}){const n=N.getLoginId(),i=N.getAnonId();if(!n||!i)return;const r={time:Date.now(),trace_id:N.getTraceId(),event:"$user_set",login_id:n,anon_id:i,user_properties:e};return se(ne(t),{data:r,headers:re(t)})}class le{constructor({plugins:e,emitter:t,config:n}){this.plugins=[],this.pluginInsMap={},this.emitter=t,this.config=n,this.registerBuiltInPlugins(e),this.created(),this.emitter.on(_,()=>{this.init()})}registerBuiltInPlugins(e){for(let t=0,n=e.length;t<n;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 n=new t({emitter:this.emitter,config:this.config});this.pluginInsMap[t.NAME]=n}}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 ce=class{constructor({emitter:e,config:t}){this.boundSend=null,this.hashEvent=null,this.emitter=e,this.config=t}init(){const e=this.config;this.boundSend=()=>{oe({event:"$PageView",properties:{$title:document.title}},e)},e.isSinglePageApp?(this.hashEvent="pushState"in window.history?"popstate":"hashchange",window.addEventListener(this.hashEvent,this.boundSend)):this.boundSend()}destroy(){this.hashEvent&&this.boundSend&&(window.removeEventListener(this.hashEvent,this.boundSend),this.hashEvent=null,this.boundSend=null)}};ce.NAME="pageview";let ue=ce;const he=class{constructor({emitter:e,config:t}){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="solwebjssdkpageleave",this.maxDuration=432e3,this.eventListeners=[],this.emitter=e,this.config=t}init(){this.pageId=Number(String(p()).slice(2,5)+String(p()).slice(2,4)+String(Date.now()).slice(-4)),this.addEventListener(),!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}pageEndHandler(){if(!0===this.pageHiddenStatus)return;const e=this.getPageLeaveProperties();!1===this.pageShowStatus&&delete e.event_duration,this.pageShowStatus=!1,this.pageHiddenStatus=!0,oe({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(v,e=>{e!==location.href&&(this.url=e,this.pageEndHandler(),this.stopHeartBeatInterval(),this.currentPageUrl=this.url,this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval())})}addPageEndListener(){["pagehide","beforeunload","unload"].forEach(e=>{if(`on${e}`in window){const t=()=>{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.pageEndHandler(),this.stopHeartBeatInterval())};document.addEventListener("visibilitychange",e),this.eventListeners.push({target:document,event:"visibilitychange",handler:e})}addHeartBeatInterval(){S.isSupport()&&this.startHeartBeatInterval()}startHeartBeatInterval(){this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),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){const t=this.getPageLeaveProperties();t.$time=Date.now(),"is_first_heartbeat"===e&&(t.event_duration=3);const n={type:"track",event:R,properties:t};n.heartbeat_interval_time=this.heartbeatIntervalTime,S.isSupport()&&S.set(`${this.storageName}-${this.pageId}`,JSON.stringify(n))}delHeartBeatData(e){S.isSupport()&&S.remove(e||`${this.storageName}-${this.pageId}`)}reissueHeartBeatData(){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=S.parse(t);i(e)&&Date.now()-e.time>e.heartbeat_interval_time+5e3&&(delete e.heartbeat_interval_time,e._flush_time=/* @__PURE__ */(new Date).getTime(),oe({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=document.documentElement&&document.documentElement.scrollTop||window.pageYOffset||document.body&&document.body.scrollTop||0,n=Math.round(t)||0,i={$title:this.title,$viewport_position:n};return 0!==e&&(i.event_duration=e),i}destroy(){this.eventListeners.forEach(({target:e,event:t,handler:n})=>{e.removeEventListener(t,n)}),this.eventListeners=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}};he.NAME="pageleave";let de=he;const ge=class{constructor({emitter:e,config:t}){this.eventSended=!1,this.emitter=e,this.config=t}init(){const e=()=>{let t=0;const n=window.performance,i={$title:document.title};if(n){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 n of e)"transferSize"in n&&(t+=n.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,oe({event:"$PageLoad",properties:i},this.config)),window.removeEventListener("load",e)};"complete"===document.readyState?e():window.addEventListener&&window.addEventListener("load",e)}};ge.NAME="pageload";let pe=ge;function fe(e,t){if(!u(e))return!1;const n=o(e.tagName)?e.tagName.toLowerCase():"unknown",i={};i.$element_type=n,i.$element_name=e.getAttribute("name"),i.$element_id=e.getAttribute("id"),i.$element_class_name=o(e.className)?e.className:null,i.$element_target_url=e.getAttribute("href"),i.$element_content=function(e,t){return o(t)&&"input"===t.toLowerCase()?("button"===(n=e).type||"submit"===n.type)&&n.value||"":function(e,t){let n="",i="";return e.textContent?n=w(e.textContent):e.innerText&&(n=w(e.innerText)),n&&(n=n.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),i=n||"","input"!==t&&"INPUT"!==t||(i=e.value||""),i}(e,t);var n}(e,n),i.$element_selector=me(e),i.$element_path=function(e){let t=[];for(;e.parentNode&&u(e);){if(!o(e.tagName))return"unknown";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.$url_path=location.pathname,i.$title=document.title;const r=function(e,t){const n=t.pageX||t.clientX+Ee().scrollLeft||t.offsetX+Ie(e).targetEleX,i=t.pageY||t.clientY+Ee().scrollTop||t.offsetY+Ie(e).targetEleY;return{$page_x:Se(n),$page_y:Se(i)}}(e,t);return i.$page_x=r.$page_x,i.$page_y=r.$page_y,i}function me(e,t=[]){if(!(e&&e.parentNode&&e.parentNode.children&&o(e.tagName)))return"unknown";t=Array.isArray(t)?t:[];const n=e.nodeName.toLowerCase();return e&&"body"!==n&&1==e.nodeType?(t.unshift(function(e){if(!e||!u(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 n=e.tagName,i=e.parentNode.children;for(let r=0,s=i.length;r<s;r++)if(i[r].tagName===n){if(e===i[r])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(" > "):me(e.parentNode,t)):(t.unshift("body"),t.join(" > "))}function Ee(){return{scrollLeft:document.body.scrollLeft||document.documentElement.scrollLeft||0,scrollTop:document.body.scrollTop||document.documentElement.scrollTop||0}}function Ie(e){if(document.documentElement.getBoundingClientRect){const t=e.getBoundingClientRect();return{targetEleX:t.left+Ee().scrollLeft||0,targetEleY:t.top+Ee().scrollTop||0}}return{targetEleX:0,targetEleY:0}}function Se(e){return Number(Number(e).toFixed(3))}const we=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("sol-disable"))return;oe({event:"$WebClick",properties:fe(t,e)||{}},this.config)}destroy(){this.boundHandleClick&&(document.removeEventListener("click",this.boundHandleClick,!0),this.boundHandleClick=null),this.isInitialized=!1}};we.NAME="webclick";let Oe=we;const _e=class{constructor({emitter:e,config:t}){this.updateInterval=null,this.fetchingPromise=null,this.emitter=e,this.config=t}init(){const e=this.config;e.enableFeatureFlag&&(this.fastFetch().then(()=>{this.emitter.emit(A)}),e.featureFlagRefreshInterval<3e4&&(e.featureFlagRefreshInterval=3e4),this.updateInterval=setInterval(()=>{this.fetchNewData().catch(console.warn)},e.featureFlagRefreshInterval))}async fastFetch(){const e=N.getABData();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}){const n=N.getLoginId(),i=N.getAnonId();if(!n||!i)return;const r={ffuser:{login_id:n,anon_id:i,props:J()||{}}};P({url:ie(e),method:"POST",data:r,headers:re(e),callback:e=>{200!==e.statusCode?console.error("Failed to fetch feature flags"):t&&t(e.json)}})}({opts:this.config,cb:t=>{N.saveABData(t.data),e(t),this.fetchingPromise=null}})})),this.fetchingPromise}async getFeatureFlag(e){return await this.fastFetch().catch(console.warn),N.getABData().find(t=>t.ffkey===e)}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null),this.fetchingPromise=null}};_e.NAME="abtest";let ve=_e;const Ae=[],Re={debug:!1,apiToken:"",apiHost:"",autoCapture:!0,beforeSend:e=>e,isSinglePageApp:!1,crossSubdomainCookie:!0,enableFeatureFlag:!1,featureFlagRefreshInterval:b,enableClickTrack:!1,batchSend:!0},be=new class{constructor(){this.__loaded=!1,this.config={},this.eventEmitter=new e,this.pluginCore={},this.commonProps={},this.spaCleanup=null,O.instance=this}init(e,t={}){t.apiToken=e,this.mergeConfig(t),this.eventEmitter.emit("init-param",this.config);const n=this.config;return N.init(n.crossSubdomainCookie),this.__loaded=!0,window._solFailedRequestsInitialized||(window._solFailedRequestsInitialized=!0,function(){const e=Z.getAll();0!==e.length&&e.forEach(e=>{te(e.url,{data:e.data,headers:e.headers},e.id)})}()),n.autoCapture&&this.autoTrack(),n.enableFeatureFlag&&Ae.push(ve),n.enableClickTrack&&Ae.push(Oe),this.pluginCore=new le({plugins:Ae,emitter:this.eventEmitter,config:n}),this.spaCleanup=function(e){let t=location.href;const n=window.history.pushState,i=window.history.replaceState,s=function(){e(t),t=location.href};return r(window.history.pushState)&&(window.history.pushState=function(...i){n.apply(window.history,i),e(t),t=location.href}),r(window.history.replaceState)&&(window.history.replaceState=function(...n){i.apply(window.history,n),e(t),t=location.href}),window.addEventListener("popstate",s),function(){r(window.history.pushState)&&(window.history.pushState=n),r(window.history.replaceState)&&(window.history.replaceState=i),window.removeEventListener("popstate",s)}}(e=>{this.eventEmitter.emit(v,e)}),this.eventEmitter.emit(_),this}mergeConfig(e){this.config={...Re,...e}}track(e){!function(e,t){const n={...e};n.time||(n.time=Date.now()),n.login_id||(n.login_id=N.getLoginId()),n.anon_id||(n.anon_id=N.getAnonId()),n.properties={...J(),...n.properties},se(ne(t),{data:n,headers:re(t)})}(e,this.config)}trackEvent(e,t){oe({event:e,properties:{...t,...this.commonProps}},this.config)}autoTrack(){Ae.push(ue,pe,de)}profileSet(e){ae({userProps:{$set:e},opts:this.config})}profileSetOnce(e){ae({userProps:{$set_once:e},opts:this.config})}profileIncrement(e){ae({userProps:{$increment:e},opts:this.config})}profileAppend(e){ae({userProps:{$append:e},opts:this.config})}profileUnion(e){ae({userProps:{$union:e},opts:this.config})}profileUnset(e){const t={};s(e)?e.forEach(function(e){t[e]=null}):t[e]=null,ae({userProps:{$unset:t},opts:this.config})}profileDelete(){ae({userProps:{$delete:!0},opts:this.config})}registerCommonProperties(e){if(!i(e))return console.warn("Commmon Properties must be an object!");this.commonProps=e}clearCommonProperties(e){if(!s(e))return console.warn("Commmon Properties to be cleared must be an array!");e.forEach(e=>{delete this.commonProps[e]})}identify(e){N.setLoginId(e),function(e){const t=N.getLoginId(),n=N.getAnonId();if(!t||!n)return;const i={time:Date.now(),trace_id:N.getTraceId(),event:"$identify",login_id:t,anon_id:n};se(ne(e),{data:i,headers:re(e)})}(this.config)}setLoginId(e){N.setLoginId(e)}getAnonId(){return N.getAnonId()}getLoginId(){return N.getLoginId()}getFeatureFlag(e){const t=this.pluginCore.getPlugin(ve.NAME);return this.config.enableFeatureFlag&&t?t.getFeatureFlag(e):Promise.reject("Feature flag is disabled")}destroy(){ee&&(ee.destroy(),ee=null),this.spaCleanup&&"function"==typeof this.spaCleanup&&(this.spaCleanup(),this.spaCleanup=null),this.pluginCore&&"function"==typeof this.pluginCore.destroy&&this.pluginCore.destroy(),this.eventEmitter&&this.eventEmitter.removeAllListeners(),O.instance===this&&(O.instance=null)}};export{be as default};
|
|
@@ -0,0 +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,n=!1){if(e&&t){if(!r(t))throw new Error("listener must be a function");this.listeners[e]=this.listeners[e]||[],this.listeners[e].push({listener:t,once:n})}}off(e,t){const n=this.listeners[e];if(!n?.length)return;"number"==typeof t&&n.splice(t,1);const i=n.findIndex(e=>e.listener===t);-1!==i&&n.splice(i,1)}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((n,i)=>{n.listener.call(this,...t),n.listener.once&&this.off(e,i)})}once(e,t){this.on(e,t,!0)}removeAllListeners(e){e?this.listeners[e]=[]:this.listeners={}}}const t={get:function(e){const t=e+"=",n=document.cookie.split(";");for(let i=0,r=n.length;i<r;i++){let e=n[i];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:n,samesite:i,secure:r,domain:s}){let o="",a="",l="",u="";if(0!==(n=null==n||void 0===n?365:n)){const e=new Date;"s"===String(n).slice(-1)?e.setTime(e.getTime()+1e3*Number(String(n).slice(0,-1))):e.setTime(e.getTime()+24*n*60*60*1e3),o="; expires="+e.toUTCString()}function c(e){return e?e.replace(/\r\n/g,""):""}i&&(l="; SameSite="+i),r&&(a="; secure");const h=c(e),d=c(t),g=c(s);g&&(u="; domain="+g),h&&d&&(document.cookie=h+"="+encodeURIComponent(d)+o+"; path=/"+u+l+a)},remove:function(e){this.set({name:e,value:"",expires:-1})},isSupport:function({samesite:e,secure:t}={}){if(!navigator.cookieEnabled)return!1;const n="sol_cookie_support_test";return this.set({name:n,value:"1",samesite:e,secure:t}),"1"===this.get(n)&&(this.remove(n),!0)}},n=Object.prototype.toString;function i(e){return"[object Object]"===n.call(e)}function r(e){const t=n.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t}function s(e){return"[object Array]"==n.call(e)}function o(e){return"[object String]"==n.call(e)}function a(e){return void 0===e}const l=Object.prototype.hasOwnProperty;function u(e){if(i(e)){for(let t in e)if(l.call(e,t))return!1;return!0}return!1}function c(e){return!(!e||1!==e.nodeType)}function h(e){let t=e;try{t=decodeURIComponent(e)}catch(n){t=e}return t}function d(e){try{return JSON.parse(e)}catch(t){return""}}const g=function(){let e=Date.now();return function(t){return Math.ceil((e=(9301*e+49297)%233280,e/233280*t))}}();function p(){if("function"==typeof Uint32Array){let e;if("undefined"!=typeof crypto&&(e=crypto),e&&i(e)&&e.getRandomValues)return e.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32)}return g(1e19)/1e19}const f=function(){function e(){let e=Date.now(),t=0;for(;e==Date.now();)t++;return e.toString(16)+t.toString(16)}return function(){let t=String(screen.height*screen.width);t=t&&/\d{5,}/.test(t)?t.toString():String(31242*p()).replace(".","").slice(0,8);return e()+"-"+p().toString(16).replace(".","")+"-"+function(){const e=navigator.userAgent;let t,n=[],i=0;function r(e,t){let i=0;for(let r=0;r<t.length;r++)i|=n[r]<<8*r;return e^i}for(let s=0;s<e.length;s++)t=e.charCodeAt(s),n.unshift(255&t),n.length>=4&&(i=r(i,n),n=[]);return n.length>0&&(i=r(i,n)),i.toString(16)}()+"-"+t+"-"+e()||(String(p())+String(p())+String(p())).slice(2,15)}}();function m(e,t){t&&"string"==typeof t||(t="");let n=null;try{n=new URL(e).hostname}catch(i){}return n||t}function E(e){let t=[];try{t=atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})}catch(n){t=[]}try{return decodeURIComponent(t.join(""))}catch(n){return t.join("")}}function I(e){let t="";try{t=btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}))}catch(n){t=e}return t}const S={get:function(e){return window.localStorage.getItem(e)},parse:function(e){let t;try{t=JSON.parse(S.get(e))||null}catch(n){console.warn(n)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(n){console.warn(n)}},remove:function(e){window.localStorage.removeItem(e)},isSupport:function(){let e=!0;try{const t="__local_store_support__",n="testIsSupportStorage";S.set(t,n),S.get(t)!==n&&(e=!1),S.remove(t)}catch(t){e=!1}return e}};function w(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}const O={},_="init-ready",v="spa-switch",A="ff-ready",R="$PageLeave",b=6e5,N={crossSubdomain:!1,requests:[],_sessionState:{},_abData:[],_trace_id:"",_state:{props:{},anon_id:"",login_id:"",identities:{}},getIdentityCookieID(){return this._state.identities?.$identity_cookie_id||""},getProps:function(){return this._state.props||{}},getAnonId(){return this.getIdentityCookieID()||this._state.anon_id||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"sol2025jssdkcross"},getABLSName:function(){return"sol2025jssdkablatest"},save:function(){let e=JSON.parse(JSON.stringify(this._state));e.identities&&(e.identities=I(JSON.stringify(e.identities)));const n=JSON.stringify(e);t.set({name:this.getCookieName(),value:n,expires:365})},init:function(e){let n,r;this.crossSubdomain=e,t.isSupport()&&(n=t.get(this.getCookieName()),r=d(n)),N._state={...r||{}},N._state.identities&&(N._state.identities=d(E(N._state.identities))),N._state.identities&&i(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())},saveABData(e){if(!e||u(e))return;this._abData=e;let t=JSON.parse(JSON.stringify(this._abData));t=I(JSON.stringify(t));try{localStorage.setItem(this.getABLSName(),JSON.stringify({time:Date.now(),data:t,anon_id:this.getAnonId(),login_id:this.getLoginId()}))}catch(n){console.warn("Failed to save abdata to localStorage",n)}},getABData(){try{let e=localStorage.getItem(this.getABLSName());if(e){const{time:t,data:n,login_id:i,anon_id:r}=d(e)||{};if(t&&n&&Date.now()-t<b&&r===this.getAnonId()&&(!i||i===this.getLoginId()))return d(E(n));localStorage.removeItem(this.getABLSName())}}catch(e){console.warn("Failed to load abdata from localStorage",e),this._abData=[]}return this._abData||[]}};function y(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 T=[];function P(e){const t={...e};t.timeout=t.timeout||6e4;const n=t.transport??"fetch",i=T.find(e=>e.transport===n)?.method??T[0]?.method;if(!i)throw new Error("No available transport method for HTTP request");i(t)}function C(e){return o(e=e||document.referrer)&&(e=h(e=e.trim()))||""}function L(e){const t=m(e=e||C());if(!t)return"";const n={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 i of Object.keys(n)){let e=n[i];for(let n=0,r=e.length;n<r;n++)if(e[n].test(t))return i}return"Unknown Search Engine"}function B(e,t){return-1!==e.indexOf(t)}"function"==typeof fetch&&T.push({transport:"fetch",method:function(e){if("undefined"==typeof fetch)return void console.error("fetch API is not available");const t=y(e),n=new Headers;e.headers&&Object.keys(e.headers).forEach(t=>{n.append(t,e.headers[t])}),t?.contentType&&n.append("Content-Type",t.contentType),fetch(e.url,{method:e.method||"GET",headers:n,body:t?.body}).then(t=>t.text().then(n=>{const i={statusCode:t.status,text:n};if(200===t.status)try{i.json=JSON.parse(n)}catch(r){console.error("Failed to parse response:",r)}e.callback?.(i)})).catch(t=>{console.error("Request failed:",t),e.callback?.({statusCode:0,text:String(t)})})}}),"undefined"!=typeof XMLHttpRequest&&T.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 n=y(e);e.headers&&Object.keys(e.headers).forEach(n=>{t.setRequestHeader(n,e.headers[n])}),n?.contentType&&t.setRequestHeader("Content-Type",n.contentType),t.timeout=e.timeout||6e4,t.withCredentials=!0,t.onreadystatechange=()=>{if(4===t.readyState){const i={statusCode:t.status,text:t.responseText};if(200===t.status)try{i.json=JSON.parse(t.responseText)}catch(n){console.error("Failed to parse JSON response:",n)}e.callback?.(i)}},t.send(n?.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"},D="(\\d+(\\.\\d+)?)",x=new RegExp("Version/"+D),M=new RegExp(F.XBOX,"i"),k=new RegExp(F.PLAYSTATION+" \\w+","i"),H=new RegExp(F.NINTENDO+" \\w+","i"),$=new RegExp(F.BLACKBERRY+"|PlayBook|BB10","i"),X=new RegExp("(HUAWEI|honor|HONOR)","i"),U=new RegExp("(Xiaomi|Redmi)","i"),q=new RegExp("(OPPO|realme)","i"),W=new RegExp("(vivo|IQOO)","i"),j={"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 G(e,t){return t=t||"",B(e," OPR/")&&B(e,"Mini")?F.OPERA_MINI:B(e," OPR/")?F.OPERA:$.test(e)?F.BLACKBERRY:B(e,"IE"+F.MOBILE)||B(e,"WPDesktop")?F.INTERNET_EXPLORER_MOBILE:B(e,F.SAMSUNG_BROWSER)?F.SAMSUNG_INTERNET:B(e,F.EDGE)||B(e,"Edg/")?F.MICROSOFT_EDGE:B(e,"FBIOS")?F.FACEBOOK+" "+F.MOBILE:B(e,"UCWEB")||B(e,"UCBrowser")?F.UC_BROWSER:B(e,"CriOS")?F.CHROME_IOS:B(e,"CrMo")||B(e,F.CHROME)?F.CHROME:B(e,F.ANDROID)&&B(e,F.SAFARI)?F.ANDROID_MOBILE:B(e,"FxiOS")?F.FIREFOX_IOS:B(e.toLowerCase(),F.KONQUEROR.toLowerCase())?F.KONQUEROR:function(e,t){return t&&B(t,F.APPLE)||B(n=e,F.SAFARI)&&!B(n,F.CHROME)&&!B(n,F.ANDROID);var n}(e,t)?B(e,F.MOBILE)?F.MOBILE_SAFARI:F.SAFARI:B(e,F.FIREFOX)?F.FIREFOX:B(e,"MSIE")||B(e,"Trident/")?F.INTERNET_EXPLORER:B(e,"Gecko")?F.FIREFOX:""}const Y={[F.INTERNET_EXPLORER_MOBILE]:[new RegExp("rv:"+D)],[F.MICROSOFT_EDGE]:[new RegExp(F.EDGE+"?\\/"+D)],[F.CHROME]:[new RegExp("("+F.CHROME+"|CrMo)\\/"+D)],[F.CHROME_IOS]:[new RegExp("CriOS\\/"+D)],[F.UC_BROWSER]:[new RegExp("(UCBrowser|UCWEB)\\/"+D)],[F.SAFARI]:[x],[F.MOBILE_SAFARI]:[x],[F.OPERA]:[new RegExp("("+F.OPERA+"|OPR)\\/"+D)],[F.FIREFOX]:[new RegExp(F.FIREFOX+"\\/"+D)],[F.FIREFOX_IOS]:[new RegExp("FxiOS\\/"+D)],[F.KONQUEROR]:[new RegExp("Konqueror[:/]?"+D,"i")],[F.BLACKBERRY]:[new RegExp(F.BLACKBERRY+" "+D),x],[F.ANDROID_MOBILE]:[new RegExp("android\\s"+D,"i")],[F.SAMSUNG_INTERNET]:[new RegExp(F.SAMSUNG_BROWSER+"\\/"+D)],[F.INTERNET_EXPLORER]:[new RegExp("(rv:|MSIE )"+D)],Mozilla:[new RegExp("rv:"+D)]};function z(e,t){const n=G(e,t),i=Y[n];if(a(i))return null;for(let r=0;r<i.length;r++){const t=i[r],n=e.match(t);if(n)return parseFloat(n[n.length-2])}return null}const K=[[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,""]],[$,[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 n=/Windows NT ([0-9.]+)/i.exec(t);if(n&&n[1]){const e=n[1];let i=j[e]||"";return/arm/i.test(t)&&(i="RT"),[F.WINDOWS,i]}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 n=[e[1],e[2],e[3]||"0"];t[1]=n.join(".")}return t}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[F.CHROME_OS,""]],[/Linux|debian/i,["Linux",""]]];function J(){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,n=navigator.userAgent,i=function(e){for(let t=0;t<K.length;t++){const[n,i]=K[t],r=n.exec(e),s=r&&("function"==typeof i?i(r,e):i);if(s)return s}return["",""]}(n)||["",""];return{$browser:G(n),$browser_version:z(n),$url:location?.href.substring(0,1e3),$host:location?.host,$viewport_height:e,$viewport_width:t,$lib:"webjs",$lib_version:"0.1.0",$search_engine:L(),$referrer:C(),$referrer_domain:m(s=s||C()),$model:(r=n,(H.test(r)?F.NINTENDO:k.test(r)?F.PLAYSTATION:M.test(r)?F.XBOX:new RegExp(F.OUYA,"i").test(r)?F.OUYA:new RegExp("("+F.WINDOWS_PHONE+"|WPDesktop)","i").test(r)?F.WINDOWS_PHONE:/iPad/.test(r)?F.IPAD:/iPod/.test(r)?"iPod Touch":/iPhone/.test(r)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(r)?F.APPLE_WATCH:$.test(r)?F.BLACKBERRY:/(kobo)\s(ereader|touch)/i.test(r)?"Kobo":new RegExp(F.NOKIA,"i").test(r)?F.NOKIA:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(r)||/(kf[a-z]+)( bui|\)).+silk\//i.test(r)?"Kindle Fire":X.test(r)?F.HUAWEI:U.test(r)?F.XIAOMI:q.test(r)?F.OPPO:W.test(r)?F.VIVO:/(Android|ZTE)/i.test(r)?!new RegExp(F.MOBILE).test(r)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(r)?/pixel[\daxl ]{1,6}/i.test(r)&&!/pixel c/i.test(r)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(r)||/lmy47v/i.test(r)&&!/QTAQZ3/i.test(r)?F.ANDROID:F.ANDROID_TABLET:F.ANDROID:new RegExp("(pda|"+F.MOBILE+")","i").test(r)?F.GENERIC_MOBILE:new RegExp(F.TABLET,"i").test(r)&&!new RegExp(F.TABLET+" pc","i").test(r)?F.GENERIC_TABLET:"")||""),$os:i?.[0]||"",$os_version:i?.[1]||"",$pathname:location?.pathname,$screen_height:Number(screen.height)||0,$screen_width:Number(screen.width)||0};var r,s}const Z=new class{constructor(){this.STORAGE_KEY="sol_unsent_events",this.MAX_QUEUE_SIZE=100,this.MAX_RETRY_COUNT=3,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.retryCount<t.maxRetries);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,n,i=this.MAX_RETRY_COUNT){try{const r={id:f(),url:e,data:t,headers:n,timestamp:Date.now(),retryCount:0,maxRetries:i};return this.queue.push(r),this.saveToStorage(),r.id}catch(r){return console.warn("Failed to enqueue request:",r),""}}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.retryCount>=t.maxRetries?(this.dequeue(e),!1):(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 Q{constructor(e={}){this.flushTimer=null,this.isFlushing=!1,this.pendingFlush=!1,this.config={maxBatchSize:e.maxBatchSize||10,flushInterval:e.flushInterval||5e3},this.startFlushTimer()}add(){Z.getAll().length>=this.config.maxBatchSize&&this.triggerFlush()}triggerFlush(){this.isFlushing?this.pendingFlush=!0:(this.isFlushing=!0,this.flush())}flush(){const e=Z.getAll();if(0===e.length)return this.isFlushing=!1,void(this.pendingFlush&&(this.pendingFlush=!1,this.triggerFlush()));const t=[],n=[];e.forEach(e=>{Array.isArray(e.data)?t.push(...e.data):t.push(e.data),n.push(e.id)});const i=t.slice(0,this.config.maxBatchSize),r=e[0],s=r.url,o=r.headers;O.instance.config.debug&&console.log(JSON.stringify(i,null,2)),P({url:s,method:"POST",data:i,headers:o,callback:e=>{200!==e.statusCode?console.error("Failed to send batch events:",e):n.forEach(e=>{Z.dequeue(e)}),this.isFlushing=!1;const t=Z.getAll();(this.pendingFlush||t.length>=this.config.maxBatchSize)&&(this.pendingFlush=!1,this.triggerFlush())}})}startFlushTimer(){this.flushTimer&&clearInterval(this.flushTimer),this.flushTimer=setInterval(()=>{this.flush()},this.config.flushInterval)}destroy(){this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flush()}}let V=null,ee=null;function te(e,t,n){return P({url:e,method:"POST",data:t.data,headers:t.headers,callback:e=>{if(200!==e.statusCode){if(n)if(Z.incrementRetryCount(n)){const e=Z.getItemById(n);if(e){const t=Math.min(1e3*Math.pow(2,e.retryCount),3e4);setTimeout(()=>{te(e.url,{data:e.data,headers:e.headers},e.id)},t)}}else console.warn("Max retries reached for request:",n)}else n&&Z.dequeue(n),t.callback&&t.callback(e.json)}})}function ne(e){return`${e.apiHost}/in/track`}function ie(e){return`${e.apiHost}/ff/evalall`}function re(e){return{"Content-Type":"application/json",ProjectToken:e.apiToken}}function se(e,t,n){O.instance.config.debug&&console.log(JSON.stringify(t.data,null,2));const i=Z.enqueue(e,t.data,t.headers);return te(e,{...t,callback:void 0},i)}function oe(e,t,n=!0){const i={time:Date.now(),trace_id:N.getTraceId(),event:e.event,properties:{...e.properties,...n?J():{}}},r=N.getLoginId(),s=N.getAnonId();r&&(i.login_id=r),s&&(i.anon_id=s);const o=ne(t),a=re(t),l=S.isSupport()?(ee||(V||(V=new Q({maxBatchSize:10,flushInterval:5e3})),ee=V),ee):null;!1!==t.batchSend&&l?(Z.enqueue(o,[i],a),l.add()):se(o,{data:[i],headers:a})}function ae({userProps:e,opts:t}){const n=N.getLoginId(),i=N.getAnonId();if(!n||!i)return;const r={time:Date.now(),trace_id:N.getTraceId(),event:"$user_set",login_id:n,anon_id:i,user_properties:e};return se(ne(t),{data:r,headers:re(t)})}class le{constructor({plugins:e,emitter:t,config:n}){this.plugins=[],this.pluginInsMap={},this.emitter=t,this.config=n,this.registerBuiltInPlugins(e),this.created(),this.emitter.on(_,()=>{this.init()})}registerBuiltInPlugins(e){for(let t=0,n=e.length;t<n;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 n=new t({emitter:this.emitter,config:this.config});this.pluginInsMap[t.NAME]=n}}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 ue=class{constructor({emitter:e,config:t}){this.boundSend=null,this.hashEvent=null,this.emitter=e,this.config=t}init(){const e=this.config;this.boundSend=()=>{oe({event:"$PageView",properties:{$title:document.title}},e)},e.isSinglePageApp?(this.hashEvent="pushState"in window.history?"popstate":"hashchange",window.addEventListener(this.hashEvent,this.boundSend)):this.boundSend()}destroy(){this.hashEvent&&this.boundSend&&(window.removeEventListener(this.hashEvent,this.boundSend),this.hashEvent=null,this.boundSend=null)}};ue.NAME="pageview";let ce=ue;const he=class{constructor({emitter:e,config:t}){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="solwebjssdkpageleave",this.maxDuration=432e3,this.eventListeners=[],this.emitter=e,this.config=t}init(){this.pageId=Number(String(p()).slice(2,5)+String(p()).slice(2,4)+String(Date.now()).slice(-4)),this.addEventListener(),!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}pageEndHandler(){if(!0===this.pageHiddenStatus)return;const e=this.getPageLeaveProperties();!1===this.pageShowStatus&&delete e.event_duration,this.pageShowStatus=!1,this.pageHiddenStatus=!0,oe({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(v,e=>{e!==location.href&&(this.url=e,this.pageEndHandler(),this.stopHeartBeatInterval(),this.currentPageUrl=this.url,this.pageStartHandler(),this.hiddenStatusHandler(),this.addHeartBeatInterval())})}addPageEndListener(){["pagehide","beforeunload","unload"].forEach(e=>{if(`on${e}`in window){const t=()=>{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.pageEndHandler(),this.stopHeartBeatInterval())};document.addEventListener("visibilitychange",e),this.eventListeners.push({target:document,event:"visibilitychange",handler:e})}addHeartBeatInterval(){S.isSupport()&&this.startHeartBeatInterval()}startHeartBeatInterval(){this.heartbeatIntervalTimer&&this.stopHeartBeatInterval(),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){const t=this.getPageLeaveProperties();t.$time=Date.now(),"is_first_heartbeat"===e&&(t.event_duration=3);const n={type:"track",event:R,properties:t};n.heartbeat_interval_time=this.heartbeatIntervalTime,S.isSupport()&&S.set(`${this.storageName}-${this.pageId}`,JSON.stringify(n))}delHeartBeatData(e){S.isSupport()&&S.remove(e||`${this.storageName}-${this.pageId}`)}reissueHeartBeatData(){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=S.parse(t);i(e)&&Date.now()-e.time>e.heartbeat_interval_time+5e3&&(delete e.heartbeat_interval_time,e._flush_time=(new Date).getTime(),oe({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=document.documentElement&&document.documentElement.scrollTop||window.pageYOffset||document.body&&document.body.scrollTop||0,n=Math.round(t)||0,i={$title:this.title,$viewport_position:n};return 0!==e&&(i.event_duration=e),i}destroy(){this.eventListeners.forEach(({target:e,event:t,handler:n})=>{e.removeEventListener(t,n)}),this.eventListeners=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.heartbeatIntervalTimer&&(clearInterval(this.heartbeatIntervalTimer),this.heartbeatIntervalTimer=null)}};he.NAME="pageleave";let de=he;const ge=class{constructor({emitter:e,config:t}){this.eventSended=!1,this.emitter=e,this.config=t}init(){const e=()=>{let t=0;const n=window.performance,i={$title:document.title};if(n){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 n of e)"transferSize"in n&&(t+=n.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,oe({event:"$PageLoad",properties:i},this.config)),window.removeEventListener("load",e)};"complete"===document.readyState?e():window.addEventListener&&window.addEventListener("load",e)}};ge.NAME="pageload";let pe=ge;function fe(e,t){if(!c(e))return!1;const n=o(e.tagName)?e.tagName.toLowerCase():"unknown",i={};i.$element_type=n,i.$element_name=e.getAttribute("name"),i.$element_id=e.getAttribute("id"),i.$element_class_name=o(e.className)?e.className:null,i.$element_target_url=e.getAttribute("href"),i.$element_content=function(e,t){return o(t)&&"input"===t.toLowerCase()?("button"===(n=e).type||"submit"===n.type)&&n.value||"":function(e,t){let n="",i="";return e.textContent?n=w(e.textContent):e.innerText&&(n=w(e.innerText)),n&&(n=n.replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255)),i=n||"","input"!==t&&"INPUT"!==t||(i=e.value||""),i}(e,t);var n}(e,n),i.$element_selector=me(e),i.$element_path=function(e){let t=[];for(;e.parentNode&&c(e);){if(!o(e.tagName))return"unknown";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.$url_path=location.pathname,i.$title=document.title;const r=function(e,t){const n=t.pageX||t.clientX+Ee().scrollLeft||t.offsetX+Ie(e).targetEleX,i=t.pageY||t.clientY+Ee().scrollTop||t.offsetY+Ie(e).targetEleY;return{$page_x:Se(n),$page_y:Se(i)}}(e,t);return i.$page_x=r.$page_x,i.$page_y=r.$page_y,i}function me(e,t=[]){if(!(e&&e.parentNode&&e.parentNode.children&&o(e.tagName)))return"unknown";t=Array.isArray(t)?t:[];const n=e.nodeName.toLowerCase();return e&&"body"!==n&&1==e.nodeType?(t.unshift(function(e){if(!e||!c(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 n=e.tagName,i=e.parentNode.children;for(let r=0,s=i.length;r<s;r++)if(i[r].tagName===n){if(e===i[r])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(" > "):me(e.parentNode,t)):(t.unshift("body"),t.join(" > "))}function Ee(){return{scrollLeft:document.body.scrollLeft||document.documentElement.scrollLeft||0,scrollTop:document.body.scrollTop||document.documentElement.scrollTop||0}}function Ie(e){if(document.documentElement.getBoundingClientRect){const t=e.getBoundingClientRect();return{targetEleX:t.left+Ee().scrollLeft||0,targetEleY:t.top+Ee().scrollTop||0}}return{targetEleX:0,targetEleY:0}}function Se(e){return Number(Number(e).toFixed(3))}const we=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("sol-disable"))return;oe({event:"$WebClick",properties:fe(t,e)||{}},this.config)}destroy(){this.boundHandleClick&&(document.removeEventListener("click",this.boundHandleClick,!0),this.boundHandleClick=null),this.isInitialized=!1}};we.NAME="webclick";let Oe=we;const _e=class{constructor({emitter:e,config:t}){this.updateInterval=null,this.fetchingPromise=null,this.emitter=e,this.config=t}init(){const e=this.config;e.enableFeatureFlag&&(this.fastFetch().then(()=>{this.emitter.emit(A)}),e.featureFlagRefreshInterval<3e4&&(e.featureFlagRefreshInterval=3e4),this.updateInterval=setInterval(()=>{this.fetchNewData().catch(console.warn)},e.featureFlagRefreshInterval))}async fastFetch(){const e=N.getABData();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}){const n=N.getLoginId(),i=N.getAnonId();if(!n||!i)return;const r={ffuser:{login_id:n,anon_id:i,props:J()||{}}};P({url:ie(e),method:"POST",data:r,headers:re(e),callback:e=>{200!==e.statusCode?console.error("Failed to fetch feature flags"):t&&t(e.json)}})}({opts:this.config,cb:t=>{N.saveABData(t.data),e(t),this.fetchingPromise=null}})})),this.fetchingPromise}async getFeatureFlag(e){return await this.fastFetch().catch(console.warn),N.getABData().find(t=>t.ffkey===e)}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null),this.fetchingPromise=null}};_e.NAME="abtest";let ve=_e;const Ae=[],Re={debug:!1,apiToken:"",apiHost:"",autoCapture:!0,beforeSend:e=>e,isSinglePageApp:!1,crossSubdomainCookie:!0,enableFeatureFlag:!1,featureFlagRefreshInterval:b,enableClickTrack:!1,batchSend:!0};return new class{constructor(){this.__loaded=!1,this.config={},this.eventEmitter=new e,this.pluginCore={},this.commonProps={},this.spaCleanup=null,O.instance=this}init(e,t={}){t.apiToken=e,this.mergeConfig(t),this.eventEmitter.emit("init-param",this.config);const n=this.config;return N.init(n.crossSubdomainCookie),this.__loaded=!0,window._solFailedRequestsInitialized||(window._solFailedRequestsInitialized=!0,function(){const e=Z.getAll();0!==e.length&&e.forEach(e=>{te(e.url,{data:e.data,headers:e.headers},e.id)})}()),n.autoCapture&&this.autoTrack(),n.enableFeatureFlag&&Ae.push(ve),n.enableClickTrack&&Ae.push(Oe),this.pluginCore=new le({plugins:Ae,emitter:this.eventEmitter,config:n}),this.spaCleanup=function(e){let t=location.href;const n=window.history.pushState,i=window.history.replaceState,s=function(){e(t),t=location.href};return r(window.history.pushState)&&(window.history.pushState=function(...i){n.apply(window.history,i),e(t),t=location.href}),r(window.history.replaceState)&&(window.history.replaceState=function(...n){i.apply(window.history,n),e(t),t=location.href}),window.addEventListener("popstate",s),function(){r(window.history.pushState)&&(window.history.pushState=n),r(window.history.replaceState)&&(window.history.replaceState=i),window.removeEventListener("popstate",s)}}(e=>{this.eventEmitter.emit(v,e)}),this.eventEmitter.emit(_),this}mergeConfig(e){this.config={...Re,...e}}track(e){!function(e,t){const n={...e};n.time||(n.time=Date.now()),n.login_id||(n.login_id=N.getLoginId()),n.anon_id||(n.anon_id=N.getAnonId()),n.properties={...J(),...n.properties},se(ne(t),{data:n,headers:re(t)})}(e,this.config)}trackEvent(e,t){oe({event:e,properties:{...t,...this.commonProps}},this.config)}autoTrack(){Ae.push(ce,pe,de)}profileSet(e){ae({userProps:{$set:e},opts:this.config})}profileSetOnce(e){ae({userProps:{$set_once:e},opts:this.config})}profileIncrement(e){ae({userProps:{$increment:e},opts:this.config})}profileAppend(e){ae({userProps:{$append:e},opts:this.config})}profileUnion(e){ae({userProps:{$union:e},opts:this.config})}profileUnset(e){const t={};s(e)?e.forEach(function(e){t[e]=null}):t[e]=null,ae({userProps:{$unset:t},opts:this.config})}profileDelete(){ae({userProps:{$delete:!0},opts:this.config})}registerCommonProperties(e){if(!i(e))return console.warn("Commmon Properties must be an object!");this.commonProps=e}clearCommonProperties(e){if(!s(e))return console.warn("Commmon Properties to be cleared must be an array!");e.forEach(e=>{delete this.commonProps[e]})}identify(e){N.setLoginId(e),function(e){const t=N.getLoginId(),n=N.getAnonId();if(!t||!n)return;const i={time:Date.now(),trace_id:N.getTraceId(),event:"$identify",login_id:t,anon_id:n};se(ne(e),{data:i,headers:re(e)})}(this.config)}setLoginId(e){N.setLoginId(e)}getAnonId(){return N.getAnonId()}getLoginId(){return N.getLoginId()}getFeatureFlag(e){const t=this.pluginCore.getPlugin(ve.NAME);return this.config.enableFeatureFlag&&t?t.getFeatureFlag(e):Promise.reject("Feature flag is disabled")}destroy(){ee&&(ee.destroy(),ee=null),this.spaCleanup&&"function"==typeof this.spaCleanup&&(this.spaCleanup(),this.spaCleanup=null),this.pluginCore&&"function"==typeof this.pluginCore.destroy&&this.pluginCore.destroy(),this.eventEmitter&&this.eventEmitter.removeAllListeners(),O.instance===this&&(O.instance=null)}}});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
type SolEvent = {
|
|
2
|
+
event: string;
|
|
3
|
+
properties: Record<string, any>;
|
|
4
|
+
};
|
|
5
|
+
type SolSendEvent = {
|
|
6
|
+
event: string;
|
|
7
|
+
properties?: Record<string, any>;
|
|
8
|
+
time: number;
|
|
9
|
+
anon_id?: string;
|
|
10
|
+
login_id?: string;
|
|
11
|
+
trace_id: string;
|
|
12
|
+
user_properties?: Record<string, any>;
|
|
13
|
+
subject_properties?: Record<string, any>;
|
|
14
|
+
};
|
|
15
|
+
type AdvanceEvent = SolSendEvent;
|
|
16
|
+
type FFUser = {
|
|
17
|
+
anon_id?: string;
|
|
18
|
+
login_id?: string;
|
|
19
|
+
props?: Record<string, any>;
|
|
20
|
+
};
|
|
21
|
+
type ABData = {
|
|
22
|
+
ff_property_name: string;
|
|
23
|
+
ffid: number;
|
|
24
|
+
ffkey: string;
|
|
25
|
+
vid: string;
|
|
26
|
+
}
|
|
27
|
+
type SolABRequestData = {
|
|
28
|
+
ffuser: {
|
|
29
|
+
anon_id?: string;
|
|
30
|
+
login_id?: string;
|
|
31
|
+
props?: Record<string, any>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
interface SolConfig {
|
|
35
|
+
debug?: boolean;
|
|
36
|
+
apiHost?: string;
|
|
37
|
+
autoCapture?: boolean;
|
|
38
|
+
beforeSend?: Function;
|
|
39
|
+
isSinglePageApp?: boolean;
|
|
40
|
+
crossSubdomainCookie?: boolean;
|
|
41
|
+
enableFeatureFlag?: boolean;
|
|
42
|
+
featureFlagRefreshInterval?: number;
|
|
43
|
+
enableClickTrack?: boolean;
|
|
44
|
+
batchSend?: boolean;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}
|
|
47
|
+
interface SolInterface {
|
|
48
|
+
trackEvent(e: string, p?: Object): void;
|
|
49
|
+
track(e: AdvanceEvent): void;
|
|
50
|
+
profileSet(p: Object): void;
|
|
51
|
+
profileSetOnce(p: Object): void;
|
|
52
|
+
profileIncrement(p: Object): void;
|
|
53
|
+
profileAppend(p: Object): void;
|
|
54
|
+
profileUnion(p: Object): void;
|
|
55
|
+
profileUnset(p: string | string[]): void;
|
|
56
|
+
profileDelete(): void;
|
|
57
|
+
registerCommonProperties(p: Record<string, string | Function>): void;
|
|
58
|
+
clearCommonProperties(p: string[]): void;
|
|
59
|
+
identify(u: string | number): void;
|
|
60
|
+
setLoginId(u: string | number): void;
|
|
61
|
+
getFeatureFlag(ffkey: string): Promise<ABData>;
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const cookie: {
|
|
2
|
+
get: (name: string) => any;
|
|
3
|
+
set: ({ name, value, expires, samesite, secure, domain }: {
|
|
4
|
+
name: string;
|
|
5
|
+
value: string;
|
|
6
|
+
expires?: number;
|
|
7
|
+
samesite?: "Lax" | "Strict" | "None";
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
domain?: string;
|
|
10
|
+
}) => void;
|
|
11
|
+
remove: (name: string) => void;
|
|
12
|
+
isSupport: ({ samesite, secure }?: {
|
|
13
|
+
samesite?: "Lax" | "Strict" | "None" | undefined;
|
|
14
|
+
secure?: boolean;
|
|
15
|
+
}) => boolean;
|
|
16
|
+
};
|
|
17
|
+
export default cookie;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class EventEmitter {
|
|
2
|
+
private listeners;
|
|
3
|
+
on(event: string, listener: (...args: any[]) => void, isOnce?: boolean): void;
|
|
4
|
+
off(event: string, listener: number | ((...args: any[]) => void)): void;
|
|
5
|
+
emit(event: string, ...args: any[]): void;
|
|
6
|
+
once(event: string, listener: (...args: any[]) => void): void;
|
|
7
|
+
removeAllListeners(event?: string): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EventEmitter } from './event-emitter';
|
|
2
|
+
import cookie from './cookie';
|
|
3
|
+
declare function isObject(arg: any): boolean;
|
|
4
|
+
declare function isFunction(arg: any): boolean;
|
|
5
|
+
declare function isDate(arg: any): boolean;
|
|
6
|
+
declare function isBoolean(arg: any): boolean;
|
|
7
|
+
declare function isArray(arg: any): boolean;
|
|
8
|
+
declare function isString(arg: any): boolean;
|
|
9
|
+
declare function isUndefined(arg: any): boolean;
|
|
10
|
+
declare function isNumber(arg: any): boolean;
|
|
11
|
+
declare function isArguments(arg: any): boolean;
|
|
12
|
+
declare function isEmptyObject(arg: any): boolean;
|
|
13
|
+
declare function isElement(arg: any): boolean;
|
|
14
|
+
declare function _decodeURIComponent(uri: string): string;
|
|
15
|
+
declare function getCookieTopLevelDomain(hostname: string | undefined, isSecureCookie?: boolean): string;
|
|
16
|
+
declare function isIOS(): boolean;
|
|
17
|
+
declare function safeJSONParse(str: string): any;
|
|
18
|
+
declare const getRandomBasic: (max: number) => number;
|
|
19
|
+
declare function getRandom(): number;
|
|
20
|
+
declare const UUID: () => string;
|
|
21
|
+
declare function getHostname(url: string, defaultValue?: string): string;
|
|
22
|
+
declare function base64Decode(str: string): string;
|
|
23
|
+
declare function base64Encode(str: string): string;
|
|
24
|
+
declare const _localStorage: {
|
|
25
|
+
get: (key: string) => string | null;
|
|
26
|
+
parse: (key: string) => any;
|
|
27
|
+
set: (key: string, value: string) => void;
|
|
28
|
+
remove: (key: string) => void;
|
|
29
|
+
isSupport: () => boolean;
|
|
30
|
+
};
|
|
31
|
+
declare function trim(str: string): string;
|
|
32
|
+
declare function formatDate(date: Date): string;
|
|
33
|
+
declare function getIOSVersion(): number | "";
|
|
34
|
+
declare function noPrototypePollution(key: any): boolean;
|
|
35
|
+
declare function getElementContent(element: HTMLElement, tagName: string): string;
|
|
36
|
+
export { EventEmitter, cookie, getCookieTopLevelDomain, isNumber, isObject, isString, isUndefined, isArray, isBoolean, isDate, isArguments, isEmptyObject, isFunction, isElement, _decodeURIComponent as decodeURIComponent, safeJSONParse, isIOS, getRandom, getRandomBasic, UUID, getHostname, base64Decode, base64Encode, noPrototypePollution, formatDate, getIOSVersion, trim, _localStorage as localStore, getElementContent };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface BatchSenderConfig {
|
|
2
|
+
maxBatchSize: number;
|
|
3
|
+
flushInterval: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class BatchSender {
|
|
6
|
+
private flushTimer;
|
|
7
|
+
private config;
|
|
8
|
+
private isFlushing;
|
|
9
|
+
private pendingFlush;
|
|
10
|
+
constructor(config?: Partial<BatchSenderConfig>);
|
|
11
|
+
add(): void;
|
|
12
|
+
private triggerFlush;
|
|
13
|
+
private flush;
|
|
14
|
+
private startFlushTimer;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function getBatchSender(config?: Partial<BatchSenderConfig>): BatchSender;
|
|
18
|
+
export declare function destroyBatchSender(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCurrentDomain(url: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEleInfo(target: HTMLElement, ev: MouseEvent): false | Record<string, any>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface QueueItem {
|
|
2
|
+
id: string;
|
|
3
|
+
url: string;
|
|
4
|
+
data: any;
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
retryCount: number;
|
|
8
|
+
maxRetries: number;
|
|
9
|
+
}
|
|
10
|
+
declare class PersistentQueue {
|
|
11
|
+
private readonly STORAGE_KEY;
|
|
12
|
+
private readonly MAX_QUEUE_SIZE;
|
|
13
|
+
private readonly MAX_RETRY_COUNT;
|
|
14
|
+
private readonly MAX_AGE_MS;
|
|
15
|
+
private queue;
|
|
16
|
+
constructor();
|
|
17
|
+
private loadFromStorage;
|
|
18
|
+
private cleanupExpiredItems;
|
|
19
|
+
private saveToStorage;
|
|
20
|
+
enqueue(url: string, data: any, headers: Record<string, string>, maxRetries?: number): string;
|
|
21
|
+
dequeue(id: string): void;
|
|
22
|
+
getAll(): QueueItem[];
|
|
23
|
+
incrementRetryCount(id: string): boolean;
|
|
24
|
+
clear(): void;
|
|
25
|
+
getItemById(id: string): QueueItem | undefined;
|
|
26
|
+
}
|
|
27
|
+
declare const _default: PersistentQueue;
|
|
28
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function getPresetEventProps(): {
|
|
2
|
+
$browser: string;
|
|
3
|
+
$browser_version: number | null;
|
|
4
|
+
$url: string;
|
|
5
|
+
$host: string;
|
|
6
|
+
$viewport_height: number;
|
|
7
|
+
$viewport_width: number;
|
|
8
|
+
$lib: string;
|
|
9
|
+
$lib_version: string | undefined;
|
|
10
|
+
$search_engine: string;
|
|
11
|
+
$referrer: string;
|
|
12
|
+
$referrer_domain: string;
|
|
13
|
+
$model: string;
|
|
14
|
+
$os: string;
|
|
15
|
+
$os_version: string;
|
|
16
|
+
$pathname: string;
|
|
17
|
+
$screen_height: number;
|
|
18
|
+
$screen_width: number;
|
|
19
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HttpRequestOptions } from '../utils/request';
|
|
2
|
+
export declare function initFailedRequestsSenderWrapper(): void;
|
|
3
|
+
export declare function cleanupBatchSender(): void;
|
|
4
|
+
export declare function send(url: string, opts: Partial<HttpRequestOptions>, cb?: Function): void;
|
|
5
|
+
export declare function sendEvent(data: SolEvent, opts: SolConfig, usePresetEventProps?: boolean): void;
|
|
6
|
+
export declare function sendSolEvent(e: SolSendEvent, opts: SolConfig): void;
|
|
7
|
+
export declare function sendIdentifyEvent(opts: SolConfig): void;
|
|
8
|
+
export declare function sendProfileEvent({ userProps, opts }: {
|
|
9
|
+
userProps: Record<string, any>;
|
|
10
|
+
opts: SolConfig;
|
|
11
|
+
}): void;
|
|
12
|
+
export declare function fetchFeatureFlags({ opts, cb }: {
|
|
13
|
+
customUser?: FFUser;
|
|
14
|
+
opts: SolConfig;
|
|
15
|
+
cb?: Function;
|
|
16
|
+
}): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const store: {
|
|
2
|
+
crossSubdomain: boolean | undefined;
|
|
3
|
+
requests: never[];
|
|
4
|
+
_sessionState: {};
|
|
5
|
+
_abData: ABData[];
|
|
6
|
+
_trace_id: string;
|
|
7
|
+
_state: {
|
|
8
|
+
props: {};
|
|
9
|
+
anon_id: string;
|
|
10
|
+
login_id: string;
|
|
11
|
+
identities: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
getIdentityCookieID(): string;
|
|
14
|
+
getProps: () => {};
|
|
15
|
+
getAnonId(): string;
|
|
16
|
+
getLoginId(): string;
|
|
17
|
+
getTraceId(): string;
|
|
18
|
+
set: (name: "props" | "anon_id" | "login_id", value: any) => void;
|
|
19
|
+
getCookieName: () => string;
|
|
20
|
+
getABLSName: () => string;
|
|
21
|
+
save: () => void;
|
|
22
|
+
init: (crossSubdomain: boolean | undefined) => void;
|
|
23
|
+
setLoginId(id: string): void;
|
|
24
|
+
saveABData(data: any): void;
|
|
25
|
+
getABData(): ABData[];
|
|
26
|
+
};
|
|
27
|
+
export default store;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const SDK_LIB_VERSION: string | undefined;
|
|
2
|
+
declare const EMIT_EVENT_NAME: {
|
|
3
|
+
INIT_PARAM: string;
|
|
4
|
+
INIT_READY: string;
|
|
5
|
+
SPA_SWITCH: string;
|
|
6
|
+
FF_READY: string;
|
|
7
|
+
};
|
|
8
|
+
declare const PRESET_EVENTS: {
|
|
9
|
+
PAGE_VIEW: string;
|
|
10
|
+
PAGE_LEAVE: string;
|
|
11
|
+
PAGE_LOAD: string;
|
|
12
|
+
WEB_CLICK: string;
|
|
13
|
+
IDENTIFY: string;
|
|
14
|
+
USER_SET: string;
|
|
15
|
+
};
|
|
16
|
+
declare const AB_LOCAL_MAX_EXPIRE_TIME: number;
|
|
17
|
+
export { AB_LOCAL_MAX_EXPIRE_TIME, SDK_LIB_VERSION, EMIT_EVENT_NAME, PRESET_EVENTS };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
type CommmonProps = {
|
|
2
|
+
[key: string]: string | Function;
|
|
3
|
+
};
|
|
4
|
+
declare class Sol {
|
|
5
|
+
private __loaded;
|
|
6
|
+
private config;
|
|
7
|
+
private eventEmitter;
|
|
8
|
+
private pluginCore;
|
|
9
|
+
private commonProps;
|
|
10
|
+
private spaCleanup;
|
|
11
|
+
constructor();
|
|
12
|
+
init(apiToken: string, config?: SolConfig): this;
|
|
13
|
+
private mergeConfig;
|
|
14
|
+
track(e: SolSendEvent): void;
|
|
15
|
+
trackEvent(event: string, properties: Record<string, any>): void;
|
|
16
|
+
private autoTrack;
|
|
17
|
+
profileSet(p: Object): void;
|
|
18
|
+
profileSetOnce(p: Object): void;
|
|
19
|
+
profileIncrement(p: Object): void;
|
|
20
|
+
profileAppend(p: Object): void;
|
|
21
|
+
profileUnion(p: Object): void;
|
|
22
|
+
profileUnset(p: string | string[]): void;
|
|
23
|
+
profileDelete(): void;
|
|
24
|
+
registerCommonProperties(p: CommmonProps): void;
|
|
25
|
+
clearCommonProperties(p: string[]): void;
|
|
26
|
+
identify(loginId: string): void;
|
|
27
|
+
setLoginId(loginId: string): void;
|
|
28
|
+
getAnonId(): string;
|
|
29
|
+
getLoginId(): string;
|
|
30
|
+
getFeatureFlag(ffkey: string): any;
|
|
31
|
+
destroy(): void;
|
|
32
|
+
}
|
|
33
|
+
declare const _default: Sol;
|
|
34
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EventEmitter } from '../../../core';
|
|
2
|
+
export declare class AbTest {
|
|
3
|
+
static NAME: string;
|
|
4
|
+
private emitter;
|
|
5
|
+
private config;
|
|
6
|
+
private updateInterval;
|
|
7
|
+
private fetchingPromise;
|
|
8
|
+
constructor({ emitter, config }: {
|
|
9
|
+
emitter: EventEmitter;
|
|
10
|
+
config: SolConfig;
|
|
11
|
+
});
|
|
12
|
+
init(): void;
|
|
13
|
+
fastFetch(): Promise<any>;
|
|
14
|
+
fetchNewData(): Promise<any>;
|
|
15
|
+
getFeatureFlag(ffkey: string): Promise<ABData | undefined>;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventEmitter } from '../../../core';
|
|
2
|
+
export default class PluginManager {
|
|
3
|
+
private plugins;
|
|
4
|
+
private pluginInsMap;
|
|
5
|
+
private emitter;
|
|
6
|
+
private config;
|
|
7
|
+
constructor({ plugins, emitter, config }: {
|
|
8
|
+
plugins: any[];
|
|
9
|
+
emitter: EventEmitter;
|
|
10
|
+
config: SolConfig;
|
|
11
|
+
});
|
|
12
|
+
registerBuiltInPlugins(buildtInPlugins: any[]): void;
|
|
13
|
+
registerPlugin(plugin: any): void;
|
|
14
|
+
getPlugins(): any[];
|
|
15
|
+
getPlugin(name: string): any;
|
|
16
|
+
created(): void;
|
|
17
|
+
init(): void;
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { EventEmitter } from '../../../core';
|
|
2
|
+
export declare class PageLeave {
|
|
3
|
+
static NAME: string;
|
|
4
|
+
private emitter;
|
|
5
|
+
private config;
|
|
6
|
+
private startTime;
|
|
7
|
+
private pageShowStatus;
|
|
8
|
+
private pageHiddenStatus;
|
|
9
|
+
private timer;
|
|
10
|
+
private currentPageUrl;
|
|
11
|
+
private url;
|
|
12
|
+
private title;
|
|
13
|
+
private heartbeatIntervalTime;
|
|
14
|
+
private heartbeatIntervalTimer;
|
|
15
|
+
private pageId;
|
|
16
|
+
private storageName;
|
|
17
|
+
private maxDuration;
|
|
18
|
+
private eventListeners;
|
|
19
|
+
constructor({ emitter, config }: {
|
|
20
|
+
emitter: EventEmitter;
|
|
21
|
+
config: SolConfig;
|
|
22
|
+
});
|
|
23
|
+
init(): void;
|
|
24
|
+
log(message: string): void;
|
|
25
|
+
refreshPageEndTimer(): void;
|
|
26
|
+
hiddenStatusHandler(): void;
|
|
27
|
+
pageStartHandler(): void;
|
|
28
|
+
pageEndHandler(): void;
|
|
29
|
+
addEventListener(): void;
|
|
30
|
+
addPageStartListener(): void;
|
|
31
|
+
addSinglePageListener(): void;
|
|
32
|
+
addPageEndListener(): void;
|
|
33
|
+
addPageSwitchListener(): void;
|
|
34
|
+
addHeartBeatInterval(): void;
|
|
35
|
+
startHeartBeatInterval(): void;
|
|
36
|
+
stopHeartBeatInterval(): void;
|
|
37
|
+
saveHeartBeatData(type?: string): void;
|
|
38
|
+
delHeartBeatData(storageKey?: string): void;
|
|
39
|
+
reissueHeartBeatData(): void;
|
|
40
|
+
getPageLeaveProperties(): Record<string, any>;
|
|
41
|
+
destroy(): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EventEmitter } from '../../../core';
|
|
2
|
+
export declare class PageLoad {
|
|
3
|
+
static NAME: string;
|
|
4
|
+
private emitter;
|
|
5
|
+
private config;
|
|
6
|
+
private eventSended;
|
|
7
|
+
constructor({ emitter, config }: {
|
|
8
|
+
emitter: EventEmitter;
|
|
9
|
+
config: SolConfig;
|
|
10
|
+
});
|
|
11
|
+
init(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventEmitter } from '../../../core';
|
|
2
|
+
export declare class PageView {
|
|
3
|
+
static NAME: string;
|
|
4
|
+
private emitter;
|
|
5
|
+
private config;
|
|
6
|
+
private boundSend;
|
|
7
|
+
private hashEvent;
|
|
8
|
+
constructor({ emitter, config }: {
|
|
9
|
+
emitter: EventEmitter;
|
|
10
|
+
config: SolConfig;
|
|
11
|
+
});
|
|
12
|
+
init(): void;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EventEmitter } from '../../../core';
|
|
2
|
+
export declare class WebClick {
|
|
3
|
+
static NAME: string;
|
|
4
|
+
private emitter;
|
|
5
|
+
private config;
|
|
6
|
+
private isInitialized;
|
|
7
|
+
private boundHandleClick;
|
|
8
|
+
constructor({ emitter, config }: {
|
|
9
|
+
emitter: EventEmitter;
|
|
10
|
+
config: SolConfig;
|
|
11
|
+
});
|
|
12
|
+
init(): void;
|
|
13
|
+
private handleClick;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface HttpResponse {
|
|
2
|
+
statusCode: number;
|
|
3
|
+
text?: string;
|
|
4
|
+
json?: any;
|
|
5
|
+
}
|
|
6
|
+
export type ResponseCallback = (response: HttpResponse) => void;
|
|
7
|
+
export interface HttpRequestOptions {
|
|
8
|
+
url: string;
|
|
9
|
+
data?: Record<string, any> | Record<string, any>[];
|
|
10
|
+
headers?: Record<string, any>;
|
|
11
|
+
transport?: 'XHR' | 'fetch';
|
|
12
|
+
method?: 'POST' | 'GET';
|
|
13
|
+
callback?: ResponseCallback;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
noRetries?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const SUPPORTS_HTTP_REQUEST: boolean;
|
|
18
|
+
interface RequestContent {
|
|
19
|
+
contentType: string;
|
|
20
|
+
body: string | BlobPart;
|
|
21
|
+
}
|
|
22
|
+
export declare function appendUrlParameters(url: string, params: Record<string, any>): string;
|
|
23
|
+
export declare function serializeJson(data: any, space?: string | number): string;
|
|
24
|
+
export declare function prepareRequestBody(options: HttpRequestOptions): RequestContent | undefined;
|
|
25
|
+
export declare function request(_options: HttpRequestOptions): void;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addSinglePageEvent(callback: Function): () => void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function includes(str: unknown[] | string, needle: unknown): boolean;
|
|
2
|
+
export declare const windowsVersionMap: Record<string, string>;
|
|
3
|
+
export declare function isSafari(userAgent: string): boolean;
|
|
4
|
+
export declare function detectBrowser(userAgent: string, vendor?: string | undefined): string;
|
|
5
|
+
export declare const versionRegexes: Record<string, RegExp[]>;
|
|
6
|
+
export declare function detectBrowserVersion(userAgent: string, vendor?: string | undefined): number | null;
|
|
7
|
+
export declare function detectOS(userAgent: string): [string, string];
|
|
8
|
+
export declare function detectDevice(userAgent: string): string;
|
|
9
|
+
export declare function detectDeviceType(userAgent: string): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@sensorswave/js-sdk",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Sensorswave JS SDK for web analytics",
|
|
6
|
+
"main": "dist/index.cjs.js",
|
|
7
|
+
"module": "dist/index.es.js",
|
|
8
|
+
"browser": "dist/index.umd.js",
|
|
9
|
+
"types": "dist/types/web/src/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build:types": "tsc --emitDeclarationOnly --outDir ../../build/dist/types",
|
|
12
|
+
"build": "rm -rf ../../build && npm run build:types && vite build && ./scripts/copy-api-types.sh",
|
|
13
|
+
"dev": "vite build --watch",
|
|
14
|
+
"test": "jest"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"sensorswave",
|
|
18
|
+
"analytics",
|
|
19
|
+
"tracking",
|
|
20
|
+
"sdk"
|
|
21
|
+
],
|
|
22
|
+
"author": "liulangyu",
|
|
23
|
+
"license": "ISC"
|
|
24
|
+
}
|