Methods
Table of contents
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.
_sva.retarget();
Get visitor ID
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.
var visitorId = _sva.getVisitorId();
Note: The output of this method can be null
. As mentioned above, the value is assigned only to the visitors that have answered any question.
Set visitor traits
To set the visitor attributes asynchronously after the script is loaded, you can use the setVisitorTraits
method.
_sva.setVisitorTraits({
"email": "Respondent's email",
"first_name": "Respondent's name",
"last_name": "Respondent's last name",
"my_custom_attribute": "Custom attribute value"
});
Note: The visitor attributes will be updated locally straight away, but the change will be visible in Survicate as soon as they answer any question.
Reset visitor
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.
_sva.destroyVisitor(function() {
console.log('Visitor destroyed.');
});
You can optionally provide callback function as a first parameter that will be triggered after visitor cleanup.
_sva.destroyVisitor(_sva.retarget);
Note: This function will not trigger any survey for the “new” visitor, but you can always call the retarget
in callback function.
Show survey
For the customers that need a custom 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 ignores all targeting options, except checking whether this visitor has already answered the survey. 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).
_sva.showSurvey('abc1234');
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. Survey will be shown regardless whether visitor has already answered this 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’. |