NAV Navbar
JavaScript

JavaScript API

Introduction

Survicate library loaded on your page provides the _sva object that can be used to execute a number of helpful methods allowing the visitors and surveys management.

Methods

Retarget

_sva.retarget();

Survicate fires the visitors targeting script whenever there is a need to find out, whether there is a survey that should be displayed to your visitor, for instance on such events as page load, survey's completion or path change in your Single Page Application. If you'd like to trigger an additional targeting script execution, you can use the retarget method.

This feature can be especially useful for Single Page Applications / Progressive Web Applications or the callbacks of asynchronous methods.

Get visitor ID

var visitorId = _sva.getVisitorId();

As soon as your visitor answers any survey's question, we assign a unique ID to them. Feel free to keep your visitors using that ID using the getVisitorId method.

Reset visitor

_sva.destroyVisitor(function() {
    console.log('Visitor destroyed.');
});

To reset the visitor and let one be treated as a new respondent or answer one survey multiple times, you can use the destroyVisitor method. This method resets all visitor's data, including their attributes, sessions and answered surveys that are stored in their localStorage / sessionStorage. This method will not change any data that Survicate has already collected. If you wish to remove that data, please visit our app.

You can optionally provide callback function as a first parameter that will be triggered after visitor cleanup.

_sva.destroyVisitor(_sva.retarget);

Show survey

_sva.showSurvey('abc1234');

For the customers that need even more advanced targeting system, we provide the showSurvey method, that makes it easy to show an arbitrary survey based on the given survey's id. The method returns true if the survey was rendered and false otherwise (e.g. another survey is already displayed or the visitor has answered the desired survey).

var options = {
  forceDisplay: true,
  displayMethod: 'delayed',
  displayOptions: {
    delay: 5
  }
};

_sva.showSurvey('abc1234', options);

Optionally, to change the default behavior of the survey, you can provide the options object as the second parameter.

options

Property Type Description
forceDisplay boolean If true, currently rendered survey will be closed in favor of the new survey.
displayMethod string Use this option in order to overwrite the current displaying configuration. Possible values: ['immediately', 'delayed', 'exitIntent', 'onScroll'].
displayOptions object See below for available options. Applicable and required only for the displayMethod values 'delayed' and 'onScroll'.

displayOptions

Property Type Description
delay integer Delay in seconds. Applicable and required only for displayMethod = 'delayed'.
scrolledPercentage integer Percentage of the page that was already scrolled. Applicable and required only for displayMethod = 'onScroll'.

Support

👋 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.