@oxvo/browser 7.4.50 → 7.5.18

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/lib/index.js CHANGED
@@ -4759,7 +4759,7 @@ class Ticker {
4759
4759
  * this value is injected during build time via rollup
4760
4760
  * */
4761
4761
  // @ts-ignore
4762
- const workerBodyFn = "!function(){\"use strict\";class t{constructor(t,s,i,e=10,n=250,h,r){this.onUnauthorised=s,this.onFailure=i,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.onCompress=h,this.pageNo=r,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.lastBatchNum=0,this.inflightKeepaliveBytes=0,this.ingestURL=t+\"/v1/events\",this.analyticsIngestURL=t+\"/v1/analytics\",this.isCompressing=void 0!==h}getQueueStatus(){return 0===this.queue.length&&!this.busy}authorise(t){this.token=t,this.busy||this.sendNext()}push(t,s=\"player\"){if(this.busy||!this.token)this.queue.push({batch:t,dataType:s});else if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t,s);else{const i=++this.lastBatchNum;this.sendBatch(t,!1,i,s)}}sendNext(){const t=this.queue.shift();if(t)if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t.batch,t.dataType);else{const s=++this.lastBatchNum;this.sendBatch(t.batch,!1,s,t.dataType)}else this.busy=!1}retry(t,s,i,e=\"player\"){if(this.attemptsCount>=this.MAX_ATTEMPTS_COUNT)return void this.onFailure(`Failed to send batch after ${this.attemptsCount} attempts.`);this.attemptsCount++;const n=new Uint8Array(t);setTimeout((()=>this.sendBatch(n,s,i,e)),this.ATTEMPT_TIMEOUT*this.attemptsCount)}sendBatch(t,s,i,e=\"player\"){var n;if(0===t.length)return console.error(\"OxvoSessions: refusing to send 0-byte batch.\",{batchNum:i,dataType:e,isCompressed:s,batch:t}),this.attemptsCount=0,void this.sendNext();const h=null==i?void 0:i.toString().replace(/^([^_]+)_([^_]+).*/,\"$1_$2_$3\");this.busy=!0;const r={Authorization:`Bearer ${this.token}`,DataType:e};if(s&&(r[\"Content-Encoding\"]=\"gzip\"),null===this.token)return void setTimeout((()=>{this.sendBatch(t,s,`${null!=i?i:\"noBatchNum\"}_newToken`,e)}),500);const a=t.length<65536&&this.inflightKeepaliveBytes+t.length<=65536;a&&(this.inflightKeepaliveBytes+=t.length);const o=()=>{a&&(this.inflightKeepaliveBytes-=t.length)},u=`${null!==(n=this.pageNo)&&void 0!==n?n:\"noPageNum\"}_${null!=h?h:\"noBatchNum\"}`,c=\"analytics\"===e?this.analyticsIngestURL:this.ingestURL;fetch(`${c}?seq=${u}&keepalive=${a?\"yes\":\"no\"}`,{body:t,method:\"POST\",headers:r,keepalive:a}).then((n=>{var h;return o(),null===(h=n.body)||void 0===h||h.cancel().catch((()=>{})),401===n.status?(this.busy=!1,void this.onUnauthorised()):413===n.status?(console.warn(\"OxvoSessions: ingest batch was rejected as too large; continuing with the next batch.\"),this.attemptsCount=0,void this.sendNext()):void(n.status>=400?this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_network:${n.status}`,e):(this.attemptsCount=0,this.sendNext()))})).catch((n=>{o(),console.warn(\"OxvoSessions:\",n),this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_reject:${n.message}`,e)}))}sendCompressed(t,s=\"player\"){const i=++this.lastBatchNum;this.sendBatch(t,!0,i,s)}sendUncompressed(t,s=\"player\"){const i=++this.lastBatchNum;this.sendBatch(t,!1,i,s)}clean(){this.sendNext(),setTimeout((()=>{this.token=null,this.queue.length=0}),10)}}const s=new Set([60,61,71,73]),i=new Set([21,22,40,41,44,45,46,47,48,79,83,84,85,87,89,116,120,121,123]),e=new Set([17,23,24,27,28,29,30,42,63,64,78,112,115,124]),n=\"function\"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let e=-1;for(let n=0,h=0,r=0;r!==s;){if(n=t.charCodeAt(r),r+=1,n>=55296&&n<=56319){if(r===s){i[e+=1]=239,i[e+=1]=191,i[e+=1]=189;break}if(h=t.charCodeAt(r),!(h>=56320&&h<=57343)){i[e+=1]=239,i[e+=1]=191,i[e+=1]=189;continue}if(n=1024*(n-55296)+h-56320+65536,r+=1,n>65535){i[e+=1]=240|n>>>18,i[e+=1]=128|n>>>12&63,i[e+=1]=128|n>>>6&63,i[e+=1]=128|63&n;continue}}n<=127?i[e+=1]=0|n:n<=2047?(i[e+=1]=192|n>>>6,i[e+=1]=128|63&n):(i[e+=1]=224|n>>>12,i[e+=1]=128|n>>>6&63,i[e+=1]=128|63&n)}return i.subarray(0,e+1)}};class h{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}getCurrentOffset(){return this.offset}getCurrentCheckpoint(){return this.checkpointOffset}checkpoint(){this.checkpointOffset=this.offset}get isEmpty(){return 0===this.offset}skip(t){return this.offset+=t,this.offset<=this.size}set(t,s){this.data.set(t,s)}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=n.encode(t),i=s.byteLength;return!(!this.uint(i)||this.offset+i>this.size)&&(this.data.set(s,this.offset),this.offset+=i,!0)}reset(){this.offset=0,this.checkpointOffset=0}rewind(t,s){t>this.offset||s>this.checkpointOffset||(this.offset=t,this.checkpointOffset=s)}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}class r extends h{encode(t){switch(t[0]){case 0:case 11:case 114:case 115:return this.uint(t[1]);case 4:case 44:case 47:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 5:case 20:case 65:case 70:case 75:case 76:case 77:return this.uint(t[1])&&this.uint(t[2]);case 6:return this.int(t[1])&&this.int(t[2]);case 7:return!0;case 8:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.string(t[4])&&this.boolean(t[5]);case 9:case 10:case 24:case 35:case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 12:case 52:case 61:case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:case 17:case 34:case 36:case 50:case 54:return this.uint(t[1])&&this.string(t[2]);case 16:return this.uint(t[1])&&this.int(t[2])&&this.int(t[3]);case 18:return this.uint(t[1])&&this.string(t[2])&&this.int(t[3]);case 19:return this.uint(t[1])&&this.boolean(t[2]);case 21:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8]);case 22:case 27:case 30:case 41:case 45:case 46:case 43:case 63:case 64:case 79:case 124:return this.string(t[1])&&this.string(t[2]);case 23:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 28:case 29:case 42:case 117:case 118:return this.string(t[1]);case 40:return this.string(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 48:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.int(t[5]);case 49:return this.int(t[1])&&this.int(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 53:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8]);case 55:return this.boolean(t[1]);case 57:case 60:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 58:case 120:return this.int(t[1]);case 68:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6]);case 69:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 78:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 81:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.int(t[4])&&this.string(t[5]);case 83:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 84:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6]);case 85:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8])&&this.uint(t[9])&&this.boolean(t[10])&&this.uint(t[11])&&this.uint(t[12])&&this.uint(t[13])&&this.uint(t[14])&&this.uint(t[15])&&this.uint(t[16])&&this.uint(t[17]);case 87:return this.string(t[1])&&this.int(t[2])&&this.int(t[3]);case 89:return this.string(t[1])&&this.int(t[2])&&this.int(t[3])&&this.int(t[4])&&this.int(t[5])&&this.string(t[6]);case 112:return this.uint(t[1])&&this.string(t[2])&&this.boolean(t[3])&&this.string(t[4])&&this.int(t[5])&&this.int(t[6]);case 113:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3]);case 116:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8])&&this.uint(t[9])&&this.boolean(t[10]);case 119:return this.string(t[1])&&this.uint(t[2]);case 121:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 122:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 123:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])}}}class a{constructor(t,s,i,e=Number.POSITIVE_INFINITY){this.bufferSize=t,this.version=s,this.dataType=i,this.messageCountLimit=e,this.sizeBuffer=new Uint8Array(3),this.snap=null,this.hasNonTimestamp=!1,this.lastPushedTs=0,this.messageCount=0,this.encoder=new r(t)}push(t,s){const i=this.encoder,e=null===this.snap,n=i.getCurrentOffset(),h=i.getCurrentCheckpoint(),r=this.messageCount;if(e){const t={pageNo:s.pageNo,firstIndex:s.index,timestamp:s.timestamp,url:s.url,tabId:s.tabId};if(!this.writeHeader(t))return i.rewind(n,h),this.messageCount=r,!1;this.snap=t,this.lastPushedTs=s.timestamp}return 0===t[0]||s.timestamp===this.lastPushedTs||this.writeMessageWithSize([0,s.timestamp])?this.writeMessageWithSize(t)?(this.lastPushedTs=s.timestamp,0!==t[0]&&(this.hasNonTimestamp=!0),!0):(i.rewind(n,h),this.messageCount=r,e&&(this.snap=null),!1):(i.rewind(n,h),this.messageCount=r,!1)}hasContent(){return null!==this.snap&&this.hasNonTimestamp}flush(){if(!this.hasContent())return this.reset(),null;const t=this.encoder.flush();return this.snap=null,this.hasNonTimestamp=!1,this.lastPushedTs=0,this.messageCount=0,t}reset(){this.encoder.reset(),this.snap=null,this.hasNonTimestamp=!1,this.lastPushedTs=0,this.messageCount=0}writeHeader(t){const s=this.encoder,i=[81,this.version,t.pageNo,t.firstIndex,t.timestamp,t.url];return!!this.canWriteMessage()&&(!!s.uint(i[0])&&(!!s.encode(i)&&(!(s.getCurrentOffset()>this.bufferSize)&&(s.checkpoint(),this.messageCount++,!!this.writeMessageWithSize([0,t.timestamp])&&!!this.writeMessageWithSize([118,t.tabId])))))}writeMessageWithSize(t){const s=this.encoder;if(!this.canWriteMessage())return!1;if(!s.uint(t[0])||!s.skip(3))return!1;const i=s.getCurrentOffset();if(!s.encode(t))return!1;const e=s.getCurrentOffset(),n=e-i;return n>16777215?(console.warn(\"OxvoSessions: max message size overflow.\"),!1):!(e>this.bufferSize)&&(this.writeSizeAt(n,i-3),s.checkpoint(),this.messageCount++,!0)}canWriteMessage(){return this.messageCount<this.messageCountLimit}writeSizeAt(t,s){for(let s=0;s<3;s++)this.sizeBuffer[s]=t>>8*s;this.encoder.set(this.sizeBuffer,s)}}class o{constructor(t,s,i,e,n,h,r=!1,a){this.pageNo=t,this.timestamp=s,this.url=i,this.onBatch=e,this.tabId=n,this.onOfflineEnd=h,this.localDebug=r,this.onLocalSave=a,this.nextIndex=0,this.beaconSize=2e5,this.beaconSizeLimit=1e6,this.protocolVersion=1,this.playerBuilder=this.createBuilder(this.beaconSize,this.playerVersion(),\"player\"),this.assetBuilder=this.createBuilder(this.beaconSize,3,\"assets\"),this.devtoolsBuilder=this.createBuilder(this.beaconSize,4,\"devtools\"),this.analyticsBuilder=this.createBuilder(this.beaconSize,5,\"analytics\")}playerVersion(){return 2===this.protocolVersion?2:1}currentCtx(){return{pageNo:this.pageNo,index:this.nextIndex,timestamp:this.timestamp,url:this.url,tabId:this.tabId}}setBeaconSizeLimit(t){this.beaconSizeLimit=t}setProtocolVersion(t){this.protocolVersion!==t&&(this.protocolVersion=t,this.playerBuilder.reset(),this.playerBuilder=this.createBuilder(this.beaconSize,this.playerVersion(),\"player\"))}writeMessage(t){if(-1===t[0])return this.finaliseBatch(),this.onOfflineEnd();0===t[0]&&(this.timestamp=t[1]),122===t[0]&&(this.url=t[1]);const s=this.routeMessage(t);this.pushTo(s,t)}routeMessage(t){if(2===this.protocolVersion){const n=t[0];if(s.has(n))return this.assetBuilder;if(i.has(n))return this.devtoolsBuilder;if(e.has(n))return this.analyticsBuilder}return this.playerBuilder}pushTo(t,s){const i=this.currentCtx();if(t.push(s,i))return void this.nextIndex++;if(this.flushBuilder(t),t.push(s,i))return void this.nextIndex++;const e=this.createBuilder(this.beaconSizeLimit,t.version,t.dataType);if(!e.push(s,i))return void console.warn(\"OxvoSessions: beacon size overflow. Skipping large message.\",s);this.nextIndex++;const n=e.flush();n&&this.emitBatch(n,t.dataType,!1)}flushBuilder(t,s=!1){const i=t.flush();return!!i&&(this.emitBatch(i,t.dataType,s),!0)}emitBatch(t,s,i){this.localDebug&&this.onLocalSave&&this.onLocalSave(`${s}-${Date.now()}`,t.slice()),this.onBatch(t,i,s)}createBuilder(t,s,i){return new a(t,s,i,4e3)}finaliseBatch(t=!1){this.flushBuilder(this.playerBuilder,t),this.flushBuilder(this.assetBuilder,t),this.flushBuilder(this.devtoolsBuilder,t),this.flushBuilder(this.analyticsBuilder,t)}clean(){this.playerBuilder.reset(),this.assetBuilder.reset(),this.devtoolsBuilder.reset(),this.analyticsBuilder.reset()}}var u;!function(t){t[t.NotActive=0]=\"NotActive\",t[t.Starting=1]=\"Starting\",t[t.Stopping=2]=\"Stopping\",t[t.Active=3]=\"Active\",t[t.Stopped=4]=\"Stopped\"}(u||(u={}));let c=null,l=null,d=u.NotActive;function p(t){l&&l.finaliseBatch(t)}function g(){return new Promise((t=>{d=u.Stopping,null!==y&&(clearInterval(y),y=null),l&&(l.clean(),l=null),c&&(c.clean(),setTimeout((()=>{c=null}),20)),setTimeout((()=>{d=u.NotActive,t(null)}),100)}))}function f(){[u.Stopped,u.Stopping].includes(d)||(postMessage(\"a_stop\"),g().then((()=>{postMessage(\"a_start\")})))}let m,y=null;self.onmessage=({data:s})=>{var i;if(\"stop\"===s)return p(),void g().then((()=>{d=u.Stopped}));if(\"forceFlushBatch\"!==s)if(\"closing\"!==s){if(!Array.isArray(s)){if(\"compressed\"===s.type){if(!c)return console.debug(\"OR WebWorker: sender not initialised. Compressed batch.\"),void f();s.batch&&c.sendCompressed(s.batch,s.dataType)}if(\"uncompressed\"===s.type){if(!c)return console.debug(\"OR WebWorker: sender not initialised. Uncompressed batch.\"),void f();s.batch&&c.sendUncompressed(s.batch,s.dataType)}return\"start\"===s.type?(d=u.Starting,c=new t(s.ingestPoint,(()=>{f()}),(t=>{!function(t){postMessage({type:\"failure\",reason:t}),g()}(t)}),s.connAttemptCount,s.connAttemptGap,((t,s)=>{postMessage({type:\"compress\",batch:t,dataType:s},[t.buffer])}),s.pageNo),l=new o(s.pageNo,s.timestamp,s.url,((t,s,i=\"player\")=>{c&&(s?c.sendUncompressed(t,i):c.push(t,i))}),s.tabId,(()=>postMessage({type:\"queue_empty\"})),null!==(i=s.localDebug)&&void 0!==i&&i,((t,s)=>{postMessage({type:\"local_save\",name:t,batch:s},[s.buffer])})),null===y&&(y=setInterval(p,3e4)),d=u.Active):\"auth\"===s.type?c?l?(c.authorise(s.token),s.beaconSizeLimit&&l.setBeaconSizeLimit(s.beaconSizeLimit),void(s.protocolVersion&&l.setProtocolVersion(s.protocolVersion))):(console.debug(\"OR WebWorker: writer not initialised. Received auth.\"),void f()):(console.debug(\"OR WebWorker: sender not initialised. Received auth.\"),void f()):void 0}if(l){const t=l;s.forEach((s=>{55===s[0]&&(s[1]?m=setTimeout((()=>f()),18e5):clearTimeout(m)),t.writeMessage(s)}))}else postMessage(\"not_init\"),f()}else p(!0);else p()}}();\n";
4762
+ const workerBodyFn = "!function(){\"use strict\";class t{constructor(t,s,e,i=10,n=250,h,r){this.onUnauthorised=s,this.onFailure=e,this.MAX_ATTEMPTS_COUNT=i,this.ATTEMPT_TIMEOUT=n,this.onCompress=h,this.pageNo=r,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.lastBatchNum=0,this.inflightKeepaliveBytes=0,this.ingestURL=t+\"/v1/events\",this.analyticsIngestURL=t+\"/v1/analytics\",this.isCompressing=void 0!==h}getQueueStatus(){return 0===this.queue.length&&!this.busy}authorise(t){this.token=t,this.busy||this.sendNext()}push(t,s=\"player\"){if(this.busy||!this.token)this.queue.push({batch:t,dataType:s});else if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t,s);else{const e=++this.lastBatchNum;this.sendBatch(t,!1,e,s)}}sendNext(){const t=this.queue.shift();if(t)if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t.batch,t.dataType);else{const s=++this.lastBatchNum;this.sendBatch(t.batch,!1,s,t.dataType)}else this.busy=!1}retry(t,s,e,i=\"player\"){if(this.attemptsCount>=this.MAX_ATTEMPTS_COUNT)return void this.onFailure(`Failed to send batch after ${this.attemptsCount} attempts.`);this.attemptsCount++;const n=new Uint8Array(t);setTimeout((()=>this.sendBatch(n,s,e,i)),this.ATTEMPT_TIMEOUT*this.attemptsCount)}sendBatch(t,s,e,i=\"player\"){var n;if(0===t.length)return console.error(\"OxvoSessions: refusing to send 0-byte batch.\",{batchNum:e,dataType:i,isCompressed:s,batch:t}),this.attemptsCount=0,void this.sendNext();const h=null==e?void 0:e.toString().replace(/^([^_]+)_([^_]+).*/,\"$1_$2_$3\");this.busy=!0;const r={Authorization:`Bearer ${this.token}`,DataType:i};if(s&&(r[\"Content-Encoding\"]=\"gzip\"),null===this.token)return void setTimeout((()=>{this.sendBatch(t,s,`${null!=e?e:\"noBatchNum\"}_newToken`,i)}),500);const a=t.length<65536&&this.inflightKeepaliveBytes+t.length<=65536;a&&(this.inflightKeepaliveBytes+=t.length);const o=()=>{a&&(this.inflightKeepaliveBytes-=t.length)},u=`${null!==(n=this.pageNo)&&void 0!==n?n:\"noPageNum\"}_${null!=h?h:\"noBatchNum\"}`,c=\"analytics\"===i?this.analyticsIngestURL:this.ingestURL;fetch(`${c}?seq=${u}&keepalive=${a?\"yes\":\"no\"}`,{body:t,method:\"POST\",headers:r,keepalive:a}).then((n=>{var h;return o(),null===(h=n.body)||void 0===h||h.cancel().catch((()=>{})),401===n.status?(this.busy=!1,void this.onUnauthorised()):413===n.status?(console.warn(\"OxvoSessions: ingest batch was rejected as too large; continuing with the next batch.\"),this.attemptsCount=0,void this.sendNext()):void(n.status>=400?this.retry(t,s,`${null!=e?e:\"noBatchNum\"}_network:${n.status}`,i):(this.attemptsCount=0,this.sendNext()))})).catch((n=>{o(),console.warn(\"OxvoSessions:\",n),this.retry(t,s,`${null!=e?e:\"noBatchNum\"}_reject:${n.message}`,i)}))}sendCompressed(t,s=\"player\"){const e=++this.lastBatchNum;this.sendBatch(t,!0,e,s)}sendUncompressed(t,s=\"player\"){const e=++this.lastBatchNum;this.sendBatch(t,!1,e,s)}clean(){this.sendNext(),setTimeout((()=>{this.token=null,this.queue.length=0}),10)}}const s=new Set([60,61,71,73]),e=new Set([21,22,40,41,44,45,46,47,48,79,83,84,85,87,89,116,120,121,123]),i=\"function\"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,e=new Uint8Array(3*s);let i=-1;for(let n=0,h=0,r=0;r!==s;){if(n=t.charCodeAt(r),r+=1,n>=55296&&n<=56319){if(r===s){e[i+=1]=239,e[i+=1]=191,e[i+=1]=189;break}if(h=t.charCodeAt(r),!(h>=56320&&h<=57343)){e[i+=1]=239,e[i+=1]=191,e[i+=1]=189;continue}if(n=1024*(n-55296)+h-56320+65536,r+=1,n>65535){e[i+=1]=240|n>>>18,e[i+=1]=128|n>>>12&63,e[i+=1]=128|n>>>6&63,e[i+=1]=128|63&n;continue}}n<=127?e[i+=1]=0|n:n<=2047?(e[i+=1]=192|n>>>6,e[i+=1]=128|63&n):(e[i+=1]=224|n>>>12,e[i+=1]=128|n>>>6&63,e[i+=1]=128|63&n)}return e.subarray(0,i+1)}};class n{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}getCurrentOffset(){return this.offset}getCurrentCheckpoint(){return this.checkpointOffset}checkpoint(){this.checkpointOffset=this.offset}get isEmpty(){return 0===this.offset}skip(t){return this.offset+=t,this.offset<=this.size}set(t,s){this.data.set(t,s)}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=i.encode(t),e=s.byteLength;return!(!this.uint(e)||this.offset+e>this.size)&&(this.data.set(s,this.offset),this.offset+=e,!0)}reset(){this.offset=0,this.checkpointOffset=0}rewind(t,s){t>this.offset||s>this.checkpointOffset||(this.offset=t,this.checkpointOffset=s)}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}class h extends n{encode(t){switch(t[0]){case 0:case 11:case 114:case 115:return this.uint(t[1]);case 4:case 44:case 47:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 5:case 20:case 65:case 70:case 75:case 76:case 77:return this.uint(t[1])&&this.uint(t[2]);case 6:return this.int(t[1])&&this.int(t[2]);case 7:return!0;case 8:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.string(t[4])&&this.boolean(t[5]);case 9:case 10:case 24:case 35:case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 12:case 52:case 61:case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:case 17:case 34:case 36:case 50:case 54:return this.uint(t[1])&&this.string(t[2]);case 16:return this.uint(t[1])&&this.int(t[2])&&this.int(t[3]);case 18:return this.uint(t[1])&&this.string(t[2])&&this.int(t[3]);case 19:return this.uint(t[1])&&this.boolean(t[2]);case 21:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8]);case 22:case 27:case 30:case 41:case 45:case 46:case 43:case 63:case 64:case 79:case 124:return this.string(t[1])&&this.string(t[2]);case 23:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 28:case 29:case 42:case 117:case 118:return this.string(t[1]);case 40:return this.string(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 48:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.int(t[5]);case 49:return this.int(t[1])&&this.int(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 53:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8]);case 55:return this.boolean(t[1]);case 57:case 60:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 58:case 120:return this.int(t[1]);case 68:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6]);case 69:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 78:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 81:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.int(t[4])&&this.string(t[5]);case 83:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 84:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6]);case 85:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8])&&this.uint(t[9])&&this.boolean(t[10])&&this.uint(t[11])&&this.uint(t[12])&&this.uint(t[13])&&this.uint(t[14])&&this.uint(t[15])&&this.uint(t[16])&&this.uint(t[17]);case 87:return this.string(t[1])&&this.int(t[2])&&this.int(t[3]);case 89:return this.string(t[1])&&this.int(t[2])&&this.int(t[3])&&this.int(t[4])&&this.int(t[5])&&this.string(t[6]);case 112:return this.uint(t[1])&&this.string(t[2])&&this.boolean(t[3])&&this.string(t[4])&&this.int(t[5])&&this.int(t[6]);case 113:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3]);case 116:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8])&&this.uint(t[9])&&this.boolean(t[10]);case 119:return this.string(t[1])&&this.uint(t[2]);case 121:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 122:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 123:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])}}}class r{constructor(t,s,e,i=Number.POSITIVE_INFINITY){this.bufferSize=t,this.version=s,this.dataType=e,this.messageCountLimit=i,this.sizeBuffer=new Uint8Array(3),this.snap=null,this.hasNonTimestamp=!1,this.lastPushedTs=0,this.messageCount=0,this.metadataSize=0,this.encoder=new h(t)}push(t,s){const e=this.encoder,i=null===this.snap,n=e.getCurrentOffset(),h=e.getCurrentCheckpoint(),r=this.messageCount;if(i){const t={pageNo:s.pageNo,firstIndex:s.index,timestamp:s.timestamp,url:s.url,tabId:s.tabId};if(!this.writeHeader(t))return e.rewind(n,h),this.messageCount=r,!1;this.snap=t,this.lastPushedTs=s.timestamp}return 0===t[0]||s.timestamp===this.lastPushedTs||this.writeMessageWithSize([0,s.timestamp])?this.writeMessageWithSize(t)?(this.lastPushedTs=s.timestamp,0!==t[0]&&(this.hasNonTimestamp=!0),!0):(e.rewind(n,h),this.messageCount=r,i&&(this.snap=null),!1):(e.rewind(n,h),this.messageCount=r,!1)}hasContent(){return null!==this.snap&&this.hasNonTimestamp}wireMessageCount(){return this.messageCount}flush(t){if(!this.hasContent())return this.reset(),null;const s=this.snap;let e=this.encoder.flush();if(void 0!==t&&t!==s.firstIndex){const i=new h(this.metadataSize+7);if(!i.uint(81)||!i.encode(this.batchMetadata(s,t)))throw new Error(\"OxvoSessions: batch index exceeds its reserved header space.\");i.checkpoint();const n=i.flush(),r=new Uint8Array(n.length+e.length-this.metadataSize);r.set(n),r.set(e.subarray(this.metadataSize),n.length),e=r}return this.reset(),e}reset(){this.encoder.reset(),this.snap=null,this.hasNonTimestamp=!1,this.lastPushedTs=0,this.messageCount=0,this.metadataSize=0}batchMetadata(t,s){return[81,this.version,t.pageNo,s,t.timestamp,t.url]}writeHeader(t){const s=this.encoder;return!!this.canWriteMessage()&&(!!s.uint(81)&&(!!s.encode(this.batchMetadata(t,t.firstIndex))&&(!(s.getCurrentOffset()+7>this.bufferSize)&&(this.metadataSize=s.getCurrentOffset(),s.checkpoint(),this.messageCount++,!!this.writeMessageWithSize([0,t.timestamp])&&!!this.writeMessageWithSize([118,t.tabId])))))}writeMessageWithSize(t){const s=this.encoder;if(!this.canWriteMessage())return!1;if(!s.uint(t[0])||!s.skip(3))return!1;const e=s.getCurrentOffset();if(!s.encode(t))return!1;const i=s.getCurrentOffset(),n=i-e;return n>16777215?(console.warn(\"OxvoSessions: max message size overflow.\"),!1):!(i+7>this.bufferSize)&&(this.writeSizeAt(n,e-3),s.checkpoint(),this.messageCount++,!0)}canWriteMessage(){return this.messageCount<this.messageCountLimit}writeSizeAt(t,s){for(let s=0;s<3;s++)this.sizeBuffer[s]=t>>8*s;this.encoder.set(this.sizeBuffer,s)}}class a{constructor(t,s,e,i,n,h,r=!1,a){this.pageNo=t,this.timestamp=s,this.url=e,this.onBatch=i,this.tabId=n,this.onOfflineEnd=h,this.localDebug=r,this.onLocalSave=a,this.nextIndex=0,this.beaconSize=2e5,this.beaconSizeLimit=1e6,this.protocolVersion=1,this.playerBuilder=this.createBuilder(this.beaconSize,this.playerVersion(),\"player\"),this.assetBuilder=this.createBuilder(this.beaconSize,3,\"assets\"),this.devtoolsBuilder=this.createBuilder(this.beaconSize,4,\"devtools\")}playerVersion(){return 2===this.protocolVersion?2:1}currentCtx(){return{pageNo:this.pageNo,index:this.nextIndex,timestamp:this.timestamp,url:this.url,tabId:this.tabId}}setBeaconSizeLimit(t){this.beaconSizeLimit=t}setProtocolVersion(t){this.protocolVersion!==t&&(this.protocolVersion=t,this.playerBuilder.reset(),this.playerBuilder=this.createBuilder(this.beaconSize,this.playerVersion(),\"player\"))}writeMessage(t){if(-1===t[0])return this.finaliseBatch(),this.onOfflineEnd();0===t[0]&&(this.timestamp=t[1]),122===t[0]&&(this.url=t[1]);const s=this.routeMessage(t);this.pushTo(s,t)}routeMessage(t){if(2===this.protocolVersion){const i=t[0];if(s.has(i))return this.assetBuilder;if(e.has(i))return this.devtoolsBuilder}return this.playerBuilder}pushTo(t,s){const e=this.currentCtx();if(t.push(s,e))return;if(this.flushBuilder(t),t.push(s,e))return;const i=this.createBuilder(this.beaconSizeLimit,t.version,t.dataType);i.push(s,e)?this.flushBuilder(i):console.warn(\"OxvoSessions: beacon size overflow. Skipping large message.\",s)}flushBuilder(t,s=!1){const e=t.wireMessageCount(),i=t.flush(this.nextIndex);return!!i&&(this.nextIndex+=e,this.emitBatch(i,t.dataType,s),!0)}emitBatch(t,s,e){this.localDebug&&this.onLocalSave&&this.onLocalSave(`${s}-${Date.now()}`,t.slice()),this.onBatch(t,e,s)}createBuilder(t,s,e){return new r(t,s,e,4e3)}finaliseBatch(t=!1){this.flushBuilder(this.playerBuilder,t),this.flushBuilder(this.assetBuilder,t),this.flushBuilder(this.devtoolsBuilder,t)}clean(){this.playerBuilder.reset(),this.assetBuilder.reset(),this.devtoolsBuilder.reset()}}var o;!function(t){t[t.NotActive=0]=\"NotActive\",t[t.Starting=1]=\"Starting\",t[t.Stopping=2]=\"Stopping\",t[t.Active=3]=\"Active\",t[t.Stopped=4]=\"Stopped\"}(o||(o={}));let u=null,c=null,l=o.NotActive;function d(t){c&&c.finaliseBatch(t)}function g(){return new Promise((t=>{l=o.Stopping,null!==m&&(clearInterval(m),m=null),c&&(c.clean(),c=null),u&&(u.clean(),setTimeout((()=>{u=null}),20)),setTimeout((()=>{l=o.NotActive,t(null)}),100)}))}function p(){[o.Stopped,o.Stopping].includes(l)||(postMessage(\"a_stop\"),g().then((()=>{postMessage(\"a_start\")})))}let f,m=null;self.onmessage=({data:s})=>{var e;if(\"stop\"===s)return d(),void g().then((()=>{l=o.Stopped}));if(\"forceFlushBatch\"!==s)if(\"closing\"!==s){if(!Array.isArray(s)){if(\"compressed\"===s.type){if(!u)return console.debug(\"OR WebWorker: sender not initialised. Compressed batch.\"),void p();s.batch&&u.sendCompressed(s.batch,s.dataType)}if(\"uncompressed\"===s.type){if(!u)return console.debug(\"OR WebWorker: sender not initialised. Uncompressed batch.\"),void p();s.batch&&u.sendUncompressed(s.batch,s.dataType)}return\"start\"===s.type?(l=o.Starting,u=new t(s.ingestPoint,(()=>{p()}),(t=>{!function(t){postMessage({type:\"failure\",reason:t}),g()}(t)}),s.connAttemptCount,s.connAttemptGap,((t,s)=>{postMessage({type:\"compress\",batch:t,dataType:s},[t.buffer])}),s.pageNo),c=new a(s.pageNo,s.timestamp,s.url,((t,s,e=\"player\")=>{u&&(s?u.sendUncompressed(t,e):u.push(t,e))}),s.tabId,(()=>postMessage({type:\"queue_empty\"})),null!==(e=s.localDebug)&&void 0!==e&&e,((t,s)=>{postMessage({type:\"local_save\",name:t,batch:s},[s.buffer])})),null===m&&(m=setInterval(d,3e4)),l=o.Active):\"auth\"===s.type?u?c?(u.authorise(s.token),s.beaconSizeLimit&&c.setBeaconSizeLimit(s.beaconSizeLimit),void(s.protocolVersion&&c.setProtocolVersion(s.protocolVersion))):(console.debug(\"OR WebWorker: writer not initialised. Received auth.\"),void p()):(console.debug(\"OR WebWorker: sender not initialised. Received auth.\"),void p()):void 0}if(c){const t=c;s.forEach((s=>{55===s[0]&&(s[1]?f=setTimeout((()=>p()),18e5):clearTimeout(f)),t.writeMessage(s)}))}else postMessage(\"not_init\"),p()}else d(!0);else d()}}();\n";
4763
4763
  const CANCELED = 'canceled';
4764
4764
  const bufferStorageKey = 'or_buffer_1';
4765
4765
  const PROTO_VERSION = '2';
@@ -4889,7 +4889,7 @@ class App {
4889
4889
  this.stopCallbacks = [];
4890
4890
  this.commitCallbacks = [];
4891
4891
  this.activityState = ActivityState.NotActive;
4892
- this.version = '7.4.50'; // TODO: version compatability check inside each plugin.
4892
+ this.version = '7.5.18'; // TODO: version compatability check inside each plugin.
4893
4893
  this.socketMode = false;
4894
4894
  this.compressionThreshold = 24 * 1000;
4895
4895
  this.bc = null;
@@ -8907,9 +8907,9 @@ function axiosSpy (app, instance, opts, sanitize, stringify) {
8907
8907
  });
8908
8908
  }
8909
8909
  function isAxiosError(payload) {
8910
- return isObject$1(payload) && payload.isAxiosError === true;
8910
+ return isObject(payload) && payload.isAxiosError === true;
8911
8911
  }
8912
- function isObject$1(thing) {
8912
+ function isObject(thing) {
8913
8913
  return thing !== null && typeof thing === 'object';
8914
8914
  }
8915
8915
 
@@ -10335,1198 +10335,6 @@ function webAnimations(app, options = {}) {
10335
10335
  });
10336
10336
  }
10337
10337
 
10338
- /**
10339
- * Detects client browser, OS, and device information
10340
- */
10341
- function uaParse(sWindow) {
10342
- const unknown = '-';
10343
- // Screen detection
10344
- let width = 0;
10345
- let height = 0;
10346
- let screenSize = '';
10347
- if (sWindow.screen.width) {
10348
- width = sWindow.screen.width;
10349
- height = sWindow.screen.height;
10350
- screenSize = `${width} x ${height}`;
10351
- }
10352
- // Browser detection
10353
- const nVer = sWindow.navigator.appVersion ?? '0';
10354
- const nAgt = sWindow.navigator.userAgent ?? 'unknown';
10355
- let browser = sWindow.navigator.appName ?? "unknown";
10356
- let version = String(parseFloat(nVer));
10357
- let nameOffset;
10358
- let verOffset;
10359
- let ix;
10360
- // Browser detection logic
10361
- if ((verOffset = nAgt.indexOf('YaBrowser')) !== -1) {
10362
- browser = 'Yandex';
10363
- version = nAgt.substring(verOffset + 10);
10364
- }
10365
- else if ((verOffset = nAgt.indexOf('SamsungBrowser')) !== -1) {
10366
- browser = 'Samsung';
10367
- version = nAgt.substring(verOffset + 15);
10368
- }
10369
- else if ((verOffset = nAgt.indexOf('UCBrowser')) !== -1) {
10370
- browser = 'UC Browser';
10371
- version = nAgt.substring(verOffset + 10);
10372
- }
10373
- else if ((verOffset = nAgt.indexOf('OPR')) !== -1) {
10374
- browser = 'Opera';
10375
- version = nAgt.substring(verOffset + 4);
10376
- }
10377
- else if ((verOffset = nAgt.indexOf('Opera')) !== -1) {
10378
- browser = 'Opera';
10379
- version = nAgt.substring(verOffset + 6);
10380
- if ((verOffset = nAgt.indexOf('Version')) !== -1) {
10381
- version = nAgt.substring(verOffset + 8);
10382
- }
10383
- }
10384
- else if ((verOffset = nAgt.indexOf('Edge')) !== -1) {
10385
- browser = 'Microsoft Legacy Edge';
10386
- version = nAgt.substring(verOffset + 5);
10387
- }
10388
- else if ((verOffset = nAgt.indexOf('Edg')) !== -1) {
10389
- browser = 'Microsoft Edge';
10390
- version = nAgt.substring(verOffset + 4);
10391
- }
10392
- else if ((verOffset = nAgt.indexOf('MSIE')) !== -1) {
10393
- browser = 'Microsoft Internet Explorer';
10394
- version = nAgt.substring(verOffset + 5);
10395
- }
10396
- else if ((verOffset = nAgt.indexOf('Chrome')) !== -1) {
10397
- browser = 'Chrome';
10398
- version = nAgt.substring(verOffset + 7);
10399
- }
10400
- else if ((verOffset = nAgt.indexOf('Safari')) !== -1) {
10401
- browser = 'Safari';
10402
- version = nAgt.substring(verOffset + 7);
10403
- if ((verOffset = nAgt.indexOf('Version')) !== -1) {
10404
- version = nAgt.substring(verOffset + 8);
10405
- }
10406
- }
10407
- else if ((verOffset = nAgt.indexOf('Firefox')) !== -1) {
10408
- browser = 'Firefox';
10409
- version = nAgt.substring(verOffset + 8);
10410
- }
10411
- else if (nAgt.indexOf('Trident/') !== -1) {
10412
- browser = 'Microsoft Internet Explorer';
10413
- version = nAgt.substring(nAgt.indexOf('rv:') + 3);
10414
- }
10415
- else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
10416
- browser = nAgt.substring(nameOffset, verOffset);
10417
- version = nAgt.substring(verOffset + 1);
10418
- if (browser.toLowerCase() === browser.toUpperCase()) {
10419
- browser = sWindow.navigator.appName;
10420
- }
10421
- }
10422
- // Trim the version string
10423
- if ((ix = version.indexOf(';')) !== -1) {
10424
- version = version.substring(0, ix);
10425
- }
10426
- if ((ix = version.indexOf(' ')) !== -1) {
10427
- version = version.substring(0, ix);
10428
- }
10429
- if ((ix = version.indexOf(')')) !== -1) {
10430
- version = version.substring(0, ix);
10431
- }
10432
- let majorVersion = parseInt(version, 10);
10433
- if (isNaN(majorVersion)) {
10434
- version = String(parseFloat(nVer));
10435
- majorVersion = parseInt(nVer, 10);
10436
- }
10437
- // Mobile detection
10438
- const mobile = /Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(nVer);
10439
- // Cookie detection
10440
- let cookieEnabled = sWindow.navigator.cookieEnabled || false;
10441
- if (typeof navigator.cookieEnabled === 'undefined' && !cookieEnabled) {
10442
- sWindow.document.cookie = 'testcookie';
10443
- cookieEnabled = sWindow.document.cookie.indexOf('testcookie') !== -1;
10444
- }
10445
- // OS detection
10446
- let os = unknown;
10447
- const clientStrings = [
10448
- { s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/ },
10449
- { s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/ },
10450
- { s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/ },
10451
- { s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/ },
10452
- { s: 'Windows Vista', r: /Windows NT 6.0/ },
10453
- { s: 'Windows Server 2003', r: /Windows NT 5.2/ },
10454
- { s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/ },
10455
- { s: 'Windows 2000', r: /(Windows NT 5.0|Windows 2000)/ },
10456
- { s: 'Windows ME', r: /(Win 9x 4.90|Windows ME)/ },
10457
- { s: 'Windows 98', r: /(Windows 98|Win98)/ },
10458
- { s: 'Windows 95', r: /(Windows 95|Win95|Windows_95)/ },
10459
- { s: 'Windows NT 4.0', r: /(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/ },
10460
- { s: 'Windows CE', r: /Windows CE/ },
10461
- { s: 'Windows 3.11', r: /Win16/ },
10462
- { s: 'Android', r: /Android/ },
10463
- { s: 'Open BSD', r: /OpenBSD/ },
10464
- { s: 'Sun OS', r: /SunOS/ },
10465
- { s: 'Chrome OS', r: /CrOS/ },
10466
- { s: 'Linux', r: /(Linux|X11(?!.*CrOS))/ },
10467
- { s: 'iOS', r: /(iPhone|iPad|iPod)/ },
10468
- { s: 'Mac OS X', r: /Mac OS X/ },
10469
- { s: 'Mac OS', r: /(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
10470
- { s: 'QNX', r: /QNX/ },
10471
- { s: 'UNIX', r: /UNIX/ },
10472
- { s: 'BeOS', r: /BeOS/ },
10473
- { s: 'OS/2', r: /OS\/2/ },
10474
- {
10475
- s: 'Search Bot',
10476
- r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/,
10477
- },
10478
- ];
10479
- // Find matching OS
10480
- for (const client of clientStrings) {
10481
- if (client.r.test(nAgt)) {
10482
- os = client.s;
10483
- break;
10484
- }
10485
- }
10486
- // OS Version detection
10487
- let osVersion = unknown;
10488
- if (/Windows/.test(os)) {
10489
- const matches = /Windows (.*)/.exec(os);
10490
- if (matches && matches[1]) {
10491
- osVersion = matches[1];
10492
- // Handle Windows 10/11 detection with newer API if available
10493
- if (osVersion === '10' && 'userAgentData' in sWindow.navigator) {
10494
- const nav = navigator;
10495
- if (nav.userAgentData) {
10496
- nav.userAgentData
10497
- .getHighEntropyValues(['platformVersion'])
10498
- .then((ua) => {
10499
- const version = parseInt(ua.platformVersion.split('.')[0], 10);
10500
- osVersion = version < 13 ? '10' : '11';
10501
- })
10502
- .catch(() => {
10503
- // ignore errors and keep osVersion as is
10504
- });
10505
- }
10506
- }
10507
- }
10508
- os = 'Windows';
10509
- }
10510
- // OS version detection for Mac/Android/iOS
10511
- switch (os) {
10512
- case 'Mac OS':
10513
- case 'Mac OS X':
10514
- case 'Android': {
10515
- const matches = /(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([\.\_\d]+)/.exec(nAgt);
10516
- osVersion = matches && matches[1] ? matches[1] : unknown;
10517
- break;
10518
- }
10519
- case 'iOS': {
10520
- const matches = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer);
10521
- if (matches && matches[1]) {
10522
- osVersion = `${matches[1]}.${matches[2]}.${parseInt(matches[3] || '0', 10)}`;
10523
- }
10524
- break;
10525
- }
10526
- }
10527
- // Return client data
10528
- return {
10529
- screen: screenSize,
10530
- width,
10531
- height,
10532
- browser,
10533
- browserVersion: version,
10534
- browserMajorVersion: majorVersion,
10535
- mobile,
10536
- os,
10537
- osVersion,
10538
- cookies: cookieEnabled,
10539
- };
10540
- }
10541
- function isObject(item) {
10542
- const isNull = item === null;
10543
- return Boolean(item && typeof item === 'object' && !Array.isArray(item) && !isNull);
10544
- }
10545
- function getUTCOffsetString() {
10546
- const date = new Date();
10547
- const offsetMinutes = date.getTimezoneOffset();
10548
- const hours = Math.abs(Math.floor(offsetMinutes / 60));
10549
- const minutes = Math.abs(offsetMinutes % 60);
10550
- const sign = offsetMinutes <= 0 ? '+' : '-';
10551
- const hoursStr = hours.toString().padStart(2, '0');
10552
- const minutesStr = minutes.toString().padStart(2, '0');
10553
- return `UTC${sign}${hoursStr}:${minutesStr}`;
10554
- }
10555
-
10556
- const refKey = '$__or__initial_ref__$';
10557
- const distinctIdKey = '$__or__distinct_device_id__$';
10558
- const utmParamsKey = '$__or__utm_params__$';
10559
- const superPropKey = '$__or__super_properties__$';
10560
- const userIdKey = '$__or__user_id__$';
10561
- const win = 'window' in globalThis
10562
- ? window
10563
- : {
10564
- navigator: { userAgent: '' },
10565
- screen: {},
10566
- document: {
10567
- cookie: '',
10568
- },
10569
- location: { search: '' },
10570
- };
10571
- const doc = 'document' in globalThis ? document : { referrer: '' };
10572
- const searchEngineList = [
10573
- 'google',
10574
- 'bing',
10575
- 'yahoo',
10576
- 'baidu',
10577
- 'yandex',
10578
- 'duckduckgo',
10579
- 'ecosia',
10580
- 'ask',
10581
- 'aol',
10582
- 'wolframalpha',
10583
- 'startpage',
10584
- 'swisscows',
10585
- 'qwant',
10586
- 'lycos',
10587
- 'dogpile',
10588
- 'info',
10589
- 'teoma',
10590
- 'webcrawler',
10591
- 'naver',
10592
- 'seznam',
10593
- 'perplexity',
10594
- ];
10595
- class ConstantProperties {
10596
- constructor(localStorage, sessionStorage) {
10597
- this.localStorage = localStorage;
10598
- this.sessionStorage = sessionStorage;
10599
- this.user_id = null;
10600
- this.setUserId = (user_id) => {
10601
- this.user_id = user_id;
10602
- this.sessionStorage.setItem(userIdKey, user_id ?? '');
10603
- };
10604
- this.resetUserId = (hard) => {
10605
- this.user_id = null;
10606
- if (hard) {
10607
- this.deviceId = this.getDistinctDeviceId(true);
10608
- }
10609
- };
10610
- this.getDistinctDeviceId = (force) => {
10611
- const potentialStored = this.localStorage.getItem(distinctIdKey);
10612
- if (potentialStored && !force) {
10613
- return potentialStored;
10614
- }
10615
- else {
10616
- const distinctId = `${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;
10617
- this.localStorage.setItem(distinctIdKey, distinctId);
10618
- return distinctId;
10619
- }
10620
- };
10621
- this.getReferrer = () => {
10622
- const potentialStored = this.sessionStorage.getItem(refKey);
10623
- if (potentialStored) {
10624
- return potentialStored;
10625
- }
10626
- else {
10627
- const ref = doc.referrer;
10628
- this.sessionStorage.setItem(refKey, ref);
10629
- return ref;
10630
- }
10631
- };
10632
- this.parseUTM = () => {
10633
- const potentialStored = this.sessionStorage.getItem(utmParamsKey);
10634
- if (potentialStored) {
10635
- const obj = JSON.parse(potentialStored);
10636
- this.utmSource = obj.utm_source;
10637
- this.utmMedium = obj.utm_medium;
10638
- this.utmCampaign = obj.utm_campaign;
10639
- }
10640
- else {
10641
- const searchParams = new URLSearchParams(win.location.search);
10642
- this.utmSource = searchParams.get('utm_source') || null;
10643
- this.utmMedium = searchParams.get('utm_medium') || null;
10644
- this.utmCampaign = searchParams.get('utm_campaign') || null;
10645
- const obj = {
10646
- utm_source: this.utmSource,
10647
- utm_medium: this.utmMedium,
10648
- utm_campaign: this.utmCampaign,
10649
- };
10650
- this.sessionStorage.setItem(utmParamsKey, JSON.stringify(obj));
10651
- }
10652
- };
10653
- this.getSearchEngine = (ref) => {
10654
- for (const searchEngine of searchEngineList) {
10655
- if (ref.includes(searchEngine)) {
10656
- return searchEngine;
10657
- }
10658
- }
10659
- return null;
10660
- };
10661
- this.getSuperProperties = () => {
10662
- const potentialStored = this.localStorage.getItem(superPropKey);
10663
- if (potentialStored) {
10664
- return JSON.parse(potentialStored);
10665
- }
10666
- else {
10667
- return {};
10668
- }
10669
- };
10670
- this.saveSuperProperties = (props) => {
10671
- this.localStorage.setItem(superPropKey, JSON.stringify(props));
10672
- };
10673
- this.clearSuperProperties = () => {
10674
- this.localStorage.setItem(superPropKey, JSON.stringify({}));
10675
- };
10676
- const { width, height, browser, browserVersion, browserMajorVersion, os, osVersion, mobile } = uaParse(win);
10677
- const storedUserId = this.sessionStorage.getItem(userIdKey);
10678
- if (storedUserId) {
10679
- this.user_id = storedUserId;
10680
- }
10681
- this.os = os;
10682
- this.osVersion = osVersion;
10683
- this.browser = `${browser}`;
10684
- this.browserVersion = `${browserVersion} (${browserMajorVersion})`;
10685
- this.platform = mobile ? 'mobile' : 'desktop';
10686
- this.screenHeight = height;
10687
- this.screenWidth = width;
10688
- this.initialReferrer = this.getReferrer();
10689
- this.deviceId = this.getDistinctDeviceId();
10690
- this.searchEngine = this.getSearchEngine(this.initialReferrer);
10691
- this.parseUTM();
10692
- }
10693
- get all() {
10694
- return {
10695
- os: this.os,
10696
- os_version: this.osVersion,
10697
- browser: this.browser,
10698
- browser_version: this.browserVersion,
10699
- platform: this.platform,
10700
- screen_height: this.screenHeight,
10701
- screen_width: this.screenWidth,
10702
- initial_referrer: this.initialReferrer,
10703
- utm_source: this.utmSource,
10704
- utm_medium: this.utmMedium,
10705
- utm_campaign: this.utmCampaign,
10706
- user_id: this.user_id,
10707
- distinct_id: this.deviceId,
10708
- sdk_edition: 'web',
10709
- sdk_version: '7.4.50',
10710
- timezone: getUTCOffsetString(),
10711
- search_engine: this.searchEngine,
10712
- };
10713
- }
10714
- get defaultPropertyKeys() {
10715
- return Object.keys(this.all);
10716
- }
10717
- get distinctId() {
10718
- return this.deviceId;
10719
- }
10720
- }
10721
-
10722
- const mutationTypes = {
10723
- identity: 'identity',
10724
- deleteUser: 'delete_user',
10725
- setProperty: 'set_property',
10726
- setPropertyOnce: 'set_property_once',
10727
- appendProperty: 'append_property',
10728
- appendUniqueProperty: 'append_unique_property',
10729
- incrementProperty: 'increment_property',
10730
- };
10731
- const categories = {
10732
- people: 'user_actions',
10733
- events: 'events',
10734
- };
10735
- const createEvent = (category, type, timestamp, payload) => {
10736
- if (category === categories.people) {
10737
- return {
10738
- category,
10739
- data: {
10740
- type,
10741
- user_id: payload.user_id,
10742
- payload: payload.properties,
10743
- timestamp,
10744
- },
10745
- };
10746
- }
10747
- else {
10748
- if (!payload) {
10749
- throw new Error('Payload is required for event creation');
10750
- }
10751
- return {
10752
- category,
10753
- data: {
10754
- name: payload.name,
10755
- payload: payload.properties,
10756
- timestamp,
10757
- },
10758
- };
10759
- }
10760
- };
10761
-
10762
- const reservedProps = ['properties', 'token', 'timestamp'];
10763
- class Events {
10764
- constructor(constantProperties, getTimestamp, batcher) {
10765
- this.constantProperties = constantProperties;
10766
- this.getTimestamp = getTimestamp;
10767
- this.batcher = batcher;
10768
- this.ownProperties = {};
10769
- /**
10770
- * Add event to batch with option to send it immediately,
10771
- * properties are optional and will not be saved as super prop
10772
- * */
10773
- this.sendEvent = (eventName, properties, options) => {
10774
- // add properties
10775
- const eventProps = {};
10776
- if (properties) {
10777
- if (!isObject(properties)) {
10778
- throw new Error('Properties must be an object');
10779
- }
10780
- Object.entries(properties).forEach(([key, value]) => {
10781
- if (!this.constantProperties.defaultPropertyKeys.includes(key)) {
10782
- eventProps[key] = value;
10783
- }
10784
- });
10785
- }
10786
- const eventPayload = {
10787
- name: eventName,
10788
- properties: { ...this.ownProperties, ...eventProps },
10789
- };
10790
- const event = createEvent(categories.events, undefined, this.getTimestamp(), eventPayload);
10791
- if (options?.send_immediately) {
10792
- void this.batcher.sendImmediately(event);
10793
- }
10794
- else {
10795
- this.batcher.addEvent(event);
10796
- }
10797
- };
10798
- /**
10799
- * creates super property for all events
10800
- * */
10801
- this.setProperty = (nameOrProperties, value) => {
10802
- let changed = false;
10803
- if (isObject(nameOrProperties)) {
10804
- Object.entries(nameOrProperties).forEach(([key, val]) => {
10805
- if (!this.constantProperties.defaultPropertyKeys.includes(key)) {
10806
- this.ownProperties[key] = val;
10807
- changed = true;
10808
- }
10809
- });
10810
- }
10811
- if (typeof nameOrProperties === 'string' && value !== undefined) {
10812
- if (!this.constantProperties.defaultPropertyKeys.includes(nameOrProperties)) {
10813
- this.ownProperties[nameOrProperties] = value;
10814
- changed = true;
10815
- }
10816
- }
10817
- if (changed) {
10818
- this.constantProperties.saveSuperProperties(this.ownProperties);
10819
- }
10820
- };
10821
- /**
10822
- * set super property only if it doesn't exist yet
10823
- * */
10824
- this.setPropertiesOnce = (nameOrProperties, value) => {
10825
- let changed = false;
10826
- if (isObject(nameOrProperties)) {
10827
- Object.entries(nameOrProperties).forEach(([key, val]) => {
10828
- if (!this.ownProperties[key] && !reservedProps.includes(key)) {
10829
- this.ownProperties[key] = val;
10830
- changed = true;
10831
- }
10832
- });
10833
- }
10834
- if (typeof nameOrProperties === 'string' && value !== undefined) {
10835
- if (!this.ownProperties[nameOrProperties] && !reservedProps.includes(nameOrProperties)) {
10836
- this.ownProperties[nameOrProperties] = value;
10837
- changed = true;
10838
- }
10839
- }
10840
- if (changed) {
10841
- this.constantProperties.saveSuperProperties(this.ownProperties);
10842
- }
10843
- };
10844
- /**
10845
- * removes properties from list of super properties
10846
- * */
10847
- this.unsetProperties = (properties) => {
10848
- let changed = false;
10849
- if (Array.isArray(properties)) {
10850
- properties.forEach((key) => {
10851
- if (this.ownProperties[key] && !reservedProps.includes(key)) {
10852
- delete this.ownProperties[key];
10853
- changed = true;
10854
- }
10855
- });
10856
- }
10857
- else if (this.ownProperties[properties] && !reservedProps.includes(properties)) {
10858
- delete this.ownProperties[properties];
10859
- changed = true;
10860
- }
10861
- if (changed) {
10862
- this.constantProperties.saveSuperProperties(this.ownProperties);
10863
- }
10864
- };
10865
- /** clears all super properties */
10866
- this.reset = () => {
10867
- this.ownProperties = {};
10868
- this.constantProperties.clearSuperProperties();
10869
- };
10870
- /** mixpanel compatibility */
10871
- this.register = this.setProperty;
10872
- this.register_once = this.setPropertiesOnce;
10873
- this.unregister = this.unsetProperties;
10874
- this.track = this.sendEvent;
10875
- this.ownProperties = this.constantProperties.getSuperProperties();
10876
- }
10877
- }
10878
-
10879
- class People {
10880
- constructor(constantProperties, getTimestamp, onId, batcher) {
10881
- this.constantProperties = constantProperties;
10882
- this.getTimestamp = getTimestamp;
10883
- this.onId = onId;
10884
- this.batcher = batcher;
10885
- this.ownProperties = {};
10886
- this.defaultPropertyKeyMap = {
10887
- email: 'email',
10888
- name: 'name',
10889
- first_name: 'first_name',
10890
- firstname: 'first_name',
10891
- last_name: 'last_name',
10892
- lastname: 'last_name',
10893
- phone: 'phone',
10894
- avatar: 'avatar',
10895
- };
10896
- this.normalizeUserPropertyKey = (rawKey) => {
10897
- const trimmed = String(rawKey || '').trim();
10898
- if (!trimmed)
10899
- return '';
10900
- const withoutPrefix = trimmed.startsWith('$') ? trimmed.slice(1) : trimmed;
10901
- const snake = withoutPrefix
10902
- .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
10903
- .replace(/[-\s]+/g, '_');
10904
- const snakeLower = snake.toLowerCase();
10905
- if (this.defaultPropertyKeyMap[snakeLower]) {
10906
- return this.defaultPropertyKeyMap[snakeLower];
10907
- }
10908
- return withoutPrefix;
10909
- };
10910
- this.normalizeUserProperties = (input) => {
10911
- if (!input || typeof input !== 'object')
10912
- return {};
10913
- const output = {};
10914
- Object.entries(input).forEach(([key, value]) => {
10915
- if (value === undefined || value === null)
10916
- return;
10917
- const normalizedKey = this.normalizeUserPropertyKey(key);
10918
- if (!normalizedKey)
10919
- return;
10920
- output[normalizedKey] = value;
10921
- });
10922
- return output;
10923
- };
10924
- this.identify = (user_id, propertiesOrOptions, options) => {
10925
- if (!user_id || typeof user_id !== 'string') {
10926
- throw new Error('OR SDK: user_id (string) is required for .identify()');
10927
- }
10928
- let properties;
10929
- let identifyOptions = options;
10930
- if (propertiesOrOptions && typeof propertiesOrOptions === 'object' && !Array.isArray(propertiesOrOptions)) {
10931
- const keys = Object.keys(propertiesOrOptions);
10932
- if (keys.length === 1 && keys[0] === 'fromTracker' && options === undefined) {
10933
- identifyOptions = propertiesOrOptions;
10934
- }
10935
- else {
10936
- properties = propertiesOrOptions;
10937
- }
10938
- }
10939
- // if user exists already, reset properties
10940
- if (this.constantProperties.user_id && this.constantProperties.user_id !== user_id) {
10941
- this.reset();
10942
- }
10943
- this.constantProperties.setUserId(user_id);
10944
- if (!identifyOptions?.fromTracker) {
10945
- this.onId(user_id);
10946
- }
10947
- const identityEvent = createEvent(categories.people, mutationTypes.identity, this.getTimestamp(), { user_id });
10948
- this.batcher.addEvent(identityEvent);
10949
- if (properties && Object.keys(properties).length > 0) {
10950
- const normalized = this.normalizeUserProperties(properties);
10951
- if (Object.keys(normalized).length > 0) {
10952
- this.setProperties(normalized);
10953
- }
10954
- }
10955
- };
10956
- /** Resets user id and own properties
10957
- *
10958
- * !hard reset will destroy persistent device id!
10959
- * */
10960
- this.reset = (hard) => {
10961
- this.constantProperties.resetUserId(hard);
10962
- this.ownProperties = {};
10963
- };
10964
- /**
10965
- * Will delete user and its data from backend, then reset all local properties
10966
- */
10967
- this.deleteUser = () => {
10968
- const removedUser = this.constantProperties.user_id;
10969
- if (!removedUser)
10970
- return;
10971
- this.constantProperties.setUserId(null);
10972
- this.ownProperties = {};
10973
- const deleteEvent = createEvent(categories.people, mutationTypes.deleteUser, undefined, {
10974
- user_id: removedUser,
10975
- });
10976
- this.batcher.addEvent(deleteEvent);
10977
- this.reset();
10978
- };
10979
- /**
10980
- * set user properties, overwriting existing ones
10981
- * */
10982
- this.setProperties = (propertyOrObj, value) => {
10983
- if (!propertyOrObj) {
10984
- throw new Error('OR SDK: no user properties provided to set');
10985
- }
10986
- const properties = {};
10987
- if (typeof propertyOrObj === 'string' && propertyOrObj && value) {
10988
- properties[propertyOrObj] = value;
10989
- }
10990
- else if (isObject(propertyOrObj)) {
10991
- Object.assign(properties, propertyOrObj);
10992
- }
10993
- else {
10994
- throw new Error('OR SDK: invalid user properties provided to set');
10995
- }
10996
- Object.entries(properties).forEach(([key, value]) => {
10997
- if (!this.constantProperties.defaultPropertyKeys.includes(key)) {
10998
- this.ownProperties[key] = value;
10999
- }
11000
- });
11001
- const setEvent = createEvent(categories.people, mutationTypes.setProperty, undefined, {
11002
- user_id: this.user_id,
11003
- properties,
11004
- });
11005
- this.batcher.addEvent(setEvent);
11006
- };
11007
- /**
11008
- * Set property if it doesn't exist yet
11009
- * */
11010
- this.setPropertiesOnce = (properties) => {
11011
- if (!isObject(properties)) {
11012
- throw new Error('Properties must be an object');
11013
- }
11014
- Object.entries(properties).forEach(([key, value]) => {
11015
- if (!this.constantProperties.defaultPropertyKeys.includes(key) && !this.ownProperties[key]) {
11016
- this.ownProperties[key] = value;
11017
- }
11018
- });
11019
- const setEvent = createEvent(categories.people, mutationTypes.setPropertyOnce, undefined, {
11020
- user_id: this.user_id,
11021
- properties,
11022
- });
11023
- this.batcher.addEvent(setEvent);
11024
- };
11025
- /**
11026
- * Add value to property (will turn string prop into array)
11027
- * */
11028
- this.appendValues = (key, value) => {
11029
- if (!this.constantProperties.defaultPropertyKeys.includes(key) && this.ownProperties[key]) {
11030
- if (Array.isArray(this.ownProperties[key])) {
11031
- this.ownProperties[key].push(value);
11032
- }
11033
- else {
11034
- this.ownProperties[key] = [this.ownProperties[key], value];
11035
- }
11036
- }
11037
- const appendEvent = createEvent(categories.people, mutationTypes.appendProperty, undefined, {
11038
- properties: { [key]: value },
11039
- user_id: this.user_id,
11040
- });
11041
- this.batcher.addEvent(appendEvent);
11042
- };
11043
- /**
11044
- * Add unique values to property (will turn string prop into array)
11045
- * */
11046
- this.appendUniqueValues = (key, value) => {
11047
- if (!this.ownProperties[key])
11048
- return;
11049
- if (Array.isArray(this.ownProperties[key])) {
11050
- if (!this.ownProperties[key].includes(value)) {
11051
- this.appendValues(key, value);
11052
- }
11053
- }
11054
- else if (this.ownProperties[key] !== value) {
11055
- this.appendValues(key, value);
11056
- }
11057
- const unionEvent = createEvent(categories.people, mutationTypes.appendUniqueProperty, undefined, {
11058
- properties: { [key]: value },
11059
- user_id: this.user_id,
11060
- });
11061
- this.batcher.addEvent(unionEvent);
11062
- };
11063
- /**
11064
- * Adds value (incl. negative) to existing numerical property
11065
- * */
11066
- this.increment = (key, value) => {
11067
- if (!this.ownProperties[key]) {
11068
- this.ownProperties[key] = 0;
11069
- }
11070
- if (this.ownProperties[key] && typeof this.ownProperties[key] !== 'number') {
11071
- throw new Error('OR SDK: Property must be a number to increment');
11072
- }
11073
- // @ts-ignore
11074
- this.ownProperties[key] += value;
11075
- const incrementEvent = createEvent(categories.people, mutationTypes.incrementProperty, undefined, {
11076
- user_id: this.user_id,
11077
- properties: { [key]: value },
11078
- });
11079
- this.batcher.addEvent(incrementEvent);
11080
- };
11081
- /** mixpanel compatibility */
11082
- this.union = this.appendUniqueValues;
11083
- this.set = this.setProperties;
11084
- this.set_once = this.setPropertiesOnce;
11085
- this.append = this.appendValues;
11086
- this.incrementBy = this.increment;
11087
- }
11088
- get user_id() {
11089
- return this.constantProperties.user_id;
11090
- }
11091
- }
11092
-
11093
- /**
11094
- * Creates batches of events, then sends them at intervals.
11095
- */
11096
- class Batcher {
11097
- constructor(backendUrl, getToken, init, standalone) {
11098
- this.backendUrl = backendUrl;
11099
- this.getToken = getToken;
11100
- this.init = init;
11101
- this.standalone = standalone;
11102
- this.autosendInterval = 5 * 1000;
11103
- this.retryTimeout = 3 * 1000;
11104
- this.retryLimit = 3;
11105
- this.apiEdp = '/v1/insights/stream';
11106
- this.batch = {
11107
- [categories.people]: [],
11108
- [categories.events]: [],
11109
- };
11110
- this.intervalId = null;
11111
- this.stopped = false;
11112
- this.paused = false;
11113
- this.onVisibilityChange = () => {
11114
- this.paused = document.hidden;
11115
- };
11116
- }
11117
- getBatches() {
11118
- this.batch[categories.people] = this.dedupePeopleEvents();
11119
- const finalData = {
11120
- data: {
11121
- [categories.people]: [...this.batch[categories.people]],
11122
- [categories.events]: [...this.batch[categories.events]],
11123
- },
11124
- };
11125
- return finalData;
11126
- }
11127
- addEvent(event) {
11128
- this.batch[event.category].push(event.data);
11129
- }
11130
- sendImmediately(event) {
11131
- this.sendBatch({ [event.category]: [event.data] });
11132
- }
11133
- /**
11134
- *
11135
- * Essentially we're dividing the batch by identify events and squash all same category events into one in each part,
11136
- * taking priority to the last one
11137
- */
11138
- dedupePeopleEvents() {
11139
- const peopleEvents = this.batch[categories.people];
11140
- const finalEvents = [];
11141
- const currentPart = [];
11142
- for (let event of peopleEvents) {
11143
- if (event.type === 'identity') {
11144
- if (currentPart.length > 0) {
11145
- finalEvents.push(...this.squashPeopleEvents(currentPart), event);
11146
- currentPart.length = 0;
11147
- }
11148
- else {
11149
- finalEvents.push(event);
11150
- }
11151
- }
11152
- else {
11153
- currentPart.push(event);
11154
- }
11155
- }
11156
- if (currentPart.length > 0) {
11157
- finalEvents.push(...this.squashPeopleEvents(currentPart));
11158
- }
11159
- return finalEvents;
11160
- }
11161
- squashPeopleEvents(events) {
11162
- if (!events || events.length === 0) {
11163
- return [];
11164
- }
11165
- const uniqueEventsByType = new Map();
11166
- for (let event of events) {
11167
- const prev = uniqueEventsByType.get(event.type);
11168
- if (prev) {
11169
- if (event.type === 'increment_property') {
11170
- const previousValues = Object.entries(prev.payload);
11171
- const currentValues = Object.entries(event.payload);
11172
- const uniqueKeys = new Set([...previousValues.map(([key]) => key), ...currentValues.map(([key]) => key)]);
11173
- const mergedPayload = {};
11174
- uniqueKeys.forEach((key) => {
11175
- const prevValue = typeof prev.payload[key] === 'number' ? prev.payload[key] : 0;
11176
- const currValue = typeof event.payload[key] === 'number' ? event.payload[key] : 0;
11177
- mergedPayload[key] = prevValue + currValue;
11178
- });
11179
- uniqueEventsByType.set(event.type, {
11180
- type: event.type,
11181
- timestamp: event.timestamp,
11182
- payload: mergedPayload,
11183
- });
11184
- continue;
11185
- }
11186
- // merge payloads, taking priority to the latest one
11187
- uniqueEventsByType.set(event.type, {
11188
- type: event.type,
11189
- timestamp: event.timestamp,
11190
- payload: { ...(prev.payload ?? {}), ...(event.payload ?? {}) },
11191
- });
11192
- }
11193
- else {
11194
- uniqueEventsByType.set(event.type, event);
11195
- }
11196
- }
11197
- return Array.from(uniqueEventsByType.values());
11198
- }
11199
- sendBatch(batch) {
11200
- if (this.stopped) {
11201
- return;
11202
- }
11203
- const sentBatch = batch;
11204
- let attempts = 0;
11205
- const send = () => {
11206
- const token = this.getToken();
11207
- if (!token) {
11208
- return;
11209
- }
11210
- attempts++;
11211
- return fetch(`${this.backendUrl}${this.apiEdp}`, {
11212
- method: 'POST',
11213
- headers: {
11214
- 'Content-Type': 'application/json',
11215
- Authorization: `Bearer ${token}`,
11216
- },
11217
- body: JSON.stringify(sentBatch),
11218
- })
11219
- .then(async (response) => {
11220
- if (response.status === 401) {
11221
- const body = await response.json().catch(() => null);
11222
- if (!this.standalone && body?.error === 'token expired') {
11223
- this.stop();
11224
- return;
11225
- }
11226
- if (attempts < this.retryLimit) {
11227
- return this.init().then(() => {
11228
- send();
11229
- });
11230
- }
11231
- return;
11232
- }
11233
- if (response.status === 403) {
11234
- if (attempts < this.retryLimit) {
11235
- return this.init().then(() => {
11236
- send();
11237
- });
11238
- }
11239
- return;
11240
- }
11241
- if (!response.ok) {
11242
- throw new Error(`HTTP error! status: ${response.status}`);
11243
- }
11244
- })
11245
- .catch(() => {
11246
- if (attempts < this.retryLimit) {
11247
- setTimeout(() => void send(), this.retryTimeout);
11248
- }
11249
- });
11250
- };
11251
- void send();
11252
- }
11253
- startAutosend() {
11254
- if (this.intervalId) {
11255
- clearInterval(this.intervalId);
11256
- }
11257
- this.paused = document.hidden;
11258
- document.addEventListener('visibilitychange', this.onVisibilityChange);
11259
- this.intervalId = setInterval(() => {
11260
- if (!this.paused) {
11261
- this.flush();
11262
- }
11263
- }, this.autosendInterval);
11264
- }
11265
- flush() {
11266
- const categories = Object.keys(this.batch);
11267
- const isEmpty = categories.every((category) => this.batch[category].length === 0);
11268
- if (isEmpty) {
11269
- return;
11270
- }
11271
- this.sendBatch(this.getBatches());
11272
- categories.forEach((key) => {
11273
- this.batch[key] = [];
11274
- });
11275
- }
11276
- stop() {
11277
- this.flush();
11278
- if (this.intervalId) {
11279
- clearInterval(this.intervalId);
11280
- this.intervalId = null;
11281
- }
11282
- document.removeEventListener('visibilitychange', this.onVisibilityChange);
11283
- this.stopped = true;
11284
- }
11285
- restart() {
11286
- this.stopped = false;
11287
- this.startAutosend();
11288
- }
11289
- }
11290
-
11291
- const STORAGEKEY = '__or_sdk_analytics_token';
11292
- const START_ATTEMPT_STORAGE_KEY = '__or_sdk_analytics_start_attempt';
11293
- const START_ATTEMPT_TTL_MS = 24 * 60 * 60 * 1000;
11294
- const normalizeIngestPoint = (ingest) => {
11295
- const base = ingest.replace(/\/$/, '');
11296
- return base.endsWith('/oxvo') ? base : `${base}/oxvo`;
11297
- };
11298
- class Analytics {
11299
- /**
11300
- * @param localStorage Class or Object that implements Storage-like interface that stores
11301
- * values persistently like window.localStorage or any other file-based storage
11302
- *
11303
- * @param sessionStorage Class or Object that implements Storage-like interface that stores values
11304
- * on per-session basis like window.sessionStorage or any other in-memory storage
11305
- *
11306
- * @param getToken Function that returns token to bind events to a session
11307
- *
11308
- * @param getTimestamp returns current timestamp
11309
- *
11310
- * @param setUserId callback for people.identify
11311
- *
11312
- * @param standalone if true, analytics will manage its own token (instead of using with oxvosessions tracker session)
11313
- * */
11314
- constructor(options) {
11315
- this.token = null;
11316
- this.standalone = false;
11317
- this.pendingStartAttempt = null;
11318
- this._getToken = () => {
11319
- if (this.standalone) {
11320
- return this.token;
11321
- }
11322
- else {
11323
- return this.getToken();
11324
- }
11325
- };
11326
- this._getTimestamp = () => {
11327
- if (this.standalone) {
11328
- return Date.now();
11329
- }
11330
- return this.getTimestamp();
11331
- };
11332
- this.init = async () => {
11333
- if (!this.standalone) {
11334
- this.batcher.startAutosend();
11335
- return;
11336
- }
11337
- else {
11338
- const defaultFields = this.constantProperties.all;
11339
- const apiEdp = `${this.backendUrl}/v1/insights/start`;
11340
- const data = {
11341
- projectKey: this.projectKey,
11342
- os: defaultFields.os,
11343
- os_version: defaultFields.os_version,
11344
- browser: defaultFields.browser,
11345
- browser_version: defaultFields.browser_version,
11346
- platform: 'web',
11347
- device_type: defaultFields.platform,
11348
- screen_height: defaultFields.screen_height,
11349
- screen_width: defaultFields.screen_width,
11350
- initial_referrer: defaultFields.initial_referrer,
11351
- utm_source: defaultFields.utm_source,
11352
- utm_medium: defaultFields.utm_medium,
11353
- utm_campaign: defaultFields.utm_campaign,
11354
- user_id: defaultFields.user_id ?? '',
11355
- device_id: defaultFields.distinct_id,
11356
- sdk_edition: defaultFields.sdk_edition,
11357
- sdk_version: defaultFields.sdk_version,
11358
- timezone: defaultFields.timezone,
11359
- search_engine: defaultFields.search_engine,
11360
- };
11361
- const attempt = this.startAttempt(JSON.stringify(data));
11362
- const resp = await fetch(apiEdp, {
11363
- method: 'POST',
11364
- headers: {
11365
- 'Content-Type': 'application/json',
11366
- 'Idempotency-Key': attempt.idempotencyKey,
11367
- },
11368
- body: attempt.requestBody,
11369
- });
11370
- if (!resp.ok) {
11371
- throw new Error(`HTTP error! status: ${resp.status}`);
11372
- }
11373
- const result = await resp.json();
11374
- if (result.token) {
11375
- this.token = result.token;
11376
- this.sessionStorage.setItem(STORAGEKEY, result.token);
11377
- this.clearStartAttempt();
11378
- }
11379
- else {
11380
- throw new Error('No token received from server');
11381
- }
11382
- }
11383
- };
11384
- /**
11385
- * Used by tracker when running in blundled mode
11386
- */
11387
- this.onStart = () => {
11388
- if (!this.standalone) {
11389
- this.batcher.restart();
11390
- }
11391
- };
11392
- this.onStop = () => {
11393
- if (!this.standalone) {
11394
- this.batcher.stop();
11395
- }
11396
- };
11397
- this.reset = () => {
11398
- this.people.reset(true);
11399
- this.events.reset();
11400
- this.batcher.stop();
11401
- if (this.standalone) {
11402
- this.token = null;
11403
- this.sessionStorage.setItem(STORAGEKEY, '');
11404
- this.clearStartAttempt();
11405
- }
11406
- };
11407
- /**
11408
- * COMPATIBILITY LAYER
11409
- * */
11410
- /**
11411
- * Identify a user with an id (e.g. email, username, etc.)
11412
- * will bind all events and properties (including device_id) to this user
11413
- *
11414
- * you will need to manually call people.reset() to clear the id on logout event
11415
- * */
11416
- this.identify = (user_id, properties) => {
11417
- return this.people.identify(user_id, properties);
11418
- };
11419
- /**
11420
- * Add event to batch with option to send it immediately,
11421
- * properties are optional and will not be saved as super prop
11422
- * */
11423
- this.track = (eventName, properties, options) => {
11424
- return this.events.track(eventName, properties, options);
11425
- };
11426
- this.sessionStorage = options.sessionStorage || sessionStorage;
11427
- this.localStorage = options.localStorage || localStorage;
11428
- this.backendUrl = normalizeIngestPoint(options.ingestPoint);
11429
- this.projectKey = options.projectKey;
11430
- this.getToken = options.getToken || (() => '');
11431
- this.getTimestamp = options.getTimestamp || (() => Date.now());
11432
- this.setUserId = options.setUserId || (() => { });
11433
- this.standalone = !options.notStandalone;
11434
- this.token = this.sessionStorage.getItem(STORAGEKEY);
11435
- this.constantProperties = new ConstantProperties(this.localStorage, this.sessionStorage);
11436
- this.batcher = new Batcher(this.backendUrl, this._getToken, this.init, this.standalone);
11437
- this.events = new Events(this.constantProperties, this._getTimestamp, this.batcher);
11438
- this.people = new People(this.constantProperties, this._getTimestamp, this.setUserId, this.batcher);
11439
- if (options.notStandalone) {
11440
- this.init();
11441
- }
11442
- }
11443
- loadStartAttempt() {
11444
- if (this.isValidStartAttempt(this.pendingStartAttempt)) {
11445
- return this.pendingStartAttempt;
11446
- }
11447
- this.pendingStartAttempt = null;
11448
- let serialized;
11449
- try {
11450
- serialized = this.sessionStorage.getItem(START_ATTEMPT_STORAGE_KEY);
11451
- }
11452
- catch {
11453
- return null;
11454
- }
11455
- if (!serialized || serialized.length > 1024 * 1024) {
11456
- return null;
11457
- }
11458
- try {
11459
- const attempt = JSON.parse(serialized);
11460
- if (this.isValidStartAttempt(attempt)) {
11461
- this.pendingStartAttempt = attempt;
11462
- return attempt;
11463
- }
11464
- }
11465
- catch {
11466
- // Treat corrupt storage as an absent pending attempt.
11467
- }
11468
- return null;
11469
- }
11470
- isValidStartAttempt(value) {
11471
- if (typeof value !== 'object' || value === null) {
11472
- return false;
11473
- }
11474
- const attempt = value;
11475
- const currentTime = Date.now();
11476
- if (attempt.version !== 1 ||
11477
- attempt.projectKey !== this.projectKey ||
11478
- typeof attempt.createdAt !== 'number' ||
11479
- !Number.isFinite(attempt.createdAt) ||
11480
- attempt.createdAt > currentTime ||
11481
- currentTime - attempt.createdAt >= START_ATTEMPT_TTL_MS ||
11482
- typeof attempt.idempotencyKey !== 'string' ||
11483
- attempt.idempotencyKey.length < 8 ||
11484
- attempt.idempotencyKey.length > 128 ||
11485
- !/^[A-Za-z0-9._:-]+$/.test(attempt.idempotencyKey) ||
11486
- typeof attempt.requestBody !== 'string' ||
11487
- attempt.requestBody.length > 1024 * 1024) {
11488
- return false;
11489
- }
11490
- try {
11491
- const request = JSON.parse(attempt.requestBody);
11492
- return request.projectKey === this.projectKey;
11493
- }
11494
- catch {
11495
- return false;
11496
- }
11497
- }
11498
- startAttempt(requestBody) {
11499
- const existing = this.loadStartAttempt();
11500
- if (existing) {
11501
- return existing;
11502
- }
11503
- const attempt = {
11504
- version: 1,
11505
- projectKey: this.projectKey,
11506
- createdAt: Date.now(),
11507
- idempotencyKey: `insights:start:${generateRandomId(40)}`,
11508
- requestBody,
11509
- };
11510
- this.pendingStartAttempt = attempt;
11511
- try {
11512
- this.sessionStorage.setItem(START_ATTEMPT_STORAGE_KEY, JSON.stringify(attempt));
11513
- }
11514
- catch {
11515
- // The in-memory copy still protects retries within this Analytics instance.
11516
- }
11517
- return attempt;
11518
- }
11519
- clearStartAttempt() {
11520
- this.pendingStartAttempt = null;
11521
- try {
11522
- this.sessionStorage.setItem(START_ATTEMPT_STORAGE_KEY, '');
11523
- }
11524
- catch {
11525
- // The in-memory copy is still cleared when storage is unavailable.
11526
- }
11527
- }
11528
- }
11529
-
11530
10338
  const Messages = _Messages;
11531
10339
  const DOCS_SETUP = '/en/sdk';
11532
10340
  function processOptions(obj) {
@@ -11571,7 +10379,7 @@ class API {
11571
10379
  this.signalStartIssue = (reason, missingApi) => {
11572
10380
  const doNotTrack = this.checkDoNotTrack();
11573
10381
  console.log("Tracker couldn't start due to:", JSON.stringify({
11574
- trackerVersion: '7.4.50',
10382
+ trackerVersion: '7.5.18',
11575
10383
  siteKey: this.options.siteKey,
11576
10384
  doNotTrack,
11577
10385
  reason: missingApi.length ? `missing api: ${missingApi.join(',')}` : reason,
@@ -11617,7 +10425,6 @@ class API {
11617
10425
  this.identify = (id, properties) => {
11618
10426
  if (typeof id === 'string' && this.app !== null) {
11619
10427
  this.app.session.setUserID(id);
11620
- this.analytics?.people.identify(id, properties, { fromTracker: true });
11621
10428
  }
11622
10429
  };
11623
10430
  this.handleError = (e, metadata = {}) => {
@@ -11723,40 +10530,6 @@ class API {
11723
10530
  }
11724
10531
  const app = new App(options.siteKey, options.sessionToken, options, this.signalStartIssue, this.crossdomainMode);
11725
10532
  this.app = app;
11726
- if (options.siteKey && options.analytics?.active) {
11727
- let isSaas = false;
11728
- if (!options.endpoint) {
11729
- isSaas = true;
11730
- }
11731
- if (options.endpoint) {
11732
- const saasHost = 'api.oxvo.com';
11733
- const urlObj = new URL(options.endpoint);
11734
- if (urlObj.hostname === saasHost) {
11735
- isSaas = true;
11736
- }
11737
- }
11738
- const defaultEdp = 'https://api.oxvo.com/oxvo';
11739
- this.analytics = new Analytics({
11740
- localStorage: options.localStorage ?? localStorage,
11741
- sessionStorage: options.sessionStorage ?? sessionStorage,
11742
- getToken: () => this.getAnalyticsToken(),
11743
- getTimestamp: () => this.app?.timestamp() ?? Date.now(),
11744
- setUserId: (id) => {
11745
- this.app?.session.setUserID(id);
11746
- },
11747
- notStandalone: true,
11748
- ingestPoint: isSaas
11749
- ? defaultEdp
11750
- : (options.analytics?.endpoint ?? options.endpoint ?? defaultEdp),
11751
- projectKey: options.siteKey,
11752
- });
11753
- app.attachStartCallback(() => {
11754
- this.analytics?.onStart();
11755
- });
11756
- app.attachStopCallback(() => {
11757
- this.analytics?.onStop();
11758
- });
11759
- }
11760
10533
  if (!this.crossdomainMode) {
11761
10534
  // no need to send iframe viewport data since its a node for us
11762
10535
  Viewport(app, options.urls);
@@ -11850,7 +10623,6 @@ class API {
11850
10623
  }
11851
10624
  if (startOpts?.userID) {
11852
10625
  this.app.session.setUserID(startOpts.userID);
11853
- this.analytics?.people.identify(startOpts.userID, undefined, { fromTracker: true });
11854
10626
  }
11855
10627
  return this.app.start(startOpts);
11856
10628
  }