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 | { |
Rated | { |
Responded | { |
Closed | { |
Still have any questions? Talk to us via live chat on your dashboard