Skip to content

Commit

Permalink
Added Setting Embedded Data by Page
Browse files Browse the repository at this point in the history
  • Loading branch information
tafakkur committed Oct 24, 2020
1 parent fdd5d6b commit d59e7c5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions JavaScript Files/Set Embedded on Page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This script is a demo of adding/modifying Embedded Data variables based on events on the page.

// The script shown below allows you to add/modify Embedded Data variables as soon as the choices are submitted.

// This allows more flexibility than the "Set Embedded Data" option in the "Survey Flow" section, as that works at block level, while this one works at Page level.

// By modifying it a bit and adding it to the addOnReady() or addOnLoad() section, you can even recorded choices that were selected and then unselected.

Qualtrics.SurveyEngine.addOnPageSubmit(function (type) { // To record the selection when the page is submitted
if (type == "next") {
var selChoice = this.getSelectedChoices(); // Get the selected choices
var choiceRef = "";
var choiceText = "";
for (let i = 0; i < selChoice.length; i++) { //Loop over all the choices selected in the question
choiceRef = "#" + this.questionId + "-" + selChoice[i] + "-label > span"; // Create a reference for the choices
choiceText = document.querySelector(choiceRef).innerHTML; //Get the value (The actual text displayed)of the choices from the webpage

// Set Embedded Data

if (choiceText.includes("Share")) {
Qualtrics.SurveyEngine.setEmbeddedData("Share", "TRUE");
} else
Qualtrics.SurveyEngine.setEmbeddedData("Share", "FALSE");

}
}
});

0 comments on commit d59e7c5

Please sign in to comment.