Record Page Title of Randomized Pages

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.

Randomization is a very popular survey tool for eliminating bias introduced by order and/or survey fatigue. Within SurveyGizmo you can randomize questions, pages (or pages in groups) or even answer options! We have a merge code [page("pagepath")] that you can use in a hidden value to store the page SKUs of each page that your survey respondent sees, however, some customers who have custom page titles would prefer to store the page title. In this example we cover a script for recording the page titles in order that they were displayed for a each response when using page randomization.

Check it out in an example survey!

OR

Add a survey with this setup to your account!

Features used in this example:

  • Custom Script Action
  • Custom Scripting function sgapiGetValue
  • Custom Scripting function sgapiSubStr
  • Custom Scripting function sgapiSetValue
  • Custom Scripting function sgapiCurrentPageTitle

Survey Setup

Set up your survey pages as you wish. 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.

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 order bias we will randomize each of the community service pages.

Setting Up the Script

To start you'll need to create a textbox question to store the random order. For our example we put this on a new page so that we can display the stored value. You can do the same for testing. Then just move it to another page in your survey and select the option to Hide By Default on the Logic tab once you've confirmed it is working properly.

Next, at the top of each page in your survey create a custom script action and paste the below code. The only change you'll need to make is the question ID for your textbox question that you created to store random order. This is highlighted in the script below.

​/********* Record Presentation Order of Randomized Pages ********
This script goes at the top of each Randomized Page.
Presentation order is saved as a comma delimited list
in a hidden textbox question.
*****************************************************/

// get current page SKU
%%ThisPage = sgapiCurrentPageTitle();

//*******************************************
// add ThisPage to end of PO (Presentation Order)

// get Existing PO list from POqid
%%POqid = 58;
%%PO = sgapiGetValue(%%POqid);

// append ThisPage to end of PO list
%%PO .= ",".%%ThisPage;

// remove leading comma if present
if (sgapiSubStr(%%PO,%%offset = 0,%%len = 1) == ",")
%%PO = sgapiSubStr(%%PO,%%offset = 1);

// test
// %%output .= "/PO:".%%PO."/";

// save PO
sgapiSetValue(%%POqid,%%PO);

//*************** end of script ************** 

Test, test, test!

Now you're ready to test. Record several responses and verify that the randomization order is storing properly.

Hide the Random Order Textbox

Now we just need to hide this field from respondents' view and you're all set! To do so, edit the question, go to the Logic tab and select the option to Hide by Default. You're all set!

Scripting and Other Out-of-the-Box Customizations

We’re always happy to help you debug any documented script. That said, we do not have the resources to write scripts on demand.

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!

@plans @pro @ent