Embedding a chatbot in a Qualtrics survey | XM Community
Question

Embedding a chatbot in a Qualtrics survey

  • 13 February 2024
  • 4 replies
  • 130 views

Badge +1

I want to run a brief session in which users chat with a chatbot as an experimental stimulus. So the chatbot will be in the middle of the survey. Thus far i have been using Landbot, but I *am* open to switching to another chatbot.

My problem is embedding the chatbot in a question. If I use an iframe, the chatbot stalls at the first user response. If I try to use javascript, I get an error message that the script (below) has “Unexpected token <”

 

<script>
window.addEventListener('mouseover', initLandbot, { once: true });
window.addEventListener('touchstart', initLandbot, { once: true });
var myLandbot;
function initLandbot() {
  if (!myLandbot) {
    var s = document.createElement('script');s.type = 'text/javascript';s.async = true;
    s.addEventListener('load', function() {
      myLandbot = new Landbot.Popup({
        configUrl: 'https://storage.googleapis.com/landbot.online/v3/H-2115917-N3AUV7GO5MNHY5BG/index.json',
      });
    });
    s.src = 'https://cdn.landbot.io/landbot-3/landbot-3.0.0.js';
    var x = document.getElementsByTagName('script')[0];
    x.parentNode.insertBefore(s, x);
  }
}
</script>

 

I have tried using solutions people have posted to a similar problem 3 years ago. It seems like my problem is new … possibly due to upgrades to both the chatbot and Qualtrics.

I am not well-versed in javascript, and I cannot figure out how to do more sophisticated api-based solutions that are suggested elsewhere I have looked for help.


4 replies

Userlevel 7
Badge +21

Remove <script> and </script>, and try again.

 

Badge +1

Thank you @ahmedA - that made it work. Chatbot still stalls after the first interaction, but thanks to your advice it *does* run.

 

Badge +1

Hi could you please show me your survey? I want to embed my chatbot from landbot too, pop-up or textbox. So may I get your reply?

Userlevel 4
Badge +8

Hi @RobB101 , You can try with below code:

 

<script>
window.addEventListener('mouseover', initLandbot, { once: true });
window.addEventListener('touchstart', initLandbot, { once: true });
var myLandbot;
function initLandbot() {
  if (!myLandbot) {
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.async = true;
    s.addEventListener('load', function() {
      myLandbot = new Landbot.Popup({
        configUrl: 'https://storage.googleapis.com/landbot.online/v3/H-2115917-N3AUV7GO5MNHY5BG/index.json',
      });
    });
    s.src = 'https://cdn.landbot.io/landbot-3/landbot-3.0.0.js';
    var x = document.getElementsByTagName('script')[0];
    x.parentNode.insertBefore(s, x);
  }
}
</script>
 

Thank you!

Leave a Reply