In-app Notifications

Configure target rules for in-app notifications.

In-app Messaging includes both Banners and Surveys. They are displayed on the basis of user activities on android.

Every event occurs in the context of an Activity. Every activity can be associated with some contextual data, which can be used as targeting rules for In-app Messaging.

To display banners or surveys in your app, integrate the following code, which should be used only once per activity.

NotifyVisitorsApi.getInstance(activityContext).show(tokens (JSONObject), customObjects (JSONObject), fragmentName (String));
NotifyVisitorsApi.getInstance(activityContext).show(tokens: JSONObject?, customObjects: JSONObject?, fragmentName: String?)

Refer to the following example,

NotifyVisitorsApi.getInstance(activityContext).show(null, null, null);
NotifyVisitorsApi.getInstance(activityContext).show(null, null, null)

DYNAMIC TOKENS (JSON Object)

Dynamic tokens are used to show personalized content in Notification messages in real time.

JSONObject tokens = new JSONObject();
try {
    tokens.put("Budget", "CAD $300,000 to $600,000");
    tokens.put("ProjectName", "| New Development | Kings Landing Condos |");
} catch (JSONException e) {
    e.printStackTrace();
}
val tokens = JSONObject()
try {
   tokens.put("Budget", "CAD $300,000 to $600,000")
   tokens.put("ProjectName", "| New Development | Kings Landing Condos |")
} catch (e: JSONException) {
   e.printStackTrace()
}

CUSTOM RULES (JSON Object)

This data can be used in configuring targeting rules for the Notifications.

JSONObject customObj = new JSONObject();
try {
    customObj.put("test","abc");
    customObj.put("PAGE_ID", "DASHBOARD");
} catch (JSONException e) {
    e.printStackTrace();
}
val customObj = JSONObject()
try {
   customObj.put("test","abc")
   customObj.put("PAGE_ID", "DASHBOARD")
} catch (e: JSONException) {
   e.printStackTrace()
}

FRAGMENT NAME (string)

If you have multiple fragment tabs in your activity, you can use this method for each fragment and pass the fragment name as the third argument.

NotifyVisitorsApi.getInstance(activityContext).show(null, null, “thirdFragment”);
NotifyVisitorsApi.getInstance(activityContext).show(null, null, “thirdFragment”)

In-app Notifications Response Callback

If you want to get callback data whenever the user clicks on in-app banners or fill-up surveys then implement the below callback method-

NotifyVisitorsApi.getInstance(activityContext).getEventResponse(new OnEventTrackListener() {
  @Override
   public void onResponse(JSONObject jsonObject) {
          // do your task
   }
});
NotifyVisitorsApi.getInstance(this).getEventResponse(object : OnEventTrackListener{
   override fun onResponse(data: JSONObject?) {
       //do your task here
   }
})

This callback will provide you output in JSON format. Sample output is shared below-

{
   "status":"success",
   "eventName":"Survey Submit",
   "message":"Survey submitted successfully.",
   "type":14.3,
   "callbackType":"survey"
}

In the above output, the parameters have different values depending on the scenario that occurs when displaying banners or surveys. Below are the different values you can get in the callback:

STATUS
EVENT NAME
MESSAGE
TYPE
CALLBACK TYPE
Success


Banner Clicked

InApp banner clicked.
15.0 to 15.11, 15.15, 15.16
Banner

Banner Impression

InApp banner shown.
15.12, 15.13, 15.14, 15.17, 15.18

Survey Attempt

Survey attempted successfully.
14.0, 14.2
Survey

Survey Submit

Survey submitted successfully.
14.1, 14.3

Navigate to webpage through in-app banner

The undermentioned function can be triggered to navigate to the webpage:

NV.openWeb("Link / User Token")

What’s Next