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.
SDK Version
Follow this doc only if you are using
MoEngage-iOS-SDK
version6.0.0
and above. If you are using version 5.2.7 or less then follow the doc in this link.
From MoEngage-iOS-SDK
version 6.0.0 InApp module is separated from the SDK to a separate module MoEngageInApp
and hence has to be added separately. Include MoEngageInApp
pod to your Pod file as shown below:
pod 'MoEngageInApp','~> 2.0.0'
Manual Integration:
To integrate the
MoEngageInApp
SDK manually to your project follow this doc.
To use In-app Messaging, add the code below to the view controller(s) in which you want to show the In-app.
MOInApp.sharedInstance().show()
[[MOInApp sharedInstance] showInApp];
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.
nudgeCampaignShown()
as shown in below example: // Get the nudge view using the method:
MOInApp.sharedInstance().getNudgeView { (nudgeView, campaignInfo) 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!);
}
}
[[MOInApp sharedInstance] getNudgeViewWithCompletionBlock:^(UIView * _Nullable nudgeView, MOInAppCampaign * _Nullable campaignInfo) {
if (nudgeView && campaignInfo) {
// Campaign Info
NSLog(@"Nudge View with Campaign ID (%@) and Campaign Name(%@)",campaignInfo.campaign_id,campaignInfo.campaign_id);
// Set Frame
CGRect frame = nudgeView.frame;
frame.origin.y = ([[UIScreen mainScreen] bounds].size.height - frame.size.height)/2.0;
frame.origin.x = 0.0;
nudgeView.frame = frame;
// Attach Nudge View
[self.view addSubview:nudgeView];
// Track Impression
[[MOInApp sharedInstance] nudgeCampaignShownWithCampaignInfo:campaignInfo];
}
}];
//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)
//For showing nudges at Top of the screen
[[MOInApp sharedInstance] showNudgeAtPosition:NudgePositionTop];
//OR
//For showing nudges at Bottom of the screen
[[MOInApp sharedInstance] showNudgeAtPosition:NudgePositionBottom];
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:
MOInApp.sharedInstance().inAppDelegate = self;
[MOInApp sharedInstance].inAppDelegate = self;
Once the delegate is set you will receive the following callbacks:
// Called when an inApp is shown on the screen
func inAppShown(withCampaignInfo inappCampaign: MOInAppCampaign) {
print("InApp Shown with Campaign ID \(inappCampaign.campaign_id)")
}
// Called when an inApp is dismissed by the user
func inAppDismissed(withCampaignInfo inappCampaign: MOInAppCampaign) {
print("InApp Dismissed with Campaign ID \(inappCampaign.campaign_id)")
}
// 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) {
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) {
print("InApp Clicked with Campaign ID \(inappCampaign.campaign_id)")
print("Navigation Action Screen Name \(navigationAction.screenName) Key Value Pairs: \((navigationAction.keyValuePairs))")
}
// Called when an inApp is shown on the screen
-(void)inAppShownWithCampaignInfo:(MOInAppCampaign *)inappCampaign{
NSLog(@"InApp Shown with Campaign ID %@",inappCampaign.campaign_id);
}
// Called when an inApp is dismissed by the user
-(void)inAppDismissedWithCampaignInfo:(MOInAppCampaign *)inappCampaign{
NSLog(@"InApp Dismissed with Campaign ID %@",inappCampaign.campaign_id);
}
// Called when an inApp is clicked by the user, and it has been configured with a custom action
-(void)inAppClickedWithCampaignInfo:(MOInAppCampaign *)inappCampaign andCustomActionInfo:(MOInAppAction *)customAction{
NSLog(@"InApp Clicked with Campaign ID %@",inappCampaign.campaign_id);
NSLog(@"Custom Action Key Value Pairs: %@", customAction.screenName);
}
// Called when an inApp is clicked by the user, and it has been configured with a navigation action
-(void)inAppClickedWithCampaignInfo:(MOInAppCampaign *)inappCampaign andNavigationActionInfo:(MOInAppAction *)navigationAction{
NSLog(@"InApp Clicked with Campaign ID %@",inappCampaign.campaign_id);
NSLog(@"Navigation Action Screen Name %@\n Key Value Pairs: %@", navigationAction.screenName,navigationAction.keyValuePairs);
}
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.
To set the current context for inApp module use setCurrentInAppContexts()
method as shown below:
MOInApp.sharedInstance().setCurrentInAppContexts(["Home","CategoriesScreen"])
[[MOInApp sharedInstance] setCurrentInAppContexts:@[@"Home",@"CategoriesScreen"]];
To reset the current context for inApp module call invalidateInAppContexts()
method:
MOInApp.sharedInstance().invalidateInAppContexts()
[[MOInApp sharedInstance] invalidateInAppContexts];
If you don't want to show inApp messages in a particular ViewController, use blockInAppInViewController:
method as shown below:
//For not showing in apps in viewController
MOInApp.sharedInstance().blockInApp(in: viewController);
//For not showing in apps in viewController
[[MOInApp sharedInstance] blockInAppInViewController:viewController];
If you do not wish to use in app messaging, set the property disableInApps. The property has to be set before the initialize call.
MOInApp.sharedInstance().disableInApps()
[[MOInApp sharedInstance] disableInApps];
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.
MOInApp.sharedInstance().getSelfHandledInApp { (campaignInfo) 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")
}
}
[[MOInApp sharedInstance] getSelfHandledInAppWithCompletionBlock:^(MOInAppSelfHandledCampaign * _Nullable campaignInfo) {
if (campaignInfo != nil) {
NSLog(@"Self Handled inApp content : %@", campaignInfo.campaignContent);
// Update UI using the self-handled content
}
else{
NSLog(@"Self-Handled InApp not 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 :
// 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) {
print("Self Handled InApp Triggered with info:\nCampaign ID:\(inappCampaign.campaign_id) \nContent: \(inappCampaign.campaignContent)")
}
// This method is called when an event triggers an in-app from the server, which is of type self handled.
-(void)selfHandledInAppTriggeredWithInfo:(MOInAppSelfHandledCampaign *)inappCampaign{
NSLog(@"Self Handled InApp Triggered with info:\nCampaign ID: %@ \nContent: %@",inappCampaign.campaign_id, inappCampaign.campaignContent);
}
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:
// Call this method when you show the self handled in-app so we can update impressions.
MOInApp.sharedInstance().selfHandledShown(withCampaignInfo: cmpInfo)
// Call this method when you show the self handled in-app so we can update impressions.
[[MOInApp sharedInstance] selfHandledShownWithCampaignInfo:campInfo];
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.
MOInApp.sharedInstance().selfHandledPrimaryClicked(withCampaignInfo: cmpInfo)
// 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)
// Call this method to track if self handled in app Primary widget is clicked.
[[MOInApp sharedInstance] selfHandledPrimaryClickedWithCampaignInfo:campInfo];
// Call this method to track if self handled in app widget(other than Primary Widget) is clicked.
[[MOInApp sharedInstance] selfHandledClickedWithCampaignInfo:campInfo];
// Call this method to track dismiss actions on the inApp.
[[MOInApp sharedInstance] selfHandledDismissedWithCampaignInfo:campInfo];
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.
We use the following rules while showing the In-App:
Preconditions for inApp to work:
Following are checked for each campaign in the list of active campaigns(sorted according to priority and Last Updated Time)
Ignore Global Delay
set for the campaign.The first campaign satisfying all the rules is shown to the user.
Updated 2 months ago