Skip to main content

Understanding NPS widget JS code of Pulse

Step by step guide to help you understand how NPS capture widget code works

Before we start looking at the possibilities of modifying the default JS of NPS widget, let's take a quick look at the default widget code provided by Pulse:

<!-- Pulse by Marmeto snippet START -->

<script>
window.pulseNPSConfig = {
surveyId: {{Pulse_NPS_survey_id}}, // Already added to your widget code by Pulse
userId: {{Unique_user_id}}, // To be added by you during implementation
userEmail: {{User_email}}, // To be added by you during implementation
userName: {{User_name}}, // To be added by you during implementation
customAttribute1: {{Any_value_of_your_choice}}, //Optional. You can add this if you want to send additional data with every NPS survey.
...
...
};
</script>
<script src="https://api.marmeto.org/pulse/scripts/nps-embed.js" defer></script>

<!-- Pulse by Marmeto snippet END -->

Key

Data type

Is it required

Description

surveyId

String

Yes

Pulse survey ID

userId

String

No

Your unique identifier to know who submitted the NPS score

Tip: Use anything which can help you understand your user quickly like their org-id or subdomain or any unique identity

userEmail

String

No

Email of the user submitting the score

userName

String

No

Name of the user submitting the score


Once the user submits a NPS survey, you might want to take actions or initiate other workflows based on their score. To make it happen, we also let you listen to events.

Using callback function

<script>
window.addEventListener('pulse:nps', (e) => {
const { event, surveyId, score } = e.detail;
console.log('[Pulse]', event, surveyId, score);
});
</script>

Example payload:

{
surveyId: "abc",
score: 9,
feedback: "Great product!",
userId: "123",
userEmail: "test@example.com"
}

Here is a quick explanation of all supported events and their payload:

Event

Payload

Opened

{

surveyId,
// A unique survey id

userId,
// Your user's id

userEmail,
// Your user's email

userName
// Your user's name

}

Rated

{

surveyId,
// A unique survey id

scoreid,
// Rating given by your user (Ranges from 0 to 10)

userId,
// Your user's id

userEmail,
// Your user's email

userName
// Your user's name

}

Responded

{

surveyId,
// A unique survey id

scoreid,
// Rating given by your user (Ranges from 0 to 10)

feedback_message,
// A feedback message added by user along with NPS score

responseId,
// A unique response id generated by Pulse

isFeedbackGiven
// A boolean value to let you know if the user gave any feedback.

userId,
// Your user's id

userEmail,
// Your user's email

userName
// Your user's name

}

Closed

{

surveyId,
// A unique survey id

reason,
// close_button or overlay_click or esc_key

userId,
// Your user's id

userEmail,
// Your user's email

userName,
// Your user's name

}

Still have any questions? Talk to us via live chat on your dashboard

Did this answer your question?