@@ -2,7 +2,7 @@ import { Batch } from '@mparticle/event-models';
22import Constants from './constants' ;
33import { SDKEvent , MParticleWebSDK , SDKLoggerApi } from './sdkRuntimeModels' ;
44import { convertEvents } from './sdkToEventsApiConverter' ;
5- import Types from './types' ;
5+ import { EventType , MessageType } from './types' ;
66import { getRampNumber , isEmpty } from './utils' ;
77import { SessionStorageVault , LocalStorageVault } from './vault' ;
88import {
@@ -167,29 +167,35 @@ export class BatchUploader {
167167 * @param event event that should be queued
168168 */
169169 public queueEvent ( event : SDKEvent ) : void {
170- if ( ! isEmpty ( event ) ) {
171- this . eventsQueuedForProcessing . push ( event ) ;
172- if ( this . offlineStorageEnabled && this . eventVault ) {
173- this . eventVault . store ( this . eventsQueuedForProcessing ) ;
174- }
175- this . mpInstance . Logger . verbose (
176- `Queuing event: ${ JSON . stringify ( event ) } `
177- ) ;
178- this . mpInstance . Logger . verbose (
179- `Queued event count: ${ this . eventsQueuedForProcessing . length } `
180- ) ;
170+ if ( isEmpty ( event ) ) {
171+ return ;
172+ }
181173
182- // TODO: Remove this check once the v2 code path is removed
183- // https://go.mparticle.com/work/SQDSDKS-3720
184- if (
185- ! this . batchingEnabled ||
186- Types . TriggerUploadType [ event . EventDataType ]
187- ) {
188- this . prepareAndUpload ( false , false ) ;
189- }
174+ const { verbose } = this . mpInstance . Logger ;
175+
176+ this . eventsQueuedForProcessing . push ( event ) ;
177+ if ( this . offlineStorageEnabled && this . eventVault ) {
178+ this . eventVault . store ( this . eventsQueuedForProcessing ) ;
179+ }
180+
181+ verbose ( `Queuing event: ${ JSON . stringify ( event ) } ` ) ;
182+ verbose ( `Queued event count: ${ this . eventsQueuedForProcessing . length } ` ) ;
183+
184+ if ( this . shouldTriggerImmediateUpload ( event . EventDataType ) ) {
185+ this . prepareAndUpload ( false , false ) ;
190186 }
191187 }
192188
189+ // https://go.mparticle.com/work/SQDSDKS-3720
190+ private shouldTriggerImmediateUpload ( eventDataType : number ) : boolean {
191+ const priorityEvents = [
192+ MessageType . Commerce ,
193+ MessageType . UserIdentityChange ,
194+ ] as const ;
195+
196+ return ! this . batchingEnabled || priorityEvents . includes ( eventDataType as typeof priorityEvents [ number ] ) ;
197+ } ;
198+
193199 /**
194200 * This implements crucial logic to:
195201 * - bucket pending events by MPID, and then by Session, and upload individual batches for each bucket.
0 commit comments