Embedded data from online experiment in Qualtrics using JavaScript/HTML | XM Community
Skip to main content
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.
The example code has:

<code>const data = event.data.json</code>

and you are using event.csv so, assuming "csv" is valid, you might need event<b>.data</b>.csv
Does a similar method work for embedding an experiment built in jsPsych into Qualtrics?

Leave a Reply