Events

A JavaScript API for observing the Question Stream

Fairing offers an event based JavaScript API for reporting on key moments of the Question Stream. You can subscribe to events using window.addEventListener (See MDN Web Docs). An event listener callback will receive a CustomEvent object with an event.detail property containing information regarding the Question Stream status. The available events are the following:

Event: fairing.questionStream.initialized

This event fires when the Fairing script is first initialized, before any questions are displayed.

window.addEventListener('fairing.questionStream.initialized', (event) => {
  const {
    initialization_time_ms
  } = event.detail;
  console.log(event.detail);
});

This event's event.detail contains the following:

  • initialization_time_ms: The time in milliseconds from DOMContentLoaded to when the Question Stream initialized

Event: fairing.question.displayed

This event fires each time a question is displayed.

window.addEventListener('fairing.question.displayed', (event) => {
  const {
    available_responses,
    customer_id,
    display_time_ms,
    order_id,
    question,
    question_id,
  } = event.detail;
  console.log(event.detail);
});

This event's event.detail contains the following:

  • available_responses: An array of text of each option displayed.
  • customer_id: The customer id.
  • display_time_ms: The duration in milliseconds from when a question was requested to being displayed.
  • order_id: The order id.
  • question: The question prompt.
  • question_id: The quesiton id.

Event: fairing.question.answered

This event fires each time a customer responds to a question.

window.addEventListener('fairing.question.answered', (event) => {
  const {
    available_responses,
    customer_id,
    order_id,
    other,
    other_text,
    question,
    question_id,
    referring_question_id,
    response,
    response_time_ms,
  } = event.detail;
  console.log(event.detail);
});

This event's event.detail contains the following:

  • available_responses: An array of text of each option displayed.
  • customer_id: The customer id.
  • order_id: The order id.
  • other: A boolean value of whether the response is an "other" response.
  • other_text: The value of the "other" option entered by the customer. Also contains the contents of Date and OpenEnded response values.
  • question: The question prompt.
  • question_id: The question id.
  • referring_question_id: If the question is a follow-up, this will contain the referring question's id.
  • response: An array of single or multiple responses.
  • response_time_ms: The time in milliseconds from when the question was displayed to when the question was answered.

Event: fairing.questionStream.completed

This event fires when a customer reaches the end of the Question Stream.

window.addEventListener('fairing.questionStream.completed', (event) => {
  const {
    total_questions_answered,
    time_to_complete_ms,
  } = event.detail;
  console.log(event.detail);
});

This event's event.detail contains the following:

  • total_questions_answered: The number of questions responded to.
  • time_to_complete_ms: The duration in milliseconds from fairing.questionStream.initialized to when the customer completed the Question Stream.

Event: fairing.questionStream.noQuestions

This event fires when there aren't questions to show to the customer.

window.addEventListener('fairing.questionStream.noQuestions', (event) => {
  const {
    order_id,
  } = event.detail;
  console.log(event.detail);
});

This event's event.detail contains the following:

  • order_id: The order id.