Transferring studySessionData from OSWeb to a subsequent component
Hi there,
I wasn't sure where this topic would fit best - feel free to send it over to JATOS if this makes more sense.
I am trying to install an experiment with 3 components on JATOS: a survey (SurveyJS), the actual experiment in OSWeb and a final page, where participants can see their results and share them on social media (simply to recruit more participants).
Of course, it is fairly easy to display the results in OpenSesame, but implementing the social media buttons seems not to be possible (correct me if I am wrong!) - hence the last page. Here's the issue:
I managed to import the jatos.studySessionData from the preceding survey to the OSWeb experiment, but I can't figure out how to send the variables from OSWeb to the subsequent component.
Here is what I have:
Exporting from survey:
survey.onComplete.add(function (result) { jatos.studySessionData.subject_number = survey.data.subject_number; if (survey.data.session_number == null){ jatos.studySessionData.session_number = 1;} else {jatos.studySessionData.session_number = survey.data.session_number;} jatos.submitResultData(JSON.stringify(result.data), jatos.startNextComponent); });
Importing to OSWeb (works):
vars.code_number = jatos.studySessionData.subject_number vars.sess_nr = jatos.studySessionData.session_number
Exporting from OSWeb (does not work):
jatos.studySessionData.accuracy = vars.acc jatos.studySessionData.rt = vars.avg_rt
How can I transfer the data from OSWeb to the last component - and how can I implement it there?
Many thanks for your responses and I hope others will find this useful aswell :)
Best,
Tim
Comments
Hi Tim,
As far as I understand your experiment has 3 components, one survey, one OSWeb and one 'last' component. Actually the code to get your data from the study session in the third component is just
var accuracy = jatos.studySessionData.accuracy;
var avg_rt = jatos.studySessionData.avg_rt;
I guess you tried this already. What are the errors you get?
Best,
Kristian
Hi Kristian,
this is exactly what I have and it returns "undefined". The console doesn't show any error messages.
I tested it with studySessionData set in OSWeb (as described above) and the data automatically set by OSWeb:
I am not very familiar with JS/HTML. Does it have to be in the head? Do I need more than
in the .html?
Best,
Tim
Hi Tim,
It looks like you forgot to initialize jatos.js. Have a look in http://www.jatos.org/Write-your-own-Study-Basics-and-Beyond.html#mandatory-lines-in-your-components-html.
Basically before you can start with using features from jatos.js (like the study session) you have to wait for it to be initialized with
jatos.onLoad
:Best,
Kristian
Hi Kristian,
many thanks for your help, I really appreciate that.
I did actually already try it with "jatos.onload()" and it didn't work either. But in this case I did indeed get an error message stating that "accuracy" (because it is the first of the four, I guess) was not defined. Without the function I would just get the value "undefined" when calling the variable.
Could it be that OSWeb somehow doesn't transfer the studySessionData, i.e. "ends" the session?
Best,
Tim
Could it be that OSWeb somehow doesn't transfer the studySessionData, i.e. "ends" the session?
Maybe I should add that I just put the .html files to a subfolder in the zipped OSWeb files. This worked flawlessly for the survey as first component though. Might this be the issue?
Hi Tim!
Could it be that OSWeb somehow doesn't transfer the studySessionData, i.e. "ends" the session?
This is handled by jatos.js. So OSWeb can't 'end' the session. Maybe there are problems with starting the last component of yours. How do you start it? Do you use one of the jatos.js functions like
jatos.startNextComponent
?Maybe I should add that I just put the .html files to a subfolder in the zipped OSWeb files. This worked flawlessly for the survey as first component though. Might this be the issue?
Putting it in the zip file is fine. As long as you add the new component to the study properties too.
Kristian
Hi Kristian,
no I didn't, as I expected OSWeb to automatically transition to the next component. I tried to add it in an inline_script in OpenSesame, but the results are the same: the last component starts, but it seems like it can't fetch studySessionData. As I said, I just added a .html which looks something like this to a folder in the osweb-zip-file:
Returns "accuracy is not defined" in the console. Calling "jatos.studySessionData.accuracy" at the end of the OpenSesame experiment works fine.
As long as you add the new component to the study properties too.
This sounds like something I didn't do; what exactly do you mean by that? I mean, I did add the file as a new component, but I did not change any properties.
Many thanks!
Best,
Tim
Hi Tim!
Try putting the logging within the onLoad function too, like:
The way you have it, console.log is called right in the start when jatos.js is not yet initialized.
But you have to add your third component to the study. When you open your study in JATOS, how many components do you have there? It should be three: survey, OSWeb experiment, and third component. If the third is missing you have to add it.
Best,
Kristian
Hi Kristian,
I'm a little confused because I could swear I've tried this before, but somehow it has worked now - thank you! This does not really belong here, but is there a way to initialize JATOS (i.e. load the variables) before the HTML is loaded (e.g. to dynamically create content)?
In any case, thank you very much for the help and the post can be marked as solved :)
Best,
Tim
Hi Tim!
That's great to hear!
And about your other question: 'is there a way to initialize JATOS (i.e. load the variables) before the HTML is loaded (e.g. to dynamically create content)?'. I don't think that is possible since jatos.js loads data asynchronous from the server. But you can always add content dynamically to your HTML. It's actually quite common to do that. E.g. you could wait for jatos.js to initialize and then add some HTML to you r DOM dynamically.
Best,
Kristian