Analytics-Kotlin FAQ
Analytics-Android is published to Maven Central where you can see all published releases.
You can see a changelog in the GitHub repository, detailing the changes made in each release.
Yes. You can use the Segment library with Maven, or any other custom build system because the core SDK is simply a JAR.
1<dependency>2<groupId>com.segment.analytics.kotlin</groupId>3<artifactId>android</artifactId>4<version>1.10.1</version>5</dependency>
The core Segment SDK is extremely lightweight. The JAR weighs in at 12.3KB.
For the Segment SDKs, you can add the following snippet to your Proguard configuration:
1- keep class com.segment.analytics.** { *; }2- keep class androidx.lifecycle.DefaultLifecycleObserver
You should also check the vendor documentation for any Device-mode destinations you are bundling, to see if they include any recommended Proguard configurations.
Yes. You can use Segment's browserify'd analytics-node package just like any other client-side JavaScript library.
Yes. Please refer to the Java Compatibility doc for sample usages.
If you're on a version prior to 1.10.4, the SDK internally uses a number of Java 8 language APIs through desugaring (see Java 8+ API desugaring support). Please make sure your project either uses Android Gradle plugin 4.0.0 or higher, has a minimum API level of 26, or is upgraded to the latest SDK.
While Analytics Kotlin will automatically track deep links that open your app when the trackDeepLinks Configuration property is set to true. There are some situations when the app is already open that could cause a deep link open event to be missed.
The openUrl function allows you to manually track that a deep link has opened your app while your app was already open:
1override fun onNewIntent(intent: Intent?) {2super.onNewIntent(intent)34// Add a deep-link opened event manually.5// This is necessary when your Activity has a android:launchMode of6// 'singleInstance', 'singleInstancePerTask', 'singleTop', or any other mode7// that will re-use an existing Activity instead of creating a new instance.8// The Analytics SDK automatically identifies when you app is started from9// a deep link if the Activity is created, but not if it is re-used. Therefore10// we have to add this code to manually capture the Deep Link info.1112val referrer = "unknown"13analytics.trackDeepLinkOpen(referrer, intent)14}
Note: Due to the way deep links are handled in Android, we can not know the referrer when a deep link causes onNewIntent() to be fired instead of onCreate().
For a sample implementation see our Kotlin Sample App.
When you successfully package a plugin in device-mode, you will no longer see the integration listed as false in the integrations object for a Segment event. This logic is now packaged in the event metadata, and is not surfaced in the Segment debugger.
The instanceId was introduced in V 1.10.1 and correlates events to a particular instance of the client in a scenario when you might have multiple instances on a single app.
To proxy events to Segment's API, you can configure your proxy URL via the requestFactory setting:
1Analytics(BuildConfig.SEGMENT_WRITE_KEY, androidContext()) {2trackApplicationLifecycleEvents = true3defaultSettings = Settings(4integrations = emptyJsonObject5)6requestFactory = object : RequestFactory() {78override fun settings(cdnHost: String, writeKey: String): HttpURLConnection {9return super.settings("cdn-segment.test.com/v1", writeKey)10}1112override fun upload(apiHost: String): HttpURLConnection {13return super.upload("api-segment.test.com/v1")14}15}16}
When proxying your events, you must forward the batched events to https://api.segment.io/v1/b. The https://api.segment.io/v1/batch endpoint is reserved for events arriving from server side sending, and proxying to that endpoint for your mobile events may result in unexpected behavior.