Community Groups are officially here!
We've released Groups, a new feature that enables us to connect community members of similar industries and interests in a shared, private space. You can check out all of the details here, including information about who can join, how to join, and what Groups are currently offered. Please leave your feedback through this Community Groups Feedback Survey.

Embedded data from online experiment in Qualtrics using JavaScript/HTML

Bjorn
Bjorn Community Member Qubie ✭

I am trying to integrate an online experiment put together using lab.js, hosted on a local server, with a questionnaire in Qualtrics. Basically, I want people to fill in a couple of questionnaires in Qualtrics before moving on to the online study where they'll see a range of images and respond using the keyboard as to how likely they are to carry out some action.

I would like to integrate the online experiment into Qualtrics, so that participants don't have to go to a different website to complete the experiment, and I will get all the data in the same file.

Using the instructions on the Lab.js website I've managed to run the study in the Qualtrics interface, but I can't get the results to be saved as Embedded Data.

I have created a text entry question in Qualtrics and entered the following code in the HTML view, which shows the study:

<iframe src="https://MyStudy.com/index.html" 
style="width: 960px; min-height: 740px; border: none;"></iframe>

This is what I've managed to put together to catch the output from the online experiment, which I've added as JavaScript to the question:

<script>
  // Listen for the study sending data
  window.addEventListener('message', (event) => {
    const data = event.csv 

     // Make sure that data is included
    if (data) {
    Qualtrics.SurveyEngine.setEmbeddedData("data",data);
    that.clickNextButton();
    }
  })
</script>

The study runs via the URL in an iFrame (as you can probably tell from the code), and the study responds to key presses, but the embedded data field doesn't record any responses. I've added data as an embedded data field in the survey flow.

I'm not great with JavaScript, so I'd appreciate any help.

Tagged:

Best Answer

  • James
    James Charlottesville, VACommunity Member, Qualtrics Brand Admin Qubie ✭
    Accepted Answer

    The example code has:
    const data = event.data.json
    and you are using event.csv so, assuming "csv" is valid, you might need event.data.csv

Answers

  • bamfojm
    bamfojm United KingdomCommunity Member - Trial User Qubie ✭

    Does a similar method work for embedding an experiment built in jsPsych into Qualtrics?