Created
June 1, 2018 17:45
-
-
Save unity/8c552d7003419e5ee5989a3502021d94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create an array of all the points we give | |
const scores = []; | |
//Helper method to push to the scores array. | |
const addToScore = points => points && scores.push(points); | |
//Scoring based on User Attributes. | |
const { | |
is_beta, | |
is_invited, | |
trial_expired, | |
embed_code_installed, | |
trial_length, | |
totalcustomproperties, | |
account_domains, | |
total_flows, | |
} = user.traits; | |
if (is_beta === true) addToScore(3); | |
if (trial_expired === true) addToScore(-1); | |
if (embed_code_installed === true) addToScore(8); | |
if (trial_length && trial_length > 14) addToScore(3); | |
if (is_invited === true) addToScore(5); | |
if (account_domains.length === 1) addToScore(-1); | |
if (total_flows) { | |
if (total_flows >= 5) { | |
addToScore(total_flows*15) | |
} else if (total_flows >= 3) { | |
addToScore(total_flows*5); | |
} else { | |
addToScore(total_flows*2); | |
} | |
} | |
//compute total score based on attribute from scratch, | |
//and save as an attribute. | |
if(scores.length>0) { | |
const total = _.sum(scores); | |
hull.traits({ | |
attribute_score: total | |
}); | |
} | |
//Scoring based on User Events | |
//Another way to do so, just use a number... | |
const event_score = 0; | |
//Loop over every event | |
events.map(e => { | |
const { event, properties, context } = e // event: "Email Opened" | |
if (event === "Email Opened") event_score += 2; | |
if (event === "Requested Demo" && properties.optin===true) event_score += 3; | |
}); | |
// Take care. Here we INCREMENT the score instead of resetting it... | |
// We do this with the {operation: "inc", value:xxx} hash | |
// And we do it because the Processor does NOT go over every event, | |
// But rather only over the NEW events when it runs. | |
if (event_score!==0) { | |
hull.traits({ | |
event_score: { operation: "inc", value: event_score } | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment