Integrate the Entire Survey Life-cycle into Your Web Application

5,463 reads

You can use SurveyJS as a regular end-user product — a separate cloud-based solution with complete survey life-cycle management. You can also take any part of SurveyJS and make it yours — integrate our UI widgets into your site, make our engine work with your custom storage, or communicate with our back-end via API.

To demonstrate what’s possible with SurveyJS, we’ve created demos for three popular web development platforms — ASP.NET Core, PHP and Node.js. The apps show how you can embed any part of survey management — from data management and builder UI to execution and result analysis — into your own website. Each demo has a link to its GitHub repository too, so you can check out the sources.

Those integration features set SurveyJS apart from other products. You can tailor a solution for any requirements by simply putting the pieces together in a way that benefits your application the most.

Before I cover the integration basics for each part of SurveyJS, I’ll quickly go over the three most common integration strategies and their respective benefits. While the first two are common enough, the last one is where SurveyJS is unrivaled.

Integration Level Zero: All in the Cloud

No integration happens at this level — everything from survey creation and execution to data analysis happens on a third party site. This scenario is so straightforward that the diagram only serves to introduce the building blocks of any survey system.

Benefits:

Zero integration effort / suits users with no programming experience.

Works well with email campaigns.

This model naturally assumes monthly or annual billing cycles, but SurveyJS so far remains completely free to use in this scenario.

Integration Level One: Front-End (Runner)

In this scenario, the parts of the survey visible to end-users are integrated into your application. In other words, the users never have to leave your website and the UI is consistent throughout. Normally, you also get some sort of data access API.

Benefits:

You can use a Survey Library beyond the usual purposes of a questionnaire or a quiz. For example, you can build an order form.

Complete customization to match your website’s visual appearance. No unexpected changes when a new service version rolls out.

Capability to restrict execution based on your website’s login details.

SurveyJS fully supports this level of integration and remains free to use.

Integration Level Two: Back-End (Data Source and Builder UI)

This is the integration level few products are capable of delivering. It allows you to manage any part of survey life-cycle within your application. You can store data in a database of your choice, you can customize the survey builder and embed it into your own website, you can communicate with the back-end via API, and so on.

(I replaced the “ANALYSIS UI” block with “RESPONSE VIEWER”, since we haven’t yet implemented full-scale data analysis dashboard for SurveyJS. You can still access results and build your own UI, as I show in a simple example later in the article)

Benefits:

You can let your employees design surveys using your custom Builder UI. In the modified builder, you can add new question types, remove unnecessary options, and so on.

You can use data from your own sources to construct questions.

You can store data on your own servers, using the database management system of your choice.

We’ve come to the only part of SurveyJS that currently requires a paid license. To integrate Survey Builder UI into a commercial application, you’ll need to purchase the library. It remains free for non-commercial use.

Now that I’m done listing what you can integrate, let’s proceed to how.

Integrate the Front-end: Survey Runner

We covered Survey Runner’s capabilities at length in our previous articles: Meet SurveyJS and SurveyJS is out of Beta. Our website also contains tons of examples on how to create and integrate a Runner when working with different client platforms: Angular 2+, jQuery, Knockout, React, and Vue.js.

Even if you’re working with a custom-built survey storage, the workflow is straightforward:

Load survey definition in JSON format from your storage.

Use it to create the Survey Runner JavaScript object (as shown in our examples).

On completing the survey, save the JSON with results into your storage.

Integrate the Back-end: Survey Editor

The simplest implementation of Survey back-end will have the following elements:

A page with the list of surveys.

The capability to create or remove entries.

Build/edit surveys using an integrated Editor UI.

Review and analyze survey results.

Security system enabling roles and permissions.

There is nothing complicated about displaying and managing a list of survey objects. The most interesting task is integrating the Survey Builder/Editor.

As any other survey service, we’ve implemented our own End-User Builder UI. Unlike other providers, we allow you to obtain this Editor UI as a widget, customize it, and integrate it into your own website, as shown in this Integrated Survey Editor Example.

Integrated SurveyJS Editor

The basic code required for such integration is shown below. It loads and saves survey definition using a local storage. Review our Plunker example to see this code in action.

var storageName = "TestSurvey";

// Create a Survey Editor with default options

var editorOptions = { };

editor = new SurveyEditor.SurveyEditor("editorElement", editorOptions);

// Enable state indication (Saving, Loading, etc) in the toolbar

editor.showState = true;

// Call saveSurveyFunc automatically on changes

// Otherwise a user will need to manually click "Save"

editor.isAutoSave = true;

// A callback function invoked when you must save changes

editor.saveSurveyFunc = function(saveNo, callback) {

window.localStorage.setItem(storageName, editor.text);

!!callback && callback(saveNo, true);

};

// Load the survey definition from storage

editor.text = window.localStorage.getItem(storageName) || "";

A few details about this code:

To load the survey definition from database, simply assign survey JSON to the editor’s text property, as shown in the last line.

definition from database, simply assign survey JSON to the editor’s property, as shown in the last line. To save the survey definition into database, write code in the saveSurveyFunc callback function. The saveNo parameter helps with asynchronous data loading/saving operations. If a request with saveNo=47 comes to your server after you have already processed saveNo=48 , you know that it’s not the most recent version and you should ignore it.

into database, write code in the callback function. The parameter helps with asynchronous data loading/saving operations. If a request with comes to your server after you have already processed , you know that it’s not the most recent version and you should ignore it. The callback function tells the Editor whether the operation #saveNo has succeeded or failed, as specified by the Boolean parameter. When you report a success, the editor updates its state from “Saving…” to “Saved”.

In most scenarios, you will also want to customize SurveyJS Editor. Detailed instructions on how to do that are better left for a separate article, and we’re already working on it. Here I will only highlight the main customization capabilities.

Localize any string, including property names.

Hide three tabs on the top (JSON Editor, Test Survey, Embed Survey).

Hide Property Grid on the right.

Remove any question type from the Question Toolbox and add custom Question types.

Add or remove properties, change their position in the Property Grid or in modal dialogs.

Register new or override current property editors.

Remove/add items in the question context menu (“Add to toolbox”, “Copy”, etc.)

Disable drag & drop and other operations for all elements or a particular element.

Integrate Ace editor into the JSON Editor tab and Select2 instead of standard dropdown widget .

To see these and other features in action, take a look at our examples.

Integrate the Back-end: View Results

Building a result list is a trivial task. You can easily obtain the dates, time stamps, user information, and everything else you need. Once you’re done with the list, you’ll need to display individual results and that’s where we can help.

Survey responses are stored in JSON format, which you’ll need to parse to display the results in a table, as way we do it in our SurveyJS.io Service. This can be easily done, as shown by the myriad of samples on the web for any server/client platform.

As an alternative, you can show results as a read-only survey with responses already filled in. To do that, you’ll only need two lines of code.

survey.data = JSON.parse(yourJSONResultAsText);

survey.mode = "display";

To instruct the viewer to show all questions on one page, add the following line:

survey.isSinglePage = true;

Review the following JSFiddle to better understand what we are talking about.

Results Page Example

Integrate the Back-end: Data Storage

If you’re planning to store data on your end, then you must create at least the following two tables with a one-to-many relationship.

Survey Service Tables

The JSON fields are where you store your survey definitions and results. You can feed those database values directly to the Survey Runner or Editor and the results produced by them also go directly into the database, without the need for any conversion or complicated database structure.

On top of all that, you may want to add security roles for your back-end users, keep data logs, and so on. SurveyJS doesn’t provide those features, since we assume that if you want that level of control and integration, then chances are you already have those systems in place in your application.

Of course you don’t have to use a custom storage and can easily take advantage of our service, which is still free to use for anyone. And even with our storage, you can have control over data from your application’s UI:

Private API allows to create, edit, view, and delete surveys, as well as obtain survey results.

Public API allows you to post survey results from your app into our storage.

Learn More about SurveyJS

SurveyJS includes three products:

A JavaScript library that enables you to run surveys on your websites (open-source and free).

A cloud service that allows you to create and store surveys, download and analyze their results (currently free for use).

An embeddable JavaScript-based survey editor UI (free non-commercial and paid commercial-use licenses are available).

Tags