amplitude / Amplitude-Android

Native Android SDK for Amplitude
MIT License
164 stars 90 forks source link

How do we get access to sessionId? #352

Open swlabrtyr opened 1 year ago

swlabrtyr commented 1 year ago

In the new Amplitude SDK doc, it says sessionId is a property of the Amplitude() object, and can be accessed accordingly -> amplitude.sessionId https://www.docs.developers.amplitude.com/data/sdks/android-kotlin/#user-sessions However, I have found that this is not true. sessionId appears to live inside the EventOptions() object. How can developers access sessionId (and other user params ie device, location etc.) from the EventOptions? Or is it possible to access sessionId some other way?

I am using SDK version analytics-android:1.6.0

qingzhuozhen commented 1 year ago

Hi @swlabrtyr, thanks for reporting this! Sorry for this issue, I believe this is due to our earlier fix around sessions. We would dive in more and take care of this. The EventOptions object is actually part of the event and you can use this to set other params easily. The event object would include the current sessionId can be retrieved via a custom plugin. This could be a temporary workaround.

swlabrtyr commented 1 year ago

Hi @qingzhuozhen thanks for your reply! How would I use this custom plugin? When accessing EventOptios directly all items are null. I assume I need to pass this object to Amplitude or some other class, please advise 🙏🏻

qingzhuozhen commented 1 year ago

Hi @swlabrtyr The custom plugin way is not super ideal and we just release a fix to enable the way described in the dev doc. Feel free to upgrade and let us know if that's still an issue for you.

swlabrtyr commented 1 year ago

Hi @qingzhuozhen thank you, 1.6.2 gives me access. I appreciate your assistance 🙏🏻 . I have one question, in the previous sdk there was a method setOffline that when set to true would not send events to Amplitude's servers. I no longer see a similar method in the documentation for the Kotlin SDK. Is there a flag/method we can call to disable sending of events to Amplitude? We use this for testing purposes. Thank you again!

qingzhuozhen commented 1 year ago

Hi @swlabrtyr, thanks for the update! Yeah, unfortunately, the offline option is not covered yet, I will discuss with the team about the support for it. For testing purposes, would optOut work for you? That's going to block any event sent to Amplitude.