Skip to content

Advanced Notification History

If you want to show the notification history with your own UI, just call the following method to get the history:

nearit.getNotificationHistory(function(items) {
  // iterate over the array of notification items
}, function(error) {
  // there was an error fetching the notification history
});

Each item has the following properties:

Name Description
read true if it has been read, false otherwise.
timestamp Epoch (in seconds).
trackingInfo A string to use when sending trackings back to NearIT.
message The notification message.
type A string that identifies the type of NearIT content.
notificationContent The content.
isNew a boolean representing whether the notification is new for the user. Its value is the same as read, unless you use markNotificationHistoryAsOld to mark all previous notifications as old. See the Updates chapter to learn more.

notificationContent object follows the structure described in the previous section.

Updates

To get notified on updates for history notifications, you can set a listener:

nearit.setNotificationHistoryUpdateListener(function(items) {
  console.log(`Notification history update! Count: ${items.filter(item => item.isNew).length}`)
});

If you want to update a badge you should use the isNew field to count new notifications. By default, this field will be the same as read, so any tracking regarding the item can change its value. If you want to manually set all the notification as acknowledged (meaning that isNew will be false), without loosing the read information or tracking every single notification interaction, you can call this method:

nearit.markNotificationHistoryAsOld();