Skip to content

Commit

Permalink
Merge pull request #705 from snowplow/release/6.2.0
Browse files Browse the repository at this point in the history
Release 6.2.0
  • Loading branch information
matus-tomlein authored Feb 13, 2025
2 parents 5cf2974 + 70ac3c5 commit 8042b4b
Show file tree
Hide file tree
Showing 17 changed files with 278 additions and 108 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 6.2.0 (2025-02-10)
--------------------------
Add an option to continue previously persisted session when the app restarts rather than starting a new one (#340)

Version 6.1.1 (2025-01-22)
--------------------------
Do not autotrack screen view events when app comes to foreground (#701)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.1
6.2.0
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {

subprojects {
group = 'com.snowplowanalytics'
version = '6.1.1'
version = '6.2.0'
repositories {
google()
maven {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ systemProp.org.gradle.internal.http.socketTimeout=120000
SONATYPE_STAGING_PROFILE=comsnowplowanalytics
GROUP=com.snowplowanalytics
POM_ARTIFACT_ID=snowplow-android-tracker
VERSION_NAME=6.1.1
VERSION_NAME=6.2.0

POM_NAME=snowplow-android-tracker
POM_PACKAGING=aar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ class Demo : Activity(), LoggerDelegate {
.installAutotracking(true)
.diagnosticAutotracking(true)
val sessionConfiguration = SessionConfiguration(
TimeMeasure(6, TimeUnit.SECONDS),
TimeMeasure(30, TimeUnit.SECONDS)
TimeMeasure(30, TimeUnit.MINUTES),
TimeMeasure(30, TimeUnit.MINUTES)
)
.continueSessionOnRestart(true)
.onSessionUpdate { state: SessionState ->
updateLogger(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ConfigurationTest {
Assert.assertEquals(protocol, scheme)
Assert.assertEquals(trackerConfiguration.appId, tracker.appId)
Assert.assertEquals("namespace", tracker.namespace)
Assert.assertEquals(tracker.session!!.continueSessionOnRestart, false)
}

@Test
Expand All @@ -83,12 +84,14 @@ class ConfigurationTest {
val networkConfig = NetworkConfiguration("fake-url", HttpMethod.POST)
val trackerConfig = TrackerConfiguration("appId")
val sessionConfig = SessionConfiguration(expectedForeground, expectedBackground)
sessionConfig.continueSessionOnRestart = true
val tracker =
createTracker(context, "namespace", networkConfig, trackerConfig, sessionConfig)
val foreground = tracker.session!!.foregroundTimeout
val background = tracker.session!!.backgroundTimeout
Assert.assertEquals(expectedForeground, foreground)
Assert.assertEquals(expectedBackground, background)
Assert.assertEquals(tracker.session!!.continueSessionOnRestart, true)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ class SessionTest {
Assert.assertEquals(300000, session.backgroundTimeout)
Assert.assertNull(sessionState)
Assert.assertNotNull(session.userId)
val sdj = session.getSessionContext("first-id-1", timestamp, false)
val sdj = session.getAndUpdateSessionForEvent("first-id-1", timestamp, false)
sessionState = session.state

Assert.assertNotNull(sdj)
Assert.assertNotNull(sessionState)
Assert.assertEquals("first-id-1", sessionState!!.firstEventId)
Assert.assertEquals(timestampDateTime, sessionState.firstEventTimestamp)
session.getSessionContext("second-id-2", timestamp + 10000, false)
session.getAndUpdateSessionForEvent("second-id-2", timestamp + 10000, false)
Assert.assertEquals("first-id-1", sessionState.firstEventId)
Assert.assertEquals(timestampDateTime, sessionState.firstEventTimestamp)
Assert.assertEquals(TrackerConstants.SESSION_SCHEMA, sdj!!.map["schema"])
Expand Down Expand Up @@ -342,21 +342,21 @@ class SessionTest {
val tracker2 = Tracker(emitter, "tracker2", "app", context = context, builder = trackerBuilder)
val session1 = tracker1.session
val session2 = tracker2.session
session1!!.getSessionContext("session1-fake-id1", timestamp, false)
session2!!.getSessionContext("session2-fake-id1", timestamp, false)
session1!!.getAndUpdateSessionForEvent("session1-fake-id1", timestamp, false)
session2!!.getAndUpdateSessionForEvent("session2-fake-id1", timestamp, false)
val initialValue1 = session1.sessionIndex?.toLong()
val id1 = session1.state!!.sessionId
val initialValue2 = session2.sessionIndex?.toLong()

// Retrigger session in tracker1
// The timeout is 20s, this sleep is only 2s - it's still the same session
Thread.sleep(2000)
session1.getSessionContext("session1-fake-id2", timestamp, false)
session1.getAndUpdateSessionForEvent("session1-fake-id2", timestamp, false)

// Retrigger timedout session in tracker2
// 20s has then passed. Session must be updated, increasing the sessionIndex by 1
Thread.sleep(18000)
session2.getSessionContext("session2-fake-id2", timestamp, false)
session2.getAndUpdateSessionForEvent("session2-fake-id2", timestamp, false)

// Check sessions have the correct state
Assert.assertEquals(0, session1.sessionIndex!! - initialValue1!!)
Expand All @@ -365,7 +365,7 @@ class SessionTest {

// Recreate tracker2
val tracker2b = Tracker(emitter, "tracker2", "app", context = context, builder = trackerBuilder)
tracker2b.session!!.getSessionContext("session2b-fake-id3", timestamp, false)
tracker2b.session!!.getAndUpdateSessionForEvent("session2b-fake-id3", timestamp, false)
val initialValue2b = tracker2b.session!!.sessionIndex?.toLong()
val previousId2b = tracker2b.session!!.state!!.previousSessionId

Expand All @@ -388,6 +388,47 @@ class SessionTest {
Assert.assertNull(context[Parameters.SESSION_PREVIOUS_ID])
}

@Test
fun testStartsNewSessionOnRestartByDefault() {
val session1 = Session(foregroundTimeout = 3, backgroundTimeout = 3, namespace = "t1", timeUnit = TimeUnit.SECONDS, context = context)
val firstSession = session1.getAndUpdateSessionForEvent("event_1", eventTimestamp = 1654496481345, userAnonymisation = false)

val session2 = Session(foregroundTimeout = 3, backgroundTimeout = 3, namespace = "t1", timeUnit = TimeUnit.SECONDS, context = context)
val secondSession = session2.getAndUpdateSessionForEvent("event_2", eventTimestamp = 1654496481345, userAnonymisation = false)

Assert.assertNotNull(firstSession?.sessionId)
Assert.assertNotEquals(firstSession?.sessionId, secondSession?.sessionId)
Assert.assertEquals(firstSession?.sessionId, secondSession?.previousSessionId)
}

@Test
fun testResumesPreviouslyPersistedSessionIfEnabled() {
val session1 = Session(foregroundTimeout = 3, backgroundTimeout = 3, namespace = "t1", continueSessionOnRestart = true, timeUnit = TimeUnit.SECONDS, context = context)
session1.getAndUpdateSessionForEvent("event_1", eventTimestamp = 1654496481345, userAnonymisation = false)
val firstSession = session1.getAndUpdateSessionForEvent("event_2", eventTimestamp = 1654496481346, userAnonymisation = false)

val session2 = Session(foregroundTimeout = 3, backgroundTimeout = 3, namespace = "t1", continueSessionOnRestart = true, timeUnit = TimeUnit.SECONDS, context = context)
val secondSession = session2.getAndUpdateSessionForEvent("event_3", eventTimestamp = 1654496481347, userAnonymisation = false)

Assert.assertNotNull(firstSession?.sessionId)
Assert.assertEquals(firstSession?.sessionId, secondSession?.sessionId)
Assert.assertEquals(secondSession?.eventIndex, 3)
}

@Test
fun testStartsNewSessionOnRestartOnTimeout() {
val session1 = Session(foregroundTimeout = 100, backgroundTimeout = 100, namespace = "t1", continueSessionOnRestart = true, timeUnit = TimeUnit.MILLISECONDS, context = context)
val firstSession = session1.getAndUpdateSessionForEvent("event_1", eventTimestamp = 1654496481345, userAnonymisation = false)

Thread.sleep(500)

val session2 = Session(foregroundTimeout = 100, backgroundTimeout = 100, namespace = "t1", continueSessionOnRestart = true, timeUnit = TimeUnit.MILLISECONDS, context = context)
val secondSession = session2.getAndUpdateSessionForEvent("event_2", eventTimestamp = 1654496481345, userAnonymisation = false)

Assert.assertNotEquals(firstSession?.sessionId, secondSession?.sessionId)
Assert.assertEquals(firstSession?.sessionId, secondSession?.previousSessionId)
}

// Private methods
private fun getSession(foregroundTimeout: Long, backgroundTimeout: Long): Session {
context.getSharedPreferences(TrackerConstants.SNOWPLOW_SESSION_VARS, Context.MODE_PRIVATE)
Expand All @@ -403,7 +444,7 @@ class SessionTest {
eventTimestamp: Long,
userAnonymisation: Boolean
): Map<String, Any>? {
return session!!.getSessionContext(
return session!!.getAndUpdateSessionForEvent(
eventId,
eventTimestamp,
userAnonymisation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ object Parameters {
const val SESSION_STORAGE = "storageMechanism"
const val SESSION_FIRST_ID = "firstEventId"
const val SESSION_FIRST_TIMESTAMP = "firstEventTimestamp"
const val SESSION_LAST_UPDATE = "lastUpdate"

// Screen Context
const val SCREEN_NAME = "name"
Expand Down
Loading

0 comments on commit 8042b4b

Please sign in to comment.