In app - optimove-tech/Optimove-SDK-Flutter GitHub Wiki
Enabling In-App Messages
As mentioned in the initialization section In-App messaging is configured during initialization.
Your optimove.json
file should look something like this:
{
"optimoveCredentials": "YOUR_OPTIMOVE_CREDENTIALS",
"optimobileCredentials": "YOUR_OPTIMOVE_MOBILE_CREDENTIALS",
"inAppConsentStrategy": "in-app-disabled|auto-enroll|explicit-by-user",
"enableDeferredDeepLinking": false
}
Setting inAppConsentStrategy
to auto-enroll
will automatically enroll all your app users to be reachable by In-App messages, the SDK will automatically present and track opens.
Setting inAppConsentStrategy
to explicit-by-user
will give you the option to manually control the consent of a user. You can control the consent by calling the following method:
Optimove.inAppUpdateConsent(boolean)
Deep-linking for In-App
The following sample code shows how to use Optimove to control the in-app buttons:
Optimove.setInAppDeeplinkHandler((data) {
// Called when a user taps on an in-app button
}
Using the In-App Inbox
In-app messages can optionally be persisted in a user-level inbox for later retrieval. This allows you to build features such as loyalty rewards or expiring coupons into your app. Regardless of whether they are stored in the inbox, the maximum amount of in-apps stored on a device is 50 (the oldest messages exceeding this limit will be evicted).
Retrieve messages
To retrieve a list of messages from the user's inbox and present the first in the list, see the following example:
var items = await Optimove.getInboxItems();
Optimove.presentInboxMessage(items.first);
Mark as read
To mark a single or all inbox messages as read:
var items = await Optimove.inAppGetInboxItems();
//single
Optimove.inAppMarkAsRead(items.first);
//all
Optimove.inAppMarkAllInboxItemsAsRead();
Delete message
You can also delete an in-app message from inbox:
var items = await Optimove.inAppGetInboxItems();
Optimove.inAppDeleteMessageFromInbox(items.first);
Inbox updated handler
In order to be notified when inbox changes you may set up a handler. The handler fires on the UI thread when one of the following happens to an in-app with an inbox configuration:
- message fetched from server
- message opened
- message marked as read
- message deleted
- message evicted (expires or limit of stored messages exceeded)
You can use it as follows:
Optimove.setOnInboxUpdatedHandler(() {
_loadState();
});
Get inbox summary
You can retrieve an inbox summary as follows:
var summary = await Optimove.inAppGetInboxSummary();
Get inbox item's image URL
Each inbox item may have an image associated with it. You can retrieve image url by doing:
var items = await Optimove.inAppGetInboxItems();
String url = items.first["imageUrl"];
Controlling In-app Message Display
SDK version 3.3.0+
It is possible to temporarily pause & resume in-app message display. This can be useful to prevent in-apps showing on particular screens in your app or interrupting full-screen experiences.
There are two in-app display modes defined:
automatic
(the default): in-app messages are shown as soon as eligiblepaused
: in-app messages may be queued for display, but not shown to the user
If display is paused, and then set to automatic, display is considered 'resumed' and any messages queued whilst the display was paused will be shown to the user as normal.
Setting the display mode
You can use the following APIs to manipulate the in-app display mode:
Optimove.inAppSetDisplayMode(OptimoveInAppDisplayMode.paused)
Optimove.inAppSetDisplayMode(OptimoveInAppDisplayMode.automatic)
Changing display mode whilst an in-app message is showing will take effect once the current message is closed.
Attempting to present an inbox item whilst display is paused will return a status enum indicating that display is paused, and the item is not presented.
Setting a default display mode
If you don't want in-app messages to show whilst your app is loading, include in your optimove.json
initialization json
the inAppDisplayMode
with paused
value to pause in-app display by default:
{
...
"inAppDisplayMode": "paused"
}
Then, when you are ready to resume display, you can set the mode to automatic:
Optimove.inAppSetDisplayMode(OptimoveInAppDisplayMode.automatic)