Skip to content

Content Handling

Listen for Events and handle the content

To listen to NearIT events, add a listener:

this.eventsSubscription = NearIT.addContentsListener(event => {
    // Your events handling code here
});

N.B: Remember to unsubscribe from events (you'd want to do this when the component is unmounted)

NearIT.removeContentsListener(this.eventsSubscription)


NearIT Content events

N.B: To access Events content we recommend to use the NearITConstants available for import from react-native-nearit

import { NearItConstants } from 'react-native-nearit'

const { Events, EventContent } = NearItConstants


Each event object is composed as follow

Field Description
EventContent.type A string event type (see below table)
EventContent.content An object that contains an event payload (see below table for specific object structure)
EventContent.fromUserAction A boolean indicating wheter the notification comes from an user actions (such as a tap on a background notification)
EventContent.trackingInfo A string to use when sending trackings back to NearIT

Event types

Value Description
Events.SimpleNotification A NearIT simple notification
Events.Content A NearIT notification with Content
Events.Feedback A NearIT notification with Feedback
Events.Coupon A NearIT notification with Coupon
Events.CustomJson A NearIT Custom JSON

Events content

  • For Events.SimpleNotification
Field Description
EventContent.message The body of the NearIT simple notification
  • For Events.Content
Field Description
EventContent.message The body of the NearIT simple notification
EventContent.title The title content (can be empty)
EventContent.text The text content (can be empty)
EventContent.image The image resource (can be empty)
EventContent.cta The cta resource object (can be empty)
  • For Events.Feedback
Field Description
EventContent.message The body of the NearIT simple notification
EventContent.feedbackId The feedbackId required to send a Feedback answer
EventContent.question The question to be displayed to the user

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

  • For Events.Coupon
Field Description
EventContent.message The body of the NearIT simple notification
EventContent.coupon The coupon object sent with the notification
  • For Events.CustomJson
Field Description
EventContent.message The body of the NearIT simple notification
EventContent.data The json of the NearIT custom JSON notification


Send Feedback

NearIT allows you to send feedback requests and get answers from your users.

NearIT Feedbacks consist of 2 parts:

  • A rating, represented as an integer from 1 to 5
  • An optional comment

After displaying the Feedback request to your user and receiving his answer, you should send the answer to NearIT using the method below:

const rating = 5 // The rating index (0 to 5)
const comment = '' // The optional comment for the rating

const feedbackSent = await NearIT.sendFeedback(feedback, rating, comment);
// or without the comment
const  feedbackSent = await NearIT.sendFeedback(feedback, rating);