Forum Discussion
Text entry variables and xAPI
We can dynamically gather these variables and values (key | value pair), store variables and their values in a single variable (xapiResponse), and send that information in an xAPI format but only with a consistent naming pattern (e.g., comment_1, comment_2, comment_3, ... comment_n). Then we can use JavaScript to retrieve each variable’s value and build a response that will be sent in the xAPI statement.
Example JavaScript:
var totalVars = 130; // less or more
var responses = [];
for (var i = 1; i <= totalVars; i++) {
var varName = "comment_" + i;
var varValue = getVar(varName);
if (varValue && varValue.trim() !== "") {
responses.push(varName + ": " + varValue);
}
}
var jointResponse = responses.join(" | ");
setVar("xapiResponse", jointResponse);
console.log("xapiResponse set to:", jointResponse);
xAPI statement:
In this example, I used the JavaScript code above along with a single xAPI statement, which is executed on the master slide when it loads.
However, this approach can be further optimized by modifying the script to only include variable | value pairs relevant to the current slide, rather than sending all comment variables and values at once.
I personally prefer sending the xAPI statement at the end, after all text entry fields have been filled. This ensures that all user inputs are captured, reducing redundant xAPI calls.
Again, this approach is only possible if a structured variable naming convention is planned ahead and followed from the beginning.
- PhilMayor9 months agoSuper Hero
This was exactly what I meant. And if you append _# then you can quickly create your variables by copy and paste.
Related Content
- 12 months ago
- 8 months ago
- 10 years ago