Events
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.
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.
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.
Question answered
As soon as the visitor answers a question, Survicate emits the question_answered
event.
Example 1: Set a cookie after response to specific question
Example 2: Open Intercom messenger after response to specific question
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.
Survey closed
If at any stage of the survey, your visitor clicks the close button, Survicate will emit the survey_closed
event.
Script loaded
As soon as the Survicate script has been fully loaded and ready, you will be informed through the SurvicateReady
window event. This event is especially useful for the Single Page Applications / Progressive Web Applications.
Example: Reset visitor after script has been loaded
Note: Due its nature, unlike the other events, the SurvicateReady
event is attached to the window object and not the _sva
object.