1. Home
  2. Embedded Survey

Embedded Survey

Survalyzer offers the possibility to integrate a survey into any webpage. The following section is a live example of an embedded survey.

To embed a survey into any webpage the following code is required:

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.11.2/css/all.css" integrity="sha384-KA6wR/X5RY4zFAHpv/CnoG2UW1uogYfdnP67Uv7eULvTveboZJg0qUpmJZb5VqzN" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://survalyzer.survalyzer.eu/assets/default/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://survalyzereu.blob.core.windows.net/public/assets/dx.common.css" />
<link rel="stylesheet" type="text/css" href="https://survalyzereu.blob.core.windows.net/public/assets/dx.light.css" />
<link href="https://survalyzer.survalyzer.eu/assets/themes/default/rt-theme.min.css" rel="stylesheet" type="text/css">
<survalyzer-survey surveyhash="elkxsnkosn" tenant="education"></survalyzer-survey>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
<script src="https://survalyzer.survalyzer.eu/assets/survalyzer-survey.js"></script>

Script location

Depending on the datacenter the scripts need to be loaded from different Urls:


<link href="https://survalyzer.survalyzer.swiss/assets/themes/default/rt-theme.min.css" rel="stylesheet" type="text/css">
<link href="https://survalyzer.survalyzer.swiss/assets/default/bootstrap.min.css" rel="stylesheet" type="text/css">
<script src="https://survalyzer.survalyzer.swiss/assets/survalyzer-survey.js"></script>


<link href="https://survalyzer.survalyzer.eu/assets/themes/default/rt-theme.min.css" rel="stylesheet" type="text/css">
<link href="https://survalyzer.survalyzer.eu/assets/default/bootstrap.min.css" rel="stylesheet" type="text/css" >
<script src="https://survalyzer.survalyzer.eu/assets/survalyzer-survey.js"></script>

Survey Tag parameters

The following parameters could be specified as attributes on the survalyzer-survey tag:

  • tenant* (The subdomain of the admin URL needs to be provided)
  • surveyHash* (The first segment of the interview URL needs to be provided)
  • interviewHash (The second segment of the interview URL could be provided for personal links)
  • interviewId (The guid of the interview to load a specific interview)
  • language (The desired language of the survey could be provided)
  • urlVariables (URL parameters like urlVar01 – urlVar20 could be provided as attributes)
  • token (A JWT panel member could be provided to prevent a second login in authenticated environments like portals)
  • scrollToTop (if not set, by default ‘true’. Controls the auto-scroll behavior after clicking ‘Next’ or ‘Back’. On some occasions the scroll to top on page switch creates a weird experience, depending on the position the survey is embedded. If set to false, the survey does not automatically scroll on page switch)

* this is a mandatory attribute

Survey API

This API allows to interact with the survey container using JavaScript.

FunctionDescriptionExample CallExample Result
answersGets or sets the answers of the surveyapi.fn.answers()
api.fn.answers({q1: “Test”, q2: 1});
{ q1: "Test", q2: 1}
changeLanguageChanges the survey language to the given languageapi.fn.changeLanguage(“de”)undefined
getCurrentLanguageGets the current survey languageapi.fn.getCurrentLanguage()“de”
goNextMoves survey to the next pageapi.fn.goNext()object
goBackMoves the survey to the previous pageapi.fn.goBack()object
submitCompletes the interviewapi.fn.submit()object
saveSaves answers without moving to another pageapi.fn.save()object
validateValidates the answers without moving to another pageapi.fn.validate(){ errors: []}
subscribeSubscribes for one of these events: next, back, completed, redirect, restarted, startedOrContinued, validationFailed, validationError, languageSwitchapi.events.subscribe(“next”, myHandler)undefined
unsubscribeUnsubscribes an event handlerapi.events.unsubscribe(myHandler);undefined
getPagesGets all pages of the surveyapi.fn.getPages()object
getCurrentPageIndexGets the index of the current pageapi.fn.getCurrentPageIndex()1
getCurrentPageGets the current page object out of the page collectionapi.fn.getCurrentPage()object

Embedding the Survey into a popup

In the right bottom corner the Popup with the question “Would you like to rate our website?” is shown.

To implement such a behavior the following 2 elements are needed:

<button onclick="javascript:showPopup()">Show Popup</button>
<div class="modal" id="popup" tabindex="-1">
  <div class="modal-dialog modal-dialog-centered modal-xl">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">How do you rate this article?</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
      <div id="modalContent" class="modal-body"></div>
function showPopup(){
   var dialog = $("#popup");
   $("#modalContent").html(`<survalyzer-survey surveyhash="djclovxsla" tenant="education" language="en"></survalyzer-survey>`);

Optional Javascript Snippet

The following script is optional and used if the pop up should close 10 seconds after the respondent submits the survey answers.

setTimeout(function () {
  api.events.subscribe('completed', function () {
    setTimeout(function () {
    }, 10 * 1000);
}, 1000);
Updated on March 7, 2023

Was this article helpful?