Survey won't open twice when using the API | XM Community
Skip to main content

I am attempting to launch a survey via a button, via JS, on my website. When I use the JS function QSI.API.load() or QSI.API.run(), with the onclick, it works fine the first time but will not open the survey a second time until the page is refreshed. Is there a better API method or something I need to add to the button or survey to get it to perform the expected behavior? Thanks!

Hi Wally,

 

You can configure 3 JS functions as mentioned below:

 

  1. This request removes the deployment code for any Intercepts or Creatives present on the page. (this is important as it will remove all the previously loaded surveys on the page, removing the need to refresh)
    QSI.API.unload();
  2. This loads the deployment code for any Intercepts or Creatives on the page. This is the same as reloading the page.
    QSI.API.load();
  3. This starts the deployment code evaluation and will make any Creative appear if it passes the display conditions.
    QSI.API.run();

Do I need to put the unload() on the survey itself in the addOnUnload function? I tried the load() function in the onclick event of the button but it will only open once. When the survey is closed, it will not open again.

Here is the code on the button

<button class="btn btn-lg display-6" onclick="QSI.API.load()" style="background-color:#007bc0; color:white;">Get Started with the Module Program Today</button>


you need to put the unload() function onclick


So something like this:

<button class="btn btn-lg display-6" onclick="QSI.API.load(); QSI.API.unload();" style="background-color:#007bc0; color:white;">Get Started with the Module Program Today</button>


Hi Wally, the unload function should be called first so that it takes care of both situations mentioned below:

  1. Clicking the button for first time will open the survey. (only load function will work as there must be nothing to unload)
  2. Clicking the button for the second time. (now the unload function will work first and then followed by the load function)

Hence, the updated html for button would be:
 

<button class="btn btn-lg display-6" onclick="QSI.API.unload(); QSI.API.load();" style="background-color:#007bc0; color:white;">Get Started with the Module Program Today</button>

 

If you still face any issues, try adding timeout function between unload & load. (code below)
 

<button class="btn btn-lg display-6"
onclick="QSI.API.unload(); setTimeout(function() { QSI.API.load(); }, 500);"
style="background-color: #007bc0; color: white;">
Get Started with the Module Program Today
</button>



 


Leave a Reply