Editing Javacript for Qualtrics (originally for Unipark) | XM Community
Question

Editing Javacript for Qualtrics (originally for Unipark)

  • 26 April 2021
  • 1 reply
  • 7 views

Hello! I have a script to collect the acceleration of a respondents phone that I would like to add to my survey, but my knowledge of Javascript is limited. What am I missing to make the connection between collecting this information and appending it to my data?
The original script is:
{
var start = now();
function SurveyMotion(e) {
this.acceleration = new Object();
if (e.accerleration !==null) {
this.acceleration.x = Math.sqrt(Math.pow(e.accerlation.x,2)+
Math.pow(e.acceleration.y,2)+
Math.pow(e.acceleration.z,2)).toFixed(2);
this.acceleration.g = abs(Math.sqrt(Math.pow(e.accelerationIncludingGravity.x,2)+
Math.pow(e.accelerationIncludingGravity.y,2)+
Math.pow(e.accelerationIncludingGravity.z,2))-
  9.80665).toFixed(2);
this.acceleration.t = Math.round(now() - start);
} else {
this.acceleration.x = null;
this.acceleration.g = null;
}
this.interval.x = null;
if (e.interval !==null) {this.interval = e.interval;
}
return (this);
};
window.addEventListener("devicemotion", update_accel, false);

});


1 reply

Userlevel 2
Badge +3

To answer your question, you want to use:
Qualtrics.SurveyEngine.setEmbeddedData("NAME_HERE", "VALUE_HERE");
For example....
if have an ED field called AccelerationX, you would save the value to it like this:
Qualtrics.SurveyEngine.setEmbeddedData("AccelerationX", this.acceleration.x);
However, after looking at your code I've noticed more issues than I can begin to address here. I can't see how this code works as you've provided it.

Leave a Reply