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(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
You can restrict the in-apps based on the user context in the application apart from restricting InApp campaigns on a specific activity.
The context is not the same context as Android Context. The user 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();
info |
Note Contextual InApp is supported starting SDK version 10.0.00. |
GIF In Apps
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 the SDK version below 10.0.00 use Fresco instead of Glide for using gifs. Ensure 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 show In-Apps call use the following:
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
For more information, refer to the InAppMessageListener and MoEInAppCampaign.
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
The application needs to notify MoEngage SDK whenever the In-App messages are displayed, clicked on, or dismissed as the application controls these actions. The following methods are called to notify the SDK. The campaign object provided to the application in the callback for self-handled in-app should be passed as a parameter to the following 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);
For more information, refer to the API documentation.
In-Apps Callback
Lifecycle callback
For InApp lifecycle callbacks like shown, dismissed implement the InAppLifeCycleListener
. Refer to the API Reference for more details.
Note: This Listener was introduced in SDK version 11.4.00
if you are using an older version use InAppMessageListener
Deprecated Lifecycle Callback
Deprecated since 11.4.00
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.
Handling Configuration change
Starting SDK version 11.4.00
in-apps are supported in both portrait and landscape modes. SDK internally handles in-app display on orientation change when the activity restart is handled by the system.
In case your activity is handling the configuration change by itself, you have to notify the SDK by invoking MoEInAppHelper.onConfigurationChanged()
API for SDK to redraw the in-app when the activity receives onConfigurationChanged()
callback.
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
MoEInAppHelper.getInstance().onConfigurationChanged()
}
@Override public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
MoEInAppHelper.getInstance().onConfigurationChanged();
}
Testing In-App
Refer to this link to read more about how to create and test in-apps.
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 these 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 initializing 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 e.g., the Payment page or splash screen add the activity list in the initializer object as described:
ArrayList inAppOptOut = new ArrayList<>();
inAppOptOut.add(MainActivity.class);
MoEngage moEngage = new MoEngage.Builder(this, "XXXXXXXXXX")
.optOutInAppOnActivity(inAppOptOut)
.build();
MoEngage.initialise(moEngage);