@@ -116,24 +116,25 @@ class EventRepository implements IEventRepository {
116
116
} ) ;
117
117
118
118
const bufferEventsBeforeConsent = shouldBufferEventsForPreConsent ( state ) ;
119
+ if ( ! bufferEventsBeforeConsent ) {
120
+ this . startDpEventsQueue ( ) ;
121
+ }
122
+ }
123
+
124
+ private startDpEventsQueue ( ) {
125
+ const bufferEventsUntilReady = state . loadOptions . value
126
+ . bufferDataPlaneEventsUntilReady as boolean ;
127
+ const hybridDestExist = state . nativeDestinations . activeDestinations . value . some (
128
+ ( dest : Destination ) => isHybridModeDestination ( dest ) ,
129
+ ) ;
130
+ const shouldBufferDpEvents = bufferEventsUntilReady && hybridDestExist ;
119
131
120
- // Start the queue processing only when the destinations are ready or hybrid mode destinations exist
121
- // However, events will be enqueued for now.
122
- // At the time of processing the events, the integrations config data from destinations
123
- // is merged into the event object
124
132
let timeoutId : number ;
133
+ // Start the queue when no event buffering is required
134
+ // or when the client destinations are ready
125
135
effect ( ( ) => {
126
- const shouldBufferDpEvents =
127
- state . loadOptions . value . bufferDataPlaneEventsUntilReady === true &&
128
- state . nativeDestinations . clientDestinationsReady . value === false ;
129
-
130
- const hybridDestExist = state . nativeDestinations . activeDestinations . value . some (
131
- ( dest : Destination ) => isHybridModeDestination ( dest ) ,
132
- ) ;
133
-
134
136
if (
135
- ( hybridDestExist === false || shouldBufferDpEvents === false ) &&
136
- ! bufferEventsBeforeConsent &&
137
+ ( ! shouldBufferDpEvents || state . nativeDestinations . clientDestinationsReady . value ) &&
137
138
this . dataplaneEventsQueue ?. scheduleTimeoutActive !== true
138
139
) {
139
140
( globalThis as typeof window ) . clearTimeout ( timeoutId ) ;
@@ -142,7 +143,7 @@ class EventRepository implements IEventRepository {
142
143
} ) ;
143
144
144
145
// Force start the data plane events queue processing after a timeout
145
- if ( state . loadOptions . value . bufferDataPlaneEventsUntilReady === true ) {
146
+ if ( shouldBufferDpEvents ) {
146
147
timeoutId = ( globalThis as typeof window ) . setTimeout ( ( ) => {
147
148
if ( this . dataplaneEventsQueue ?. scheduleTimeoutActive !== true ) {
148
149
this . dataplaneEventsQueue ?. start ( ) ;
@@ -152,14 +153,15 @@ class EventRepository implements IEventRepository {
152
153
}
153
154
154
155
resume ( ) {
155
- if ( this . dataplaneEventsQueue ?. scheduleTimeoutActive !== true ) {
156
- if ( state . consents . postConsent . value . discardPreConsentEvents ) {
157
- this . dataplaneEventsQueue ?. clear ( ) ;
158
- this . destinationsEventsQueue ?. clear ( ) ;
159
- }
160
-
161
- this . dataplaneEventsQueue ?. start ( ) ;
156
+ if (
157
+ this . dataplaneEventsQueue ?. scheduleTimeoutActive !== true &&
158
+ state . consents . postConsent . value . discardPreConsentEvents
159
+ ) {
160
+ this . dataplaneEventsQueue ?. clear ( ) ;
161
+ this . destinationsEventsQueue ?. clear ( ) ;
162
162
}
163
+
164
+ this . startDpEventsQueue ( ) ;
163
165
}
164
166
165
167
/**
0 commit comments