@@ -61,17 +61,17 @@ export class IntegrationManager {
6161 if ( integration . setup ) {
6262 this . integration . setup ( this . config , this . client ) . then (
6363 ( ) => {
64- this . queue . tracker = this . integration . track . bind ( integration ) ;
64+ this . queue . setTracker ( this . integration . track . bind ( integration ) ) ;
6565 this . resolve ( ) ;
6666 } ,
6767 ( e ) => {
6868 console . error ( 'Integration setup failed.' , e ) ;
69- this . queue . tracker = this . integration . track . bind ( integration ) ;
69+ this . queue . setTracker ( this . integration . track . bind ( integration ) ) ;
7070 this . resolve ( ) ;
7171 } ,
7272 ) ;
7373 } else {
74- this . queue . tracker = this . integration . track . bind ( integration ) ;
74+ this . queue . setTracker ( this . integration . track . bind ( integration ) ) ;
7575 this . resolve ( ) ;
7676 }
7777 }
@@ -170,20 +170,11 @@ export class PersistentTrackingQueue {
170170 private readonly maxQueueSize : number ;
171171 private readonly isLocalStorageAvailable = isLocalStorageAvailable ( ) ;
172172 private inMemoryQueue : ExperimentEvent [ ] = [ ] ;
173- private poller : any | undefined ;
174-
175- tracker : ( ( event : ExperimentEvent ) => boolean ) | undefined ;
173+ private tracker : ( ( event : ExperimentEvent ) => boolean ) | undefined ;
176174
177175 constructor ( instanceName : string , maxQueueSize : number = MAX_QUEUE_SIZE ) {
178176 this . storageKey = `EXP_unsent_${ instanceName } ` ;
179177 this . maxQueueSize = maxQueueSize ;
180- this . loadQueue ( ) ;
181- if ( this . inMemoryQueue . length > 0 ) {
182- this . poller = safeGlobal . setInterval ( ( ) => {
183- this . loadFlushStore ( ) ;
184- } , 1000 ) ;
185- }
186- this . loadFlushStore ( ) ;
187178 }
188179
189180 push ( event : ExperimentEvent ) : void {
@@ -193,17 +184,18 @@ export class PersistentTrackingQueue {
193184 this . storeQueue ( ) ;
194185 }
195186
187+ setTracker ( tracker : ( event : ExperimentEvent ) => boolean ) : void {
188+ this . tracker = tracker ;
189+ this . loadFlushStore ( ) ;
190+ }
191+
196192 private flush ( ) : void {
197193 if ( ! this . tracker ) return ;
198194 if ( this . inMemoryQueue . length === 0 ) return ;
199195 for ( const event of this . inMemoryQueue ) {
200196 if ( ! this . tracker ( event ) ) return ;
201197 }
202198 this . inMemoryQueue = [ ] ;
203- if ( this . poller ) {
204- safeGlobal . clearInterval ( this . poller ) ;
205- this . poller = undefined ;
206- }
207199 }
208200
209201 private loadQueue ( ) : void {
0 commit comments