I am wondering if there is a way to embed an internet speed tester into a Qualtrics question, so a survey respondent would be able to click a button or test their speed in Mbps upon the question being displayed. We are assessing some variables about broadband equity. We do not want them to be directed to an external URL. Is there any code or embedded data that would allow this? Thanks!
Hi there, if you still need, I found a thread that I think will be helpful to you. In that, several options are discussed but they generally involve recording how long it takes to download an image file. I adapted the code from user john Smith in that thread to perform a speedtest and capture the value in an embedded data field each time a button is clicked.
To give it a try, first create an Embedded Data element called "speed" and put it at the top of the Survey Flow.
Next, create a Text/Graphic question and use the Rich Content Editor's HTML/Source view "<>" to update the Question Text with the below.
Click to write the question text
Speed: 0
Finally, add the below to the question's JavaScript in the OnReady section:
var speed=0;
document.getElementById("button1").onclick=function(){
var testConnectionSpeed = {
imageAddr : "https://upload.wikimedia.org/wikipedia/commons/a/a6/Brandenburger_Tor_abends.jpg", // this is just an example, you rather want an image hosted on your server
downloadSize : 2707459, // Must match the file above (from your server ideally)
run:function(mbps_max,cb_gt,cb_lt){
testConnectionSpeed.mbps_max = parseFloat(mbps_max) ? parseFloat(mbps_max) : 0;
testConnectionSpeed.cb_gt = cb_gt;
testConnectionSpeed.cb_lt = cb_lt;
testConnectionSpeed.InitiateSpeedDetection();
},
InitiateSpeedDetection: function() {
window.setTimeout(testConnectionSpeed.MeasureConnectionSpeed, 1);
},
result:function(){
var duration = (endTime - startTime) / 1000;
var bitsLoaded = testConnectionSpeed.downloadSize * 8;
var speedBps = (bitsLoaded / duration).toFixed(2);
var speedKbps = (speedBps / 1024).toFixed(2);
var speedMbps = (speedKbps / 1024).toFixed(2);
if(speedMbps >= (testConnectionSpeed.max_mbps ? testConnectionSpeed.max_mbps : 1) ){
testConnectionSpeed.cb_gt ? testConnectionSpeed.cb_gt(speedMbps) : false;
}else {
testConnectionSpeed.cb_lt ? testConnectionSpeed.cb_lt(speedMbps) : false;
}
},
MeasureConnectionSpeed:function() {
var download = new Image();
download.onload = function () {
endTime = (new Date()).getTime();
testConnectionSpeed.result();
}
startTime = (new Date()).getTime();
var cacheBuster = "?nnn=" + startTime;
download.src = testConnectionSpeed.imageAddr + cacheBuster;
}
}
testConnectionSpeed.run(1.5, function(mbps){
console.log(mbps+"Mbps"),
speed = mbps+"Mbps",
document.getElementById("speed").innerHTML=speed,
Qualtrics.SurveyEngine.setEmbeddedData('speed', speed)
})
}
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.