Passing a created variable to another website

URL of experiment:

Description of the problem: In my study I have a code component that randomly assigns people to different conditions. I would like to export this condition variable to qualtrics using a query string. However, in qualtrics the variable is showing up as ‘undefined’. I looked through the javascript and the redirect URL is above the point where my condition variable is defined.

Any thoughts on how to work around this?

In case it helps, here is the redirect URL:


and the js code component that creates my condition variable:

cond = [“control”,“comp_orig”, “comp_scale”, “familiar”][Math.floor(Math.random() * 4)];


If anyone else has a javascript solution, I would love to check it out.

In the meantime I was able to figure out a workaround and wanted to share it with anyone else who has the same issue.

In my study flow, I am linking SONA to Qualtrics to Pavlovia to Qualtrics and back to SONA. SONA creates a unique id for each participant which I am using as a participant number. The first qualtrics study is the consent form, and passes the participant number from SONA to pavlovia. In the first Qualtrics survey, I set up a new embedded condition which randomly selected the condition. I then passed this from Qualtrics to Pavlovia. This ensures that the condition variable comes before the redirect URL.

Here is a screenshot of the Qualtrics Survey Flow:

Here is an example of the redirect URL from Qualtrics to Pavlovia${e://Field/id}&qcond=${e://Field/cond}

Here is a picture of the experiment settings on pavlovia.

Next you have to tell psychopy that the expinfo variable is your condition variable

cond = expInfo['qcond'];

Now you can use it to pull specific excel files


Lastly the redirect URL to pass it along to the next survey. In my case Qualtrics


Hi there,

Sounds like you have found out lots of useful information about the issue already. Please can I check what version of PsychoPy you are using? the newest version has a “Before Experiment” tab in the code component, which might allow you to implement the JS code component you mention there before the redirect url.


EDIT: saw that you found a solution after posting to your initial question - pleased you found a work around and thanks for sharing your solution :slight_smile: