In-App Nativ

Version

In-App Campaigns are 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.

warning

SDK Version

Follow this doc only if you are using MoEngage-iOS-SDK version 8.2.0 and later. If you are using version 5.2.7 or less then follow the doc in this link.

f93ec45-vlcsnap-2016-11-08-16h16m41s386.png

SDK Installation

Install using CocoaPod

Integrate the MoEngageInApp framework by adding the dependency in the pod file as described.

Ruby
pod 'MoEngageInApp','~> 3.2.0'

Now run pod install to install the framework

Install using Swift Package Manager

MoEngageInApp is supported through SPM from SDK version 3.2.0. To integrate use the following GitHub URL link and set the branch as master or version as 3.2.0 and above https://github.com/moengage/MoEngage-iOS-InApps.git

Manual Integration

info

Manual Integration:

To integrate the MoEngageInApp SDK manually to your project follow this doc.

How to show In-App Message?

To use In-app Messaging, add the code below to the view controller(s) in which you want to show the In-app.

Swift Objective-C
MOInApp.sharedInstance().showCampaign()

Nudges

a0b0f6f-IMG_3966.jpeg

Nudges are banner-like views. They can be embedded in the current view or floated over the existing view. There are two options using which you can show the nudges.

  • The first option, you can get the nudge and show it yourself. To get a nudge view, follow the code block below, and in this case, make sure to call the method to track impression for Nudge nudgeCampaignShown() as shown in the below example:
Swift Objective-C
  // Get the nudge view using the method: 
   MOInApp.sharedInstance().getNudgeView { nudgeView, campaignInfo, accountInfo in
            if let nudgeView = nudgeView {
                // Campaign Info
                print("Nudge inApp with Campaign ID\(campaignInfo?.campaign_id) and CampaignName\(campaignInfo?.campaign_name)");
                // Set Frame
                var frame = nudgeView.frame
                frame.origin.y = (UIScreen.main.bounds.size.height - frame.height)/2.0
                frame.origin.x = 0.0
                nudgeView.frame = frame
                
                // Attach the nudge view
                self.view.addSubview(nudgeView)
                
                // Track Impression
                MOInApp.sharedInstance().nudgeCampaignShown(withCampaignInfo: campaignInfo!);
            }
   }
  • Second option, you can let the SDK show the nudges. In this case, SDK can show Nudges in two positions (i.e, at top or bottom of the screen). Use the following code in the view controller(s) where you want SDK to show the nudges :
Swift Objective-C
//For showing nudges at Top of the screen
 MOInApp.sharedInstance().showNudge(at: NudgePositionTop)

//OR

//For showing nudges at Bottom of the screen
MOInApp.sharedInstance().showNudge(at: NudgePositionBottom)

 

InApp Callbacks

warning

Note

Make sure the class is configured with MOInAppNativDelegate to receive all the callbacks.

To observe callbacks whenever an inApp is shown, dismissed or clicked implement MOInAppNativDelegate. First set the delegate as shown below:

Swift Objective-C
MOInApp.sharedInstance().setInAppDelegate(self)

Once the delegate is set you will receive the following callbacks:

Swift Objective-C
// Called when an inApp is shown on the screen
func inAppShown(withCampaignInfo inappCampaign: MOInAppCampaign, for accountMeta: MOAccountMeta) {
   print("InApp shown callback for Campaign ID(\(inappCampaign.campaign_id)) and CampaignName(\(inappCampaign.campaign_name))")
   print("Account Meta AppID: \(accountMeta.appID)")
}

// Called when an inApp is dismissed by the user
func inAppDismissed(withCampaignInfo inappCampaign: MOInAppCampaign, for accountMeta: MOAccountMeta) {
    print("InApp dismissed callback for Campaign ID(\(inappCampaign.campaign_id)) and CampaignName(\(inappCampaign.campaign_name))")
    print("Account Meta AppID: \(accountMeta.appID)")
}

// Called when an inApp is clicked by the user, and it has been configured with a custom action
func inAppClicked(withCampaignInfo inappCampaign: MOInAppCampaign, andCustomActionInfo customAction: MOInAppAction, for accountMeta: MOAccountMeta) {
     print("InApp Clicked with Campaign ID \(inappCampaign.campaign_id)")
     print("Custom Actions Key Value Pairs: \(customAction.keyValuePairs)")
}

// Called when an inApp is clicked by the user, and it has been configured with a navigation action
func inAppClicked(withCampaignInfo inappCampaign: MOInAppCampaign, andNavigationActionInfo navigationAction: MOInAppAction, for accountMeta: MOAccountMeta) {
     print("InApp Clicked with Campaign ID \(inappCampaign.campaign_id)")
     print("Navigation Action Screen Name \(navigationAction.screenName) Key Value Pairs: \((navigationAction.keyValuePairs))")
}
    

Context-Based InApps

We have introduced context-based InApps with SDK version 6.0.0. While creating InApp campaigns you can set the contexts OR tags to the campaign. SDK will check with the current context set in the App and show the inApp only when a current set context matches the campaign context.

Set Current Context:

To set the current context for the InApp module use setCurrentInAppContexts() method as shown below:

Swift Objective-C
MOInApp.sharedInstance().setCurrentInAppContexts(["Home","CategoriesScreen"])

Reset Context:

To reset the current context for the InApp module call invalidateInAppContexts() method:

Swift Objective-C
MOInApp.sharedInstance().invalidateInAppContexts()

Disable In-Apps in ViewController

If you don't want to show InApp messages in a particular ViewController, use blockInAppInViewController: method as shown below:

Swift Objective-C
//For not showing in apps in viewController
MOInApp.sharedInstance().blockInApp(in: viewController);

Disabling In-Apps for App

If you do not wish to use InApp messaging, set the property disableInApps. The property has to be set before the initial call.

Swift Objective-C
MOInApp.sharedInstance().disableInApps()

Self handled In-Apps

Self handled In-Apps are not shown by the SDK. While creating the campaign, a json payload has to be provided. The same payload will be provided in case of General InApp Campaign by the SDK on calling getSelfHandledInApp method.

Swift Objective-C
MOInApp.sharedInstance().getSelfHandledInApp { (campaignInfo, accountMeta) in
      if let campaignInfo = campaignInfo{ print("Self-Hanled InApp Content \(campaignInfo.campaignContent)")
          // Update UI with Self Handled InApp Content
                
      } else{
          print("No Self Handled campaign available")
                
      }
}

Getting Self Handled InApp payload in case of Smart Trigger:

For getting the Self Handled InApp payload in case of Smart Trigger, use the selfHandledInAppTriggered delegate method :

Swift Objective-C
// This method is called when an event triggers an in-app from the server, which is of type self handled.
func selfHandledInAppTriggered(withInfo inappCampaign: MOInAppSelfHandledCampaign, for accountMeta: MOAccountMeta) {
    print("Self Handled InApp Triggered with info:\nCampaign ID:\(inappCampaign.campaign_id) \nContent: \(inappCampaign.campaignContent)")
}
info

Note

The above method will also be called when trying to test the self-handled campaign through test push.

Tracking InApp Shown And Clicked:

For tracking In-App shown for self handled in-apps use selfHandledShown method and provide campaign instance as a parameter:

Swift Objective-C
// Call this method when you show the self handled in-app so we can update impressions.
MOInApp.sharedInstance().selfHandledShown(withCampaignInfo: cmpInfo)

For tracking InApp Clicked information for stats, call the following methods :

Swift Objective-C

// Call this method to track if self handled in app widget(other than Primary Widget) is clicked.
MOInApp.sharedInstance().selfHandledClicked(withCampaignInfo: cmpInfo)

// Call this method to track dismiss actions on the inApp.
MOInApp.sharedInstance().selfHandledDismissed(withCampaignInfo: cmpInfo)

Update Delay between In-Apps

You can also change the minimum time delay between two in-apps. By default it is 15 mins.
Go to Settings in the MoEngage dashboard. Go to In-App NATIV Settings Menu.

There's a field Delay between InApp:. Change that to the desired delay.

572355b-Screen_Shot_2016-11-08_at_17.22.29.png

In-App Messaging Rules

We use the following rules while showing the In-App:

Preconditions for inApp to work:

  • If InApp Backend Sync was successful in the current session or not.
  • Check if InApp is disabled on the current screen.

Following are checked for each campaign in the list of active campaigns(sorted according to priority and Last Updated Time)

  • Check Global Delay has lapsed, skip this if Ignore Global Delay set for the campaign.
  • Check if the campaign has expired
  • Display Rules
  • Check Show Only in Screen
  • Check with current contexts
  • Delivery Controls
  • Persistence Check(If primary action of InApp is done but still want to show the inApp)
  • Check if the campaign has been shown Max Times
  • Check if the campaign level delay has crossed.
  • Check Device Orientation is Portrait for Native InApp and required Orientation for HTML InApp(as selected during campaign creation).

The first campaign satisfying all the rules is shown to the user.

 

 

 

Previous

Next

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

How can we improve this article?