Qualtrics - Getting data from a behavioral task (BART)

newtothis Regina, SKCommunity Member - Trial User Qubie ✭

I'm currently trying to get a behavioral task to work with Qualtrics using Javascript. Essentially, the task consists of people pumping a balloon. Each pump brings it closer to popping the balloon, but they get more rewards based on the number of times they pump. They can collect rewards at any time. In total, they repeat pumping balloon and collecting rewards 30 times (30 rounds). I'm interested in how many times they press the pump button in each round.

I was able to find a script online that can be used to display the task in Qualtrics (did not write it myself). I'll add the code to the comments. The only thing that was missing was a way to get Qualtrics to record the data I want. I've looked through forums and found that the following script can be used to get Qualtrics to record data:

Qualtrics.SurveyEngine.setEmbeddedData( 'embeddedDataVariable', value );
Qualtrics.SurveyEngine.getEmbeddedData( 'embeddedDataVariable');

I would also have to set and embedded data variable in the survey flow in Qualtrics. I thought that the best way to do this is to have an embedded data variable representing pumps for each round (e.g., BART1 for pumps in the first round, BART2 for pumps in the second round). The code would be set up to have a conditional (if) statement that would record the number of pumps using the above code if the round # matched the embedded data variable I want to record. E.g.:

} if (round = 1){
            Qualtrics.SurveyEngine.setEmbeddedData("BART1", value);
          } else if (round = 2){
            Qualtrics.SurveyEngine.setEmbeddedData("BART2", value);

I have 2 issues that I've been trying to resolve. First, I'm not sure where in the script I'm supposed to put the two Qualtrics lines of code. I've tried putting it at different points in the script (within the pump button function, collect button function, and the continue button function), but none of them seem to work.

The other issue, which is related to the first, is what variable I should be recording (what variable do I input in the value field of the Qualtrics code). I assume I should be putting either the "pumps" or "pumpmeup" variable depending on where in the script the Qualtrics set and add lines of code are, but if you guys have any other suggestions, let me know.

If any of you can help me out with this, I'd really appreciate it! I'm very much a beginner in Javascript (very little experience), so any help is appreciated.

Best Answer

  • LaurenK
    LaurenK Seattle, WA, USACommunity Administrator Administrator
    edited February 2019 Accepted Answer

    Hey @newtothis! For a question involving this much custom code, we would recommend reaching out to an external consultant! They will best be suited to review your code as needed and provide the appropriate suggestions! :)


  • newtothis
    newtothis Regina, SKCommunity Member - Trial User Qubie ✭
        <script>$(document).ready(function() {
            var saveThis = 'hidden'; // text fields that saves data should not be shown; can be shown in testing
            // initialize values
            var round = 0;
            var start_size = 150; // start value of widht & height of the image; must correspond to the value that is specified for the #ballon id in style.css
            var increase = 2; // number of pixels by which balloon is increased each pump
            var size; // start_size incremented by 'increase'
            var pumps;
            var total = 0; // money that has been earned in total
            var rounds_played = 30;
            var explode_array =  [31, 80,  63, 103, 20,  26, 100,  75, 109,  72,  88,  77, 113, 22,  83,  86,  57,  14, 9,  90,  56,  41,  56,  27, 108,  42, 116,  18,  43,  95];
            var maximal_pumps = 128;
            var pumpmeup; // number pumps in a given round; is updated each round
            var number_pumps = []; // arrays for saving number of pumps
            var exploded = []; // array for saving whether ballon has exploded
            var explosion; // will an explosion occur? 1 = yes, 0 = no
            var last_win = 0; // initialize variable that contains the win of the previous round
            // initialize language
            var label_press = 'Pump Balloon';
            var label_collect = 'Collect Money';
            var label_balance = 'Total money collected:';
            var label_last = 'Money gained last round:';
            var label_currency = ' USD';
            var label_header = 'Balloon Pump Round ';
            var label_gonext1 = 'Start Next Round';
            var label_gonext2 = 'Spiel beenden';
            var msg_explosion1 = '<p>The Balloon exploded after ';
            var msg_explosion2 = ' pumps. No money will be transfered to the bank. <p>Click below to start the next round.</p>';
            var msg_collect1 = '<p>The balloon did not explode!</p><p>The money collected in Round 1 is ';
            var msg_collect2 = ' USD.</p><p> The money you collected will be put into the bank</p>';
            var msg_end1 = '<p>Damit ist dieser Teil der Studie abgeschlossen. Sie haben im Ballon-Spiel ';
            var msg_end2 = ' Taler Gewinn gemacht. </p><p>Klicken Sie auf <i>Weiter</i>, um mit der Studie fortzufahren.</p>';
            var err_msg = 'You need to pump the balloon at least once before collecting the money. Please click "Pump Balloon"';
  • newtothis
    newtothis Regina, SKCommunity Member - Trial User Qubie ✭

    Rest of code (because I didn't have enough space):

                // initialize labels
                // below: create functions that define game functionality
                // what happens when a new round starts
                var new_round = function() {
                    round += 1;
                    size = start_size;
                    pumps = 0;
                // what happens when the game ends
                var end_game = function() {
                    store_data(); // note: this function needs to be defined properly
                // Important: this function will have to be replaced to ensure that
                // the data is actually sent to _your_ server:
                var store_data = function() {
                    $('#saveThis1').html('<input type='+saveThis+' name ="v_177" value="'+number_pumps+'" />');
                    $('#saveThis2').html('<input type='+saveThis+' name ="v_178" value="'+exploded+'" />');
                    $('#saveThis3').html('<input type='+saveThis+' name ="v_577" value="'+total+'" />');
                // message shown if balloon explodes
                var explosion_message = function() {
                // message shown if balloon does not explode
                var collected_message = function() {
                // animate explosion using jQuery UI explosion
                var balloon_explode = function() {
                    $('#ballon').hide( "explode", {pieces: 48}, 1000 );
                    // activate this if you have a sound file to play a sound
                    // when the balloon explodes:
                    // document.getElementById('explosion_sound').play();
                // show button that starts next round
                var gonext_message = function() {
                    if (round < rounds_played) {
                    } else {
                // add money to bank
                var increase_value = function() {
                var show_last = function() {
                // button functionalities
                // pump button functionality
                $('#press').click(function() {
                    if (pumps >= 0 && pumps < maximal_pumps) { // interacts with the collect function, which sets pumps to -1, making the button temporarily unclickable
                        explosion = 0; // is set to one if pumping goes beyond explosion point; see below
                        pumps += 1;
                        if (pumps < explode_array[round-1]) {
                        size +=increase;
                        } else {
                        last_win = 0;
                        pumpmeup = pumps;
                      pumps = -1; // makes pumping button unclickable until new round starts
                        explosion = 1; // save that balloon has exploded this round
                        exploded.push(explosion); // save whether balloon has exploded or not
                        number_pumps.push(pumpmeup); // save number of pumps
                      setTimeout(explosion_message, 1200);
                        setTimeout(gonext_message, 1200);
                        setTimeout(show_last, 1200);
                // collect button: release pressure and hope for money
                $('#collect').click(function() {
                    if (pumps === 0) {
                    } else if (pumps > 0) { // only works after at least one pump has been made
                  exploded.push(explosion); // save whether balloon has exploded or not
                        // activate this if you have a sound file to play a sound
                        // when the balloon does not explode:
                    // document.getElementById('tada_sound').play();
                  number_pumps.push(pumps); // save number of pumps
                    pumpmeup = pumps;
                  pumps = -1; // makes pumping button unclickable until new round starts
                    total += pumpmeup;
                    last_win = pumpmeup;
                // click this button to start the next round (or end game when all rounds are played)
                $('#gonext').click(function() {
                    if (round < rounds_played) {
                    } else {
                // continue button is shown when the game has ended. This needs to be replaced
                // by a function that takes into account on which platform the BART runs (i.e.
                // how will the page be submitted?)
                $("#goOn").click(function() {
                // start the game!
  • McKennaDalton
    McKennaDalton Southern UtahCommunity Member Qubie ✭

    Hello! I was wondering if you had made any progress in resolving this issue? I am also doing a study that uses the BART program, and am having a similar issue where I am only able to record the data from the first balloon and none of the data from the 29 subsequent balloons are being recorded. I am also very new to javascript, so I was wondering if you had discovered anything that may help guide my search.