Skip to content
Konstantin Antipochkin edited this page Nov 1, 2022 · 11 revisions

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"];