added getSessionId
:bulb: Motivation and Context
I need your sessionId to help correlate your events with my own server events.
https://github.com/PostHog/posthog-ios/issues/164
:green_heart: How did you test it?
In my app.
:pencil: Checklist
- [ X] I reviewed the submitted code.
- [ ] I added tests to verify the changes.
- [ ] I updated the docs if needed.
- [ ] No breaking change or entry added to the changelog.
NOTE: The code I wrote is this:
@objc public func getSessionId() -> String {
if !isEnabled() {
return ""
}
return sessionLock.withLock {
return sessionId ?? ""
}
}
which would have been better as this (return optional, use guard), but I did the above to match your other similar functions...
@objc public func getSessionId() -> String? {
guard isEnabled() { return nil }
return sessionLock.withLock {
return sessionId
}
}
Anyway, this will help me, thanks!
I didn't bump version or edit changelog - I can if you'd like, but I figured that'd be you folks' department. It'd be nice for this to get deployed with new version so spm would pull it down right away...
Also, not quite sure which tests you'd want... brand new one? Shoehorn into "identify sets distinct and anon Ids"? How would it be done?
@colin-persona thanks for the PR.
the guard option is a nice idea, I can refactor all methods later.
getSessionId can return nil since it's not guaranteed that the session feature is enabled.
feel free to add a changelog entry, just put it under Next and follow the others as an example.
You can add a test on PostHogSDKTest since the sessionId is created during SDK init, you just need to guarantee that the getSessionId returns non-nil.
@colin-persona you can run make format (commit and push if needed) and later make lint to guarantee that CI is happy, and of course make test if you add a test.
closed in favor of https://github.com/PostHog/posthog-ios/pull/170