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.
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:
This model naturally assumes monthly or annual billing cycles, but SurveyJS so far remains completely free to use in this scenario.
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:
SurveyJS fully supports this level of integration and remains free to use.
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:
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.
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:
The simplest implementation of Survey back-end will have the following elements:
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 optionsvar editorOptions = { };editor = new SurveyEditor.SurveyEditor("editorElement", editorOptions);
// Enable state indication (Saving, Loading, etc) in the toolbareditor.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 changeseditor.saveSurveyFunc = function(saveNo, callback) {window.localStorage.setItem(storageName, editor.text);!!callback && callback(saveNo, true);};
// Load the survey definition from storageeditor.text = window.localStorage.getItem(storageName) || "";
A few details about this code:
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.
To see these and other features in action, take a look at our examples.
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
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:
SurveyJS includes three products: