Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update lastActiveTimestamp value when reset call is made #412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[builder withRecordScreenViews:YES];
[builder withDataPlaneUrl:rudderConfig.DEV_DATA_PLANE_URL];
[builder withControlPlaneUrl:rudderConfig.DEV_CONTROL_PLANE_URL];
[builder withSleepTimeOut:3000];
[builder withDBEncryption:[[RSDBEncryption alloc] initWithKey:@"test1234" enable:NO databaseProvider:[EncryptedDatabaseProvider new]]];
[RSClient getInstance:rudderConfig.WRITE_KEY config:[builder build]];
}
Expand Down
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PODS:
- RSCrashReporter (= 1.0.0)
- RudderKit (= 1.4.0)
- RSCrashReporter (1.0.0)
- Rudder (1.20.0):
- Rudder (1.23.0):
- MetricsReporter (= 1.1.1)
- RudderKit (1.4.0)
- SQLCipher (4.5.4):
Expand Down Expand Up @@ -33,10 +33,10 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
MetricsReporter: d4265e0ac833e2c0078bbe044b3f9dbe29f53a48
RSCrashReporter: 7e26b51ac816e967acb58fa458040946a93a9e65
Rudder: d9e8730c891325da05ac4c454db09bc449d3b9ff
Rudder: 125d9dc03e178b35b0f74487aa694afe1a8e6f4f
RudderKit: d9d6997696e1642b753d8bdf94e57af643a68f03
SQLCipher: 905b145f65f349f26da9e60a19901ad24adcd381

PODFILE CHECKSUM: b6937cee06e0633464427ff0d975d40e17419e9f

COCOAPODS: 1.13.0
COCOAPODS: 1.11.3
8 changes: 4 additions & 4 deletions Sources/Classes/Headers/Public/RSPreferenceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern NSString *const RSOptStatus;
extern NSString *const RSOptInTimeKey;
extern NSString *const RSOptOutTimeKey;
extern NSString *const RSSessionIdKey;
extern NSString *const RSLastEventTimeStamp;
extern NSString *const RSLastActiveTimestamp;
extern NSString *const RSSessionAutoTrackStatus;

+ (instancetype) getInstance;
Expand Down Expand Up @@ -73,9 +73,9 @@ extern NSString *const RSSessionAutoTrackStatus;
- (NSNumber * __nullable) getSessionId;
- (void) clearSessionId;

- (void) saveLastEventTimeStamp: (NSNumber *) lastEventTimeStamp;
- (NSNumber * __nullable) getLastEventTimeStamp;
- (void) clearLastEventTimeStamp;
- (void) saveLastActiveTimestamp: (NSNumber *) lastActiveTimestamp;
- (NSNumber * __nullable) getLastActiveTimestamp;
- (void) clearLastActiveTimestamp;

- (void) saveAutoTrackingStatus: (BOOL) autoTrackingStatus;
- (BOOL) getAutoTrackingStatus;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Classes/Headers/Public/RSUserSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
long sessionInActivityTimeOut;
NSNumber *sessionId;
BOOL sessionStart;
NSNumber *lastEventTimeStamp;
NSNumber *lastActiveTimestamp;
RSPreferenceManager* preferenceManager;
}

Expand All @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)startSessionIfExpired;
- (void)refreshSession;
- (void)clearSession;
- (void)updateLastEventTimeStamp;
- (void)updateLastActiveTimestamp;
- (NSNumber * __nullable)getSessionId;
- (BOOL)getSessionStart;

Expand Down
5 changes: 4 additions & 1 deletion Sources/Classes/RSEventRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,17 @@ - (void)applySession:(RSMessage *)message withUserSession:(RSUserSession *)_user
[message setSessionData: _userSession];
}
if(rudderConfig.trackLifecycleEvents && rudderConfig.automaticSessionTracking) {
[_userSession updateLastEventTimeStamp];
[_userSession updateLastActiveTimestamp];
}
}

-(void) reset {
if([self->userSession getSessionId] != nil) {
[RSLogger logDebug: @"EventRepository: reset: Refreshing the session as the reset is triggered"];
[self->userSession refreshSession];
if(self->config.trackLifecycleEvents && self->config.automaticSessionTracking) {
[self->userSession updateLastActiveTimestamp];
}
}

[RSLogger logDebug: @"EventRepository: reset: clearing the CTS Auth token as the reset is triggered"];
Expand Down
18 changes: 9 additions & 9 deletions Sources/Classes/RSPreferenceManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ @implementation RSPreferenceManager
NSString *const RSOptInTimeKey = @"rl_opt_in_time";
NSString *const RSOptOutTimeKey = @"rl_opt_out_time";
NSString *const RSSessionIdKey = @"rl_session_id";
NSString *const RSLastEventTimeStamp = @"rl_last_event_time_stamp";
NSString *const RSLastActiveTimestamp = @"rl_last_event_time_stamp";
NSString *const RSSessionAutoTrackStatus = @"rl_session_auto_track_status";
NSString *const RSEventDeletionStatus = @"rl_event_deletion_status";

Expand Down Expand Up @@ -238,21 +238,21 @@ - (void) clearSessionId {
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (void) saveLastEventTimeStamp:(NSNumber *) lastEventTimeStamp {
[[NSUserDefaults standardUserDefaults] setValue:lastEventTimeStamp forKey:RSLastEventTimeStamp];
- (void) saveLastActiveTimestamp:(NSNumber *) lastActiveTimestamp {
[[NSUserDefaults standardUserDefaults] setValue:lastActiveTimestamp forKey:RSLastActiveTimestamp];
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSNumber * __nullable) getLastEventTimeStamp {
NSNumber *lastEventTimeStamp = [[NSUserDefaults standardUserDefaults] valueForKey:RSLastEventTimeStamp];
if(lastEventTimeStamp == nil) {
- (NSNumber * __nullable) getLastActiveTimestamp {
NSNumber *lastActiveTimestamp = [[NSUserDefaults standardUserDefaults] valueForKey:RSLastActiveTimestamp];
if(lastActiveTimestamp == nil) {
return nil;
}
return lastEventTimeStamp;
return lastActiveTimestamp;
}

- (void) clearLastEventTimeStamp {
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:RSLastEventTimeStamp];
- (void) clearLastActiveTimestamp {
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:RSLastActiveTimestamp];
[[NSUserDefaults standardUserDefaults] synchronize];
}

Expand Down
16 changes: 8 additions & 8 deletions Sources/Classes/RSUserSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (instancetype) init:(long)sessionInActivityTimeOut with:(RSPreferenceManager *
self->sessionInActivityTimeOut = sessionInActivityTimeOut;
self->preferenceManager = preferenceManager;
self->sessionId = [self->preferenceManager getSessionId];
self->lastEventTimeStamp = [self->preferenceManager getLastEventTimeStamp];
self->lastActiveTimestamp = [self->preferenceManager getLastActiveTimestamp];
}
return self;
}
Expand Down Expand Up @@ -61,11 +61,11 @@ - (void) startSessionIfExpired {
}

- (BOOL) isSessionExpired {
if(self->lastEventTimeStamp == nil)
if(self->lastActiveTimestamp == nil)
return YES;
__block NSTimeInterval timeDifference;
dispatch_sync(queue, ^{
timeDifference = labs([RSUtils getTimeStampLong] - [self->lastEventTimeStamp longValue]);
timeDifference = labs([RSUtils getTimeStampLong] - [self->lastActiveTimestamp longValue]);
});
if (timeDifference > (self->sessionInActivityTimeOut / 1000)) {
return YES;
Expand All @@ -83,9 +83,9 @@ - (void) clearSession {
dispatch_sync(queue, ^{
self->sessionId = nil;
self->sessionStart = NO;
self->lastEventTimeStamp = nil;
self->lastActiveTimestamp = nil;
[self->preferenceManager clearSessionId];
[self->preferenceManager clearLastEventTimeStamp];
[self->preferenceManager clearLastActiveTimestamp];
});
}

Expand Down Expand Up @@ -113,10 +113,10 @@ - (void) setSessionStart:(BOOL)sessionStart {
});
}

- (void) updateLastEventTimeStamp {
- (void) updateLastActiveTimestamp {
dispatch_sync(queue, ^{
self->lastEventTimeStamp = [[NSNumber alloc] initWithLong:[RSUtils getTimeStampLong]];
[self->preferenceManager saveLastEventTimeStamp:lastEventTimeStamp];
self->lastActiveTimestamp = [[NSNumber alloc] initWithLong:[RSUtils getTimeStampLong]];
[self->preferenceManager saveLastActiveTimestamp:lastActiveTimestamp];
});
}
@end
2 changes: 1 addition & 1 deletion Tests/ContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ContextTests: XCTestCase {
preferenceManager.clearTraits()
preferenceManager.clearExternalIds()
preferenceManager.clearSessionId()
preferenceManager.clearLastEventTimeStamp()
preferenceManager.clearLastActiveTimestamp()
preferenceManager.saveAnonymousId("testAnonymousId")
context = RSContext(config: RSConfig())
testUtils = TestUtils()
Expand Down
Loading