App Setup: How to integrate Segment/Leanplum [Android]

Installation

To install the Leanplum SDK through Segment, make sure to follow the setup instructions as detailed on the Segment docs at https://segment.com/docs/integrations/leanplum/#getting-started

In addition to the standard Segment integration dependencies, also the following needs to be added in order to get the Leanplum SDK:

compile 'com.leanplum.segment:LeanplumIntegration:+'

 

Usage

This is an example of how to use Leanplum once is integrated through Segment. 

Make sure to place the initialization part in your project Application class:

private static final String SEGMENT_WRITE_KEY = " ... ";

Analytics analytics = new Analytics
  .Builder(getApplicationContext(), SEGMENT_WRITE_KEY)
  .use(LeanplumIntegration.FACTORY)
  .build();

Now you can use Segment as you are used to, e.g.:

analytics.track(" ... ", ... );

Note: There is no need to explicitly call Leanplum.start, as it is called within the LeanplumIntegration.

In addition to that you can also use the advanced features of Leanplum. Once the Leanplum SDK is successfully registered, Segement executes a callback:

analytics.onIntegrationReady(LeanplumIntegration.LEANPLUM_SEGMENT_KEY,
    new Analytics.Callback() {
      @Override
      public void onReady(Object instance) {
        Leanplum.addVariablesChangedHandler( ... );
      }
    });

Sample
An Android sample project is available here.


Was this article helpful?
Have more questions? Submit a request