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

feat: callback when session id changes #725

Merged
merged 4 commits into from
Jul 7, 2023

Conversation

pauldambra
Copy link
Member

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

@pauldambra pauldambra added the bump minor Bump minor version when this PR gets merged label Jul 7, 2023
@github-actions
Copy link

github-actions bot commented Jul 7, 2023

Size Change: +2.14 kB (0%)

Total Size: 664 kB

Filename Size Change
dist/array.full.js 172 kB +535 B (0%)
dist/array.js 113 kB +535 B (0%)
dist/es.js 113 kB +535 B (0%)
dist/module.js 113 kB +535 B (0%)
ℹ️ View Unchanged
Filename Size
dist/recorder-v2.js 93.6 kB
dist/recorder.js 58.3 kB

compressed-size-action

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) {
Copy link
Collaborator

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's way nicer 💖

src/posthog-core.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@neilkakkar neilkakkar left a comment

Choose a reason for hiding this comment

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

🚀

@pauldambra pauldambra merged commit 0d112d8 into master Jul 7, 2023
11 checks passed
@pauldambra pauldambra deleted the feat/callback-when-session-id-changes branch July 7, 2023 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants