Link Search Menu Expand Document

Events

Table of contents

  1. Survey displayed
  2. Question answered
  3. Survey completed
  4. Survey closed
  5. Script loaded

Survicate provides a number of events that you might find useful to trigger certain actions in your application based on the visitor’s actions. You can set up listeners to hook into these events. By calling the _sva.addEventListener method multiple times, you can set up more than one listener for a given event.

var listenerId = _sva.addEventListener('event', callback);

If you don’t need the listener anymore, you can use _sva.removeEventListener method to remove the previously registered listener. It is possible to remove either all the listeners that are hooked into a given event or a single listener based on the listenerId returned from the _sva.addEventListener method.

// Remove an event listener based on its id
_sva.removeEventListener(listenerId); 
  
// Remove all listeners hooked into a given event
_sva.removeEventListener('question_answered');

Note: All events are emitted asynchronously - we cannot guarantee that the event has already been reflected in Survicate at the time of the emission. For instance, an answer for a certain question might not be present in Survicate yet.


Survey displayed

Every display of a survey is followed by the survey_displayed event emission.

_sva.addEventListener('survey_displayed', function(surveyId) {
  // do stuff
});

Question answered

As soon as the visitor answers a question, Survicate emits the question_answered event.

_sva.addEventListener('question_answered', function(surveyId, questionId, answer) {
  // do stuff
});
_sva.addEventListener('question_answered', function(surveyId, questionId, answer) {
  if (questionId == 1234) { //replace 1234 with your question ID
    document.cookie = "surveyAnswered=true; expires=Fri, 31 Dec 9999 23:59:59 GMT"; 
  }
});

Example 2: Open Intercom messenger after response to specific question

_sva.addEventListener('question_answered', function(surveyId, questionId, answer) {
  if (questionId == 1234) { //replace 1234 with your question ID
    Intercom('showNewMessage', 'pre-populated content'); //replace pre-populated content with your content
  }
});

Answer object properties

Property Type Description    
answer_type string Answer type.    
answer_id integer Answer ID. Applicable only for type = [‘single’, ‘smiley_scale’, ‘dropdown_list’].    
answer_ids integer[] Array of answer IDs. Applicable only for type = [‘multiple’].    
answer_value string Context value of the answer. Applicable only for type = [‘text’, ‘nps’, ‘date’, ‘rating’].    

Note: At the moment we support passing the answer_id, answer_ids and answer_value properties only for the cases enlisted in the table above. Therefore, expect that there might be answer objects that consist only of the answer_type property.


Survey completed

Once a survey has been completed, Survicate emits the survey_completed event. Survey is considered to be completed, when a visitor has answered every single question that was displayed to them in the configured flow.

_sva.addEventListener('survey_completed', function(surveyId) {
  // do stuff
});

Survey closed

If at any stage of the survey, your visitor clicks the close button, Survicate will emit the survey_closed event.

_sva.addEventListener('survey_closed', function(surveyId) {
  // do stuff
});

Script loaded

As soon as the Survicate script has been fully loaded and ready, you will be informed through the SurvicateReadywindow event. This event is especially useful for the Single Page Applications / Progressive Web Applications.

window.addEventListener('SurvicateReady', function() {
  // do stuff
});

Example: Reset visitor after script has been loaded

window.addEventListener('SurvicateReady', function() {
  _sva.destroyVisitor(_sva.retarget);
});

Note: Due its nature, unlike the other events, the SurvicateReady event is attached to the window object and not the _sva object.

← Methods


👋 If you bump into any problems or need more support, just start a conversation using Intercom in the bottom-right corner and you will be immediately routed to our Customer Support Engineers.