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 using Artifact ID as described in Installation using Artifact ID. However, installation using Catalog ID is the recommended approach as installing using Artifact ID may lead to version mismatch if mapped incorrectly.
Requirements for displaying images and GIFs in InApp
Starting InApp version 7.0.0, SDK requires Glide to show images and GIFs in the in-apps. You need to add the below dependency in your build.gradle file.
dependencies { ... implementation("com.github.bumptech.glide:glide:4.9.0") }
Display InApp
MoEngage can not show the InApp by default, and the app should call the following method in the places where necessary to show the InApps to the user. We recommend adding this method in onStart() of your activity or onResume() of your fragment. MoEInAppHelper.getInstance().showInApp(context)
MoEInAppHelper.getInstance().showInApp(context)
Display Nudges
Starting with version 7.0.0, MoEngage InApp SDK supports displaying Non-Intrusive nudges.
MoEngage can not show the Nudges by default, and the app should call the following method in the places where necessary to show the Nudges to the user. We would recommend you add this method in onStart() of your activity or onResume() of your fragment. MoEInAppHelper.getInstance().showNudge(context)
MoEInAppHelper.getInstance().showNudge(context)
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();
}
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 the SDK delivers to the application, and the application builds the UI using the SDK's delivered payload.
Single Self-Handled InApps
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(), the listener callback would be called with the payload.
Event-Triggered Self Handled InApps
To get a callback for an 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.
Multiple Self-Handled InApps
info |
Information
|
Fetch Multiple Self Handled Campaigns using getSelfHandledInApps(). The MoEngage SDK will return up to 5 campaigns(in the order of campaign priority set at the time of campaign creation) in the campaigns available callback method onCampaignsAvailable().
MoEInAppHelper.getInstance().getSelfHandledInApps(context, listener)
MoEInAppHelper.getInstance().getSelfHandledInApps(context, listener);
The listener is an instance of SelfHandledCampaignsAvailableListener.
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 onCampaignsAvailable() callback of the listener would be called with the payload.
Tracking Statistics for Multiple Self-Handled In-Apps
The onCampaignsAvailable() callback method returns SelfHandledCampaignsData, which contains a list of SelfHandledCampaignData objects. The statistics for each SelfHandledCampaignData object must be tracked individually below APIs.
Fetching Contextual Multiple Self-Handled InApps
To fetch contextual multiple self-handled inapps, set the inapp contexts using setInAppContext() before calling getSelfHandledInApps(). This will return a list of contextual and non-contextual inapps(in the order of campaign priority set at the time of campaign creation).
Tracking Statistics for Self-Handled In-Apps
The application must 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 SelfHandledCampaignData 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.
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(inAppOptOut,true))
.build()
MoEngage.initialise(moengage)
Set<Class<?>> inAppOptOut = new HashSet<>();
inAppOptOut.add(SplashActivity.class);
MoEngage.Builder builder = new MoEngage.Builder(application, "XXXXXXXXXX")
.configureInApps(new InAppConfig(inAppOptOut,true));
MoEngage.initialise(builder.build());
Testing In-App
Refer to this link to read more about how to create and test in-apps.
Implementing Embedded Nudges (Deprecated)
info |
Note Starting InApp version 7.0.0, embedded nudges are no longer supported. |
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());