In-App Messaging are custom views which 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 |
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.
MoEngage.sharedInstance().handleInAppMessage()
MoEngage.sharedInstance().delegate = self
[[MoEngage sharedInstance]handleInAppMessage];
[MoEngage sharedInstance].delegate = self;
To handle the button action for In-App, confirm your view controller to MOInAppDelegate (optional). The method will provide the data which will help you to navigate screens or take appropriate actions.
//This delegate will be called when an In-App is shown. You can use this to ensure not showing alerts or pop ups of your own at the same time.
func inAppShown(withCampaignID campaignID: String!) {
}
// The enum InAppWidget is for the different types of widgets which can be clicked in the In-App.
func inAppClicked(for widget: InAppWidget, screenName: String!, andDataDict dataDict: [AnyHashable : Any]!) {
}
// The enum InAppWidget is for the different types of widgets which can be clicked in the In-App.
-(void)inAppClickedForWidget:(InAppWidget)widget screenName:(NSString*)screenName andDataDict:(NSDictionary *)dataDict{
// Here the dataDict will have the screen name and the key value pairs.
}
//This delegate will be called when an In-App is shown. You can use this to ensure not showing alerts or pop ups of your own at the same time.
-(void)inAppShownWithCampaignID:(NSString*)campaignID{
}
Nudges
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.
- First option, you can get the nudge and show it yourself .To get a nudge view, use the following code:
// Get the nudge view using the method:
MoEngage.sharedInstance().getNudgeViewWithCompletionBlock { (nudgeView: UIView!, campaignId: String!) in
//If it exists, decide the frame where you wish to show it. Once you have the frame and the view, add it to self.view.
if((nudgeView) != nil){
nudgeView.frame = CGRectMake(0, 64, nudgeView.frame.size.width, nudgeView.frame.size.height)
self.view .addSubview(nudgeView)
// Don't forget to call this method. This method tells us that the nudge view is shown to the end user.
MoEngage.sharedInstance().nudgeViewShownWithCampaignID(campaignId)
}
}
// Get the nudge view using the method:
[[MoEngage sharedInstance]getNudgeViewWithCompletionBlock:^(UIView *nudgeView, NSString *campaignID) {
//If it exists, decide the frame where you wish to show it. Once you have the frame and the view, add it to self.view.
if(nudgeView){
nudgeView.frame = CGRectMake(0, 64, nudgeView.frame.size.width, nudgeView.height);
[self.view addSubview:nudgeView];
// Don't forget to call this method. This method tells us that the nudge view is shown to the end user.
[[MoEngage sharedInstance]nudgeViewShownWithCampaignID:campaignID];
}
}];
- 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 :
//For showing nudges at Top of the screen
MoEngage.sharedInstance().showNudgeViewAtNudgePosition(NudgeTop)
//OR
//For showing nudges at Bottom of the screen
MoEngage.sharedInstance().showNudgeViewAtNudgePosition(NudgeBottom)
//For showing nudges at Top of the screen
[[MoEngage sharedInstance] showNudgeViewAtNudgePosition:NudgeTop];
//OR
//For showing nudges at Bottom of the screen
[[MoEngage sharedInstance] showNudgeViewAtNudgePosition:NudgeBottom];
Disable In-Apps in ViewController
If you don't want to show in app messages in a particular ViewController, use dontShowInAppInViewController: method as shown below:
//For not showing in apps in viewController
MoEngage.sharedInstance().dontShowInAppInViewController(viewController)
//For not showing in apps in viewController
[[MoEngage sharedInstance] dontShowInAppInViewController:viewController];
Disabling In-Apps for App
If you do not wish to use in app messaging, set the property disableInApps. The property has to be set before the initialize call.
MoEngage.sharedInstance().disableInApps = true
[MoEngage sharedInstance].disableInApps = YES;
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.
// Call this method to get the self handled in-app. This will return the json payload as NSDictionary
MoEngage.sharedInstance().getSelfHandledInApp()
// Call this method to get the self handled in-app. This will return the json payload as NSDictionary
NSDictionary* payloadDict = [[MoEngage sharedInstance] getSelfHandledInApp];
info |
Note Self-handled InApp payload will be provided, only when In-App Messaging Rules are satisfied. If not then this method return's nil. |
Getting Self Handled InApp payload in case of Smart Trigger:
For getting the Self Handled InApp payload in case of Smart Trigger, use the eventTriggeredInAppAvailableWithData:
delegate method :
/**
This method is called when an event triggers an in-app from the server, which is of type self handled.
*/
func eventTriggeredInAppAvailable(withData data: Any!) {
}
/**
This method is called when an event triggers an in-app from the server, which is of type self handled.
*/
-(void)eventTriggeredInAppAvailableWithData:(id)data{
}
Tracking InApp Shown And Clicked:
For tracking In-App shown for self handled in-apps use selfHandledInAppViewShownWithCampaignID: method and provide campaign ID as parameter.
// Call this method when you show the self handled in-app so we can update impressions. Pass the campaign id of the campaign shown.
MoEngage.sharedInstance().selfHandledInAppViewShownWithCampaignID('campaignID')
// Call this method when you show the self handled in-app so we can update impressions. Pass the campaign id of the campaign shown.
[[MoEngage sharedInstance] selfHandledInAppViewShownWithCampaignID:'campaign id'];
For tracking InApp Clicked information for stats, call the following methods :
// Call this method to track if self handled in app Primary widget is clicked.
MoEngage.sharedInstance().selfHandledInAppClickedWithPrimaryActionAndCampaignID('campaignID')
// Call this method to track if self handled in app widget(other than Primary Widget) is clicked.
MoEngage.sharedInstance().selfHandledInAppClickedWithSecondaryActionAndCampaignID('campaignID')
// Call this method to track dismiss actions on the inApp.
MoEngage.sharedInstance().selfHandledInAppClickedWithDismissActionAndCampaignID('campaignID')
// Call this method to track if self handled in app Primary widget is clicked.
[[MoEngage sharedInstance] selfHandledInAppClickedWithPrimaryActionAndCampaignID:'campaign id'];
// Call this method to track if self handled in app widget(other than Primary Widget) is clicked.
[[MoEngage sharedInstance] selfHandledInAppClickedWithSecondaryActionAndCampaignID:'campaign id'];
// Call this method to track dismiss actions on the inApp.
[[MoEngage sharedInstance] selfHandledInAppClickedWithDismissActionAndCampaignID:'campaign id'];
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.
In-App Messaging Rules
We use the following rules while showing the In-App:
Rule 1: We check for the global delay between inApps . This comes as a property from the server, and configurable under Settings > InApp Nativ in the MoEngage dashboard (The default is set to 15 mins). If min delay has crossed go to the next step, else return. This rule is not applicable on Nudges.
Rule 2: Next we check if the InApp has expired or not. If it has not, then proceed to next rule else discard this inApp and check for other active InApp campaign.
Rule 3: Next we check the campaign level delay. If the delay (interval) between showing the same in-app has passed, go to the next rule. If not, then repeat from Step 2 for the next active InApp campaign.
Rule 4: Then we check if the in-app is already been clicked. —> Check if it’s a persistent in-app, if yes, continue to Rule 5, if not, check if Primary Widget is already clicked. If already clicked, repeat from Step 2 for the next active InApp campaign.
Rule 5: At last we check for max no. of times inApp can be shown. If max no. of times is not reached show the inApp, or else repeat from Step 2 for the next active InApp campaign.