MoEngage Docs

Android Integration

Integrating MoEngage with Segment in Android

SDK Installation

Add segment's bundled library dependency in the app's build.gradle

If you are updating from 2.x.x, please check notes here before updating.

dependencies {
    implementation 'com.segment.analytics.android:analytics:+'
    implementation('com.moengage:moengage-segment-integration:3.1.02') {
        transitive = true
    }
}

Setup MoEngage

To setup MoEngage do the following :

  1. First get your key(AppID) from MoEngage dashboard.
  2. Go to Segment dashboard, go to Integrations and select MoEngage.
  3. Enable MoEngage Integration.
  4. Go to MoEngage Settings and enter the MoEngage AppID, obtained in Step1.
  5. Save the changes.

Initializing Segment and MoEngage

In the Application subclass, initialize Segment and tell segment that you are using MoEngage bundled with Segment. Add the following code snippet in your Application class.

public class SegmentDemoApplication extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    Analytics analytics = new Analytics.Builder(getApplicationContext(),
            "writeKey")//use your own write key
    .logLevel(Analytics.LogLevel.VERBOSE)// should be added only in debug builds. Make sure this
    // is removed before a signed apk is generated.
    .use(MoEngageIntegration.FACTORY)//enable MoEngage integration
    .build();

    Analytics.setSingletonInstance(analytics);//recommended as creating a new instance every time
    // is expensive in terms of resources used
    
// this is the instance of the application class and "XXXXXXXXXXX" is the APP ID from the dashboard.
MoEngage moEngage = new MoEngage.Builder(this, "XXXXXXXXXXX")
            .enableSegmentIntegration()
            .build();
    MoEngage.initialise(moEngage);
  }
}

Tracking User Attributes

Analytics.with(MainActivity.this).identify("user attributes", new Traits().putFirstName("Umang").putGender("Male"),  null);

To know more about tracking user attributes you can refer this link

Tracking Events using Segment

Analytics.with(MainActivity.this).track("Email button Click", new Properties().putValue("email", "opened"));

To know more about tracking events you can refer this link

Configuring MoEngage SDK

For configuring the MoEngage SDK further refer to this link.

Sample Implementation

Further refer to this github repository for sample implementation