InApp NATIV 4.x.x

InApp 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.

Show InApp

Call the below API to show an inApp campaign on a screen.

Dart
import 'package:moengage_flutter/moengage_flutter.dart';
final MoEngageFlutter _moengagePlugin = MoEngageFlutter();
_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.

Dart
import 'package:moengage_flutter/moengage_flutter.dart';
final MoEngageFlutter _moengagePlugin = MoEngageFlutter();
_moengagePlugin.getSelfHandledInApp();    

To get the self-handled campaign register for the callback as shown below.

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.

Dart
import 'package:moengage_flutter/moengage_flutter.dart';
final MoEngageFlutter _moengagePlugin = MoEngageFlutter();
// call this method to notify campaign was shown.
_moengagePlugin.selfHandledShown();
// 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 inAppShown and inAppClicked events and you can register for the same as shown below.

Dart
import 'package:moengage_flutter/moengage_flutter.dart';
import 'package:moengage_flutter/inapp_campaign.dart';

  void _onInAppClick(InAppCampaign message) {
    print("This is a inapp click callback from native to flutter. Payload " +
        message.toString());
  }

  void _onInAppShown(InAppCampaign message) {
    print("This is a callback on inapp shown from native to flutter. Payload " +
        message.toString());
  }

  void _onInAppDismiss(InAppCampaign message) {
    print("This is a callback on inapp dismiss from native to flutter. Payload " +
        message.toString());
  }

  void _onInAppCustomAction(InAppCampaign message) {
    print("This is a callback on inapp custom action from native to flutter. Payload " +
        message.toString());
  }

  void _onInAppSelfHandle(InAppCampaign message) {
    print("This is a callback on inapp self handle from native to flutter. Payload " +
        message.toString());
  }

final MoEngageFlutter _moengagePlugin = MoEngageFlutter();
//Register for callbacks
    _moengagePlugin.setUpInAppCallbacks(
      onInAppClick: _onInAppClick,
      onInAppShown: _onInAppShown,
      onInAppDismiss: _onInAppDismiss,
      onInAppCustomAction: _onInAppCustomAction,
      onInAppSelfHandle: _onInAppSelfHandle
    );

InApp Payload

InApp Payload will be received in the below format:

Dart
class InAppCampaign {
    /// Unique identifier for each campaign.
  String campaignId;

  /// Campaign Name
  String campaignName;

  /// Native platform from which the callback was triggered.
  String platform;

  /// Instance of [NavigationAction]
  NavigationAction navigationAction;

  /// Instance of [SelfHandled]
  SelfHandled selfHandled;

  /// Instance of [CustomAction]
  CustomAction customAction;
}

class NavigationAction {
  /// Type of Navigation action.
  ///
  /// Possible value deep_linking or screen
  String navigationType;

  /// Deeplink Url or the Screen Name used for the action.
  String url;

  /// [Map] of Key-Value pairs entered on the MoEngage Platform for
  /// navigation action of the campaign.
  Map<String, dynamic> keyValuePairs;
}

class CustomAction {
  ///Key-Value Pair entered on the MoEngage Platform during campaign creation.
  Map<String, dynamic> keyValuePair;
}

class SelfHandled {
  /// Self handled campaign payload.
  String campaignContent;

  /// Interval after which in-app should be dismissed, unit - Seconds
  int dismissInterval;

  /// Should the campaign be dismissed by pressing the back button or using
  /// the back gesture. if the value is true campaign should be dismissed on
  /// back press.
  bool cancellable;
}

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:

  1. Add the API call in the Android native part of your app
  2. 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.

Kotlin
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 on orientation change.

Kotlin
_moengagePlugin.onOrientationChanged();

Previous

Next

Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?