Skip to content

Handle In-app Content

NearIT takes care of delivering content at the right time, you will just need to request notification permission and handle content presentation.

Request notification permission

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

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

Listen for Events

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

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


Feedbacks

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

NearIT Feedbacks consist of 2 parts:

  • A rating, represented as an integer from 0 to 5
  • An optional comment, to allow your user to comment on a rating

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

import NearIT from 'react-native-nearit'

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

const feedbackSent = await NearIT.sendFeedback(feedbackId, rating, comment) // Full method call
// or
const  feedbackSent = await NearIT.sendFeedback(feedbackId, rating) // Method call without comment string


Trackings

NearIT analytics on recipes are built from trackings describing the status of user engagement with a recipe.

The two recipe states are "Received" and "Opened" to represent a recipe delivered to the user and a recipe that the user responded to.

N.B: Built-in background recipes (displayed when the app is not foreground) track themselves as notified and engaged.

Foreground recipes don't have automatic tracking. You need to track both the "Received" and the "Opened" statuses when it's the best appropriate for you scenario.

import NearIT, { NearItConstants } from 'react-native-nearit'
const { Statuses } = NearItConstants

...

NearIT.sendTracking(trackingInfo, Statuses.received); // Track recipe as 'Received'

NearIT.sendTracking(trackingInfo, Statuses.opened); // Track recipe as 'Opened'

NearIT.sendTracking(trackingInfo, 'custom-event'); // Track a custom event to the recipe

N.B: The recipe cooldown feature uses tracking calls to hook its functionality, so failing to properly track user interactions will result in the cooldown not being applied.


Fetch current user coupons

We handle the complete emission and redemption coupon cycle in our platform, and we deliver a coupon content only when a coupon is emitted (you will not be notified of recipes when a profile has already received the coupon, even if the coupon is still valid).

You can ask the library to fetch the list of all the user current coupons with the method:

import NearIT from 'react-native-nearit'

...

const coupons = await NearIT.getCoupons() // Will return an array of coupon objects

The method will also return already redeemed coupons so you get to decide to filter them if necessary.