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.
SDK Installation
Installing using Catalog
Integration using a Version Catalog is the recommended way of integration; refer to the Configure Version Catalog document to configure a catalog if you still need to do so. Once you have configured the catalog add the dependency in the app/build.gradle file as shown below
dependencies {
...
implementation(moengage.inapp)
}
Alternatively, you can add the dependency directly, as shown below.
Installing using Artifact Id
Add the following dependency in the app/build.gradle file.
dependencies {
...
implementation("com.moengage:inapp:$sdkVersion")
}
replace $sdkVersion with the appropriate SDK version
Display InApp
To show an InApp Campaign call MoEInAppHelper.getInstance().showInApp(context) from the onResume() of your Fragment or onStart() of your activity.
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.getInstance().onConfigurationChanged() API for SDK to redraw the in-app when the activity receives onConfigurationChanged() callback from the framework.
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
MoEInAppHelper.getInstance().onConfigurationChanged()
}
@Override public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
MoEInAppHelper.getInstance().onConfigurationChanged();
}
GIF In Apps
SDK supports showing Gif in In-App messages using Glide.
To use GIFs, you need to add the below dependency in your build.gradle file.
dependencies {
...
implementation("com.github.bumptech.glide:glide:4.9.0")
annotationProcessor("com.github.bumptech.glide:compiler:4.9.0")
}
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's context in the application, apart from restricting InApp campaigns on a specific screen/activity. To set the user's context in the application, use setInAppContext() API, as shown below.
Set Context
Call the below method in the onStart() of your Activity or Fragment before calling showInApp().
MoEInAppHelper.getInstance().setInAppContext(setOf("context1", "context2", "context3"))
Set<String> inAppContext = new HashSet<>();
inAppContext.add("context1");
inAppContext.add("context2");
inAppContext.add("context3");
MoEInAppHelper.getInstance().setInAppContext(inAppContext);
The context is not the same context as Android Context. This user's context in the application flow.
Reset Context
Once the user is moving out of the context, use the restInAppContext() API to reset/clear the existing context.
MoEInAppHelper.getInstance().resetInAppContext()
MoEInAppHelper.getInstance().resetInAppContext();
Self Handled InApps
Self-handled In Apps are messages that are delivered by the SDK to the application, and the application builds the UI using the delivered payload by the SDK. To get the self-handled in-app, use the below API.
MoEInAppHelper.getInstance().getSelfHandledInApp(context, listener)
MoEInAppHelper.getInstance().getSelfHandledInApp(context, listener);
The listener is an instance of SelfHandledAvailableListener.
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, once the payload is available onSelfHandledAvailable() callback of the listener would be called with the payload.
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 data 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, data)
// call whenever in-app is clicked
MoEInAppHelper.getInstance().selfHandledClicked(context, data)
// call whenever in-app is dismissed
MoEInAppHelper.getInstance().selfHandledDismissed(context, data)
// call whenever in-app is shown
MoEInAppHelper.getInstance().selfHandledShown(context, data);
// call whenever in-app is clicked
MoEInAppHelper.getInstance().selfHandledClicked(context, data);
// call whenever in-app is dismissed
MoEInAppHelper.getInstance().selfHandledDismissed(context, data);
For more information, refer to the API documentation.
Event-Triggered Self Handled InApps
To get a callback for for event triggered, implement SelfHandledAvailableListener and register for a listener using MoEInAppHelper.getInstance().setSelfHandledListener(). SDK will notify the registered listener once the campaign is available.
We recommend registering this listener in the onCreate() of the Application class if the trigger event can happen on multiple screens.
In-Apps Callback
Lifecycle callback
To get callbacks whenever an InApp campaign is shown or dismissed, implement the InAppLifeCycleListener and register for the callbacks using MoEInAppHelper.getInstance().addInAppLifeCycleListener().
Click Callback
To handle user navigation or custom action, SDK provides a callback whenever an in-app widget is clicked with either Navigation or Custom action. To get callbacks implement the OnClickActionListener interface and register for the callbacks using MoEInAppHelper.getInstance().setClickActionListener().
Blocking InApps on Screens
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() API to pass on the configuration to the SDK.
// 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());
Testing In-App
Refer to this link to read more about how to create and test in-apps.
Version Compatibility
The inapp artifact or module is dependent on the Core SDK or moe-android-sdk artifact or module.
Based on the version of the Core SDK you are using, choose the right version of the InApp module.
Core SDK Version | InApp Version |
---|---|
12.2.02 and later | 6.2.0 and later |