@openreplay/tracker 17.2.3 → 17.2.4

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/cjs/index.js CHANGED
@@ -3852,7 +3852,7 @@ class App {
3852
3852
  this.stopCallbacks = [];
3853
3853
  this.commitCallbacks = [];
3854
3854
  this.activityState = ActivityState.NotActive;
3855
- this.version = '17.2.3'; // TODO: version compatability check inside each plugin.
3855
+ this.version = '17.2.4'; // TODO: version compatability check inside each plugin.
3856
3856
  this.socketMode = false;
3857
3857
  this.compressionThreshold = 24 * 1000;
3858
3858
  this.bc = null;
@@ -6176,7 +6176,7 @@ function getUniqueSiblingClass(el) {
6176
6176
  return null;
6177
6177
  }
6178
6178
 
6179
- let e=-1;const t=t=>{addEventListener("pageshow",(n=>{n.persisted&&(e=n.timeStamp,t(n));}),true);},n=(e,t,n,i)=>{let s,o;return r=>{t.value>=0&&(r||i)&&(o=t.value-(s??0),(o||void 0===s)&&(s=t.value,t.delta=o,t.rating=((e,t)=>e>t[1]?"poor":e>t[0]?"needs-improvement":"good")(t.value,n),e(t)));}},i=e=>{requestAnimationFrame((()=>requestAnimationFrame((()=>e()))));},s=()=>{const e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},o=()=>{const e=s();return e?.activationStart??0},r=(t,n=-1)=>{const i=s();let r="navigate";e>=0?r="back-forward-cache":i&&(document.prerendering||o()>0?r="prerender":document.wasDiscarded?r="restore":i.type&&(r=i.type.replace(/_/g,"-")));return {name:t,value:n,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:r}},c=new WeakMap;function a(e,t){return c.get(e)||c.set(e,new t),c.get(e)}class d{t;i=0;o=[];h(e){if(e.hadRecentInput)return;const t=this.o[0],n=this.o.at(-1);this.i&&t&&n&&e.startTime-n.startTime<1e3&&e.startTime-t.startTime<5e3?(this.i+=e.value,this.o.push(e)):(this.i=e.value,this.o=[e]),this.t?.(e);}}const h=(e,t,n={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){const i=new PerformanceObserver((e=>{Promise.resolve().then((()=>{t(e.getEntries());}));}));return i.observe({type:e,buffered:!0,...n}),i}}catch{}},f=e=>{let t=false;return ()=>{t||(e(),t=true);}};let u=-1;const l=new Set,m=()=>"hidden"!==document.visibilityState||document.prerendering?1/0:0,p=e=>{if("hidden"===document.visibilityState){if("visibilitychange"===e.type)for(const e of l)e();isFinite(u)||(u="visibilitychange"===e.type?e.timeStamp:0,removeEventListener("prerenderingchange",p,true));}},v=()=>{if(u<0){const e=o(),n=document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").filter((t=>"hidden"===t.name&&t.startTime>e))[0]?.startTime;u=n??m(),addEventListener("visibilitychange",p,true),addEventListener("prerenderingchange",p,true),t((()=>{setTimeout((()=>{u=m();}));}));}return {get firstHiddenTime(){return u},onHidden(e){l.add(e);}}},g=e=>{document.prerendering?addEventListener("prerenderingchange",(()=>e()),true):e();},y=[1800,3e3],E=(e,s={})=>{g((()=>{const c=v();let a,d=r("FCP");const f=h("paint",(e=>{for(const t of e)"first-contentful-paint"===t.name&&(f.disconnect(),t.startTime<c.firstHiddenTime&&(d.value=Math.max(t.startTime-o(),0),d.entries.push(t),a(true)));}));f&&(a=n(e,d,y,s.reportAllChanges),t((t=>{d=r("FCP"),a=n(e,d,y,s.reportAllChanges),i((()=>{d.value=performance.now()-t.timeStamp,a(true);}));})));}));},b=[.1,.25],L=(e,s={})=>{const o=v();E(f((()=>{let c,f=r("CLS",0);const u=a(s,d),l=e=>{for(const t of e)u.h(t);u.i>f.value&&(f.value=u.i,f.entries=u.o,c());},m=h("layout-shift",l);m&&(c=n(e,f,b,s.reportAllChanges),o.onHidden((()=>{l(m.takeRecords()),c(true);})),t((()=>{u.i=0,f=r("CLS",0),c=n(e,f,b,s.reportAllChanges),i((()=>c()));})),setTimeout(c));})));};let P=0,T=1/0,_=0;const M=e=>{for(const t of e)t.interactionId&&(T=Math.min(T,t.interactionId),_=Math.max(_,t.interactionId),P=_?(_-T)/7+1:0);};let w;const C=()=>w?P:performance.interactionCount??0,I=()=>{"interactionCount"in performance||w||(w=h("event",M,{type:"event",buffered:true,durationThreshold:0}));};let F=0;class k{u=[];l=new Map;m;p;v(){F=C(),this.u.length=0,this.l.clear();}L(){const e=Math.min(this.u.length-1,Math.floor((C()-F)/50));return this.u[e]}h(e){if(this.m?.(e),!e.interactionId&&"first-input"!==e.entryType)return;const t=this.u.at(-1);let n=this.l.get(e.interactionId);if(n||this.u.length<10||e.duration>t.P){if(n?e.duration>n.P?(n.entries=[e],n.P=e.duration):e.duration===n.P&&e.startTime===n.entries[0].startTime&&n.entries.push(e):(n={id:e.interactionId,entries:[e],P:e.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort(((e,t)=>t.P-e.P)),this.u.length>10){const e=this.u.splice(10);for(const t of e)this.l.delete(t.id);}this.p?.(n);}}}const A=e=>{const t=globalThis.requestIdleCallback||setTimeout;"hidden"===document.visibilityState?e():(e=f(e),addEventListener("visibilitychange",e,{once:true,capture:true}),t((()=>{e(),removeEventListener("visibilitychange",e,{capture:true});})));},B=[200,500],S=(e,i={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;const s=v();g((()=>{I();let o,c=r("INP");const d=a(i,k),f=e=>{A((()=>{for(const t of e)d.h(t);const t=d.L();t&&t.P!==c.value&&(c.value=t.P,c.entries=t.entries,o());}));},u=h("event",f,{durationThreshold:i.durationThreshold??40});o=n(e,c,B,i.reportAllChanges),u&&(u.observe({type:"first-input",buffered:true}),s.onHidden((()=>{f(u.takeRecords()),o(true);})),t((()=>{d.v(),c=r("INP"),o=n(e,c,B,i.reportAllChanges);})));}));};class N{m;h(e){this.m?.(e);}}const q=[2500,4e3],x=(e,s={})=>{g((()=>{const c=v();let d,u=r("LCP");const l=a(s,N),m=e=>{s.reportAllChanges||(e=e.slice(-1));for(const t of e)l.h(t),t.startTime<c.firstHiddenTime&&(u.value=Math.max(t.startTime-o(),0),u.entries=[t],d());},p=h("largest-contentful-paint",m);if(p){d=n(e,u,q,s.reportAllChanges);const o=f((()=>{m(p.takeRecords()),p.disconnect(),d(true);})),c=e=>{e.isTrusted&&(A(o),removeEventListener(e.type,c,{capture:true}));};for(const e of ["keydown","click","visibilitychange"])addEventListener(e,c,{capture:true});t((t=>{u=r("LCP"),d=n(e,u,q,s.reportAllChanges),i((()=>{u.value=performance.now()-t.timeStamp,d(true);}));}));}}));},H=[800,1800],O=e=>{document.prerendering?g((()=>O(e))):"complete"!==document.readyState?addEventListener("load",(()=>O(e)),true):setTimeout(e);},$=(e,i={})=>{let c=r("TTFB"),a=n(e,c,H,i.reportAllChanges);O((()=>{const d=s();d&&(c.value=Math.max(d.responseStart-o(),0),c.entries=[d],a(true),t((()=>{c=r("TTFB",0),a=n(e,c,H,i.reportAllChanges),a(true);})));}));};
6179
+ var e,o=-1,a=function(e){addEventListener("pageshow",(function(n){n.persisted&&(o=n.timeStamp,e(n));}),true);},c=function(){var e=self.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},u=function(){var e=c();return e&&e.activationStart||0},f=function(e,n){var t=c(),r="navigate";o>=0?r="back-forward-cache":t&&(document.prerendering||u()>0?r="prerender":document.wasDiscarded?r="restore":t.type&&(r=t.type.replace(/_/g,"-")));return {name:e,value:void 0===n?-1:n,rating:"good",delta:0,entries:[],id:"v4-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r}},s=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var r=new PerformanceObserver((function(e){Promise.resolve().then((function(){n(e.getEntries());}));}));return r.observe(Object.assign({type:e,buffered:!0},t||{})),r}}catch(e){}},d=function(e,n,t,r){var i,o;return function(a){n.value>=0&&(a||r)&&((o=n.value-(i||0))||void 0===i)&&(i=n.value,n.delta=o,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n));}},l=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}));},p=function(e){document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState&&e();}));},v=function(e){var n=false;return function(){n||(e(),n=true);}},m=-1,h=function(){return "hidden"!==document.visibilityState||document.prerendering?1/0:0},g=function(e){"hidden"===document.visibilityState&&m>-1&&(m="visibilitychange"===e.type?e.timeStamp:0,T());},y=function(){addEventListener("visibilitychange",g,true),addEventListener("prerenderingchange",g,true);},T=function(){removeEventListener("visibilitychange",g,true),removeEventListener("prerenderingchange",g,true);},E=function(){return m<0&&(m=h(),y(),a((function(){setTimeout((function(){m=h(),y();}),0);}))),{get firstHiddenTime(){return m}}},C=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),true):e();},b=[1800,3e3],S=function(e,n){n=n||{},C((function(){var t,r=E(),i=f("FCP"),o=s("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(o.disconnect(),e.startTime<r.firstHiddenTime&&(i.value=Math.max(e.startTime-u(),0),i.entries.push(e),t(true)));}));}));o&&(t=d(e,i,b,n.reportAllChanges),a((function(r){i=f("FCP"),t=d(e,i,b,n.reportAllChanges),l((function(){i.value=performance.now()-r.timeStamp,t(true);}));})));}));},L=[.1,.25],w=function(e,n){n=n||{},S(v((function(){var t,r=f("CLS",0),i=0,o=[],c=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=o[0],t=o[o.length-1];i&&e.startTime-t.startTime<1e3&&e.startTime-n.startTime<5e3?(i+=e.value,o.push(e)):(i=e.value,o=[e]);}})),i>r.value&&(r.value=i,r.entries=o,t());},u=s("layout-shift",c);u&&(t=d(e,r,L,n.reportAllChanges),p((function(){c(u.takeRecords()),t(true);})),a((function(){i=0,r=f("CLS",0),t=d(e,r,L,n.reportAllChanges),l((function(){return t()}));})),setTimeout(t,0));})));},A=0,I=1/0,P=0,M=function(e){e.forEach((function(e){e.interactionId&&(I=Math.min(I,e.interactionId),P=Math.max(P,e.interactionId),A=P?(P-I)/7+1:0);}));},k=function(){return e?A:performance.interactionCount||0},F=function(){"interactionCount"in performance||e||(e=s("event",M,{type:"event",buffered:true,durationThreshold:0}));},D=[],x=new Map,R=0,B=function(){var e=Math.min(D.length-1,Math.floor((k()-R)/50));return D[e]},H=[],q=function(e){if(H.forEach((function(n){return n(e)})),e.interactionId||"first-input"===e.entryType){var n=D[D.length-1],t=x.get(e.interactionId);if(t||D.length<10||e.duration>n.latency){if(t)e.duration>t.latency?(t.entries=[e],t.latency=e.duration):e.duration===t.latency&&e.startTime===t.entries[0].startTime&&t.entries.push(e);else {var r={id:e.interactionId,latency:e.duration,entries:[e]};x.set(r.id,r),D.push(r);}D.sort((function(e,n){return n.latency-e.latency})),D.length>10&&D.splice(10).forEach((function(e){return x.delete(e.id)}));}}},O=function(e){var n=self.requestIdleCallback||self.setTimeout,t=-1;return e=v(e),"hidden"===document.visibilityState?e():(t=n(e),p(e)),t},N=[200,500],j=function(e,n){"PerformanceEventTiming"in self&&"interactionId"in PerformanceEventTiming.prototype&&(n=n||{},C((function(){var t;F();var r,i=f("INP"),o=function(e){O((function(){e.forEach(q);var n=B();n&&n.latency!==i.value&&(i.value=n.latency,i.entries=n.entries,r());}));},c=s("event",o,{durationThreshold:null!==(t=n.durationThreshold)&&void 0!==t?t:40});r=d(e,i,N,n.reportAllChanges),c&&(c.observe({type:"first-input",buffered:true}),p((function(){o(c.takeRecords()),r(true);})),a((function(){R=k(),D.length=0,x.clear(),i=f("INP"),r=d(e,i,N,n.reportAllChanges);})));})));},_=[2500,4e3],z={},G=function(e,n){n=n||{},C((function(){var t,r=E(),i=f("LCP"),o=function(e){n.reportAllChanges||(e=e.slice(-1)),e.forEach((function(e){e.startTime<r.firstHiddenTime&&(i.value=Math.max(e.startTime-u(),0),i.entries=[e],t());}));},c=s("largest-contentful-paint",o);if(c){t=d(e,i,_,n.reportAllChanges);var m=v((function(){z[i.id]||(o(c.takeRecords()),c.disconnect(),z[i.id]=true,t(true));}));["keydown","click"].forEach((function(e){addEventListener(e,(function(){return O(m)}),{once:true,capture:true});})),p(m),a((function(r){i=f("LCP"),t=d(e,i,_,n.reportAllChanges),l((function(){i.value=performance.now()-r.timeStamp,z[i.id]=true,t(true);}));}));}}));},J=[800,1800],K=function e(n){document.prerendering?C((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),true):setTimeout(n,0);},Q=function(e,n){n=n||{};var t=f("TTFB"),r=d(e,t,J,n.reportAllChanges);K((function(){var i=c();i&&(t.value=Math.max(i.responseStart-u(),0),t.entries=[i],r(true),a((function(){t=f("TTFB",0),(r=d(e,t,J,n.reportAllChanges))(true);})));}));};
6180
6180
 
6181
6181
  function getPaintBlocks(resources) {
6182
6182
  const paintBlocks = [];
@@ -6309,10 +6309,10 @@ function Timing (app, opts) {
6309
6309
  // onINP(): Chromium
6310
6310
  // onLCP(): Chromium, Firefox
6311
6311
  // onTTFB(): Chromium, Firefox, Safari
6312
- L(onVitalsSignal);
6313
- S(onVitalsSignal);
6314
- x(onVitalsSignal);
6315
- $(onVitalsSignal);
6312
+ w(onVitalsSignal);
6313
+ j(onVitalsSignal);
6314
+ G(onVitalsSignal);
6315
+ Q(onVitalsSignal);
6316
6316
  });
6317
6317
  app.attachStopCallback(function () {
6318
6318
  observer.disconnect();
@@ -7113,9 +7113,7 @@ class NetworkMessage {
7113
7113
  });
7114
7114
  if (!messageInfo)
7115
7115
  return null;
7116
- const gqlHeader = "application/graphql-response";
7117
- const isGraphql = messageInfo.url.includes("/graphql")
7118
- || Object.values(messageInfo.request.headers).some(v => v.includes(gqlHeader));
7116
+ const isGraphql = messageInfo.url.includes("/graphql");
7119
7117
  if (isGraphql && messageInfo.response.body && typeof messageInfo.response.body === 'string') {
7120
7118
  const isError = messageInfo.response.body.includes("errors");
7121
7119
  messageInfo.status = isError ? 400 : 200;
@@ -7421,7 +7419,6 @@ class FetchProxyHandler {
7421
7419
  this.tokenUrlMatcher = tokenUrlMatcher;
7422
7420
  }
7423
7421
  apply(target, _, argsList) {
7424
- var _a;
7425
7422
  const input = argsList[0];
7426
7423
  const init = argsList[1];
7427
7424
  if (!input ||
@@ -7437,31 +7434,6 @@ class FetchProxyHandler {
7437
7434
  }
7438
7435
  const item = new NetworkMessage(this.ignoredHeaders, this.setSessionTokenHeader, this.sanitize);
7439
7436
  this.beforeFetch(item, input, init);
7440
- const signal = (argsList[0] instanceof Request ? argsList[0].signal : undefined) ||
7441
- ((_a = argsList[1]) === null || _a === void 0 ? void 0 : _a.signal);
7442
- // guard to avoid double-send
7443
- let abortedNotified = false;
7444
- const notifyAbort = () => {
7445
- if (abortedNotified)
7446
- return;
7447
- abortedNotified = true;
7448
- item.endTime = performance.now();
7449
- item.duration = item.endTime - (item.startTime || item.endTime);
7450
- item.status = 0;
7451
- item.statusText = "Aborted";
7452
- item.readyState = 0;
7453
- const msg = item.getMessage();
7454
- if (msg)
7455
- this.sendMessage(msg);
7456
- };
7457
- if (signal) {
7458
- if (signal.aborted) {
7459
- notifyAbort();
7460
- }
7461
- else {
7462
- signal.addEventListener("abort", notifyAbort, { once: true });
7463
- }
7464
- }
7465
7437
  this.setSessionTokenHeader((name, value) => {
7466
7438
  if (this.tokenUrlMatcher !== undefined) {
7467
7439
  if (!this.tokenUrlMatcher(item.url)) {
@@ -7490,22 +7462,11 @@ class FetchProxyHandler {
7490
7462
  }
7491
7463
  });
7492
7464
  return target.apply(window, argsList)
7493
- .then(this.afterFetch(item, () => {
7494
- abortedNotified = true;
7495
- }))
7465
+ .then(this.afterFetch(item))
7496
7466
  .catch((e) => {
7467
+ // mock finally
7497
7468
  item.endTime = performance.now();
7498
7469
  item.duration = item.endTime - (item.startTime || item.endTime);
7499
- if (e && e.name === "AbortError") {
7500
- item.status = 0;
7501
- item.statusText = "Aborted";
7502
- item.readyState = 0;
7503
- if (!abortedNotified) {
7504
- const msg = item.getMessage();
7505
- if (msg)
7506
- this.sendMessage(msg);
7507
- }
7508
- }
7509
7470
  throw e;
7510
7471
  });
7511
7472
  }
@@ -7557,10 +7518,8 @@ class FetchProxyHandler {
7557
7518
  item.requestData = genStringBody(init.body);
7558
7519
  }
7559
7520
  }
7560
- afterFetch(item, onResolved) {
7521
+ afterFetch(item) {
7561
7522
  return (resp) => {
7562
- if (onResolved)
7563
- onResolved === null || onResolved === void 0 ? void 0 : onResolved();
7564
7523
  item.endTime = performance.now();
7565
7524
  item.duration = item.endTime - (item.startTime || item.endTime);
7566
7525
  item.status = resp.status;
@@ -7596,15 +7555,7 @@ class FetchProxyHandler {
7596
7555
  }
7597
7556
  })
7598
7557
  .catch((e) => {
7599
- if (e.name === "AbortError") {
7600
- item.status = 0;
7601
- item.statusText = "Aborted";
7602
- item.readyState = 0;
7603
- const msg = item.getMessage();
7604
- if (msg)
7605
- this.sendMessage(msg);
7606
- }
7607
- else {
7558
+ if (e.name !== "AbortError") {
7608
7559
  throw e;
7609
7560
  }
7610
7561
  });
@@ -8705,7 +8656,7 @@ class ConstantProperties {
8705
8656
  user_id: this.user_id,
8706
8657
  distinct_id: this.deviceId,
8707
8658
  sdk_edition: 'web',
8708
- sdk_version: '17.2.3',
8659
+ sdk_version: '17.2.4',
8709
8660
  timezone: getUTCOffsetString(),
8710
8661
  search_engine: this.searchEngine,
8711
8662
  };
@@ -9038,10 +8989,11 @@ class People {
9038
8989
  * Creates batches of events, then sends them at intervals.
9039
8990
  */
9040
8991
  class Batcher {
9041
- constructor(backendUrl, getToken, init) {
8992
+ constructor(backendUrl, getToken, init, standalone) {
9042
8993
  this.backendUrl = backendUrl;
9043
8994
  this.getToken = getToken;
9044
8995
  this.init = init;
8996
+ this.standalone = standalone;
9045
8997
  this.autosendInterval = 5 * 1000;
9046
8998
  this.retryTimeout = 3 * 1000;
9047
8999
  this.retryLimit = 3;
@@ -9051,10 +9003,20 @@ class Batcher {
9051
9003
  [categories.events]: [],
9052
9004
  };
9053
9005
  this.intervalId = null;
9006
+ this.stopped = false;
9007
+ this.paused = false;
9008
+ this.onVisibilityChange = () => {
9009
+ this.paused = document.hidden;
9010
+ };
9054
9011
  }
9055
9012
  getBatches() {
9056
9013
  this.batch[categories.people] = this.dedupePeopleEvents();
9057
- const finalData = { data: this.batch };
9014
+ const finalData = {
9015
+ data: {
9016
+ [categories.people]: [...this.batch[categories.people]],
9017
+ [categories.events]: [...this.batch[categories.events]],
9018
+ },
9019
+ };
9058
9020
  return finalData;
9059
9021
  }
9060
9022
  addEvent(event) {
@@ -9130,6 +9092,9 @@ class Batcher {
9130
9092
  return Array.from(uniqueEventsByType.values());
9131
9093
  }
9132
9094
  sendBatch(batch) {
9095
+ if (this.stopped) {
9096
+ return;
9097
+ }
9133
9098
  const sentBatch = batch;
9134
9099
  let attempts = 0;
9135
9100
  const send = () => {
@@ -9146,8 +9111,21 @@ class Batcher {
9146
9111
  },
9147
9112
  body: JSON.stringify(sentBatch),
9148
9113
  })
9149
- .then((response) => {
9150
- if ([403, 401].includes(response.status)) {
9114
+ .then(async (response) => {
9115
+ if (response.status === 401) {
9116
+ const body = await response.json().catch(() => null);
9117
+ if (!this.standalone && body?.error === 'token expired') {
9118
+ this.stop();
9119
+ return;
9120
+ }
9121
+ if (attempts < this.retryLimit) {
9122
+ return this.init().then(() => {
9123
+ send();
9124
+ });
9125
+ }
9126
+ return;
9127
+ }
9128
+ if (response.status === 403) {
9151
9129
  if (attempts < this.retryLimit) {
9152
9130
  return this.init().then(() => {
9153
9131
  send();
@@ -9171,8 +9149,12 @@ class Batcher {
9171
9149
  if (this.intervalId) {
9172
9150
  clearInterval(this.intervalId);
9173
9151
  }
9152
+ this.paused = document.hidden;
9153
+ document.addEventListener('visibilitychange', this.onVisibilityChange);
9174
9154
  this.intervalId = setInterval(() => {
9175
- this.flush();
9155
+ if (!this.paused) {
9156
+ this.flush();
9157
+ }
9176
9158
  }, this.autosendInterval);
9177
9159
  }
9178
9160
  flush() {
@@ -9192,6 +9174,12 @@ class Batcher {
9192
9174
  clearInterval(this.intervalId);
9193
9175
  this.intervalId = null;
9194
9176
  }
9177
+ document.removeEventListener('visibilitychange', this.onVisibilityChange);
9178
+ this.stopped = true;
9179
+ }
9180
+ restart() {
9181
+ this.stopped = false;
9182
+ this.startAutosend();
9195
9183
  }
9196
9184
  }
9197
9185
 
@@ -9258,6 +9246,19 @@ class Analytics {
9258
9246
  }
9259
9247
  }
9260
9248
  };
9249
+ /**
9250
+ * Used by tracker when running in blundled mode
9251
+ */
9252
+ this.onStart = () => {
9253
+ if (!this.standalone) {
9254
+ this.batcher.restart();
9255
+ }
9256
+ };
9257
+ this.onStop = () => {
9258
+ if (!this.standalone) {
9259
+ this.batcher.stop();
9260
+ }
9261
+ };
9261
9262
  this.reset = () => {
9262
9263
  this.people.reset(true);
9263
9264
  this.events.reset();
@@ -9296,7 +9297,7 @@ class Analytics {
9296
9297
  this.standalone = !options.notStandalone;
9297
9298
  this.token = this.sessionStorage.getItem(STORAGEKEY);
9298
9299
  this.constantProperties = new ConstantProperties(this.localStorage, this.sessionStorage);
9299
- this.batcher = new Batcher(this.backendUrl, this._getToken, this.init);
9300
+ this.batcher = new Batcher(this.backendUrl, this._getToken, this.init, this.standalone);
9300
9301
  this.events = new Events(this.constantProperties, this._getTimestamp, this.batcher);
9301
9302
  this.people = new People(this.constantProperties, this._getTimestamp, this.setUserId, this.batcher);
9302
9303
  if (options.notStandalone) {
@@ -9357,7 +9358,7 @@ class API {
9357
9358
  this.signalStartIssue = (reason, missingApi) => {
9358
9359
  const doNotTrack = this.checkDoNotTrack();
9359
9360
  console.log("Tracker couldn't start due to:", JSON.stringify({
9360
- trackerVersion: '17.2.3',
9361
+ trackerVersion: '17.2.4',
9361
9362
  projectKey: this.options.projectKey,
9362
9363
  doNotTrack,
9363
9364
  reason: missingApi.length ? `missing api: ${missingApi.join(',')}` : reason,
@@ -9509,6 +9510,12 @@ class API {
9509
9510
  : (options.analytics?.ingestPoint ?? options.ingestPoint ?? defaultEdp),
9510
9511
  projectKey: options.projectKey,
9511
9512
  });
9513
+ app.attachStartCallback(() => {
9514
+ this.analytics?.onStart();
9515
+ });
9516
+ app.attachStopCallback(() => {
9517
+ this.analytics?.onStop();
9518
+ });
9512
9519
  }
9513
9520
  if (!this.crossdomainMode) {
9514
9521
  // no need to send iframe viewport data since its a node for us