MoEngage Docs

In-App NATIV

In-App NATIV Campaigns target your users by showing a message while the user is using your app. They are very effective in providing contextual information and help to cross-sell/up-sell on desired screens of your app or/and on desired actions performed by the user in your app.

Call Show InApp

Call MoEInAppHelper.getInstance().showInApp(context) in the onResume() of your Fragment or onStart() of your activity. Refer to the API documentation for more details.

Additionally, you can block in-app on a specific screen or handle the status bar visibility using the InAppConfig object and pass it to the SDK using the MoEngage.Builder object. Use the configureInApps() to pass on the configuration to the SDK.
Refer to the InAppConfig API reference for all possible options.

// Set of activity classes on which in-app should not be shown
    val inAppOptOut = mutableSetOf<Class<*>>()
    inAppOptOut.add(SplashActivity::class.java)
    
    val moengage = MoEngage.Builder(application, "XXXXXXXX")
            .configureInApps(InAppConfig(true, inAppOptOut))
            .build()
    MoEngage.initialise(moengage)
Set<Class<?>> inAppOptOut = new HashSet<>();
    inAppOptOut.add(SplashActivity.class);

    MoEngage.Builder builder = new MoEngage.Builder(application, "XXXXXXXXXX")
        .configureInApps(new InAppConfig(true, inAppOptOut));
    MoEngage.initialise(builder.build());

Implementing Nudges

Nudges are non-disruptive messages which can be placed anywhere in the activity.

Add the following code in the activity/fragment layout file.

<com.moengage.widgets.NudgeView
    android:id="@+id/nudge"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</com.moengage.widgets.NudgeView>

Using in an Activity

Get an instance of the nudge view in the onCreate() and initialize the nudge view in the onStart() of the Activity.

Using in a Fragment

Get an instance of the nudge view in the onCreateView() and initialize the nudge view in the onResume() of the fragment.

Use the below code to get the instance of the NudgeView and initialize it.

// get instance of the view
val nudge = findViewById<NudgeView>(R.id.nudge)
// initialize
nudge.initialiseNudgeView(activity)
// get instance of the view
NudgeView nv = (NudgeView)findViewById(R.id.nudge);
// initialize
nv.initialiseNudgeView(getActivity());

Contextual InApp

Apart from restricting InApp campaigns on a specific activity, you can restrict the in-apps based on the user's context in the application.
The context here does not mean the Android Context. By context we the user's context in the application flow.

Set Context

val contextList = arrayListOf<String>("C1", "C2", "C3", "C4")
MoEHelper.getInstance(requireContext()).appContext = contextList
List<String> contextList = new ArrayList<>();
    contextList.add("C1");
    contextList.add("C2");
    contextList.add("C3");
    contextList.add("C4");
    MoEHelper.getInstance(getApplicationContext()).setAppContext(contextList);

Reset Context

MoEHelper.getInstance(requireContext()).resetAppContext()
MoEHelper.getInstance(requireContext()).resetAppContext();

🚧

Contextual InApp is supported starting SDK version 10.0.00

GIF inApps

In-App messages support GIFs with Glide
To use GIFs you need to add the below dependency in your build.gradle file.

implementation "com.github.bumptech.glide:glide:4.9.0"
annotationProcessor "com.github.bumptech.glide:compiler:4.9.0"

When using SDK version below 10.0.00 you need to use Fresco instead of Glide for using gifs. Make sure to add the animated-gif artifact as well.

Self Handled InApps

Self handled In Apps are messages which are delivered by the SDK but showing it has to be done by the App.
To shown In-Apps call the below method.

MoEInAppHelper.getInstance().getSelfHandledInApp(context)
MoEInAppHelper.getInstance().getSelfHandledInApp(context);

This method should be called in the onResume() of your Fragment or onStart() of your activity.
The above method is asynchronous and does not return the payload immediately.
To get the payload implement the InAppMessageListener and override the onSelfHandledAvailable(). Once the payload is available this method will be called with the payload.
The payload can be accessed using MoEInAppCampaign.selfHandledCampaign
Refer to the InAppMessageListener and MoEInAppCampaign documentation for more details.

To get the above callback you would need to register the listener with the SDK using MoEInAppHelper.getInstance().registerListener()

Tracking Statistics for Self Handled In-Apps

Since display, click, and dismiss for Self-Handled InApp shown controlled by the application we need you to notify the SDK whenever the In-App is Shown, Clicked, Dismissed. Below are the methods you need to call to notify the SDK. The campaign object provided to the application in the callback for self-handled in-app should be passed in as a parameter to the below APIs.

// call whenever in-app is shown
MoEInAppHelper.getInstance().selfHandledShown(context, inAppCampaign)
// call whenever in-app is clicked
MoEInAppHelper.getInstance().selfHandledClicked(context, inAppCampaign)
 // call whenever in-app is dismissed
MoEInAppHelper.getInstance().selfHandledDismissed(context, inAppCampaign)
// call whenever in-app is shown
MoEInAppHelper.getInstance().selfHandledShown(context, inAppCampaign);
// call whenever in-app is clicked
MoEInAppHelper.getInstance().selfHandledClicked(context, inAppCampaign);
 // call whenever in-app is dismissed
MoEInAppHelper.getInstance().selfHandledDismissed(context, inAppCampaign);

Refer to the API documentation for more details.

In-Apps Callback

SDK provides callbacks to the client application whenever is shown or closed/dismissed.
To get a callback implement the InAppMessageListener and override the onShown() and onClosed() respectively.
To get the above callback you would need to register the listener with the SDK using MoEInAppHelper.getInstance().registerListener()

Refer to the documentation of InAppMessageListener and MoEInAppCampaign for more details.

Testing InApp

Refer to this link to read more about how to create and test in-apps.

For SDK version below 11.0.00

Starting SDK version 10.0.00 showing of InApp automatically on Activity launch is deprecated. Use showInApp() instead.

To ensure backward compatibility despite the deprecation the SDK still shows in-app automatically on Activity launch.
To use shownInApp() follow the below steps.

Opt-out default In-App Display

Opt-out of the default behavior on lifecycle callbacks. To opt-out call optOutDefaultInAppDisplay() in the MoEngage Builder when initialising the SDK.

val moEngage = MoEngage.Builder(this, "XXXXXXXXXXX")
        .optOutDefaultInAppDisplay()
        .build()
MoEngage.initialise(moEngage)
MoEngage moEngage =
        new MoEngage.Builder(this, "XXXXXXXXXXX")
        .optOutDefaultInAppDisplay()
        .build();
MoEngage.initialise(moEngage);

Suppressing In-App

If you want to suppress the In-APP in a particular activity for e.g., the Payment page or splash screen add the activity list in the initializer object as shown below

ArrayList<Class> inAppOptOut = new ArrayList<>();
    inAppOptOut.add(MainActivity.class);
    MoEngage moEngage =
        new MoEngage.Builder(this, "XXXXXXXXXX")
            .optOutInAppOnActivity(inAppOptOut)
            .build();
    MoEngage.initialise(moEngage);

Updated 9 days ago


What's Next

Cards

In-App NATIV


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.