Extracting mTurk worker ID

196 views
Skip to first unread message

Håvard

unread,
Mar 14, 2019, 5:41:36 PM3/14/19
to LIONESS Lab help and discussion
Hello,

When using Lioness to conduct an experiment on mTurk, is the session-variable "externalID" supposed to be the mTurk workers ID? As far as we can see, it does not record this automatically, and the documentation does not mention it.

We would like to record the mTurk worker ID as a variable for an experiment that is soon to be conducted. This is because the payment for some of our workers in a few different experiments will depend on decisions of other workers in our main experiment at a later time, and we would like to extract the worker ID as a failsafe and for convenience when calculating the contingent payoffs to our participants in the first few experiments.

We have found that it is possible to add the worker ID to the URL's when workers accept our HIT on mTurk (by implementing the code in this link). But (with our very limited programming experience) we struggle to find a way for Lioness to extract and record this.

By following the instructions in the link, the URL for mTurk workers will look something like: https://example.com/.../_beginParticipant.php?workerID="workerID"
Note that the URL will change from _beginParticipant.php?workerID="workerID" to stage12345.php (first stage), where the addition we made to end of the the URL dissappears. We have a javascript (see below) that is able to capture the workerID in the URL when we put it in a script on our first stage, but since the page has been redirected from _beginParticipant the stage the URL no longer contains the values we are looking for. If we manually manipulate the URL in the first stage, the value is recorded the way we want.

We have tried integrating the javascript in the file _begin.php (we put it right above the command location.replace that forwards participants to the first stage), but when testing the experiment on our server we were unable to start the experiment. It works again as soon as we remove our script.

Does anyone have experience with this or suggestions on how to approach our problem?

Best regards
Håvard


Here is the javascript we use:

let searchParams = new URLSearchParams(window.location.search);
searchParams.has('workerID'); // true
let workerID = searchParams.get('workerID');
record('workerID', workerID);


Lucas Molleman - LIONESS Lab Development Team

unread,
Mar 15, 2019, 7:45:45 AM3/15/19
to LIONESS Lab help and discussion
Hi Håvard,

Recently I have done something similar. However, it's not elegant due to this immediate redirect from _beginParticipant.php. It basically follow the same kind of logic that you already propose. Here are the three steps that got this working for me:

1. After downloading your experiment, you have to manually edit the _begin.php script (in the basis folder), and get the parameter by adding this in the PHP part (assuming your link passes the workerID in the way you write): 

$workerid=$_GET['workerid'];

2. In the JS part of _begin.php, in the location.replace command you want to pass on the parameter to the first stage. You should write:  

location.replace('<?php echo FIRSTPAGE . ".php?worker_id=".urldecode($workerid)."&session_index=" . $_SESSION['sessionID'];?>');

3. In the first stage of your experiment (so in LIONESS Lab), you can get the parameter with JS and record it in the database. In a JS element you could write:

url = window.location.href; 
result = /workerid=([^&]+)/.exec(url)[1]; 
record('workerID', result);

Please let me know whether this works for you!

Cheers,
Lucas

hava...@gmail.com

unread,
Mar 17, 2019, 4:35:17 PM3/17/19
to LIONESS Lab help and discussion
Hi Lucas,

I just had the chance to try out your suggestion and it works perfectly!

I agree that it is not the most elegant solution, but as long as it works we are really happy. Thank you for taking your time to guide us, we really appreciate it!

Regards
Håvard

Marcus Giamattei

unread,
Apr 1, 2019, 6:35:06 AM4/1/19
to LIONESS Lab help and discussion
Hi Harvard,

another solution is to use the build-in external id. This is automatically stored if you add _beginParticipant.php?tic=12345. Then 12345 is stored as externalID.

Best, Marcus

die List

unread,
Mar 29, 2023, 8:10:50 AM3/29/23
to LIONESS Lab help and discussion
Hello,

I had the sam problem and the solution worked! 
Thanks!

How can I best use this variable to get a link for the payment on en external site like:

www.externalpayment.com/"instert: participation_id"


Thank you 
Best 
Emanuel

in...@lioness-lab.org

unread,
Mar 31, 2023, 9:33:23 AM3/31/23
to die List, LIONESS Lab help and discussion

Hi Emanuel,

 

I am not sure what you mean with ‘getting a link for the payment on an external site’. Once the worker ID has been recorded you can use it as a URL parameter by appending it, e.g.

 

workerid=getValue(‘workerID’)

extUrl=’www.externalpayment.com?workerid=”+workerid;

 

and then use html to show the extUrl.

 

NB if you are conducting your experiment on MTurk, there are standard payment procedures in place: https://lioness-doc.readthedocs.io/en/latest/0304_run.html#pay-your-participants-1

 

Best, Lucas

--
You received this message because you are subscribed to the Google Groups "LIONESS Lab help and discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lioness-lab...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/lioness-lab/b91e4720-5aff-4705-a933-94567365b5ffn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages