Show a Number of Randomly Selected Pages from a Survey

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!

Legacy Custom Scripting Language Deprecation Plans 

  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.

As part of our core randomization options you have the ability to display X number of random questions on the page. Unfortunately, there is not a built-in way to do the same with pages in a survey. Never fear! We'll cover the steps to use a pretty simple script to accomplish just this. These steps assume a basic familiarity with SurveyGizmo and programming.

Test it out in the survey here:

https://www.surveygizmo.com/s3/4530467/Show-a-Number-of-Randomly-Selected-Pages

OR

Add a survey with this setup to your account!

This script uses the following custom scripting functions:

  • explode
  • shuffle
  • hidepage

Survey Setup

Set up your survey pages as you wish. This script supports static pages throughout the pages that are being randomized.

For our example we're conducting a community services survey. The survey has an initial page where we collect demographic information from the respondent and a thank you page. These pages will always display to each survey respondent.

Following the initial page, there are four pages where we collect information about the following four community services:

  • waste collection (page ID 3)
  • the recycling program (page ID 4)
  • city parks (page ID 5)
  • dog parks (page ID 6)

In the interest of reducing survey fatigue and survey abandonment and ultimately getting better data, we only want to burden each respondent with responding to two of the four community services pages.

To set this up we added a custom script action to the initial page (which everyone will see) and pasted the the below script. The highlighted portions of the script can be modified with the page IDs that you would like to randomly select from and the number of random pages you would like to show.

//Page IDs to be randomly hidden go here. Make sure they are comma separated, no spaces, and inside quotes.
%%pagesHideRan = "3,4,5,6" ;
//Number of pages you want shown from the list above. No quotes or commas are needed.
%%shown = 2;

//Do not change after this line.
%%arr = sgapiExplode(',',%%pagesHideRan);
sgapiShuffle(%%arr);
foreach(%%arr as %%page)
{
sgapiHidePage(%%page,true);
}
for (%%i=0; %%i<%%shown; %%i++)
{
sgapiHidePage(%%arr[''.%%i],false);
}

You're all set. Be sure to test it out to ensure that the pages are being randomly displayed.

Scripting and Other Custom Solutions

We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.

If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for SurveyGizmo features and functionality ideas that might meet your customization. Beyond this, you might want to consult with someone on our Programming Services Team; these folks might have the scripting chops to help you to achieve what you are looking for!