Skip to content

Instantly share code, notes, and snippets.

@unity
Last active August 10, 2018 14:47
Show Gist options
  • Save unity/9fbab6e1c66888f7535ea8d8cf7c387c to your computer and use it in GitHub Desktop.
Save unity/9fbab6e1c66888f7535ea8d8cf7c387c to your computer and use it in GitHub Desktop.
Writes an attribute at the user level indicating the direction the NPS score is going. This way you can easily find all users who are decreasing in nps rating
//Returns the category of the customer based on the NPS score,
const getCategory = nps => {
if (nps > 8) return "promoter";
if (nps > 6) return "passive";
return "detractor";
}
if (changes && changes.user) {
const { nps_rating } = changes.user;
// If the NPS Rating Changes
if (nps_rating[0]!==undefined) {
hull.traits({
// Tells you if the latest score was an increase or a drecrease.
direction: nps_rating[1] > nps_rating[0] ? "increase" : "decrease"
category: getCategory(nps_rating[1])
}, { source: "nps" });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment