Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Analytics Kotlin Localytics Plugin


The Analytics-Kotlin Localytics Destination Plugin(link takes you to an external page) is open sourced on GitHub.


Getting started

getting-started page anchor
  1. From the Segment Destinations page click Add Destination.
  2. Search for Localytics and select it in the results that appear.
  3. Choose which source to connect to your Localytics destination.
  4. Add your Localytics App Key to the destination's settings tab.

Once the Segment library is integrated with your site or app, toggle Localytics on in your Segment destinations, and add your application's App Key which you can find in your Localytics app settings. These new settings will take up to an hour to propogate to all of your existing users. For new users, it'll be instanteneous.

If you are using version 1.3.0 or higher of the Segment-Localytics Android SDK, you can include a localytics.xml file in your Android project's res/values folder to define your settings. Note that any settings entered in the Segment UI will override the equivalent values defined in your localytics.xml file. You can read more about the localytics.xml file in Localytics's documentation(link takes you to an external page).


To install the Segment-Localytics integration, add this line to your gradle file:

implementation 'com.segment.analytics.kotlin.destinations:localytics:<latest_version>'

Or the following for Kotlin DSL:

implementation("com.segment.analytics.kotlin.destinations:localytics:<latest_version>")

Also add the Maven Localytics repo (since Localytics doesn't publish it on Maven Central) in project-level build.gradle.

1
allprojects {
2
repositories {
3
mavenCentral()
4
maven {
5
url 'https://maven.localytics.com/public'
6
}
7
}
8
}

Or the following for Kotlin DSL:

1
allprojects {
2
repositories {
3
mavenCentral()
4
maven {
5
url = uri("https://maven.localytics.com/public")
6
}
7
}
8
}

Using the plugin in your app

using-the-plugin-in-your-app page anchor

Open the file where you set up and configured the Analytics-Kotlin library. Add this plugin to the list of imports.

import com.segment.analytics.kotlin.destinations.localytics.LocalyticsDestination

Under your Analytics-Kotlin library setup, call analytics.add(plugin = ...) to add an instance of the plugin to the Analytics timeline.

1
analytics = Analytics("<YOUR WRITE KEY>", applicationContext) {
2
this.flushAt = 3
3
this.trackApplicationLifecycleEvents = true
4
}
5
analytics.add(plugin = LocalyticsDestination())

Your events now have Localytics session data and start flowing to Localytics in device-mode.


When you make an Identify call, Segment sets the Localytics customerId and any special Localytics traits you provide, like name, email, or custom traits.


When you make a Track call, Segment logs an event with Localytics containing the name of the event and any optional event properties.


To enable push notifications on your Android app, complete the following steps:

  1. To confirm that Localytics is bundled, verify that Localytics is set to false in your integrations object. For more information about bundled integrations, see Segment's Android documentation.
  2. Follow steps 1-3 of Localytics' documentation to set up the permission in your AndroidManifest.xml(link takes you to an external page).
  3. Make the AndroidManifest changes to the GcmReceiver, GcmListenerService, InstanceIDListenerServer, and PushTrackingActivity classes as noted in the Localytics Push messaging documentation(link takes you to an external page).
  4. Register the Push receiver in your Activity or Application class within a Segment onIntegrationReady method:
1
@Override protected void onResume() {
2
super.onResume();
3
Analytics.with(this).onIntegrationReady(BundledIntegration.LOCALYTICS, new Callback() {
4
@Override public void onIntegrationReady(Object integration) {
5
Localytics.registerPush("YOUR-SENDER-ID");
6
}
7
});
8
}