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.

Add the following SDK for creating nudge templates, such as PIP Video & Native Display:

implementation("com.notifyvisitors.nudges:notifyvisitors-nudges:v0.0.8")

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)

If you want to have a callback, then implement the function below instead of the above.

NotifyVisitorsApi.getInstance(activityContext).show(null, null, null, new OnInAppTriggerListener() {
    @Override
     public void onDisplay(JSONObject response) {
             //do your task here
     }
});
NotifyVisitorsApi.getInstance(activityContext).show(null, null, null, object : OnInAppTriggerListener {
       override fun onDisplay(response: JSONObject) {
           //do your task here
       }
})

Callback Response

{
   “status”:“success”,
   “message”:“Found some active & inactive notifications.”,
   “type”:19.1,
   “notificationsShown”:[
      
   ],
   “notificationsNotShown”:[
      “4185”
   ]
}

In the above response, the STATUS field represents whether the banner/survey data was processed successfully or not, the MESSAGE field represents details of why the status failed and, the TYPE field is used for the SDK internal process. All other responses are mentioned in the table below.

status message type notificationsShown notificationsNotShown
success Found some active & inactive notifications. 19.1 [133,168] or [] [146] or []
fail No internet found 19.0
No banner|survey is active. If active on NV dashboard then kindly check DEBUG|LIVE mode of your app and mode in NV dashboard for active notifications. 19.3
Something went wrong with error -> 19.6, 19.5, 19.2
No data found regarding any banner/survey 19.4

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")

notificationClickCallback Listener (SDK v5.5.4+)

What this does (purpose):

Registers a callback that fires when a user taps a NotifyVisitors message that triggers openInAppScreen() or openDeeplink() from your campaign’s JS. Use it to route users to screens, process deeplinks, or read custom parameters.

Import

// Java
import com.notifyvisitors.notifyvisitors.interfaces.OnNotificationClicksHandler;
// Kotlin
import com.notifyvisitors.notifyvisitors.interfaces.OnNotificationClicksHandler

Register the listener

NotifyVisitorsApi.getInstance(context).notificationClickCallback(new OnNotificationClicksHandler() {
   @Override
   public void onClick(JSONObject response) {
       // do your work here
   }
});

NotifyVisitorsApi.getInstance(context).notificationClickCallback(OnNotificationClicksHandler { response ->
    // do your work here
})

Example callback payload (JSON)

{
  "notifyvisitors_cta": {
    "type": "banner",
    "source": "nv",
    "actionURL": "com.example..MainActivity",
    "target": 0,
    "callToAction": "1",
    "parameters": {
      "Nav_screen_attr1": "val1",
      "nav_screen_attr2": 100,
      "nav_screen_attr3": 123.11,
      "nav_screen_attr4": true}
  }
}

Description of Callback Payload Parameters

  • type (String): the template/source type of the message that was clicked (for example "push""inbox""banner").
  • source (String): the origin of the payload; this will always be "nv".
  • actionURL (String): the target URL or intent string to act on — this could be a web URL, an app activity/intent (for example com.example.app.MainActivity), or any deep link your campaign configured. Use this to route the user.
  • target (Integer): numeric code that indicates how to handle actionURL. Use the mapping below to decide behavior:
    • 0 — Navigate to App (open an activity/screen inside your app)
    • 1 — Navigate to Web (open a browser / webview with the URL)
    • 2 — Navigate to Third-Party App (launch an external app if installed)
    • 3 — Share (trigger platform share sheet)
    • 4 — Call (place a phone call)
    • 6 — Universal Link (open a platform-level universal/deferred link)
  • parameters (JSONObject): a map of custom key → value pairs you set as actionParams in the campaign. This is where you’ll find navigation attributes or any contextual data (e.g., { "Nav_screen_attr1": "val1", "nav_screen_attr2": 100 }). Read these values to populate screens, pass IDs, or decide routing logic.
  • callToImageIndex (Integer, optional): present when an image inside a carousel/slider was clicked. Values: 1 = first image, 2 = second image, 3 = third image.
  • callToAction (Integer, optional): indicates which CTA within a template was clicked. Values: 0 = default button, 1 = button one, 2 = button two.

What’s Next