posthog
posthog copied to clipboard
Add `$session_id` to all client libraries
Is your feature request related to a problem?
For the session analysis features to work, events need to be sent with a $session_id
property. Right now, this property is only sent from posthog-js
, but is should be added to the libraries for:
- iOS
- Android
- React Native
- Flutter
- Posthog-js lite?
Describe the solution you'd like
- Every event sent from these clients should have a
$session_id
property as a uuid on it. - The same
$session_id
should be appended to all events until there's a 30 minute gap in activity. At which point, the$session_id
should rotate - The 30 minute gap used above should be configurable. The name should be close to
session_expiration_time_seconds
(accounting for platform naming conventions) - A function should be exposed that resets the session_id (and expiration timer). On posthog-js, this is done with
posthog.sessionManager.resetSessionId()
- [Added after discussion below] The
$session_id
should persist across app restarts (meaning, not stored in memory)
Additional context
Thank you for your feature request – we love each and every one!
Sounds straight forward enough. Is this meant to be a purely in-memory thing or should it persist between session "pauses" (like backgrounding an app for example)?
Also wondering if it makes sense to create an client-library document that covers implementation details like this so that we always have a point of reference?
Is this meant to be a purely in-memory thing or should it persist between session "pauses" (like backgrounding an app for example)?
Great question, it should persist between backgrounding the app etc, so not memory. On browsers we use LocalStorage
for it.
Also wondering if it makes sense to create a client-library document that covers implementation details like this so that we always have a point of reference?
Makes a ton of sense to me. There are a bunch of details around "how do feature flags cache" or "what is reset when you call .reset()
" that would be great to have spec'd out. Wondering where the best place for it would be? Maybe here in posthog.com or in the meta repo?
Implemented as part of this: https://github.com/PostHog/posthog-js-lite/pull/4
Can probably be closed? Android, iOS, RN, and Flutter have this already.