Files
2026-09-15 16:25:45 +07:00

2 lines
43 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
!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).LandingSDK=t()}(this,function(){"use strict";function e(e){var t=function(e){for(var t=String(null==e?"":e),n=[],r=0;r<t.length;r++){var o=t.charCodeAt(r);if(o<128)n.push(o);else if(o<2048)n.push(192|o>>6,128|63&o);else if(o>=55296&&o<=56319&&r+1<t.length){var i=t.charCodeAt(r+1);if(i>=56320&&i<=57343){var s=i-56320+(o-55296<<10)+65536;n.push(240|s>>18,128|s>>12&63,128|s>>6&63,128|63&s),r++}else n.push(224|o>>12,128|o>>6&63,128|63&o)}else n.push(224|o>>12,128|o>>6&63,128|63&o)}return n}(String(null==e?"":e)),n=8*t.length;for(t.push(128);t.length%64!=56;)t.push(0);for(var r=0;r<8;r++)t.push(n>>>8*r&255);for(var o=function(e,t){return e<<t|e>>>32-t},i=function(e,t){return((e>>>0)+(t>>>0)&4294967295)>>>0},s=function(e,t,n,r){return i(i(e,t),i(n,r))},a=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],u=new Array(64),c=0;c<64;c++)u[c]=Math.floor(4294967296*Math.abs(Math.sin(c+1)))>>>0;for(var f=1732584193,l=4023233417,h=2562383102,d=271733878,p=0;p<t.length;p+=64){for(var v=new Array(16),g=0;g<16;g++){var y=p+4*g;v[g]=(t[y]|t[y+1]<<8|t[y+2]<<16|t[y+3]<<24)>>>0}for(var m=f,_=l,w=h,b=d,P=0;P<64;P++){var S,C;P<16?(S=_&w|~_&b,C=P):P<32?(S=b&_|~b&w,C=(5*P+1)%16):P<48?(S=_^w^b,C=(3*P+5)%16):(S=w^(_|~b),C=7*P%16);var k=b;b=w,w=_,_=i(_,o(s(m,S,u[P],v[C]),a[P])),m=k}f=i(f,m),l=i(l,_),h=i(h,w),d=i(d,b)}var E=function(e){for(var t="",n=0;n<4;n++)t+=(256+(e>>>8*n&255)).toString(16).slice(1);return t};return E(f)+E(l)+E(h)+E(d)}function t(e,t){var n=65535&e,r=65535&t;return n*r+((e>>>16&65535)*r+n*(t>>>16&65535)<<16>>>0)|0}function n(e){for(var n=String(null==e?"":e),r=2166136261,o=0;o<n.length;o++)r=t(r^=n.charCodeAt(o),16777619);for(var i=(r>>>0).toString(16);i.length<8;)i="0"+i;return i}function r(e,t){if(null===e)return"__t:null__";if("string"==typeof e)return"__t:str__:"+e;if("number"==typeof e&&isFinite(e))return"__t:num__:"+String(e);if("boolean"==typeof e)return"__t:bool__:"+(e?"1":"0");if(Array.isArray(e)){if(-1!==t.indexOf(e))return"__t:circular__";t.push(e);var n="["+e.map(function(e){return r(e,t)}).join(",")+"]";return t.splice(t.indexOf(e),1),n}if(null!==e&&"object"==typeof e){if(-1!==t.indexOf(e))return"__t:circular__";t.push(e);var o="{"+Object.keys(e).sort().map(function(n){return n+":"+r(e[n],t)}).join(",")+"}";return t.splice(t.indexOf(e),1),o}return"__t:any__:"+String(e)}function o(e){return r(e,[])}function i(t){var n=t||{},r=Object.keys(n).filter(function(e){return"event_id"!==e}).sort();if(!r.length)return e("");var i=r.map(function(t){return e(o(n[t]))}).join("");return e(i)}function s(){if("undefined"==typeof navigator)return"PC";var e=navigator.userAgent||"";return/Android/i.test(e)?"Android":/iPhone|iPad|iPod/i.test(e)?"iOS":"PC"}function a(){try{var e="undefined"!=typeof navigator?navigator:{},t="undefined"!=typeof screen?screen:{},r="undefined"!=typeof Intl&&Intl.DateTimeFormat&&Intl.DateTimeFormat().resolvedOptions().timeZone||"",o=e.language||"",i=Array.isArray(e.languages)?e.languages.join(","):"",s=t.colorDepth||"",a=t.pixelDepth||"",u=void 0!==t.width&&void 0!==t.height?t.width+"x"+t.height:"",c=void 0!==t.availWidth&&void 0!==t.availHeight?t.availWidth+"x"+t.availHeight:"",f="undefined"!=typeof window&&window.devicePixelRatio?window.devicePixelRatio:"",l=e.maxTouchPoints||0,h=e.hardwareConcurrency||"",d=e.deviceMemory||"";return"fp_"+n([e.userAgent||"",e.platform||"",e.vendor||"",o,i,r,(new Date).getTimezoneOffset(),u,c,s,a,f,l,h,d].join("||"))}catch(e){return""}}function u(e){var t=String(null==e?"":e).trim();return t&&/^\d+\.\d+\.\d+$/.test(t)?t:"1.0.0"}function c(e){var t=e||{};return{app_id:String(t.appId||""),uid:null!=t.uid?t.uid:0,channel:String(t.channel||""),sid:String(t.sid||""),client_ts:Math.floor(Date.now()/1e3),device:String(t.deviceType||"PC"),device_id:String(t.deviceId||""),device_brand:String(t.deviceBrand||""),device_model:String(t.deviceModel||""),device_fingerprint:String(t.deviceFingerprint||""),fp_version:String(t.fpVersion||""),user_agent:"undefined"!=typeof navigator&&navigator.userAgent||"",sdk_version:String(t.sdkVersion||""),app_version:String(t.appVersion||"1.0.0")}}var f="__landing_sdk_sid__",l="__landing_sdk_sid_v1",h="__landing_sdk_device_id__",d="__landing_sdk_device_fp__",p="__landing_sdk_ping__",v=18e5,g=null,y=null;function m(){try{return!("undefined"==typeof window||!window.localStorage||(window.localStorage.setItem(p,"1"),window.localStorage.removeItem(p),0))}catch(e){return!1}}function _(){var e=new Uint8Array(16);if("undefined"!=typeof crypto&&crypto.getRandomValues)crypto.getRandomValues(e);else for(var t=0;t<16;t++)e[t]=Math.floor(256*Math.random());for(var n="",r=0;r<e.length;r++)n+=("0"+e[r].toString(16)).slice(-2);return n}function w(){return"undefined"!=typeof document&&"string"==typeof document.cookie}function b(e){try{var t=JSON.parse(e);if(!t||!t.sid)return null;var n=String(t.sid).trim();if(!n)return null;var r="number"==typeof t.lastBehaviorAt?t.lastBehaviorAt:"number"==typeof t.ts?t.ts:null;return null!==r&&"number"==typeof r&&isFinite(r)?{sid:n,lastBehaviorAt:r}:null}catch(e){return null}}function P(e){var t=JSON.stringify(e);if(m())try{window.localStorage.setItem(f,t)}catch(e){}!function(e){if(w())try{var t=encodeURIComponent(e),n="path=/;max-age=31536000;SameSite=Lax";"undefined"!=typeof location&&"https:"===location.protocol&&(n+=";Secure"),document.cookie=encodeURIComponent(l)+"="+t+";"+n}catch(e){}}(t)}function S(e){var t={sid:_(),lastBehaviorAt:e};return g=t,P(t),t.sid}function C(){var e=Date.now();if(!m()){var t=function(){if(!w())return null;for(var e=encodeURIComponent(l)+"=",t=document.cookie.split("; "),n=0;n<t.length;n++)if(0===t[n].indexOf(e))try{return decodeURIComponent(t[n].slice(e.length))}catch(e){return null}return null}(),n=t?b(t):null,r=g||n;return!r||e-r.lastBehaviorAt>v?S(e):(g=r={sid:r.sid,lastBehaviorAt:e},P(r),r.sid)}var o=null;try{o=window.localStorage.getItem(f)}catch(e){}var i=o?b(o):null;if(!i&&g&&(i=g),!i||e-i.lastBehaviorAt>v)return S(e);var s={sid:i.sid,lastBehaviorAt:e};return g=s,P(s),s.sid}function k(){if(!m())return y||(y=_()),Promise.resolve(y);try{var e=window.localStorage.getItem(h);if(e&&/^[0-9a-f]{32}$/.test(e))return Promise.resolve(e);var t=_();return window.localStorage.setItem(h,t),Promise.resolve(t)}catch(e){return y||(y=_()),Promise.resolve(y)}}function E(e){try{if(m()){var t=window.localStorage.getItem(d);if(t)return t}var n=e();if(n&&m())try{window.localStorage.setItem(d,n)}catch(e){}return n}catch(e){return""}}function A(e,t,n){if(n=n||{},!e)return Promise.resolve({sent:!1,ok:!1,status:0,reason:"no_endpoint"});if(!Array.isArray(t)||0===t.length)return Promise.resolve({sent:!0,ok:!0,status:200,reason:"empty_batch"});var r=JSON.stringify(t),o=!0===n.useBeacon,i=!1!==n.requireHttps,s=Number(n.timeoutMs),a=isFinite(s)&&s>0?Math.floor(s):1e4;if(!function(e,t){if(!t)return!0;var n,r=String(e||"").match(/^(https?):\/\/([^/:?#]+)/i);return!!r&&("https"===r[1].toLowerCase()||"http"===r[1].toLowerCase()&&("localhost"===(n=String(r[2]||"").toLowerCase())||"127.0.0.1"===n||"::1"===n))}(e,i))return"undefined"!=typeof console&&console.warn&&console.warn("[sdk][web] 已拒绝非 HTTPS 上报地址(localhost HTTP 除外)"),Promise.resolve({sent:!1,ok:!1,status:0,reason:"insecure_endpoint"});if(o&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon)try{var u=new Blob([r],{type:"application/json"});if(navigator.sendBeacon(e,u))return Promise.resolve({sent:!0,ok:!0,status:200,transport:"beacon",uncertain:!0})}catch(e){}return function(e,t,n){if("function"!=typeof fetch)return Promise.resolve(null);var r="undefined"!=typeof AbortController?new AbortController:null,o=r&&n>0?setTimeout(function(){r.abort()},n):null;return fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:t,keepalive:!0,signal:r?r.signal:void 0}).then(function(e){return o&&clearTimeout(o),{sent:!0,ok:e.ok,status:Number(e.status||0),transport:"fetch"}}).catch(function(e){return o&&clearTimeout(o),e&&"object"==typeof e&&"AbortError"===e.name?{sent:!1,ok:!1,status:0,reason:"timeout",transport:"fetch"}:null})}(e,r,a).then(function(t){return null!==t?t:function(e,t,n){return new Promise(function(r){try{if("undefined"==typeof XMLHttpRequest)return r({sent:!1,ok:!1,status:0,reason:"no_xhr"});var o=new XMLHttpRequest;o.open("POST",e,!0),o.timeout=n,o.setRequestHeader("Content-Type","application/json"),o.onreadystatechange=function(){4===o.readyState&&r({sent:!0,ok:o.status>=200&&o.status<300,status:o.status,transport:"xhr"})},o.onerror=function(){r({sent:!1,ok:!1,status:0,reason:"xhr_error"})},o.ontimeout=function(){r({sent:!1,ok:!1,status:0,reason:"timeout",transport:"xhr"})},o.send(t)}catch(e){r({sent:!1,ok:!1,status:0,reason:"xhr_exception"})}})}(e,r,a)})}var T="2.0.0",x="1.0.0",O="/dcserv/api/eventTracking/batchReport.json",B="/dcserv/api/eventTracking/report.json",I=5e3,D=!1;function M(e){e=e||{},this.selectedBatchEndpoint="",this.remoteEndpoints=[],this.remoteProbePromise=null,this.remoteProbeKey="",this.shouldPersistOnFail=!1,this.hasBatchProbeStarted=!1,this.initialized=!1,this.initPromise=null,this.endpointReadyListeners=[],this.timeoutMs=Number(e.pingTimeoutMs)||1500}M.prototype.normalizeBatchEndpoints=function(e){return(Array.isArray(e)?e:[]).map(function(e){return String(e||"").trim()}).filter(Boolean).filter(function(e){return/^https:\/\//i.test(e)}).map(function(e){var t=e.match(/^(https?:\/\/[^/?#]+)/i);return(t?t[1]:e.replace(/\/+$/,""))+"/api/eventTracking/batchReport.json"})},M.prototype._withTimeout=function(e,t){return new Promise(function(n,r){var o=setTimeout(function(){r(new Error("timeout"))},t);e.then(function(e){clearTimeout(o),n(e)}).catch(function(e){clearTimeout(o),r(e)})})},M.prototype._xhrRace=function(e,t){return e.length?new Promise(function(n){var r=e.length,o=!1,i=[];function s(){for(var e=0;e<i.length;e++)try{i[e].abort()}catch(e){}}for(var a=0;a<e.length;a++)(function(e){try{var a=new XMLHttpRequest,u=null,c=!1;function f(t){c||(c=!0,u&&(clearTimeout(u),u=null),t&&!o?(o=!0,s(),n(e)):t||(r--,o||0!==r||n("")))}i.push(a),u=setTimeout(function(){f(!1)},t),a.open("POST",e,!0),a.setRequestHeader("Content-Type","application/json"),a.onreadystatechange=function(){4===a.readyState&&f(a.status>0)},a.onerror=function(){f(!1)},a.send("[]")}catch(l){r--,o||0!==r||n("")}})(e[a])}):Promise.resolve("")},M.prototype._pickFastest=function(e,t){var n=this;if("undefined"==typeof fetch)return n._xhrRace(e,t);if(!e.length)return Promise.resolve("");var r="undefined"!=typeof AbortController,o=[];function i(){if(r)for(var e=0;e<o.length;e++)try{o[e].abort()}catch(e){}}return new Promise(function(s){for(var a=e.length,u=!1,c=0;c<e.length;c++)(function(e){var c=r?new AbortController:null;c&&o.push(c);var f={method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:"[]",cache:"no-store"};c&&(f.signal=c.signal),n._withTimeout(fetch(e,f),t).then(function(t){t&&t.status>0?u||(u=!0,i(),s(e)):(a--,u||0!==a||s(""))}).catch(function(){a--,u||0!==a||s("")})})(e[c])})},M.prototype._notifyReady=function(){var e=this.selectedBatchEndpoint;this.endpointReadyListeners.forEach(function(t){try{t(e)}catch(e){}})},M.prototype._setSelectedEndpoint=function(e){var t=String(e||"");t&&t!==this.selectedBatchEndpoint&&(this.selectedBatchEndpoint=t,this._notifyReady())},M.prototype.startRemoteProbe=function(e){var t=e.join("|");if(!e.length)return Promise.resolve("");if(this.remoteProbePromise&&this.remoteProbeKey===t)return this.remoteProbePromise;this.remoteProbeKey=t,this.shouldPersistOnFail=!1;var n=this,r=this._pickFastest(e,this.timeoutMs).then(function(t){if(n.remoteProbePromise!==r)return n.selectedBatchEndpoint;if(n.remoteProbePromise=null,t)n._setSelectedEndpoint(t);else if(!n.selectedBatchEndpoint&&e.length){n.shouldPersistOnFail=!0;var o=e[Math.floor(Math.random()*e.length)];n._setSelectedEndpoint(o)}return n.selectedBatchEndpoint}).catch(function(){return n.remoteProbePromise===r&&(n.remoteProbePromise=null),n.selectedBatchEndpoint});return this.remoteProbePromise=r,r},M.prototype.refreshDomainConfig=function(e){var t=this;return e().then(function(e){var n=t.normalizeBatchEndpoints(e);return t.remoteEndpoints=n,n.length?(t.hasBatchProbeStarted=!0,t.startRemoteProbe(n)):t.selectedBatchEndpoint})},M.prototype.init=function(e){return this.initialized?Promise.resolve():(this.initPromise||(this.initialized=!0,this.initPromise=this.refreshDomainConfig(e).catch(function(){})),this.initPromise)},M.prototype.resolveEndpoint=function(e,t){if(t)return Promise.resolve(t);var n=this;return this.init(e).then(function(){return n.selectedBatchEndpoint||""})},M.prototype.onEndpointReady=function(e){if("function"!=typeof e)return function(){};this.endpointReadyListeners.push(e);var t=this;return function(){var n=t.endpointReadyListeners.indexOf(e);n>=0&&t.endpointReadyListeners.splice(n,1)}},M.prototype.consumeProbeFailurePersistSignal=function(){return!!this.shouldPersistOnFail&&(this.shouldPersistOnFail=!1,!0)},M.prototype.getEndpointState=function(){return this.selectedBatchEndpoint?"ready":this.remoteEndpoints.length>0?"probing":"unavailable"},M.prototype.getSelectedBatchEndpoint=function(){return this.selectedBatchEndpoint};var j="__web_sdk_remote_config_cache__",R=function(){var e=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],t=[1,2,4,8,16,32,64,128,27,54];function n(e){return 255&(e<<1^(128&e?27:0))}function r(t){return(e[t>>>24&255]<<24|e[t>>>16&255]<<16|e[t>>>8&255]<<8|e[255&t])>>>0}function o(t,r){var o,i,s,a,u,c,f,l,h,d,p,v,g=t.slice(0);for(s=[],a=0;a<16;a++)g[a]=255&(g[a]^r[a>>2]>>>24-8*(3&a));for(u=1;u<=14;u++){for(o=[],a=0;a<16;a++)o[a]=e[g[a]];for(i=[],f=0;f<4;f++)for(l=0;l<4;l++)i[f+4*l]=o[f+4*(l+f&3)];if(u<14){for(s=[],c=0;c<4;c++)d=i[4*c+1],p=i[4*c+2],v=i[4*c+3],s[4*c]=255&(n(h=i[4*c])^n(d)^d^p^v),s[4*c+1]=255&(h^n(d)^n(p)^p^v),s[4*c+2]=255&(h^d^n(p)^n(v)^v),s[4*c+3]=255&(n(h)^h^d^p^n(v));for(g=s,s=[],a=0;a<16;a++)g[a]=255&(g[a]^r[4*u+(a>>2)]>>>24-8*(3&a))}else for(g=i,a=0;a<16;a++)g[a]=255&(g[a]^r[4*u+(a>>2)]>>>24-8*(3&a))}return g}function i(e,t){var n,r,o,i=[],s=t.slice(0);for(n=0;n<16;n++)i[n]=0;for(n=0;n<128;n++){if(e[n>>3]&128>>(7&n))for(r=0;r<16;r++)i[r]^=s[r];for(o=1&s[15],r=15;r>0;r--)s[r]=255&(s[r]>>>1|s[r-1]<<7);s[0]=s[0]>>>1&255,o&&(s[0]^=225)}return i}function s(e){var t,n=e.slice(0);for(t=15;t>=12&&(n[t]=n[t]+1&255,!n[t]);t--);return n}return{decrypt:function(e,n,a){var u,c,f,l,h,d,p,v,g,y,m,_,w,b,P=[],S=[],C=[],k=[];for(u=0;u<32;u++)P[u]=e[u]||0;for(u=0;u<12;u++)S[u]=n[u]||0;if((f=a.length-16)<0)return null;for(u=0;u<f;u++)C[u]=a[u];for(u=0;u<16;u++)k[u]=a[f+u];for(l=function(e){var n,o,i=[];for(n=0;n<8;n++)i[n]=(e[4*n]<<24|e[4*n+1]<<16|e[4*n+2]<<8|e[4*n+3])>>>0;for(n=8;n<60;n++)o=i[n-1],n%8?n%8==4&&(o=r(o)):o=(r((o<<8|o>>>24)>>>0)^t[n/8-1]<<24)>>>0,i[n]=(i[n-8]^o)>>>0;return i}(P),h=[],u=0;u<16;u++)h[u]=0;for(d=o(h,l),p=S.slice(0),u=12;u<15;u++)p[u]=0;for(p[15]=1,v=o(p,l),g=s(p),y=[],u=0;u<f;u+=16)for(m=o(g,l),g=s(g),c=0;c<16&&u+c<f;c++)y[u+c]=C[u+c]^m[c];for(_=C.slice(0);15&_.length;)_.push(0);for(u=0;u<8;u++)_.push(0);for(w=8*f,_.push(0,0,0,0),_.push(w>>>24&255,w>>>16&255,w>>>8&255,255&w),b=function(e,t){var n,r,o=[];for(n=0;n<16;n++)o[n]=0;for(n=0;n<t.length;n+=16){for(r=0;r<16;r++)o[r]^=t[n+r]||0;o=i(o,e)}return o}(d,_),u=0;u<16;u++)if((v[u]^b[u])!==k[u])return null;return y}}}();function F(e){this.encryptedConfigText=(e=e||{}).encryptedConfig||e.configCipher||"",this.cachedConfigPromise=null,this._secondGcmKeyBase64="en1BNo0VBrN/zi+mI2LO7E9W40ehCBYwC+frBn8s3rQ="}F.prototype.setEncryptedConfig=function(e){this.encryptedConfigText!==e&&(this.encryptedConfigText=e,this.cachedConfigPromise=null)},F.prototype._tryParse=function(e){try{return JSON.parse(e)}catch(t){return e}},F.prototype._unwrap=function(e,t){t=t||3;for(var n=e,r=0;r<t&&"string"==typeof n;r++){var o=this._tryParse(n);if(o===n)break;n=o}return n},F.prototype._toStringArray=function(e){var t=this._unwrap(e);if(Array.isArray(t))return t.map(function(e){return String(e||"").trim()}).filter(Boolean);if("string"==typeof t&&t.trim()){var n=this._tryParse(t);return Array.isArray(n)?n.map(function(e){return String(e||"").trim()}).filter(Boolean):[t.trim()]}return[]},F.prototype._getStorage=function(){try{return"undefined"!=typeof window&&window.localStorage?window.localStorage:null}catch(e){return null}},F.prototype._readPersisted=function(){try{var e=this._getStorage();if(!e)return{};var t=e.getItem(j);if(!t)return{};var n=JSON.parse(t);return Date.now()-(n.updatedAt||0)>24e5?{}:this._mapPayload(n)}catch(e){return{}}},F.prototype._mapPayload=function(e){if(!e||"object"!=typeof e)return{};var t=e.data&&"object"==typeof e.data?e.data:e;return{batchUrls:this._toStringArray(null!=t.batchUrls?t.batchUrls:t.domainList),eventCodes:this._toStringArray(null!=t.eventCodes?t.eventCodes:t.eventList)}},F.prototype._persist=function(e){try{var t=this._getStorage();if(!t)return;t.setItem(j,JSON.stringify({batchUrls:this._toStringArray(e.batchUrls),eventCodes:this._toStringArray(e.eventCodes),updatedAt:Date.now()}))}catch(e){}},F.prototype._base64ToBytes=function(e){for(var t=String(e||"").trim().replace(/-/g,"+").replace(/_/g,"/"),n=t.length%4?4-t.length%4:0,r=0;r<n;r++)t+="=";if("undefined"!=typeof atob&&"undefined"!=typeof Uint8Array){for(var o=atob(t),i=new Uint8Array(o.length),s=0;s<o.length;s++)i[s]=o.charCodeAt(s);return i}return new Uint8Array(0)},F.prototype._decryptAes256Gcm=function(e,t){try{var n=this._base64ToBytes(e);if(n.length<28)return Promise.reject(new Error("密文过短"));var r=this._base64ToBytes(t),o=n.slice(0,12),i=n.slice(12);if("undefined"!=typeof crypto&&crypto.subtle)return crypto.subtle.importKey("raw",r,{name:"AES-GCM"},!1,["decrypt"]).then(function(e){return crypto.subtle.decrypt({name:"AES-GCM",iv:o},e,i)}).then(function(e){return new Uint8Array(e)});var s,a=R.decrypt(r,o,i);if(!a)return Promise.reject(new Error("AES-GCM 认证标签校验失败"));if("undefined"!=typeof Uint8Array){s=new Uint8Array(a.length);for(var u=0;u<a.length;u++)s[u]=a[u]}else s=a;return Promise.resolve(s)}catch(e){return Promise.reject(e)}},F.prototype.fetchAndDecryptConfig=function(){if(this.cachedConfigPromise)return this.cachedConfigPromise;var e=this,t=this._readPersisted();if(!this.encryptedConfigText)return this.cachedConfigPromise=Promise.resolve(t),this.cachedConfigPromise;var n=this._decryptAes256Gcm(this.encryptedConfigText,this._secondGcmKeyBase64).then(function(t){var n;if("undefined"!=typeof TextDecoder)n=(new TextDecoder).decode(t);else{for(var r=[],o=0;o<t.length;o++)r[o]=t[o];n=String.fromCharCode.apply(null,r)}var i=e._mapPayload(JSON.parse(n));return e._persist(i),i}).catch(function(e){return"undefined"!=typeof console&&console.warn&&console.warn("[sdk][config] 解密失败:",e),t});return this.cachedConfigPromise=n,n},F.prototype.getBatchEndpoints=function(){return this.fetchAndDecryptConfig().then(function(e){return e.batchUrls||[]})},F.prototype.getEventCodes=function(){return this.fetchAndDecryptConfig().then(function(e){return Array.isArray(e.eventCodes)&&e.eventCodes.length>0?e.eventCodes:[]})},F.prototype.prewarm=function(){this.fetchAndDecryptConfig().catch(function(){})},F.prototype.forceRefresh=function(){this.cachedConfigPromise=null};var q="events";function L(e,t){var n=String(e&&e.event_id||"").trim();return n?n+"|||"+String(t||""):null}function H(e){for(var t={},n=Object.keys(e),r=0;r<n.length;r++)t[n[r]]=e[n[r]];return t}function V(){this.maxSize=2e3}V.prototype.isAvailable=function(){return"undefined"!=typeof indexedDB&&"undefined"!=typeof window&&null!=window.indexedDB},V.prototype.openDb=function(){var e=this;return new Promise(function(t,n){if(!e.isAvailable())return t(null);var r=indexedDB.open("landing_event_queue",1);r.onerror=function(){n(r.error||new Error("open indexedDB failed"))},r.onupgradeneeded=function(){var e=r.result;if(!e.objectStoreNames.contains(q)){var t=e.createObjectStore(q,{keyPath:"id",autoIncrement:!0});t.createIndex("createdAt","createdAt",{unique:!1}),t.createIndex("pendingDedupeKey","pendingDedupeKey",{unique:!0})}},r.onsuccess=function(){t(r.result)}})},V.prototype._txDone=function(e){return new Promise(function(t,n){e.oncomplete=function(){t()},e.onerror=function(){n(e.error||new Error("tx failed"))},e.onabort=function(){n(e.error||new Error("tx aborted"))}})},V.prototype._trimOverflow=function(e){var t=this,n=q,r=e.transaction(n,"readonly");return new Promise(function(e,t){var o=r.objectStore(n).count();o.onsuccess=function(){e(Number(o.result||0))},o.onerror=function(){t(o.error)}}).then(function(e){return t._txDone(r).then(function(){return e})}).then(function(r){if(!(r<=t.maxSize)){var o=r-t.maxSize,i=e.transaction(n,"readwrite"),s=i.objectStore(n).index("createdAt"),a=0;return new Promise(function(e,t){var r=s.openCursor();r.onerror=function(){t(r.error)},r.onsuccess=function(){var t=r.result;if(!t||a>=o)return e();i.objectStore(n).delete(t.primaryKey),a++,t.continue()}}).then(function(){return t._txDone(i)})}})},V.prototype.enqueueMany=function(e){var t=this;return e&&e.length?this.openDb().then(function(n){if(n){var r=Date.now(),o=e.map(function(e,t){var n=e&&"object"==typeof e&&"record"in e?e:{record:e},o=L(n.record,n.endpointOverride||""),i={createdAt:r+t,record:n.record,endpointOverride:n.endpointOverride||"",retryCount:0,nextRetryAt:0};return o&&(i.pendingDedupeKey=o),i});return new Promise(function(e,t){var r=n.transaction(q,"readwrite"),i=r.objectStore(q);r.oncomplete=function(){e()},r.onerror=function(){t(r.error)},r.onabort=function(){t(r.error)};var s=0;!function e(){if(!(s>=o.length)){var n=o[s++],r=i.add(n);r.onsuccess=function(){e()},r.onerror=function(n){var o=r.error;if(o&&"ConstraintError"===o.name)return n.preventDefault(),void e();t(o||new Error("add failed"))}}}()}).then(function(){return t._trimOverflow(n)}).then(function(){n.close()}).catch(function(e){throw n.close(),e})}}):Promise.resolve()},V.prototype.readOldest=function(e){return e=e||20,this.openDb().then(function(t){if(!t)return[];var n=Date.now(),r=[];return new Promise(function(o,i){var s=t.transaction(q,"readonly").objectStore(q).index("createdAt").openCursor();s.onerror=function(){i(s.error)},s.onsuccess=function(){var t=s.result;if(!t||r.length>=e)return o();var i=t.value,a=Number(i.nextRetryAt),u=isFinite(a)?Math.floor(a):0;if(u<=n){var c=H(i);c.endpointOverride=i.endpointOverride||"";var f=Number(i.retryCount);c.retryCount=isFinite(f)?Math.floor(f):0,c.nextRetryAt=u,r.push(c)}t.continue()}}).then(function(){return t.close(),r}).catch(function(e){throw t.close(),e})})},V.prototype.removeByIds=function(e){var t=this;return e&&e.length?this.openDb().then(function(n){if(n){for(var r=n.transaction(q,"readwrite"),o=r.objectStore(q),i=0;i<e.length;i++)o.delete(e[i]);return t._txDone(r).then(function(){n.close()}).catch(function(e){throw n.close(),e})}}):Promise.resolve()},V.prototype.updateRetryMeta=function(e,t,n){var r=this;return e&&e.length?this.openDb().then(function(o){if(!o)return{dropped:0,kept:0};for(var i=Date.now(),s=Number(t),a=isFinite(s)?Math.max(0,Math.floor(s)):0,u=Number(n),c=isFinite(u)?Math.max(0,Math.floor(u)):0,f=0,l=0,h=o.transaction(q,"readwrite"),d=h.objectStore(q),p=0;p<e.length;p++){var v=e[p],g=Number(v.retryCount),y=(isFinite(g)?Math.floor(g):0)+1;if(y>c)f++,d.delete(v.id);else{l++;var m=v.pendingDedupeKey||L(v.record,v.endpointOverride||""),_=H(v);m&&(_.pendingDedupeKey=m),_.retryCount=y,_.nextRetryAt=i+a,d.put(_)}}return r._txDone(h).then(function(){return o.close(),{dropped:f,kept:l}}).catch(function(e){throw o.close(),e})}):Promise.resolve({dropped:0,kept:0})},V.prototype.count=function(){var e=this;return this.openDb().then(function(t){if(!t)return 0;var n=t.transaction(q,"readonly");return new Promise(function(e,t){var r=n.objectStore(q).count();r.onsuccess=function(){e(Number(r.result||0))},r.onerror=function(){t(r.error)}}).then(function(r){return e._txDone(n).then(function(){return t.close(),r})}).catch(function(e){throw t.close(),e})})};var N={landingPageView:{landing_page_id:1},landingPageClick:{landing_page_id:1,tab_key:0,tab_name:0,click_coordinates_x:3,click_coordinates_y:3,click_x_percent:3,click_y_percent:3,screen_width:3,screen_height:3,trace_id:1}},U={landingPageView:"landing_page_view",landingPageClick:"landing_page_click"};function K(e,t){var n=N[e];if(!n)throw new Error("[sdk][landing] 未知事件方法:"+e);var r=t||{},o={},i=[],s=[];if(Object.keys(n).forEach(function(e){var t,a=n[e],u=1&a,c=a>>1&3,f=!!(8&a),l=r[e];f&&null===l&&(l=""),!u||f||null!=l&&""!==l?u&&f&&void 0===l?i.push(e):(u||null!=l)&&((1===c?"number"==typeof(t=l)&&isFinite(t)&&t===Math.floor(t):function(e){return"string"==typeof e}(l))?o[e]=l:s.push(e+"(expected "+(1===c?"int":"string")+")")):i.push(e)}),i.length||s.length){var a=new Error("[sdk][landing] 事件字段校验失败:"+e);throw a.name="EventValidationError",a.eventMethod=e,a.missingFields=i.slice(),a.typeErrorFields=s.slice(),a}return o}var z=Object.keys(U).reduce(function(e,t){var n=U[t];return e[t]=function(e){return{event:n,payload:K(t,e||{})}},e},{});function Q(){for(var e={},t=0;t<arguments.length;t++){var n=arguments[t];if(n)for(var r=Object.keys(n),o=0;o<r.length;o++)e[r[o]]=n[r[o]]}return e}var G="undefined"!=typeof console&&console.warn?function(e){console.warn(e)}:function(){},J=6e4,$="__landing_sdk_recent_ok_event_ids__",W=function(){var e={};function t(t){for(var n=Object.keys(e),r=0;r<n.length;r++)t-e[n[r]]>J&&delete e[n[r]]}function n(){try{"undefined"!=typeof window&&window.localStorage&&window.localStorage.setItem($,JSON.stringify(e))}catch(e){}}if(function(){try{if("undefined"!=typeof window&&window.localStorage){var t=window.localStorage.getItem($);if(t)for(var n=JSON.parse(t),r=Date.now(),o=Object.keys(n),i=0;i<o.length;i++)/^[0-9a-f]{32}$/.test(o[i])&&r-n[o[i]]<=J&&(e[o[i]]=n[o[i]])}}catch(e){}}(),"undefined"!=typeof window)try{window.addEventListener("storage",function(t){try{if(t.key!==$||!t.newValue)return;for(var n=JSON.parse(t.newValue),r=Date.now(),o=Object.keys(n),i=0;i<o.length;i++){var s=n[o[i]];/^[0-9a-f]{32}$/.test(o[i])&&r-s<=J&&(e[o[i]]=s)}}catch(e){}})}catch(e){}return{has:function(n){if(!n)return!1;var r=Date.now();t(r);var o=e[n];return void 0!==o&&r-o<=J},set:function(r){var o=Date.now();t(o);for(var i=0;i<r.length;i++)r[i]&&(e[r[i]]=o);var s=Object.keys(e);if(s.length>500){for(var a="",u=1/0,c=0;c<s.length;c++)e[s[c]]<u&&(u=e[s[c]],a=s[c]);a&&delete e[a]}n()},reset:function(){e={},n()}}}();function X(e,t){this.opts=e,this.resolver=t,this.queue=[],this.timer=null,this.flushTail=Promise.resolve(),this.replaying=!1,this.replayTimer=null,this.hasPersistentItems=!0,this.persistentQueue=new V,this._resolveEndpoint=null,this._getEventCodes=null,this.startReplayTimer()}function Y(e){if("undefined"==typeof window)return G("[sdk][landing] 非浏览器环境(SSR/Node.js),SDK 仅支持浏览器,初始化已跳过。"),this._ssrSkipped=!0,this.options=e,this.configMgr=null,this.resolver=null,void(this.batcher=null);if(!Object.prototype.hasOwnProperty.call(e,"channel"))throw new Error('channel 为必传字段(可传空字符串 ""');this._ssrSkipped=!1;var t=Q(e);t.channel=null==e.channel?"":String(e.channel),this.options=t,this.configMgr=new F(e),this.resolver=new M({pingTimeoutMs:1500}),this.batcher=new X(this.options,this.resolver);var n=this;this.batcher._resolveEndpoint=function(e){if(!n.options.encryptedConfig){var t=e||n.options.endpoint||"";return!t&&n.options.domain&&(t=n.options.domain.replace(/\/+$/,"")+(n.options.batch?O:B)),Promise.resolve(t)}return n.resolver.resolveEndpoint(function(){return n.configMgr.getBatchEndpoints()},e)},this.batcher._getEventCodes=function(){return n.options.encryptedConfig?n.configMgr.getEventCodes():Promise.resolve(null)},this._unsubReady=null,this._onPageHide=null,this._onVisChange=null,this._refreshTimer=null,this._init({}),this._registerLifecycle()}X.prototype.startReplayTimer=function(){var e=this;this.replayTimer=setInterval(function(){e.replayPersistent()},I)},X.prototype._stopTimer=function(){this.timer&&(clearTimeout(this.timer),this.timer=null)},X.prototype._settleItem=function(e,t){e.settled||(e.settled=!0,e.timeoutTimer&&(clearTimeout(e.timeoutTimer),e.timeoutTimer=null),e.resolve(t))},X.prototype._purgeSettled=function(){this.queue.length&&(this.queue=this.queue.filter(function(e){return!e.settled}))},X.prototype._toPersistentEntries=function(e){return e.map(function(e){return{record:e.record,endpointOverride:e.endpointOverride||"",retryCount:0,nextRetryAt:0}})},X.prototype._getRetryDelay=function(e){var t=Math.min(10,Math.max(0,e));return Math.min(6e4,Math.max(I,Math.floor(I*Math.pow(2,t))))},X.prototype.schedule=function(){var e=this;this._purgeSettled(),!this.timer&&this.queue.length&&(this.timer=setTimeout(function(){e.timer=null,e.flush().catch(function(){})},2e3))},X.prototype.flush=function(){var e=this,t=this.flushTail.then(function(){return e.flushOnce()});return this.flushTail=t.catch(function(){}),t},X.prototype._processFlushGroup=function(e,t,n){for(var r=this,o="__default__"===e?"":e,i=[],s=[],a=0;a<t.length;a++){var u=t[a],c=String(u.record&&u.record.event_id||"").trim();(c&&W.has(c)?s:i).push(u)}for(var f=0;f<s.length;f++)r._settleItem(s[f],{sent:!1,ok:!1,status:0,reason:"cross_batch_recent_success_deduped"});if(!i.length)return Promise.resolve();if(!r._resolveEndpoint){G("[sdk][landing] _resolveEndpoint 未注入,事件无法发送");for(var l=0;l<i.length;l++)r._settleItem(i[l],{sent:!1,ok:!1,status:0,reason:"no_endpoint_resolver"});return Promise.resolve()}for(var h={},d=[],p={},v=0;v<i.length;v++){var g=i[v],y=String(g.record&&g.record.event_id||"").trim()||"__empty__:"+v;h[y]||(h[y]=!0,d.push(g.record),p[v]=!0)}return r.resolver.consumeProbeFailurePersistSignal()?r.persistentQueue.enqueueMany(r._toPersistentEntries(i)).then(function(){r.hasPersistentItems=!0;for(var e=0;e<i.length;e++)r._settleItem(i[e],{sent:!1,ok:!1,status:0,reason:"probe_all_failed"})}).catch(function(){}):r._resolveEndpoint(o).then(function(e){if(e){for(var t=[],o=0;o<d.length;o++){var s=String(d[o]&&d[o].event_id||"").trim();if(s&&W.has(s)){for(var a=0;a<i.length;a++)if(p[a]&&String(i[a].record&&i[a].record.event_id||"").trim()===s){r._settleItem(i[a],{sent:!1,ok:!1,status:0,reason:"cross_batch_recent_success_deduped"}),p[a]=!1;break}}else t.push(d[o])}if(!t.length){for(var u=0;u<i.length;u++)p[u]||r._settleItem(i[u],{sent:!1,ok:!1,status:0,reason:"batch_deduped_duplicate"});return Promise.resolve()}return A(e,t,{useBeacon:D}).then(function(e){var n=Promise.resolve();if(e&&e.ok){for(var o=[],s=0;s<t.length;s++){var a=String(t[s]&&t[s].event_id||"").trim();a&&o.push(a)}W.set(o)}else{for(var u=[],c=0;c<i.length;c++)p[c]&&u.push(i[c]);n=r.persistentQueue.enqueueMany(r._toPersistentEntries(u)).then(function(){r.hasPersistentItems=!0}).catch(function(){})}return n.then(function(){for(var t=0;t<i.length;t++)r._settleItem(i[t],p[t]?e:{sent:!1,ok:!1,status:0,reason:"batch_deduped_duplicate"})})})}if("unavailable"===r.resolver.getEndpointState())return r.persistentQueue.enqueueMany(r._toPersistentEntries(i)).then(function(){r.hasPersistentItems=!0;for(var e=0;e<i.length;e++)r._settleItem(i[e],{sent:!1,ok:!1,status:0,reason:"endpoint_unavailable"})}).catch(function(){});for(var c=0;c<i.length;c++)n.push(i[c])})},X.prototype.flushOnce=function(){var e=this;if(this._purgeSettled(),!this.queue.length)return Promise.resolve();this._stopTimer();for(var t=this.queue.splice(0,10),n={},r=0;r<t.length;r++){var o=t[r];if(!o.settled){var i=o.endpointOverride||"__default__";n[i]||(n[i]=[]),n[i].push(o)}}for(var s=[],a=Object.keys(n),u=Promise.resolve(),c=0;c<a.length;c++)(function(t){u=u.then(function(){return e._processFlushGroup(t,n[t],s)})})(a[c]);return u.then(function(){if(s.length){for(var t=Date.now(),n=[],r=[],o=0;o<s.length;o++)(s[o].timeoutAt<=t?n:r).push(s[o]);for(var i=0;i<r.length;i++)e.queue.push(r[i]);for(var a=Promise.resolve(),u=0;u<n.length;u++)(function(t){a=a.then(function(){return e.persistentQueue.enqueueMany(e._toPersistentEntries([t])).catch(function(){}).then(function(){e.hasPersistentItems=!0,e._settleItem(t,{sent:!1,ok:!1,status:0,reason:"track_timeout",transport:"queue"})})})})(n[u]);return a}}).then(function(){e.queue.length&&e.schedule()},function(t){throw e.queue.length&&e.schedule(),t})},X.prototype._processReplayGroup=function(e,t){var n=this;return n._resolveEndpoint?n._resolveEndpoint("__default__"===e?"":e).then(function(e){if(e){for(var r={},o=[],i=[],s=[],a=0;a<t.length;a++){var u=t[a],c=String(u.record&&u.record.event_id||"").trim()||"__empty__:"+u.id,f=String(u.record&&u.record.event_id||"").trim();f&&W.has(f)||r[c]?s.push(u.id):(r[c]=!0,o.push(u.record),i.push(u.id))}var l=Promise.resolve();return s.length&&(l=l.then(function(){return n.persistentQueue.removeByIds(s)})),o.length?l.then(function(){return A(e,o,{useBeacon:D})}).then(function(e){if(e&&e.ok){for(var r=[],a=0;a<o.length;a++){var u=String(o[a]&&o[a].event_id||"").trim();u&&r.push(u)}W.set(r);for(var c=[],f=0;f<i.length;f++)c.push(i[f]);for(var l=0;l<s.length;l++)c.push(s[l]);return n.persistentQueue.removeByIds(c)}for(var h=0,d=0;d<t.length;d++){var p=t[d].retryCount||0;p>h&&(h=p)}var v=n._getRetryDelay(h);return n.persistentQueue.updateRetryMeta(t,v,5)}):l}}):(G("[sdk][landing] _resolveEndpoint 未注入,持久队列重试跳过"),Promise.resolve())},X.prototype.replayPersistent=function(){var e=this;return!this.hasPersistentItems||this.replaying?Promise.resolve():(this.replaying=!0,this.persistentQueue.readOldest(10).then(function(t){if(!t.length)return e.persistentQueue.count().then(function(t){0===t&&(e.hasPersistentItems=!1)});for(var n={},r=0;r<t.length;r++){var o=t[r],i=o.endpointOverride||"__default__";n[i]||(n[i]=[]),n[i].push(o)}for(var s=Object.keys(n),a=Promise.resolve(),u=0;u<s.length;u++)(function(t){a=a.then(function(){return e._processReplayGroup(t,n[t])})})(s[u]);return a}).catch(function(){}).then(function(){e.replaying=!1},function(){e.replaying=!1}))},X.prototype.track=function(e,t){var n=this;return k().then(function(r){var o=c({appId:n.opts.appId,channel:n.opts.channel,uid:n.opts.uid||"",sid:C(),deviceId:n.opts.deviceId||r,deviceType:s(),deviceBrand:"",deviceModel:"",deviceFingerprint:E(a),fpVersion:x,sdkVersion:T,appVersion:u(n.opts.appVersion)}),f=String(e.event||"").trim(),l=Q(e.payload||{}),h={event:1,payload:1,event_id:1};Object.keys(e).forEach(function(t){h[t]||Object.prototype.hasOwnProperty.call(o,t)||(l[t]=e[t])});var d=function(e,t){var n=function(){for(var e={},t=0;t<arguments.length;t++){var n=arguments[t];if(n)for(var r=Object.keys(n),o=0;o<r.length;o++)e[r[o]]=n[r[o]]}return e}(e,t);return n.event_id||(n.event_id=i(n)),n}(o,{event:f,payload:l});return(n._getEventCodes?n._getEventCodes():Promise.resolve([])).then(function(e){return e&&0===e.length?(G("[sdk][landing] 当前没有事件允许上报,请检查服务端配置(eventCodes 为空)"),{sent:!1,ok:!1,status:0,reason:"event_code_not_allowed",event:d.event}):e&&-1===e.indexOf(d.event)?(G('[sdk][landing] 事件 "'+d.event+'" 不在服务端允许上报的列表中,已忽略'),{sent:!1,ok:!1,status:0,reason:"event_code_not_allowed",event:d.event}):new Promise(function(e,r){var o=Date.now(),i={record:d,endpointOverride:t||"",resolve:e,reject:r,settled:!1,timeoutAt:o+3e4,timeoutTimer:null};i.timeoutTimer=setTimeout(function(){i.settled||n.persistentQueue.enqueueMany(n._toPersistentEntries([i])).catch(function(){}).then(function(){n.hasPersistentItems=!0,n._settleItem(i,{sent:!1,ok:!1,status:0,reason:"track_timeout",transport:"queue"})})},3e4),n.queue.push(i),n.queue.length>=10?n.flush().catch(function(){}):n.schedule()})})})},X.prototype.stop=function(){this._stopTimer(),this.replayTimer&&(clearInterval(this.replayTimer),this.replayTimer=null);var e={sent:!1,ok:!1,status:0,reason:"stopped"},t=this;this.queue.splice(0).forEach(function(n){t._settleItem(n,e)})},X.prototype.getConfig=function(){return{batchMaxSize:10,batchIntervalMs:2e3,replayBatchSize:10,replayIntervalMs:I}},Y.prototype._registerLifecycle=function(){if("undefined"!=typeof window){var e=this;this._onPageHide=function(){e.batcher.flush().catch(function(){})},this._onVisChange=function(){"undefined"!=typeof document&&"hidden"===document.visibilityState&&e.batcher.flush().catch(function(){})},window.addEventListener("pagehide",this._onPageHide),window.addEventListener("visibilitychange",this._onVisChange)}},Y.prototype._init=function(e){if(this._ssrSkipped)return this._buildInitReturn();for(var t=Object.keys(e||{}),n=0;n<t.length;n++)this.options[t[n]]=e[t[n]];null==this.options.channel&&(this.options.channel=""),this.configMgr.setEncryptedConfig(this.options.encryptedConfig||this.options.configCipher||""),this.configMgr.prewarm();var r=this;return this.options.encryptedConfig&&this.resolver.init(function(){return r.configMgr.getBatchEndpoints()}),this._refreshTimer&&clearInterval(this._refreshTimer),this._refreshTimer=setInterval(function(){r.refreshConfig()},12e5),this._unsubReady&&this._unsubReady(),this.options.encryptedConfig&&(this._unsubReady=this.resolver.onEndpointReady(function(){r.batcher.flush().catch(function(){})})),this._buildInitReturn()},Y.prototype.refreshConfig=function(){var e=this;return this.configMgr.forceRefresh(),this.options.encryptedConfig?this.resolver.refreshDomainConfig(function(){return e.configMgr.getBatchEndpoints()}).catch(function(){}):Promise.resolve()},Y.prototype.track=function(e,t){return this._ssrSkipped?Promise.resolve({sent:!1,ok:!0,status:0,reason:"ssr_skipped"}):this.batcher.track(e,t)},Y.prototype.setContext=function(e){if(this._ssrSkipped)return this.getConfig();var t=e&&"object"==typeof e?e:{};return Object.prototype.hasOwnProperty.call(t,"uid")&&(this.options.uid=null==t.uid?"":String(t.uid)),Object.prototype.hasOwnProperty.call(t,"channel")&&(this.options.channel=null==t.channel?"":String(t.channel)),this.batcher.opts=Q(this.options),this.getConfig()},Y.prototype.setUid=function(e){return this.setContext({uid:e})},Y.prototype.getSelectedHost=function(){if(this._ssrSkipped||!this.resolver)return"";var e=this.resolver.getSelectedBatchEndpoint();if(!e)return"";var t=/^(https?:\/\/[^/]+)/.exec(e);return t?t[1]:""},Y.prototype._buildInitReturn=function(){return this._ssrSkipped||!this.batcher?{selectedHost:"",version:T}:Q(this.batcher.getConfig(),{selectedHost:this.getSelectedHost(),version:T})},Y.prototype.getConfig=function(){if(this._ssrSkipped||!this.batcher)return Q(this.options,{selectedHost:"",selectedBatchEndpoint:"",version:T});var e=Q(this.options,this.batcher.getConfig(),{selectedHost:this.getSelectedHost(),selectedBatchEndpoint:this.resolver.getSelectedBatchEndpoint(),version:T});return delete e.encryptedConfig,delete e.configCipher,e},Y.prototype.flush=function(){return this._ssrSkipped?Promise.resolve():this.batcher.flush()},Y.prototype.refreshDomainConfig=function(){if(this._ssrSkipped)return Promise.resolve({selectedBatchEndpoint:"",selectedHost:"",version:T});if(!this.options.encryptedConfig){var e=this.options.endpoint||"";return!e&&this.options.domain&&(e=this.options.domain.replace(/\/+$/,"")+(this.options.batch?O:B)),Promise.resolve({selectedBatchEndpoint:e,selectedHost:e?e.replace(/\/[^/]+$/,""):"",version:T})}var t=this;return this.resolver.refreshDomainConfig(function(){return t.configMgr.getBatchEndpoints()}).then(function(e){return{selectedBatchEndpoint:e,selectedHost:t.getSelectedHost(),version:T}})},Y.prototype.stop=function(){this._ssrSkipped||(this._unsubReady&&(this._unsubReady(),this._unsubReady=null),"undefined"!=typeof window&&(this._onPageHide&&window.removeEventListener("pagehide",this._onPageHide),this._onVisChange&&window.removeEventListener("visibilitychange",this._onVisChange)),this._refreshTimer&&(clearInterval(this._refreshTimer),this._refreshTimer=null),this.batcher.stop())};var Z=null,ee=[],te=null;function ne(e){if(!Z)throw new Error("请先调用 init() 初始化(参数须包含 channel");return Z}function re(e,t,n){if(n>=e.length)return Promise.resolve();if(!Z||Z!==t){for(var r=e.slice(n),o=r.length-1;o>=0;o--)ee.unshift(r[o]);return Promise.resolve()}var i=e[n];return t.track(i.event,i.endpoint).catch(function(){}).then(function(){return re(e,t,n+1)})}function oe(e,t){if(Z){var n=Z;return(te||Promise.resolve()).then(function(){return n.track(e,t)})}return ee.push({event:e,endpoint:t}),ee.length>500&&ee.shift(),Promise.resolve({sent:!1,ok:!0,status:0,reason:"pre_init_cached"})}var ie=oe;ie.setContext=function(e){return ne().setContext(e)},ie.setUid=function(e){return ne().setUid(e)},ie.setChannel=function(e){return ne().setContext({channel:e})},ie.notifyPageLoad=function(){S(Date.now())},ie.getConfig=function(){return ne().getConfig()},ie.flush=function(){return ne().flush()},ie.refreshDomainConfig=function(){return ne().refreshDomainConfig()},ie.stop=function(){Z?(Z.stop(),Z=null):ee.length=0},ie.version=T,ie.getCommonFields=function(e){var t=Z?Z.getConfig():{};return k().then(function(n){var r=c({appId:t.appId,channel:t.channel,uid:t.uid,deviceId:t.deviceId||n,sid:C(),deviceType:s(),deviceBrand:"",deviceModel:"",deviceFingerprint:E(a),fpVersion:x,sdkVersion:T,appVersion:u(t.appVersion)});if(!Array.isArray(e)||!e.length)return r;for(var o={},i=0;i<e.length;i++){var f=String(e[i]||"").trim();f&&(o[f]=Object.prototype.hasOwnProperty.call(r,f)?r[f]:"")}return o})},ie.getCommonField=function(e){var t=String(e||"").trim();return t?ie.getCommonFields([t]).then(function(e){return e[t]}):Promise.resolve("")},ie.init=function(e){if(Z){var t=Z;Z=null,t.flush().catch(function(){}).then(function(){t.stop()})}var n=new Y(e);Z=n;var r,o=re(ee.splice(0),n,0).then(function(){te===r&&(te=null)},function(){te===r&&(te=null)});return te=r=o,Q(n._buildInitReturn(),{track:ie.track,setContext:ie.setContext,setUid:ie.setUid,setChannel:ie.setChannel,notifyPageLoad:ie.notifyPageLoad,getCommonFields:ie.getCommonFields,getCommonField:ie.getCommonField})};var se=function(){return G("[sdk][landing] 非法上报:禁止直接调用 LandingSDK.track({...}),请使用 LandingSDK.track.landingPageView/Click({...}) 等具名方法"),Promise.resolve({sent:!1,ok:!1,status:0,reason:"direct_track_forbidden"})};if(Object.keys(z).forEach(function(e){var t=z[e];se[e]=function(n,r){try{return oe(t(n),r)}catch(t){if(t&&"EventValidationError"===t.name)return Promise.resolve({sent:!1,ok:!1,status:0,reason:"event_validation_failed",event:t.eventMethod||e,missingFields:t.missingFields||[],typeErrorFields:t.typeErrorFields||[]});throw t}}}),ie.track="undefined"!=typeof Proxy?new Proxy(se,{get:function(e,t){return"string"!=typeof t||t in e||!/^[a-z]/.test(t)?e[t]:function(){return G('[sdk][landing] 未知上报事件 "'+t+'",该方法不存在,事件未上报'),Promise.resolve({sent:!1,ok:!1,status:0,reason:"unknown_event_method",method:t})}}}):se,"undefined"!=typeof globalThis)try{globalThis.LandingSDK=ie}catch(n){}else"undefined"!=typeof window&&(window.LandingSDK=ie);return ie});