All Collections
Website Surveys
FAQs
Manually Triggering Surveys With JavaScript
Manually Triggering Surveys With JavaScript

Learn how to control when a survey is displayed with our install method

Updated over a week ago

By default, when the Iterate script is loaded onto the page it will automatically check to see if a survey matches the visitor's current state based on the targeting options of your surveys and display it.

In addition to this default behavior, you can control when a survey is displayed by using the "install" method of our javascript API.

There are two primary use cases for this method

1. Displaying a survey in response to a user action

Using the "install" method of our javascript API, you can easily show a survey at any moment of your choosing. You can call this method in response to a button click, or any event of your choosing.

When triggering a survey with the "install" method, we will still respect all other targeting options (first-time visit, exit intent, user properties, etc) and show the survey if the user matches all of those options. if the user has previously filled out the survey or dismissed it, they will not see the survey again.

Usage

The "install" method takes a string containing the id of the survey you want to show. You can get the survey id by selecting "manually" as your trigger (see below).

Iterate('install', '59ca8e222af1ad00010047f0');

Finding the survey id

On the "targeting" tab, you'll see a list of options for choosing when the survey should be shown. If you select "manually" you'll see a code snippet that includes the survey id that you can easily copy and paste into your site.

Uninstall

If you have called the install method and later wish to uninstall the survey so it doesn't show up for the visitor, you can do that with the uninstall method.

Iterate('uninstall', '59ca8e222af1ad00010047f0');

For example on an e-commerce website if you wanted to run an exit-intent survey for visitors who abandon the checkout process you can install a survey when the visitor clicks the checkout button and uninstall it if they complete the process. This way only visitors who don't complete the checkout will see the exit intent survey.

2. Delaying the check for matching surveys

When the Iterate script is put onto the page, it will automatically check for any surveys that match the user's state. You may want to delay this default behavior if you are targeting a survey with custom user properties and you need to wait to request any matching surveys until you have all of the user data and made a request to our Identify API.

To disable the default behavior of automatically checking for surveys when the script is loaded you can set the 'installOnLoad' setting to false in your iterateSettings objects.

 window.iterateSettings = {
 apiKey: 'your_api_key',
 installOnLoad: false,
 };

Then when you are ready to make the request to check for surveys to display, call the 'install' API (without any parameters)

Iterate('install');

Did this answer your question?