Skip to content

Content Handling

Listen for Events and handle the content

To listen to NearIT events, add a listener:

nearit.addEventListener(function(event) {
  // handle the content obtaining values from the `event` object
})


The event object will contain the following fields

Name Description
trackingInfo A string to use when sending trackings back to NearIT
message Contains notification message
type A string that identifies the type of NearIT content (see table below)

Type

Content Type EventType
Simple Notification nearit.eventType.CDVNE_Event_Simple
CustomJSON nearit.eventType.CDVNE_Event_CustomJSON
Content nearit.eventType.CDVNE_Event_Content
Feedback nearit.eventType.CDVNE_Event_Feedback
Coupon nearit.eventType.CDVNE_Event_Coupon

Other properties are specific to the content type:

Simple Notification

{
    trackingInfo: "...",
    message: "sample Simple message event notification"
}

Content

{
    trackingInfo: "...",
    message: "sample Content event notification",
    title: "This is the content title",
    text: "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>",
    image: {
        small: "https://placehold.it/300x300",
        full: "https://placehold.it/1920x1080"
    },
    cta: {
        label: "Click me!",
        url: "https://placehold.it/1920x1080"
    }
}

Feedback request

{
    trackingInfo: "...",
    message: "sample Feedback event notification",
    feedbackId: "...",
    question: "In a world without walls and fences, who needs windows and gates?"
}

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

CustomJSON

{
    trackingInfo: "...",
    message: "sample Custom JSON event notification",
    data: {
      'this': 'is',
      'a': 'json'
    }
}

Coupon

{
    trackingInfo: "...",
    message: "sample Coupon event notification",
    coupon: {
      title: "test coupon",
      description: "description",
      value: "120",
      expiresAt: "2018-12-21 09:00:00",
      redeemableFrom: "2017-09-21 09:00:00",
      serial: "123456",
      claimedAt: "2017-09-28 09:00:00",
      redeemedAt: "2017-09-28 16:00:00",
      image: {
        fullSize: "http://via.placeholder.com/750x350",
        squareSize: "http://via.placeholder.com/300x300"
      }
    }
}

N.B.: We handle the complete coupon emission and redemption cycle in our platform. We deliver each coupon content only once, when that coupon is emitted.


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 (1 to 5)
const comment = '' // The optional comment for the rating

nearit.sendFeedbackWithComment(
    feedbackId,
    rating,
    comment,
    function() {
        console.log("successfully sent feedback");
    }, function(){
        console.log("failed sending feedback");
    }
);

// OR

nearit.sendFeedback(
    feedbackId,
    rating,
    function() {
        console.log("successfully sent feedback");
    },
    function(){
        console.log("failed sending feedback");
    }
);