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 Request: Add a way to be notified when the session id changes #454

Closed
jboulter11 opened this issue Jun 27, 2023 · 2 comments
Closed

Comments

@jboulter11
Copy link

Summary

While there is a very helpful method to get the session id from Amplitude, there is no way to be notified of when it changes. We'd like some way of knowing when the session changes so we can log our own session start events as well as so we can expose a lightweight way of being notified about the changes that do not require linking to the Amplitude SDK directly.

Two example ways of doing this might be:

  1. A public delegate protocol we can adopt to be directly notified about session changes.
protocol AmplitudeSessionIdNotificationDelegate {
    func sessionIdDidChange(oldSessionId: Int64, newSessionId: Int64)
}
  1. An NSNotificationCenter notification we could observe with a frozen (never changing ever) notification name.

I'd specifically like to be notified when the ID changes. I'd expect that the method would be called on every new app boot as well as any time the session id changes when the app's still stood up (not terminated). My names above are only suggestions, obviously feel free to name it what you think makes the most sense.

Motivations

At Dropbox, we're in the process of re-working a lot of our analytics logging. One thing that's missing is that we don't have a good app-wide session ID, we only have what get logged by Amplitude (to which only a subset of our logs are passed). We would like to adopt the Amplitude SDK's session id as our app-wide session id.

In order to do this, we'd want to also attach it to our legacy events and events that might go to other destinations besides where Amplitude sends events, as well as logging our own session start/end events with custom information and naming. The feature would allow us to log those custom session start/end events as well as more easily expose the session id via rx-style observables to other parts of the app without needing to link to the Amplitude SDK.

Lastly, this would be something we'd also want on Android's SDK.

Please let me know how amenable this is and whether it can be done. Thank you!

@Mercy811
Copy link
Contributor

HI @jboulter11, thanks for providing such detailed description and potential solutions. Can I know why you want to log your own session start events as the SDK supports out-of-box session tracking?

Also a heads up here that we are planning to GA Swift SDK next quarter and put iOS SDK to end-of-support status according to the maintenance and support policy. We will put this into our backlog, but regarding to our deprecation plan, unless it's blocking data ingestion, it has a limited chance to be put into our roadmap unfortunately.

@justin-fiedler
Copy link
Contributor

justin-fiedler commented Jun 30, 2023

Hi @jboulter11, you can hook into the event stream using Middleware. Middleware is called for each event, including session events. If you set trackingSessionEvents = YES you can then add a custom middleware to handle the event_type=session_start event. Hope this helps!

Documentation here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants