Is there a way to carry over variables/data from .addOnReady to .addOnUnload | XM Community
Question

Is there a way to carry over variables/data from .addOnReady to .addOnUnload

  • 24 May 2020
  • 1 reply
  • 4 views

Hello!
I have this "game" or task that's coded with the Qualtrics API. It lasts about 900 seconds but we would like to give the option for the participant to click the next button if they choose not to do the task to completion. However, the issue with the way the JS is coded is that all of the .setEmbeddedData lines happen after the entire game has completed and the code is finishing up. The way it's written right now, no data from the code will be embedded into Qualtrics if the participant presses the next button early and cuts off the game prematurely.
I was hoping to resolve this by moving the .setEmbeddedData lines from the end of the game to the .addOnUnload section so that all of the data will be embedded when the participant presses the next button. However, I learned that none of the variables/data carry over between the sections. Is there a way to carry over that data from .addOnReady to .addOnUnload or must we rewrite the JS so that code is embedding the data into Qualtrics while they're playing the game?
Thank you!


1 reply

Userlevel 7
Badge +22

Declare all your variables, outside/ or above - .addOnload function.
Use addOnPageSubmit function to set the embedded data.

Leave a Reply