In-App Messaging is custom views that you can send to a segment of users to show custom messages or give new offers or take to some specific pages. They can be created from your MoEngage account.
Installing Android Dependency
Add the following dependency in the android/app/build.gradle file.
dependencies {
...
implementation("com.moengage:inapp:$sdkVersion")
}
replace $sdkVersion with the appropriate SDK version
Show InApp
Call the below API to show an inApp campaign on a screen.
import 'package:moengage_flutter/moengage_flutter.dart';
final MoEngageFlutter _moengagePlugin = MoEngageFlutter(YOUR_Workspace_ID);
_moengagePlugin.initialise();
_moengagePlugin.showInApp();
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.
import 'package:moengage_flutter/moengage_flutter.dart';
import 'package:moengage_flutter/model/inapp/self_handled_data.dart';
final MoEngageFlutter _moengagePlugin = MoEngageFlutter(YOUR_Workspace_ID);
_moengagePlugin.getSelfHandledInApp();
To get the self-handled campaign, register for the callback as shown below.
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 provided to the application in the callback for self-handled in-app should be passed as a parameter to the following APIs.
import 'package:moengage_flutter/moengage_flutter.dart';
import 'package:moengage_flutter/model/inapp/self_handled_data.dart';
final MoEngageFlutter _moengagePlugin = MoEngageFlutter(YOUR_Workspace_ID);
// call this method to notify campaign was shown.
_moengagePlugin.selfHandledShown(message);
// call this method to noftify campaign was clicked.
_moengagePlugin.selfHandledClicked(message);
// call this method to notify campaign was dismissed.
_moengagePlugin.selfHandledDismissed(message);
InApp Callbacks
We provide callbacks for in-app shown, in-app clicked, in-app dismissed, and self-Handled in-app available events. You can register for the same as shown below.
import 'package:moengage_flutter/moengage_flutter.dart';
import 'package:moengage_flutter/model/inapp/click_data.dart';
import 'package:moengage_flutter/model/inapp/inapp_data.dart';
import 'package:moengage_flutter/model/inapp/self_handled_data.dart';
void _onInAppClick(ClickData message) {
print("This is a inapp click callback from native to flutter. Payload " +
message.toString());
}
void _onInAppShown(InAppData message) {
print("This is a callback on inapp shown from native to flutter. Payload " +
message.toString());
}
void _onInAppDismiss(InAppData message) {
print("This is a callback on inapp dismiss from native to flutter. Payload " +
message.toString());
}
void _onInAppSelfHandle(SelfHandledCampaignData message) {
print("This is a callback on inapp self handle from native to flutter. Payload " +
message.toString());
}
final MoEngageFlutter _moengagePlugin = MoEngageFlutter(YOUR_Workspace_ID);
//Register for callbacks
_moengagePlugin.setInAppClickHandler(_onInAppClick);
_moengagePlugin.setInAppShownCallbackHandler(_onInAppShown);
_moengagePlugin.setInAppDismissedCallbackHandler(_onInAppDismiss);
_moengagePlugin.setSelfHandledInAppHandler(_onInAppSelfHandle);
//NOTE: set up callbacks before initialise()
_moengagePlugin.initialise();
InApp Payload
InApp Data will be received in the below format:
class InAppData {
/// Native platform from which the callback was triggered.
Platforms platform;
//Account Data
AccountMeta accountMeta;
///In-App Campaign Data
CampaignData campaignData;
}
class CampaignData {
/// Unique identifier for each campaign.
String campaignId;
///Campaign Name
String campaignName;
...
}
class ClickData {
/// Native platform from which the callback was triggered.
Platforms platform;
/// Account Data
AccountMeta accountMeta;
/// In-App Campaign Data
CampaignData campaignData;
/// Action data with type navigation/custom
Action action;
}
class NavigationAction extends Action {
/// Type of Navigation action.
/// Possible value deep_linking or screen
NavigationType navigationType;
/// Deeplink Url or the Screen Name used for the action.
String navigationUrl;
/// [Map] of Key-Value pairs entered on the MoEngage Platform for
/// navigation action of the campaign.
Map<String, dynamic> keyValuePairs;
}
class CustomAction extends Action {
///Key-Value Pair entered on the MoEngage Platform during campaign creation.
Map<String, dynamic> keyValuePairs;
}
class SelfHandledCampaignData {
/// Native platform from which the callback was triggered.
Platforms platform;
/// Account Data
AccountMeta accountMeta;
/// In-App Campaign Data
CampaignData campaignData;
//Self handled data
SelfHandledCampaign campaign;
}
class SelfHandledCampaign {
/// Self handled campaign payload.
String payload;
/// Interval after which in-app should be dismissed, unit - Seconds
int dismissInterval;
}
Handling Orientation Change
info |
Note This is only for the Android platform |
Starting SDK version 4.1.0
in-apps are supported in both portrait and landscape modes.
SDK has to be notified when the device orientation changes for SDK to handle in-app display.
There are two ways to do it:
- Add the API call in the Android native part of your app
- Call MoEngage plugin's
onOrientationChanged()
Add the API call in the Android native part of your app
Notify the SDK when onConfigurationChanged() API callback is received in your App's Activity class.
public class MainActivity extends FlutterActivity {
...
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
MoEFlutterHelper.getInstance().onConfigurationChanged();
...
}
...
}
Call MoEngage plugin's orientation change API
Call the below API to notify SDK of the orientation change.
_moengagePlugin.onOrientationChanged();