Skip to content

Instantly share code, notes, and snippets.

@LuisPaGarcia
Created November 22, 2021 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuisPaGarcia/4e0da1d5f319333211d6999e13bf3337 to your computer and use it in GitHub Desktop.
Save LuisPaGarcia/4e0da1d5f319333211d6999e13bf3337 to your computer and use it in GitHub Desktop.
/* Map function to iterate over questions and add the `asertion` any */
function mapAgeGenderQuestionsAddAny(question) {
question.assertion = "any";
return question;
}
/* Reducer function to alter the props of the age_and_gender{_2} pages */
function reducerAgeAndGenderQuestion(questionProps) {
var tooltipValue = "You’ll miss out on certain plan types if you don’t submit your birth date and gender! If you only want to see Medicare Advantage, you can hit “Continue” to skip this question.";
var questions = questionProps.questions.map(mapAgeGenderQuestionsAddAny);
questionProps.tooltipHeadline = tooltipValue;
return Object.assign({}, questionProps, questions);
}
/* Function to trigger the kraken events since the begining */
function sendKrakenEvents() {
/* Get the HC session value */
var hcSession = window.hc.sem.storage.getHCStorage().healthcareSession;
/* Create the default kraken values for dob, age, and gender */
var eventsObj = {
"applicant.dob": "01/01/1900",
"applicant.age": 0,
"applicant.gender": "N/A",
};
/* Generate the timestap for the events */
var timestamp = (new Date()).toISOString();
/* Create the event structure for those 3 events */
var events = Object.keys( eventsObj ).map(function ( key ) {
return {
"topic": "healthcare.flow.survey.captured",
"payload": {
"sessionId": hcSession,
"on": timestamp,
"key": key,
"value": eventsObj[key]
}
};
});
/* Publish the kraken events using the Kraken-js lib */
window.kraken('publish', events);
}
window.executeWhenFinishToRender = window.executeWhenFinishToRender || [];
window.executeWhenFinishToRender.push(function () {
try {
/* Modified Flow */
var flow = {
age_and_gender: reducerAgeAndGenderQuestion,
age_and_gender_2: reducerAgeAndGenderQuestion,
};
/* Attach the flow to the modificators object */
var modificators = {
flow,
};
/* Execute the alter flow, using the modificators */
hcDynamic.push(["alterFlow", modificators]);
/* Send DOB, Gender, Age kraken events */
sendKrakenEvents();
} catch (error) {
/* Send error to raygun */
rg4js("send", {
error: error,
tags: ["env:prd", "company:hc", "vwo:1288", "variation:variation-1"],
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment