Skip to content

Handle In-app Content

This setup allows NearIT to deliver and show notifications and content.

Request notification permission

Please, remember to request notification permission: no content will be delivered if user did not grant it.

NearIT.requestNotificationPermission({
  // optional
  explanation : "YOUR MESSAGE THAT EXPLAINS WHY YOU ARE REQUESTING THIS PERMISSION",

  dialogClosed: function(result) {
    if (result.notifications) {
      console.log("notifications permission granted!");
    }
  }
});

When a NearIT notification is tapped, the app is launched and a Titanium event will be emitted.

Listen for Events and Handle the content

To listen to NearIT events, just add a new EventListener to NearIT.

N.B: To access Events content we recommend to use the constants available from the module.

NearIT.addEventListener(NearIT.NEARIT_EVENTS, function(event) {
  var message = event.content.message;
  var trackingInfo = event.trackingInfo;
  var contentType = event.contentType;
  var content = event.content;
  switch (contentType) {
    case NearIT.SIMPLE:
      // it's a simple notification with no content
      break;
    case NearIT.CONTENT_NOTIFICATION:
      // show the content
      NearIT.showContent(event);
      break;
    case NearIT.FEEDBACK:
      // show the content
      NearIT.showContent(event);
      break;
    case NearIT.COUPON:
      // show the content
      NearIT.showContent(event);
      break;
    case NearIT.CUSTOM_JSON:
      // handle json
      break;
    default:
      // Content type unrecognized: this shouldn't happen
  }
});


NearIT Content events

Each event object is composed as follow

Field Description
contentType A string that describes the content type (see table below)
content An object that contains an event payload (see table below for specific object structure)
trackingInfo A string to use when sending trackings back to NearIT

Valid contentType values are:

NearIT.SIMPLE A NearIT simple notification
NearIT.CONTENT_NOTIFICATION A NearIT notification with Content
NearIT.FEEDBACK A NearIT notification with Feedback
NearIT.COUPON A NearIT notification with Coupon
NearIT.CUSTOM_JSON A NearIT Custom JSON

Content properties

  • For NearIT.SIMPLE
Field Description
message The notification text
  • For NearIT.CONTENT_NOTIFICATION
Field Description
message The notification text
title The content title (can be empty)
text The content text (can be empty)
image The content image resource object (can be empty), composed by fullSize and squareSize URLs
cta The content cta resource object (can be empty), composed by label and url
  • For NearIT.FEEDBACK
Field Description
message The notification text
feedbackId The feedbackId (required to send a Feedback answer)
question The question text

See below to learn how to send a Feedback answer to NearIT.

  • For NearIT.COUPON
Field Description
message The notification text
coupon The coupon object sent with the notification
  • For NearIT.CUSTOM_JSON
Field Description
message The notification text
data The json of the NearIT custom JSON notification


Notification History

If you want to show the user notification history, you can do it by calling the following method:

NearIT.showNotificationHistory();

Coupon History

NearIT.showCouponList();