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: rotate session id when reset is called #168

Merged
merged 3 commits into from
Aug 29, 2024
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
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
Loading