Using the Widget API to control the Informizely widget programmatically
Our Enterprise plan allows for using our Javascript Widget API to control the Informizely widget programmatically.
Using the API you can manually show a particular survey at the moment you want, e.g. when a certain button is clicked on your website.
The only requirement for this to work is that the survey that you want to show is loaded on the page where you want to show it,
so make sure that the correct URL specification is configured in the survey’s target settings.
You also want to prevent automatic activation of the survey. This can be done by adding the custom property
"ondemand=true" (or some other custom property that is never set in code)
in the survey’s target settings. As long as you don't set this property in Javascript code, the survey will
never be shown automatically (
more about custom properties).
Note: the term "insitez" used below refers to the previous name of Informizely.
To use the API, add the following code directly
before the normal Informizely code snippet:
Once stored, the API object
'informizelyApi' can be used in your own JavaScript functions.
To show a survey, e.g. on a button click, you need to know the survey's ID. This ID can be be retrieved from the survey’s URL in the
Informizely members site. It is the part after the last '/' in the URL of the survey's configuration page.
To show a survey on demand, call the function
informizelyApi.showScript(<surveyId>)
.
This will return a
WidgetController object, which can be used to further control the widget.
Complete example
WidgetController reference
Function |
Arguments |
Returns |
Description |
addEventHandler |
eventName (string), handler (function) |
void |
Adds a callback function which is called when a certain event occurs.
The callback has one argument: an object with event-specific data.
Supported events:
-
"scriptEnd": the widget is closed.
Callback argument: { surveyId (string), closeAction (number) }
closeAction values: 0=unknown, 1=completed, 2=closed.
closeAction has a value of 0 if the widget was closed because another widget was shown
(e.g. due to another call to 'informizelyApi.showScript').
-
"showPage": a new survey page is shown.
Callback argument: { surveyId (string), pageId (string) }
|
removeEventHandler |
eventName (string), handler (function) |
void |
Removes a callback function previously added with 'addEventHandler'.
|
stop |
(none) |
void |
Stops the active widget. After this call the WidgetController should be disregarded.
To show this or another survey again, call 'informizelyApi.showScript' again and use the returned WidgetController.
|
gotoPage |
pageId (string) |
void |
Shows the survey page with the specified ID, regardless of the configured survey logic.
Note: survey page IDs are currently not exposed on the survey's configuration page,
but they are passed to the "showPage" event handler.
|