Skip to content

Commit

Permalink
fix: rotate session id when reset is called (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Aug 29, 2024
1 parent 341bedf commit 26038a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Next

- recording: expose session id ([#166](https://github.com/PostHog/posthog-android/pull/166))
- fix: rotate session id when reset is called ([#168](https://github.com/PostHog/posthog-android/pull/168))
- feat: add `$is_identified` property ([#167](https://github.com/PostHog/posthog-android/pull/167))
- fix: identify should not allow already identified users ([#167](https://github.com/PostHog/posthog-android/pull/167))

Expand Down
1 change: 1 addition & 0 deletions posthog/src/main/java/com/posthog/PostHog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ public class PostHog private constructor(
}

endSession()
startSession()
}

private fun isEnabled(): Boolean {
Expand Down
10 changes: 7 additions & 3 deletions posthog/src/test/java/com/posthog/PostHogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ internal class PostHogTest {
}

@Test
fun `does not set session id when reset is called`() {
fun `reset session id when reset is called`() {
val http = mockHttp()
val url = http.url("/")

Expand All @@ -1069,7 +1069,8 @@ internal class PostHogTest {
var batch = serializer.deserialize<PostHogBatchEvent>(content.reader())

var theEvent = batch.batch.first()
assertNotNull(theEvent.properties!!["\$session_id"])
val currentSessionId = theEvent.properties!!["\$session_id"]
assertNotNull(currentSessionId)

sut.reset()

Expand All @@ -1091,7 +1092,10 @@ internal class PostHogTest {
batch = serializer.deserialize<PostHogBatchEvent>(content.reader())

theEvent = batch.batch.first()
assertNull(theEvent.properties!!["\$session_id"])
val newSessionId = theEvent.properties!!["\$session_id"]
assertNotNull(newSessionId)

assertTrue(currentSessionId != newSessionId)

sut.close()
}
Expand Down

0 comments on commit 26038a4

Please sign in to comment.