Skip to content

Commit 04dff63

Browse files
Save Point
1 parent 2209b69 commit 04dff63

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

src/batchUploader.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Batch } from '@mparticle/event-models';
22
import Constants from './constants';
33
import { SDKEvent, MParticleWebSDK, SDKLoggerApi } from './sdkRuntimeModels';
44
import { convertEvents } from './sdkToEventsApiConverter';
5-
import Types from './types';
5+
import { EventType, MessageType } from './types';
66
import { getRampNumber, isEmpty } from './utils';
77
import { SessionStorageVault, LocalStorageVault } from './vault';
88
import {
@@ -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.

src/types.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ export const MessageType = {
2020
UserIdentityChange: 18 as const,
2121
};
2222

23-
// Dictionary that contains MessageTypes that will
24-
// trigger an immediate upload.
25-
export const TriggerUploadType = {
26-
[MessageType.Commerce]: 1 as const,
27-
[MessageType.UserIdentityChange]: 1 as const,
28-
};
29-
3023
export const EventType = {
3124
Unknown: 0 as const,
3225
Navigation: 1 as const,
@@ -393,7 +386,5 @@ export default {
393386
ApplicationTransitionType,
394387
ProductActionType,
395388
PromotionActionType,
396-
TriggerUploadType,
397-
398389
Environment: Constants.Environment,
399390
} as const;

0 commit comments

Comments
 (0)