diff --git a/modules/CountlyClass.js b/modules/CountlyClass.js index 5820a88..64bf65c 100644 --- a/modules/CountlyClass.js +++ b/modules/CountlyClass.js @@ -191,6 +191,8 @@ class CountlyClass { log(logLevelEnums.DEBUG, "initialize, No device ID type info from the previous session, falling back to DEVELOPER_SUPPLIED, for event flushing"); deviceIdType = DeviceIdTypeInternalEnums.DEVELOPER_SUPPLIED; } + // process async queue before sending events + processAsyncQueue(); sendEventsForced(); // set them back to their initial values this.device_id = undefined; @@ -1002,6 +1004,8 @@ class CountlyClass { // eslint-disable-next-line eqeqeq if (this.device_id != newId) { if (!merge) { + // process async queue before sending events + processAsyncQueue(); // empty event queue sendEventsForced(); // end current session @@ -1254,7 +1258,10 @@ class CountlyClass { this.user_details = function (user) { log(logLevelEnums.INFO, "user_details, Trying to add user details: ", user); if (this.check_consent(featureEnums.USERS)) { - sendEventsForced(); // flush events to event queue to prevent a drill issue + // process async queue before sending events + processAsyncQueue(); + // flush events to event queue to prevent a drill issue + sendEventsForced(); log(logLevelEnums.INFO, "user_details, flushed the event queue"); // truncating user values and custom object key value pairs user.name = truncateSingleValue(user.name, self.maxValueSize, "user_details", log); @@ -1457,7 +1464,10 @@ class CountlyClass { save: function () { log(logLevelEnums.INFO, "[userData] save, Saving changes to user's custom property"); if (self.check_consent(featureEnums.USERS)) { - sendEventsForced(); // flush events to event queue to prevent a drill issue + // process async queue before sending events + processAsyncQueue(); + // flush events to event queue to prevent a drill issue + sendEventsForced(); log(logLevelEnums.INFO, "user_details, flushed the event queue"); toRequestQueue({ user_details: JSON.stringify({ custom: customData }) }); } @@ -1808,6 +1818,8 @@ class CountlyClass { this.start_time(); // end session on unload add_event_listener(window, "beforeunload", function () { + // process async queue before sending events + processAsyncQueue(); // empty the event queue sendEventsForced(); self.end_session(); @@ -3452,7 +3464,6 @@ class CountlyClass { * Check and send the events to request queue if there are any, empty the event queue */ function sendEventsForced() { - processAsyncQueue(); // process async queue before sending events if (eventQueue.length > 0) { log(logLevelEnums.DEBUG, "Flushing events"); toRequestQueue({ events: JSON.stringify(eventQueue) });