The SegmenKT Kotlin SDK is a Kotlin-first SDK for Segment. Its API is similar to the Segment Android SDK but also supports multiplatform projects, enabling you to use Segment directly from your common source targeting iOS and Android.
Run gradle task in this project
Locate the framework in the following directory
Add the xcframework file to your xcode project, OR you can grab it from this repo in Examples/ios/frameworks/
In order for ios to work you will also need to include the segment framework to your ios project.
How to use
Initialise segment with a config
val segmentConfig = Configuration( writeKey = WriteKey( android = "123", ios = "ABC" ), context = context ) Analytics.setupWithConfiguration(segmentConfig)
No need to define a key for iOS if you are using just Android.
let segmentConfig = Configuration(writeKey: WriteKey(android: nil, ios: ""), context: nil) Analytics.Companion().setupWithConfiguration(configuration: segmentConfig)
Then when you want to Track, Identify, Group, Screen
Analytics.shared().track("Cool Event") Analytics.shared().identify("1") Analytics.shared().group("1") Analytics.shared().screen("Cool Screen")
Analytics.Companion().shared(context: nil).track(name: "Cool Event", properties: nil) Analytics.Companion().shared(context: nil).identify(userId: "1", traits: nil) Analytics.Companion().shared(context: nil).group(groupId: "1", traits: nil) Analytics.Companion().shared(context: nil).screen(screenTitle: "Cool Screen", properties: nil)
Run the examples from the examples directory for KMM, Android and iOS
This project is set up as an open source project. As such, if there are any suggestions that you have for features, for improving the code itself, or you have come across any problems; you can raise them and/or suggest changes in implementation.
If you are interested in contributing to this codebase, please follow the contributing guidelines. This contains guides on both contributing directly and raising feature requests or bug reports. Please adhere to our code of conduct when doing any of the above.