Embedding JavaScript in Qualtrics | XM Community
Skip to main content

Hi,
We have JavaScript that works outside of Qualtrics to capture broadband download and upload speed. While it works outside of Qualtrics, it does not work inside of Qualtrics. Does anyone have advice on this issue?
Thank you!

IDHI2021 Can you please elaborate more as to what you're trying to achieve by running this javascript within Qualtrics? Or provide a use case scenario such that we can help you better?


ndt7-v2.zipAanurag_QC Yes. We are trying to run a broadband speed test within the Qualtrics survey we are deploying if participants agree to it. Please find the file of the JavaScript attached as well as comments below of getting it to work locally as well as instructions on how we tried to put in Qualtrics. This code works outside of Qualtrics but not in Qualtrics. Any help is greatly appreciated!
 
Here's an example of using the NDT7 client (attached). You can test it locally by putting the two files (index.html and index.javascript) in the same folder, rename "index.javascript" to "index.js" (Google doesn't let me send a .js file in email) and opening index.html. Note, you may have to mark the files as trusted on windows after downloading them by right clicking ndt7.zip => properties and then clicking "Unblock" in the Security section.

Note, when you're ready to add this to the survey, you can just copy the index.js file in as you did with the javascript snippet (assuming Qualtrics doesn't do something funky with the script). Then you'll just comment out the two lines in the "Qualtrics Code Here" section so it looks like this:

// Qualtrics Code Here
 
function setSurveyValue(name, value) {
 //alert("Setting Value " + name + " " + value);
 Qualtrics.SurveyEngine.setEmbeddedData(name, value);
}
 
//document.addEventListener("DOMContentLoaded", function() { onLoad(); });
Qualtrics.SurveyEngine.addOnload(function() { onLoad(); });
 
// End Qualtrics Code
 
It can take probably up to about 30 seconds to complete and you'll know someone completed the full test when you see a value of 0 set to the survey value "testCompletedWithCode".


I know this is an old question now, but I think you’ve likely ran into code compatibility issues. JavaScript is executed on the user’s local web browser (AKA client side), so the fact that sometimes code runs well on the development machine (in a browser or in node.js) but not within Qualtrics is because it is not compatible with the web browser that Qualtrics is running on in the respondents computer. This is a standard issue in web development and the solution is to ensure compatibility in terms of the JS version of the code and modules.

Importing a module in Qualtrics is also its own issue that works very differently than in a standard web dev project and after using what code I could find on here I haven’t ever been able to get it to work. So using modules then that is also likely an issue for those trying to do similar things to OP.


Leave a Reply