Class

Survey

Survey

Encapsulates the definition of the survey.

Classes

Survey

Members

string

# description

Survey's description to help better understand the goal and possible use cases of the survey. E.g. Survey to use after introducing various insurance plans to the visitor.

string

# id

Survey's ID.

string

# name

Survey's name.

object

# QUESTION_TYPES

Properties:
Name Type Description
BOOLEAN string Expects a JS boolean as a response
SCALE string Expects an integer from 1 to 5 as a response
SINGLE_CHOICE string Expects a choice ID as a response
TEXT string Expects a string as a response
Array.<SurveyQuestion>

# questions

List of questions included in the given survey. See SurveyQuestion for more info.

Example

Questions format

    {
      "questions":[
        {
          "id": "b123428e-9be8-4131-a8e7-8e28138fba1c",
          "type": "scale",
          "text": "The dealership",
          "name": "Question name",
          "required": false,
          "position": 0
        },
        {
          "id": "2cddcf52-6b7f-49b0-9276-7a57d7b1e570",
          "type": "boolean",
          "text": "This operator"
          "name": "Question name"
          "required": true,
          "position": 1
        },
        {
          "id": "79234723-5e39-4300-be62-a13aac0ea117",
          "type": "text",
          "text": "Other thoughts"
          "name": "Question name"
          "required": true,
          "position": 2
        },
        {
          "id": "27af1364-4d08-4f73-b621-87234b726ac2",
          "type": "single_choice",
          "text": "What was the order value",
          "name": "Question name"
          "required": false,
          "position": 3
          "options": [
            {id: "uuid", label: "Choice 1", is_default: false, position: 0},
            {id: "uuid", label: "Choice 2", is_default: true, position: 1},
            {id: "uuid", label: "Choice 3", is_default: false, position: 2}
          ],
        }
      ]
    }
string

# title

Survey's title as shown to the person who starts filling in the survey.

string

# type

Indicates which of the engagement's participants is supposed to answer the survey: operator or visitor.

Methods

# answer(answers) → {Promise}

Responds to a survey. See Survey#QUESTION_TYPES for required response types.

Parameters:
Name Type Description
answers Array An array with answers. Every answer is an Object containing question ID and response.
Fulfilled with an {success: true} object when successful or rejected with an {Error}.
Promise
Example

Respond to Survey

   const engagementRequest = glia.requestEngagement('text');

   engagementRequest.engagementPromise.then((engagement) => {
     engagement.addEventListener(engagement.EVENTS.END, () => {
       const gotSurvey = (survey) => {
         // show survey to the visitor

         // collect answers
         const answers = [
           {questionId: 'uuid', response: 'Yes'},
           {questionId: 'uuid', response: 2},
           {questionId: 'uuid', response: 2341},
           {questionId: 'uuid', response: 'Awesome'},
         ];

         survey
           .answer(answers)
           .then(() => { alert('Answers sent') })
           .catch(() => { alert('Error') });

         engagement.getSurvey().then(gotSurvey);
       };
     });
   });