-
Notifications
You must be signed in to change notification settings - Fork 93
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
Add an option to continue previously persisted session when the app restarts rather than starting a new one #912
base: release/6.1.0
Are you sure you want to change the base?
Conversation
…he app restarts rather than starting a new one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -65,18 +70,28 @@ public class SessionConfiguration: SerializableConfiguration, SessionConfigurati | |||
/// The timeout set for the inactivity of app when in background. | |||
@objc | |||
public var backgroundTimeoutInSeconds: Int { | |||
get { return _backgroundTimeoutInSeconds ?? sourceConfig?.backgroundTimeoutInSeconds ?? 1800 } | |||
get { return _backgroundTimeoutInSeconds ?? sourceConfig?.backgroundTimeoutInSeconds ?? TrackerDefaults.backgroundTimeout } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good spot
/// If enabled, will be able to continue the previous session when the app is closed and reopened (if it doesn't timeout). | ||
/// Disabled by default, which means that every restart of the app starts a new session. | ||
/// When enabled, every event will result in the session being updated in the UserDefaults. | ||
@objc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this builder method have @objc
annotation but the one above (onSessionStateUpdate()
) doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I think we missed the @objc
annotation on the onSessionStateUpdate
builder function! Will add it here.
@@ -127,25 +134,27 @@ class Session { | |||
/// - firstEventTimestamp: Device created timestamp of the first event of the session | |||
/// - userAnonymisation: Whether to anonymise user identifiers | |||
/// - Returns: a SnowplowPayload containing the session dictionary | |||
func getDictWithEventId(_ eventId: String?, eventTimestamp: Int64, userAnonymisation: Bool) -> [String : Any]? { | |||
func getAndUpdateSessionForEvent(_ eventId: String?, eventTimestamp: Int64, userAnonymisation: Bool) -> [String : Any]? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much better name!
… in SessionConfiguration
Adds an option to continue the previously persisted session when the app restarts.
The default behaviour is to always start a new session when a new tracker is created (i.e., when the app restarts) regardless of whether the previous one timed out or not.
With the option enabled, every session update is persisted to the UserDefaults storage. This includes the current event index in the session and a timestamp of the last update of the session. In case it's disabled, only session changes are persisted to UserDefaults.
The option can be configured using
SessionConfiguration
: