# Pavlovia survey issue with group allocation using a random number

**URL:** <https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188>\
**Category:** Pavlovia Surveys\
**Created:** [January 12, 2024, 4:50pm UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188 "2024-01-12T16:50:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lcamus](https://avatars.discourse-cdn.com/v4/letter/l/f6c823/32.png) [@lcamus](https://discourse.psychopy.org/u/lcamus)\
**Post date:** [January 12, 2024, 4:50pm UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/1 "2024-01-12T16:50:50Z")

</div>

Hi everyone,

I’ve tried to implement a simple survey where a random number is generated, which is then used to assign participants to one of two groups. Participants then see different pages depending on the group they’ve been assigned. This is the survey: [Pavlovia Survey](https://run.pavlovia.org/pavlovia/survey/?surveyId=3fa43e2c-9d89-4732-a98b-5e8eee06632f)

The issue is that, while it works fine when no answers are submitted, when I type in answers it starts going back and forth between the pages/reassigning participants to another group.  
For example: participant is assigned to group A, sees the page for group A, types in an answer, clicks Next. The survey goes back to the random number/group allocation page, sometimes assigns group B instead, participant sees the page for group B.

I’m not sure if that’s entirely clear, so I’ve taken a screen capture of what is happening, which is in the folder attached. In the folder are also the survey’s JSON file and a data file, where you can see on line 3 that I’ve been able to answer question1 (on the group A page) and question2 (on the group B page), which is because of what I’ve explained.  
[survey-group-issue.zip](https://discourse.psychopy.org/uploads/short-url/xhVIgKaKf06hgG2EQLTQoco5edo.zip) (3.0 MB)

I’ve looked at all my settings and can’t see anything that would cause this, so not sure if this is my fault or if there’s a bug maybe?

Thanks in advance for your help!  
Lorna

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 12, 2024, 5:45pm UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/2 "2024-01-12T17:45:18Z")

</div>

Sorry, but I’m afraid this is a bug. I’m hoping it will be fixed over the next month or so.

> [@Answering questions on fourth page of survey jumps the user back to first page](https://discourse.psychopy.org/t/answering-questions-on-fourth-page-of-survey-jumps-the-user-back-to-first-page/37935):
>
> In my survey, the first page is an HTML file, the second page is consent and third demographics questions, the fourth page has true or false yes/no Boolean questions, however when participants click on any of the questions and sometimes on empty space, the survey jumps them back to the first page. Their answers up to that point are saved for them, however they are also not showing to me as incomplete responses. How can I stop the study from jumping back to the first page please?

> [@Re-evaluating expressions on every button press? (block random assignment question)](https://discourse.psychopy.org/t/re-evaluating-expressions-on-every-button-press-block-random-assignment-question/37726):
>
> Hi folks, I am using Wake’s [Post](https://discourse.psychopy.org/t/what-ar-the-allowed-functions-in-expression-questions-in-survey/32886/2) as a workaround to displaying 1 of 4 possible pages in a randomised way to participants. I have created 2 variables in the main survey logic tab under Calculated Values: randNum, which is set to random()\*4+1 (so random number between 1 and 5) condition, which is set to iif({randNum} \> 4, "cond1", iif({randNum} \> 3, "cond2", iif({randNum} \> 2, "cond3", "cond4"))) I have a welcome page that I want everyone to see and then 4 pages with questions on them. I want…

[https://run.pavlovia.org/pavlovia/survey/?surveyId=0a1c0544-25d1-476d-b735-e1f074b3e387](https://run.pavlovia.org/pavlovia/survey/?surveyId=0a1c0544-25d1-476d-b735-e1f074b3e387)

---

<div class="post-metadata">

**Author:** ![lcamus](https://avatars.discourse-cdn.com/v4/letter/l/f6c823/32.png) [@lcamus](https://discourse.psychopy.org/u/lcamus)\
**Post date:** [January 15, 2024, 9:17am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/3 "2024-01-15T09:17:23Z")

</div>

Good to know, thanks Wake!

---

<div class="post-metadata">

**Author:** ![AndrewFlood](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/andrewflood/32/36896_2.png) [@AndrewFlood](https://discourse.psychopy.org/u/AndrewFlood)\
**Post date:** [February 8, 2024, 4:46pm UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/4 "2024-02-08T16:46:25Z")

</div>

I’m helping about 115 students with final year projects and they have started to get to the point where this bug manifests - it does seem to have appeared since the Autumn as I demoed using the method back in October. Hate to be putting the pressure on but any sense of that ‘month’ estimate to fix it given 27 days ago means it may well get fixed in the next week (which basically would save us a huge amount of grief) or is it further out in which case I need to dfind a workaround

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [February 8, 2024, 5:50pm UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/5 "2024-02-08T17:50:44Z")

</div>

Hi Andrew,

Honestly I’m not sure whether it will be fixed by next week.

However, I’ve just written a workaround

[https://run.pavlovia.org/vespr/survey-group](https://run.pavlovia.org/vespr/survey-group)

To launch a survey create a URL of the form

[https://run.pavlovia.org/vespr/survey-group?surveyID=733492ba-8997-416b-9c8c-4fe08c3519bc&groups=3](https://run.pavlovia.org/vespr/survey-group?surveyID=733492ba-8997-416b-9c8c-4fe08c3519bc&groups=3)

This will launch survey 733492ba-8997-416b-9c8c-4fe08c3519bc and randomly allocate a value for group between 1 and 3.

Please test.

---

<div class="post-metadata">

**Author:** ![AndrewFlood](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/andrewflood/32/36896_2.png) [@AndrewFlood](https://discourse.psychopy.org/u/AndrewFlood)\
**Post date:** [February 9, 2024, 8:32am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/6 "2024-02-09T08:32:05Z")

</div>

Hi Wake, I’m afraid when I click on [https://run.pavlovia.org/Wake/survey-group](https://run.pavlovia.org/Wake/survey-group) I’m getting a 404 not found page

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [February 9, 2024, 8:34am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/7 "2024-02-09T08:34:02Z")

</div>

Sorry, wrong link. I moved it to [https://run.pavlovia.org/vespr/survey-group/](https://run.pavlovia.org/vespr/survey-group/)

---

<div class="post-metadata">

**Author:** ![AndrewFlood](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/andrewflood/32/36896_2.png) [@AndrewFlood](https://discourse.psychopy.org/u/AndrewFlood)\
**Post date:** [February 9, 2024, 9:30am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/8 "2024-02-09T09:30:15Z")

</div>

> [@wakecarter](#):
>
> [survey-group [PsychoPy]](https://run.pavlovia.org/vespr/survey-group/)

Thanks that appears to be working with quick test at [survey-group [PsychoPy]](https://run.pavlovia.org/vespr/survey-group/?surveyId=cf5941be-5509-4c8a-b0da-f9680187162f&groups=3)

Note for anyone else you then use Display page logic like {group} = ‘1’

I presume however this method will not pass Sona credit data to the survey - any chance of a variant that would do so?

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [February 9, 2024, 9:51am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/9 "2024-02-09T09:51:22Z")

</div>

What variable do you need to pass? It already passes participant.

---

<div class="post-metadata">

**Author:** ![AndrewFlood](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/andrewflood/32/36896_2.png) [@AndrewFlood](https://discourse.psychopy.org/u/AndrewFlood)\
**Post date:** [February 9, 2024, 10:12am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/10 "2024-02-09T10:12:45Z")

</div>

Unless I’m misunderstanding the completion URL Sona is also expecting experiment\_id and credit\_token

The completion URL on the overview page should look something like this:  
`'https://ucd-ie.sona-systems.com/webstudy_credit.aspx?experiment_id=453&credit_token=249cfe8d848b4e1bb0099f8386be61bc&survey_code=' + {participant}`

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [February 9, 2024, 11:07am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/11 "2024-02-09T11:07:09Z")

</div>

Since experiment\_id and credit\_token don’t change for a given experiment then these can be hard coded in the overview page (as per your link). Is that working?

---

<div class="post-metadata">

**Author:** ![AndrewFlood](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/andrewflood/32/36896_2.png) [@AndrewFlood](https://discourse.psychopy.org/u/AndrewFlood)\
**Post date:** [February 12, 2024, 10:38am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/12 "2024-02-12T10:38:54Z")

</div>

> [@AndrewFlood](#):
>
> ‘`https://ucd-ie.sona-systems.com/webstudy_credit.aspx?experiment_id=453&credit_token=249cfe8d848b4e1bb0099f8386be61bc&survey_code=`’ + {participant}

Ah thanks, I wasn’t thinking that through fully but yes that should work for them

---

<div class="post-metadata">

**Author:** ![wendyross](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wendyross](https://discourse.psychopy.org/u/wendyross)\
**Post date:** [November 17, 2024, 5:36pm UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/13 "2024-11-17T17:36:38Z")

</div>

Hi everyone,

Trying to go with random allocation of participants to groups and I have followed Wake’s workaround (thank you as always, Wake) but I can’t seem to get the pages to display according to that logic. I have put {group} = ‘1’ etc., in the logic for each page but it still shows all the pages. I can tell from the URL that it is changing the group number. Have I missed a stage?  
Thanks!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 17, 2024, 9:20pm UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/14 "2024-11-17T21:20:02Z")

</div>

Please could you show an example of a URL? You can replace some of the survey code with xxx if you want to keep it private.

I also might need to update my code to cope with 2024 survey URLs.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 18, 2024, 9:39am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/15 "2024-11-18T09:39:01Z")

</div>

Split this topic on November 18, 2024, 9:39am UTC

2 posts were split to a new topic: [Random allocation to Condition 1 or Condition 2 in Pavlovia](https://discourse.psychopy.org/t/random-allocation-to-condition-1-or-condition-2-in-pavlovia/42965)

---

<div class="post-metadata">

**Author:** ![wendyross](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wendyross](https://discourse.psychopy.org/u/wendyross)\
**Post date:** [November 18, 2024, 5:19am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/16 "2024-11-18T05:19:42Z")

</div>

Hi, this is the link I am using : [survey-group [PsychoPy]](https://run.pavlovia.org/vespr/survey-group/?surveyId=87fff09f-8f5b-43ac-9495-0d6f06b4bd78&groups=3). Thank you!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 18, 2024, 9:37am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/18 "2024-11-18T09:37:06Z")

</div>

The URL you are using is correct. The missing step is that in the survey you need a hidden expression question to copy the value for group. I’ve just been testing with:

[https://run.pavlovia.org/vespr/survey-group/?surveyId=733492ba-8997-416b-9c8c-4fe08c3519bc&groups=3](https://run.pavlovia.org/vespr/survey-group/?surveyId=733492ba-8997-416b-9c8c-4fe08c3519bc&groups=3)

It fails if I remove this question:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/e/3e534107511449ca1e915de875c7411278e95a49.png)

N.B. Invisible expression questions fail unless “Clear the value if the question becomes hidden” is set to None

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/4/648562263e72014a06985cb1e6a7ba5ff667128c.png)

---

<div class="post-metadata">

**Author:** ![wendyross](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wendyross](https://discourse.psychopy.org/u/wendyross)\
**Post date:** [November 18, 2024, 10:10am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/19 "2024-11-18T10:10:02Z")

</div>

Yep - I have it to evaluate that now and return the group number on the first page so that variable must be set but then it does not display any of the options. This is what I have done on each page:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/1/21639da99f2605f1c610736b5f9996c771eefdf7.png)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 18, 2024, 10:16am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/20 "2024-11-18T10:16:36Z")

</div>

Try adding a final page that everyone sees. I think that there may be an issue with not being able to dynamically turn a Complete button into a Next button.

I am currently assuming that you only have one block. The survey-group code sends to the 2024.1.0 URL which only works with single blocks.

---

<div class="post-metadata">

**Author:** ![wendyross](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wendyross](https://discourse.psychopy.org/u/wendyross)\
**Post date:** [November 18, 2024, 10:29am UTC](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188/21 "2024-11-18T10:29:42Z")

</div>

Yes, only one block. I tried that and it just skipped all the questions. I often find I am doing something silly but I am going to use this as a template for students and staff so I need to get it right! I attach the json in case that helps  
[survey\_87fff09f-8f5b-43ac-9495-0d6f06b4bd78.json](https://discourse.psychopy.org/uploads/short-url/qahVkn18GxfFLPoXhfSGnSkBf4C.json) (1.6 KB)

[Next page](https://discourse.psychopy.org/t/pavlovia-survey-issue-with-group-allocation-using-a-random-number/38188.md?page=2)
