Can't store data points that I'm attempting to update in embedded data on survey. | XM Community
Skip to main content

Hello, 

 

I’m a student that is trying to use Qualtrics for a class project. I’m fairly alright with code, but I can’t seem to figure this out. No matter what I try I keep “0” values.

      1. I’ve initialized the code in its own block at the top of the survey.

  1. I’ve set the values to zero, and set them as numbers.
  2. I’ve named the variables initialized in the embedded data block with the “__js_” prefix I’ve seen mentioned.
  3. I’m not using an API key, not sure that this matters.

Here is my code:
 

Qualtrics.SurveyEngine.addOnload(function() {
// Initialize global variables (or retrieve them if already set)
var totalClicks = this.getJSEmbeddedData('totalClicks') || 0;
var totalTime = this.getJSEmbeddedData('totalTime') || 0;
var timeSchemaField = this.getJSEmbeddedData('timeSchemaField') || 0;
var clicksSchemaField = this.getJSEmbeddedData('clicksSchemaField') || 0;

// Record the start time for the page
var start = Math.round(Date.now() / 1000);

this.questionclick = function(event, element) {
// Increment total clicks
clicksSchemaField++
totalClicks++;
this.setJSEmbeddedData('totalClicks', totalClicks);
this.setJSEmbeddedData('clicksSchemaField',clicksSchemaField);
};

this.setJSEmbeddedData('start', start); // Save the start time for use in the unload function
});

Qualtrics.SurveyEngine.addOnUnload(function() {
// Retrieve start time
var start = parseInt(this.getJSEmbeddedData('start'));

// Get the end time
var end = Math.round(Date.now() / 1000);

// Calculate total time on the page
var tempTime = end - start;

// Update and save the total time spent in the survey
var totalTime = this.getJSEmbeddedData('totalTime') || 0;
totalTime += tempTime;
this.setJSEmbeddedData('totalTime', totalTime);
this.setJSEmbeddedData('timeSchemaField', tempTime);

});

Any help would be appreciated.

Be the first to reply!

Leave a Reply