Skip to content

Commit

Permalink
seperated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
turtledreams committed Jan 29, 2024
1 parent ccf2bfe commit e58624a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions modules/CountlyClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 }) });
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) });
Expand Down

0 comments on commit e58624a

Please sign in to comment.