-
Notifications
You must be signed in to change notification settings - Fork 120
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
feat: callback when session id changes #725
Conversation
Size Change: +2.14 kB (0%) Total Size: 664 kB
ℹ️ View Unchanged
|
src/sessionid.ts
Outdated
@@ -26,6 +28,10 @@ export class SessionIdManager { | |||
this._sessionStartTimestamp = null | |||
this._sessionActivityTimestamp = null | |||
|
|||
if (this.config.on_session_id_changed_fn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional API design idea:
This seems a bit awkward to use to me, since I have to copy all my business logic to posthog at initialisation time, when it might not exist (say, I need to load user data so I can feed these new sessionID values to the backend, bla bla). I also can't change this during the session posthog is initialised.
Another option here is to expose the callback function instead: Whenever the sessionID changes, we call the onSessionIdChanged with whatever has happened. You can remove your callback fns, add new ones, attach in the middle when you're ready to handle, etc. etc.
See onFeatureFlags()
callback for an example of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's way nicer 💖
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Changes
See zendesk ticket https://posthoghelp.zendesk.com/agent/tickets/4038
If someone wants to filter for session recordings using backend events. They can't, because we can only filter for events that have a $session_id property.
We don't care how the event got that property.
Adds an optional callback to config that is called with session id and window id whenever either changes. Some can use this to synchronise the session id to their backend and allow it to enrich events with the session id
Checklist