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.

ab8683f-71c6364-f93ec45-vlcsnap-2016-11-08-16h16m41s386.png

Installing Android Dependency

Add the following dependency to the android/app/build.gradle file.

build.gradle
dependencies {
    ...
implementation("com.moengage:inapp:$sdkVersion")
}

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.

Groovy

dependencies {
 ...
 implementation("com.github.bumptech.glide:glide:4.9.0")
}

Display InApp

Call the showInApp() wherever InApp has to be shown in the app as shown below:

TypeScript
import { MoECapacitorCore } from 'capacitor-moengage-core';
MoECapacitorCore.showInApp({ appId: YOUR Worskpace ID });

Self-Handled InApps

Self-handled In Apps are messages which are delivered by the SDK but displaying it has to be handled by the App.
To get self-handled In-App call the below method.

TypeScript
import { MoECapacitorCore } from 'capacitor-moengage-core';
MoECapacitorCore.getSelfHandledInApp({ appId: YOUR Workspace ID });

The payload for self-handled in-app is returned via a callback. Register a callback as shown below.

TypeScript
import { MoECapacitorCore, MoEInAppSelfHandledCampaignData } from 'capacitor-moengage-core';
MoECapacitorCore.addListener("inAppCampaignSelfHandled", (data: MoEInAppSelfHandledCampaignData) => {
 console.log(" Received callback 'inAppCampaignSelfHandled',  data: " + JSON.stringify(data))
});

Tracking Statistics

Since display, click, and dismiss for Self-Handled InApp is controlled by the application we need you to notify the SDK whenever the In-App is Shown, Clicked, or Dismissed. Below are the methods you need to call to notify the SDK. The campaign object provided to the application in the callback for self-handled in-app should be passed in as a parameter to the below APIs.

TypeScript
import { MoECapacitorCore, MoEInAppSelfHandledCampaignData } from 'capacitor-moengage-core';
//Track self handled shown
MoECapacitorCore.selfHandledShown(selfHandledCampaignData)
//Track self handled widget clicked
MoECapacitorCore.selfHandledClicked(selfHandledCampaignData)
//Track self handled dismissed
MoECapacitorCore.selfHandledDismissed(selfHandledCampaignData)

InApp Callbacks

warning

Warning

Make sure you are calling initialize() method of the plugin to receive these callbacks. Refer to this document for more information.

We provide callbacks whenever an InApp campaign is shown, dismissed, or clicked you can register for the same as shown below.

TypeScript
import { MoECapacitorCore, MoEInAppLifecycleData, MoEInAppNavigationData, MoEInAppCustomActionData } from 'capacitor-moengage-core';

MoECapacitorCore.addListener("inAppCampaignShown", (data: MoEInAppLifecycleData) => {
    console.log(" Received callback 'inAppCampaignShown',  data: " + JSON.stringify(data))
});

MoECapacitorCore.addListener("inAppCampaignDismissed", (data: MoEInAppLifecycleData) => {
    console.log(" Received callback 'inAppCampaignDismissed',  data: " + JSON.stringify(data))
});

MoECapacitorCore.addListener("inAppCampaignClicked", (data: MoEInAppNavigationData) => {
    console.log(" Received callback 'inAppCampaignClicked',  data: " + JSON.stringify(data))
});

MoECapacitorCore.addListener("inAppCampaignCustomAction", (data: MoEInAppCustomActionData) => {
    console.log(" Received callback 'inAppCampaignCustomAction',  data: " + JSON.stringify(data))
});
Event Type Event Name
InApp Shown inAppCampaignShown
InApp Clicked inAppCampaignClicked
InApp Dismissed inAppCampaignDismissed
InApp Clicked with Custom Action inAppCampaignCustomAction

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 to set the context, before calling showInApp().

JavaScript
import { MoECapacitorCore } from 'capacitor-moengage-core';
 
// replace array elements with actual values. MoECapacitorCore.setInAppContext({ contexts: ["c1","c2"] , appId: YOUR Workspace ID });

Reset Context

Once the user is moving out of the context use the resetInAppContext() API to reset/clear the existing context.

JavaScript
import { MoECapacitorCore } from 'capacitor-moengage-core';
MoECapacitorCore.resetInAppContext({ appId: YOUR Workspace ID });

Payload Structure

TypeScript
 /**
 * In-App lifecycle event camapaign data
 */
export interface MoEInAppLifecycleData {
    /**
     * Account information
     */
    accountMeta: MoEAccountMeta;
    /**
     * In-App Campaign data
     */
    campaignData: MoEInAppCampaignData;
    /**
     * Platform information
     */
    platform: MoEPlatform;
}

/**
 * Campaign data.
 */
export interface MoEInAppCampaignData {
    /**
     * Unique Identifier for the campaign
     */
    campaignId: string;
    /**
     * Name given to the campaign while creation on the MoEngage Dashboard.
     */
    campaignName: string;
    /**
     * Additional Meta data related to the campaign.
     */
    campaignContext: MoEInAppCampaignContext;
}

/**
 * In-App navigation event campaign data
 */
export interface MoEInAppNavigationData {
    /**
     * Account information
     */
    accountMeta: MoEAccountMeta;
    /**
     * In-App Campaign data
     */
    campaignData: MoEInAppCampaignData;
    /**
     * Navigation action data
     */
    navigation: MoEInAppNavigation;
    /**
     * Platform Data
     */
    platform: MoEPlatform;
}

/**
 * In-App navigation action data
 */
export interface MoEInAppNavigation {
    /**
     * InApp Action type
     */
    actionType: MoEInAppActionType;
    /**
     * Type of Navigation.
     */
    navigationType: string;
    /**
     * Navigation URL
     */
    navigationUrl: string;
    /**
     * Key-Value Pair entered on the MoEngage Platform during campaign creation.
     */
    kvPair: Map<string, Object>;
}

/**
 * In-App custom event campaign data
 */
export interface MoEInAppCustomActionData {
    /**
     * Account information
     */
    accountMeta: MoEAccountMeta;
    /**
     * In-App Campaign data
     */
    campaignData: MoEInAppCampaignData;
    /**
     * Custom Action data
     */
    customAction: MoEInAppCustomAction;
    /**
     * Platform information
     */
    platform: MoEPlatform;
}

/**
 * InApp Action type
 */
export declare enum MoEInAppActionType {
    NAVIGATION = "navigation",
    CUSTOM = "custom"
}
/**
 * In-App custom action data
 */
export interface MoEInAppCustomAction {
    /**
     * InApp Action type
     */
    actionType: MoEInAppActionType;
    /**
     * Key-Value Pair entered on the MoEngage Platform during campaign creation.
     */
    kvPair: Map<string, object>;
}
      
/**
* Data for self handled campaign.
*/
export interface MoEInAppSelfHandledCampaignData {
    /**
     * Account information
     */
     accountMeta: MoEAccountMeta;
    /**
     * In-App Campaign data
     */
    campaignData: MoEInAppCampaignData;
    /**
     * SelfHandled data
     */
    selfHandled: MoEInAppSelfHandledCampaign; 
}

/**
* Self Handled campaign object
*/
export interface MoEInAppSelfHandledCampaign {
    /**
     * Self handled campaign payload.
     */
     payload: string;
    /**
     * Interval after which in-app should be dismissed, unit - Seconds
     */
     dismissInterval: number;
    /**
     * 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.
     */
     isCancellable: boolean; 
}

 

Handling Orientation Change

info

Note

This is only for the Android platform

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

Java
import android.content.res.Configuration;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.moengage.capacitor.MoECapacitorCorePlugin;
import com.moengage.capacitor.MoECapacitorHelper;

public class MainActivity extends BridgeActivity {

  @Override public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    MoECapacitorHelper.INSTANCE.onConfigurationChanged();
  }
}

Call MoEngage plugin's orientation change API

Call the below API to notify SDK on orientation change.

TypeScript
import { MoECapacitorCore } from 'capacitor-moengage-core';
MoECapacitorCore.onOrientationChanged();

Previous

Next

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

How can we improve this article?