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

Add an option to continue previously persisted session when the app restarts rather than starting a new one #912

Open
wants to merge 2 commits into
base: release/6.1.0
Choose a base branch
from

Conversation

matus-tomlein
Copy link
Contributor

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:

        let sessionConfig = SessionConfiguration()
            .continueSessionOnRestart(true)

…he app restarts rather than starting a new one
@mscwilson mscwilson changed the base branch from master to release/6.1.0 December 16, 2024 10:29
Copy link
Contributor

@mscwilson mscwilson left a 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 }
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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]? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much better name!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants