Skip to content

Commit

Permalink
fix: fixed automatic session not getting cleared on dynamically disab…
Browse files Browse the repository at this point in the history
…ling track life cycle events (#344)

Co-authored-by: Desu Sai Venkat <[email protected]>
Co-authored-by: Abhishek Pandey <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2023
1 parent cbdf123 commit 0b580d9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Sources/Classes/RSEventRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,18 @@ - (instancetype)init:(NSString*)_writeKey config:(RSConfig*)_config client:(RSCl
self->userSession = [RSUserSession initiate:self->config.sessionInActivityTimeOut with: self->preferenceManager];

// clear session if automatic session tracking was enabled previously but disabled presently or vice versa.
BOOL currentAutoTrackingStatus = self->config.automaticSessionTracking && self->config.trackLifecycleEvents;
BOOL previousAutoTrackingStatus = [self->preferenceManager getAutoTrackingStatus];
if(previousAutoTrackingStatus && previousAutoTrackingStatus != config.automaticSessionTracking) {
if(previousAutoTrackingStatus && previousAutoTrackingStatus != currentAutoTrackingStatus) {
[RSLogger logDebug:@"EventRepository: Automatic Session Tracking status has been updated since last launch, hence clearing the session"];
[self->userSession clearSession];
}
[self->preferenceManager saveAutoTrackingStatus:config.automaticSessionTracking];

if(self->config.trackLifecycleEvents && self->config.automaticSessionTracking) {
if(currentAutoTrackingStatus) {
[self->preferenceManager saveAutoTrackingStatus:YES];
[RSLogger logDebug:@"EventRepository: Starting Automatic Sessions"];
[self->userSession startSessionIfExpired];
} else {
[self->preferenceManager saveAutoTrackingStatus:NO];
}

[RSLogger logDebug:@"EventRepository: Initiating RSApplicationLifeCycleManager"];
Expand Down

0 comments on commit 0b580d9

Please sign in to comment.