Re: [oTree] Additional Parameters to Start Links

690 views
Skip to first unread message

Chris @ oTree

unread,
Apr 27, 2021, 10:09:01 PM4/27/21
to Benson Njogu, oTree help & discussion
The only official way to get participant vars into oTree is via the REST API. If that is not an option for you, then maybe you can somehow encode your extra data into the participant_label parameter in the URL, then parse it in the backend by accessing participant.label. 

Sent from my phone

On Apr 22, 2021, at 9:55 PM, Benson Njogu <benso...@gmail.com> wrote:

I would like to pass some additional parameters to participant start links e.g 


Any suggestions on how to approach it? The additional parameters should be saved into the player object.

--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/3a662618-6423-4999-943f-1c46e38ea598n%40googlegroups.com.

Chris @ oTree

unread,
Apr 27, 2021, 10:09:01 PM4/27/21
to Benson Njogu, oTree help & discussion
If your other server cannot make POST calls, then you can make a simple service that sits in between that server and oTree and converts the GET parameters into a rest API call then redirects the user to oTree. That’s what oTree HR does. 

Sent from my phone

On Apr 22, 2021, at 9:59 PM, Chris @ oTree <ch...@otree.org> wrote:

The only official way to get participant vars into oTree is via the REST API. If that is not an option for you, then maybe you can somehow encode your extra data into the participant_label parameter in the URL, then parse it in the backend by accessing participant.label. 
Message has been deleted

Itamar Bellaiche

unread,
Aug 16, 2021, 10:31:54 AM8/16/21
to oTree help & discussion

Hello everyone,

I have a similar situation.

I work with a platform that requires adding an extention ".aspx?id=XXX" to the start link of my oTree survey.
The platform will generate an id for each participant.
For example, participant number 324 will click on the URL:
"https://my_oTree_app_name.herokuapp.com/join/tahereki.aspx?id=324" (where tahereki is an example taken from a session-wide link)

How can I record and save the id number and add it as a participant variable?

Thank you very much,

Itamar

BonnEconLab

unread,
Aug 16, 2021, 12:43:05 PM8/16/21
to oTree help & discussion
Hi,

Maybe I’m naïve, but shouldn’t the following work in your situation?

When I set up a room in oTree without explicit participant labels provided in a .txt file, I can record the required extension “.aspx?id=XXX” as a participant label. Here is an example using oTree’s “built-in” “Room for live demo (no participant labels)”: Setting up this room yields a (demo) URL


If I extend this URL so that it reads


then the participant.label column in the data set contains the information that you need. The same trick works for session-wide links such as


If all you need is to record that variable, then that should suffice, shouldn’t it? If, for some reason, you need to evaluate or manipulate this variable (say, to extract only the three digits), then you can access it in your oTree code (via player.participant.label in the “no-self” version), as Chris already suggested in April.

Best,

Holger

Itamar Bellaiche

unread,
Aug 25, 2021, 6:29:08 AM8/25/21
to BonnEconLab, oTree help & discussion
Hi everyone,

Firstly, I want to thank Holger for his answer! So thank you Holger.

Now what Holger proposed works fine, unless I have an extra "&" in the variable I need to record.

In fact, I need to record variables like: .aspx?id=XXX&session=YYY.

Unfortunately, when I use http://localhost:8000/room/live_demo/?participant_label=.aspx?id=XXX&session=YYY, the variable recorded is:
participant.label = .aspx?id=XXX.

What can I do in order to get the whole expression .aspx?id=XXX&session=YYY ?

Thank you very much!

Itamar



You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/FIDiiE-H3Tc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/80e7267f-f3b8-45cc-b7a8-0245cd851f15n%40googlegroups.com.

Chris @ oTree

unread,
Aug 25, 2021, 6:52:31 AM8/25/21
to oTree help & discussion
I doubt that platform wants to put .aspx at the end of your URLs. That doesn't make sense. They were probably using that as an example since it's a common ending for URLs, just like .php. 
But oTree URLs don't end in .aspx.

Chris @ oTree

unread,
Aug 25, 2021, 6:56:07 AM8/25/21
to oTree help & discussion
Anyway, it seems the efficient solution would be for the other platform to let you configure the name of the URL parameters, so that instead of "id" you can call it "participant_label". Because oTree doesn't recognize URL parameters called "id" or "session" and in the future they may be reserved for other things.

Itamar Bellaiche

unread,
Aug 25, 2021, 7:30:36 AM8/25/21
to Chris @ oTree, oTree help & discussion
Hi and thank you,

Chris, you are right about the .asp, it was just an example.

But the issue is this:

When initializing a participant by http://localhost:8000/join/damuzete/?participant_label=.whatever&extratext, only the "whatever" part is recorded as the participant label, meaning participant.label = whatever.
Is there any way to record the whole expression, including the ampersand (&) and what comes after it ("extratext" in my example), as the participant label?
Meaning I would like it to record as: participant.label = whatever&extratext.

Thank you very much,

Itamar

Chris @ oTree

unread,
Aug 25, 2021, 7:39:33 AM8/25/21
to oTree help & discussion
That won't work. The & automatically separates it into a separate parameter.

Max R. P. Grossmann

unread,
Aug 25, 2021, 7:46:37 AM8/25/21
to Itamar Bellaiche, oTree help & discussion
Itamar,

Recall that you can easily extract GET parameters using JavaScript: https://stackoverflow.com/a/5448595

So, in the worst case, you "just" need to put another oTree experiment before the actual experiment; the first "experiment" then extracts the relevant parameters using JavaScript and redirects to the actual experiment, perhaps using a different and more convenient parameterization.

Best,

Max

25 Aug 2021 13:30:50 Itamar Bellaiche <itamar.b...@mail.huji.ac.il>:

> Hi and thank you,
>
> Chris, you are right about the .asp, it was just an example.
>
> But the issue is this:
>
> When initializing a participant by http://localhost:8000/join/damuzete/?participant_label=.whatever&extratext, only the "whatever" part is recorded as the participant label, meaning participant.label = whatever.
> Is there any way to record the whole expression, including the ampersand (&) and what comes after it ("extratext" in my example), as the participant label?
> Meaning I would like it to record as: participant.label = whatever&extratext.
>
> Thank you very much,
>
> Itamar
>
> On Wed, Aug 25, 2021 at 1:56 PM Chris @ oTree <ch...@otree.org> wrote:
>> Anyway, it seems the efficient solution would be for the other platform to let you configure the name of the URL parameters, so that instead of "id" you can call it "participant_label". Because oTree doesn't recognize URL parameters called "id" or "session" and in the future they may be reserved for other things.
>>
>> On Wednesday, August 25, 2021 at 4:52:31 AM UTC-6 Chris @ oTree wrote:
>>> I doubt that platform wants to put .aspx at the end of your URLs. That doesn't make sense. They were probably using that as an example since it's a common ending for URLs, just like .php. 
>>> But oTree URLs don't end in .aspx.
>>>
>>> On Wednesday, August 25, 2021 at 4:29:08 AM UTC-6 itamar.b...@mail.huji.ac.il wrote:
>>>> Hi everyone,
>>>>
>>>> Firstly, I want to thank Holger for his answer! So thank you Holger.
>>>>
>>>> Now what Holger proposed works fine, unless I have an extra "&" in the variable I need to record.
>>>>
>>>> In fact, I need to record variables like: *.aspx?id=XXX&session=YYY*.
>>>>
>>>> Unfortunately, when I use http://localhost:8000/room/live_demo/?participant_label=.aspx?id=XXX&session=YYY, the variable recorded is:
>>>> participant.label = .aspx?id=XXX.
>>>>
>>>> What can I do in order to get the whole expression _.aspx?id=XXX&session=YYY_ ?
>>>>
>>>> Thank you very much!
>>>>
>>>> Itamar
>>>>
>>>>
>>>>
>>>> On Mon, Aug 16, 2021 at 7:43 PM BonnEconLab <bonne...@uni-bonn.de> wrote:
>>>>> Hi,
>>>>>
>>>>> Maybe I’m naïve, but shouldn’t the following work in your situation?
>>>>>
>>>>> When I set up a room in oTree without explicit participant labels provided in a /.txt/ file, I can record the required extension “.aspx?id=XXX” as a participant label. Here is an example using oTree’s “built-in” “Room for live demo (no participant labels)”: Setting up this room yields a (demo) URL
>>>>>
>>>>> http://localhost:8000/room/live_demo
>>>>>
>>>>> If I extend this URL so that it reads
>>>>>
>>>>> http://localhost:8000/room/live_demo/?participant_label=.aspx?id=XXX
>>>>>
>>>>> then the participant.label column in the data set contains the information that you need. The same trick works for session-wide links such as
>>>>>
>>>>> http://localhost:8000/join/damuzete/?participant_label=.aspx?id=XXX
>>>>>
>>>>> If all you need is to record that variable, then that should suffice, shouldn’t it? If, for some reason, you need to evaluate or manipulate this variable (say, to extract only the three digits), then you can access it in your oTree code (via player.participant.label in the “no-self” version), as Chris already suggested in April.
>>>>>
>>>>> Best,
>>>>>
>>>>> Holger
>>>>>
>>>>>
>>>>>
>>>>> itamar.b...@mail.huji.ac.il schrieb am Montag, 16. August 2021 um 16:31:54 UTC+2:
>>>>>> …
>>>>> --
>>>>> You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
>>>>> To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/FIDiiE-H3Tc/unsubscribe.
>>>>> To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
>>>>> To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/80e7267f-f3b8-45cc-b7a8-0245cd851f15n%40googlegroups.com[https://groups.google.com/d/msgid/otree/80e7267f-f3b8-45cc-b7a8-0245cd851f15n%40googlegroups.com?utm_medium=email&utm_source=footer].
>> --
>> You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/FIDiiE-H3Tc/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
>> To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/1d2e9294-5d9b-44d9-907d-6479751db5d5n%40googlegroups.com[https://groups.google.com/d/msgid/otree/1d2e9294-5d9b-44d9-907d-6479751db5d5n%40googlegroups.com?utm_medium=email&utm_source=footer].
> --
> You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/CAOJj8PcUgqCuy92Uy8xHBUEdTTjruEi%3D3GFSXgWYAGvoq7d2oQ%40mail.gmail.com[https://groups.google.com/d/msgid/otree/CAOJj8PcUgqCuy92Uy8xHBUEdTTjruEi%3D3GFSXgWYAGvoq7d2oQ%40mail.gmail.com?utm_medium=email&utm_source=footer].

Max R. P. Grossmann

unread,
Aug 25, 2021, 8:18:22 AM8/25/21
to Itamar Bellaiche, oTree help & discussion
Itamar,

Please see here for an example: https://cdn.mg.sb/get.html?participant_label=xyz123&session=5

As you can see in the source code of this page, you don't even need to use a separate oTree experiment. A static HTML page with some JavaScript is entirely sufficient.

Best,

Max
> To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/458f97a2-a985-44d9-a36f-ca1501cb14ec%40max.pm.

BonnEconLab

unread,
Aug 25, 2021, 11:49:21 AM8/25/21
to oTree help & discussion
Dear Itamar (et al.),

Max’s method sounds like a good solution to me for your case because it provides a lot of flexibility.

Here are two additional (speculative) suggestions if Max’s method should not be feasible in your case:

I know you wrote that the format should be “id=XXX&session=YYY”. Being able to include a session ID implies, however, that your mailing platform provides some sort of flexibility. So maybe the following two suggestions work:
  1. Maybe your mailing platform is able to combine the session ID and the subject ID into a single number. For instance, if the session ID is a number and the subject ID is no larger than 999, multiply the session ID by 1000 and add the subject ID to get
    http://localhost:8000/room/live_demo/?participant_label=YYYXXX.
       
  2. If you can send out different URLs to different subgroups, you could create one room per session in oTree (via settings.py) and send out links like
    http://localhost:8000/room/session001/?participant_label=XXX
    http://localhost:8000/room/session002/?participant_label=XXX
    etc.
Cheers,

Holger

Chris @ oTree

unread,
Aug 25, 2021, 12:21:45 PM8/25/21
to oTree help & discussion
Thanks Holger and Max, these are both good approaches.

Another approach would be to use oTree's REST API. I have added an example here: https://github.com/oTree-org/extra-url-params

Itamar Bellaiche

unread,
Aug 27, 2021, 1:08:06 PM8/27/21
to Chris @ oTree, oTree help & discussion
Thank you very much, all of you (Max, Holger and Max)!!

Your help is very appreciated.

Itamar

Reply all
Reply to author
Forward
0 new messages