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

Feature/189/session replay min duration #199

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

karntrehan
Copy link

💡 Motivation and Context

#189

💚 How did you test it?

WIP

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

@karntrehan karntrehan marked this pull request as draft October 17, 2024 08:12
@karntrehan
Copy link
Author

@marandaneto could you please review the implementation? Thanks! Would then go ahead with the test cases.

@karntrehan karntrehan marked this pull request as ready for review October 21, 2024 05:42
@karntrehan
Copy link
Author

Hie @marandaneto just following up on this PR.

@marandaneto
Copy link
Member

Hie @marandaneto just following up on this PR.

Sorry i am on pto this week so a bit slow to review, maybe @ioannisj or @pauldambra can take a look for now? Otherwise i will have a look within the next couple days

@karntrehan
Copy link
Author

No problem. Take your time @marandaneto. Also, please feel free to mention me in other issues that you think I can contribute to. I have kept some time aside to make the hog hoggier!

@@ -118,6 +119,15 @@ public class PostHogReplayIntegration(
private val isSessionReplayEnabled: Boolean
get() = PostHog.isSessionReplayActive()

private var sessionStartTime = 0L
private val events = mutableListOf<RREvent>()
private var minSessionThresholdCrossed = false
Copy link
Member

Choose a reason for hiding this comment

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

This flag has to be cached per session id, so ideally this is part of ViewTreeSnapshotStatus I think, or it has to be reset when the session_id changes as well.

Copy link
Author

Choose a reason for hiding this comment

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

This is not very clear to me. What we are doing here is setting the threshold once for 1 launch session of the user.

The behavior we have currently is: User launches the app, we start caching events & wait for the minimum threshold, if the user closes the app before the threshold the events are not captured / dropped. Once the threshold is crossed, all cached events are captured immediately and subsequent events are captured right away. Is this the expected behavior?

I am not sure of ViewTreeSnapshotStatus and where the session_id is set / unset. Could you help me with more info on this?

Copy link
Member

Choose a reason for hiding this comment

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

So all this information should be related to a specific sessionId.
Right now the sessionStartTime is gonna be used even if the session rotates, etc.
So we need a way of Map<SessionId, Object> where Object contains the properties (sessionStartTime, events, mouseInteractions, etc...)

Copy link
Member

Choose a reason for hiding this comment

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

An example is that if the app is in the background for more than 30 minutes, the sessionId rotates, and the new session will start once the app is in the background, but we are still using the sessionStartTime from the last session.

Copy link
Author

Choose a reason for hiding this comment

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

Got it. Looking at PostHogSessionManager right now. Thanks!

Comment on lines +856 to +857
//FIXME -> Remove this true hardcoding
return true || config?.sessionReplay == true && featureFlags?.isSessionReplayFlagActive() == true
Copy link
Member

Choose a reason for hiding this comment

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

rollback

@marandaneto marandaneto marked this pull request as draft October 28, 2024 13:12
@marandaneto
Copy link
Member

No problem. Take your time @marandaneto. Also, please feel free to mention me in other issues that you think I can contribute to. I have kept some time aside to make the hog hoggier!

@karntrehan did another pass, let me know if something is unclear, I understand some parts might be tricky

@karntrehan
Copy link
Author

@marandaneto I have made some changes basis your feedback. Please check.

It has helped me understand the code flow better. Thanks!

@marandaneto
Copy link
Member

@marandaneto I have made some changes basis your feedback. Please check.

It has helped me understand the code flow better. Thanks!

Thanks @karntrehan , I am currently on an offsite with my team but will review asap.

@marandaneto
Copy link
Member

PostHogOkHttpInterceptor also has to respect the min session duration.

@marandaneto
Copy link
Member

@karntrehan left a few new comments, a few things to address but it's in the right direction.

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