1. Segmanta Help Center
  2. Dynamic Embed & Website Surveys

Dynamic Embed - JavaScript API

Segmanta offers a Dynamic Embed SDK with capabilities to receive dynamic information about how a survey's Scenario is executed on your website.

Checking whether a respondent has reached the survey goal in a Scenario

You can request information on whether the survey goal in a specific Scenario has been reached for a respondent. This may be useful, for example, in enabling you to control elements on your front end website that show if a survey has been taken or not.

The following callback function

SEG_EMBED_API.hasCompletedScenarioSurvey({scenario_id}, callbackFn(), checkServerBoolean)

 

Returns with values true / false

The Scenario ID parameter is the number that identifies the scenario you are looking to check. It can be found in the URL when you create or edit a scenario:

In the above scenario configuration on the Dynamic embed dashboard, the URL is:

https://app.segmanta.com/dashboard/account/685/dynamic_embed/domain/29/scenario/101/ , therefore the Scenario ID is 101.

The checkServerBoolean parameter controls whether the check is to be made against the server side (true) or in the browser using the localStorage information available (false); this defaults to false.

For example, assuming your Scenario ID is 165, your call would resemble the below:

SEG_EMBED_API.hasCompletedScenarioSurvey(178, (hasResponded) => {
// hasResponded will be either true or false, insert logic here
}, true)

Calling the aforementioned method would return "true" if the respondent has reached the survey goal against the server side, or "false" if the goal has not been reached.

Event Emitter

The SEG_EMBED_API also exposes an "on" function, which takes an event name (detailed below) and passes back positioned parameters to expose information about "to what" happened. 

This event API looks like the following;

window.SEG_EMBED_API.on('SURVEY_GOAL_REACHED', (scenarioid, surveyid) => {
console.log(scenarioid, surveyid)
})

We currently publish 4 events, which we expose through this emitter;

SURVEY_GOAL_REACHED - The user completed the survey (or reached a predefined goal)
SCENARIO_SEEN_BY_USER - The survey popup appeared on the page.
PRE_SURVEY_DIALOG_NO - The user closed the dialog before starting the survey.
RESPONDENT_COMPLETED_SURVEY - The user completed the survey

Events SURVEY_GOAL_REACHED, SCENARIO_SEEN_BY_USER and PRE_SURVEY_DIALOG_NO publish the same information, which are exposed via positional parameters:

scenarioid => the Dynamic Embed Scenario ID that triggered the event
surveyid => the public survey id which was completed

Event RESPONDENT_COMPLETED_SURVEY publishes an additional positional parameter:

window.SEG_EMBED_API.on('RESPONDENT_COMPLETED_SURVEY', (scenarioid, surveyid, respondentData) => {
console.log(scenarioid, surveyid, respondentData)
})

respondentData => the Response ID corresponding to that respondent’s survey completion

Event Handler

The Event Handler enables you to add event listeners before the Dynamic Embed library is ready. Once the library is ready, it will pick up all registered event listeners. You will need to add the code below, just before you register the event listeners.

window.SEG_EMBED_API&&window.SEG_EMBED_API.q?window.SEG_EMBED_API=Object.assign(window.SEG_EMBED_API,{e:[],on:function(E,n){this.e.push({eventConstName:E,callback:n})}}):window.SEG_EMBED_API=window.SEG_EMBED_API||{e:[],on:function(E,n){this.e.push({eventConstName:E,callback:n})}};