Variables
Variables
The variable functionality is an essential component of online survey questionnaire systems. It significantly enhances the overall capabilities of the system through dynamic content generation, data referencing and calculations, simplified questionnaire design, and complex logic implementation. It is a powerful tool for designing complex questionnaires, improving flexibility and interactivity, and providing robust support for data analysis and user experience optimization.
Advantages of Variables
The system's variable functionality not only allows for the referencing of respondents' answers but also introduces greater dynamism into questionnaire design and editing. This enhances the flexibility, data quality, and analytical capabilities of questionnaires, making it a crucial tool for improving survey effectiveness. The main advantages include:
Enhancing Questionnaire Flexibility
- Smarter Skip Logic: Dynamically adjust subsequent questions based on respondents' answers, avoiding irrelevant questions and improving survey efficiency.
- Personalized Questions: Customize questions based on respondent information (e.g., name, region) to increase engagement and relevance.
- Dynamic Options: Adjust answer choices based on previous responses, ensuring the suitability of options.
Improving Data Quality
- Reducing Errors: Avoid inaccuracies caused by irrelevant answers or inappropriate options through skip logic and dynamic choices.
- Increasing Completion Rates: Personalized questionnaires encourage respondents to complete the survey, reducing drop-off rates.
- More Accurate Data: Dynamic adjustments ensure the collected data aligns more closely with research objectives.
Simplifying Questionnaire Design
- Reducing Repetitive Questions: Avoid redundant questions by referencing variables, shortening the questionnaire length.
- Clearer Logic: Variable functionality makes complex logic easier to implement, improving design efficiency.
- Template Design: Save commonly used variables as templates for easy reuse in future questionnaires.
Strengthening Data Analysis Capabilities
- Data Correlation Analysis: Track response paths through variables, enabling deeper analysis of relationships between different answers.
- Segmented Audience Analysis: Classify respondents based on variables for more detailed group analysis.
- Data Visualization: Generate charts and graphs using variables to present data more intuitively.
Other Advantages
- Multilingual Support: Dynamically switch questionnaire language based on respondents' preferences.
- A/B Testing: Implement different versions of questionnaires using variables for comparative testing.
- Enhancing User Experience: Personalized questionnaires make respondents feel valued, increasing their engagement.
Basic Concepts of Variables
Generally speaking, the attributes of a question, such as the question text, option text, the maximum and minimum number of selections allowed, and the maximum number of characters that can be entered in a fill-in-the-blank question, are determined when designing the survey. For example, you might set a multiple-choice question to allow a maximum of 6 selections and a minimum of 2 selections, or set a fill-in-the-blank question to allow a maximum of 8 characters.
However, in complex scenarios, some conditions cannot be determined beforehand and instead depend on the respondents' answers to certain previous questions.
For instance, the maximum number of selections for the current question might be half of the number of selections made in another question. That means if a previous multiple-choice question has 6 options selected, the maximum number of selections for the current question would be 3; if 10 options are selected in the previous question, the maximum number of selections for the current question would be 5.
For content that cannot be determined beforehand and can only be dynamically decided based on conditions during the survey-taking process, variables are needed.
Building on the previous example, let's change "half" to "twice" and see the effect.
Actual application scenarios can be even more complex and variable. Below is a detailed introduction to the rules for creating and using variables.
Categorize Variables by Type
There are six types of variables, click to view detailed explanations.
Create a Variable
Click the "Variables" button in the left toolbar to open the Custom Variables panel. Click the "Create Variable" button to add a new variable to the list. Select the variable, and its contents will be displayed on the right side, where you can edit the variable name and variable value.
String Variable
A string variable's evaluation result is a sequence of characters. The value of a string variable can be a sequence of plain characters entered directly or it can reference other variables.
Numeric Variable
The evaluation result of a numeric variable must be a numerical value. Built-in numeric operators can be used to perform calculations on data. If a non-numeric variable is referenced as part of the calculation, its result will be converted to a numerical value before the calculation is performed.
Numeric Operators
When editing a numeric variable, pressing "@" brings up a variable selector, which includes commonly used numeric operation operators under "Numeric Operators". When performing numeric operations, the operators used must be selected from "Numeric Operators"; using keyboard input symbols such as plus, minus, multiplication, and division is ineffective.
-
+: Adds two numbers.
-
-: Subtracts one number from another.
-
/: Divides one number by another.
-
*: Multiplies two numbers.
-
SUM: Sums up multiple subsequent data points.
For operations like "SUM question/selected options/option values," although there is only one variable label afterward, this label contains multiple values, so the sum of all option values in the question will be calculated.
-
MIN: Finds the minimum value among multiple subsequent data points.
-
MAX: Finds the maximum value among multiple subsequent data points.
-
AVG: Calculates the average of multiple subsequent data points.
-
ROUND: Rounds off a subsequent number.
-
FLOOR: Rounds down a subsequent number to the nearest integer.
-
CEIL: Rounds up a subsequent number to the nearest integer.
-
(: Used in conjunction with the ) operator to control the precedence of operations.
-
): Used in conjunction with the ( operator to control the precedence of operations.
If the numeric calculation is too complex to be achieved with these operators alone, interface request variables can be used for the calculation.
Boolean Variable
The evaluation result of a boolean variable can only be true or false. When displayed on the answer page, "true" will be shown as "True," and "false" will be shown as "False."
Unlike other variables, a boolean variable must use existing variables or combinations of existing variables as its value, meaning it must be the result of a logical operation. Directly entered content will be ignored, such as setting a value to "1" or "abc" is not allowed; instead, existing variables should be used as values through the "@" method. Besides user-created boolean variables, the system also provides many boolean values automatically judged and given by the system, such as "too long duration," "too short duration," and so on.
The evaluation result of a boolean variable can only be "true" or "false." If the content referred to by the variable value is not of boolean type, it will be converted to a boolean type according to rules, specifically:
- If it is an empty string, it will be converted to "false."
- If it is 0, it will be converted to "false."
- Otherwise, it will be converted to "true."
The variable value input box for boolean variables can also reference boolean operators to perform boolean operations on existing variables.
When a boolean variable is directly referenced in question text or other places, it will be displayed as "True" or "False" on the answer page, typically used during questionnaire previews and testing. For example, when testing a questionnaire, temporarily printing out the result of a boolean variable in the question text will display it as "True" or "False," used to verify if the test result is correct. After verification, the boolean variable used for testing can be deleted.
Media Variable
Media variables are used to deliver image media resources. While images are typically used within the system-provided UI settings, media variables offer greater flexibility by allowing images to be inserted into various scenarios, such as within problem text or option text. The variable values of media variables generally reference existing images in the media library or are media variables extracted from nodes or options. For example, "node images" extracted from image selection questions and "option images" extracted from options are implicit variables.
Media variables ignore any text they receive.
Clicking on an embedded media variable tag will bring up the Variable Filter panel, which can be used to control the displayed size of the image.
API Request Variable
API request variables obtain their values through API requests, and the results can be boolean values, numbers, or strings. Generally, API request variables are used when the variable calculation process is complex and cannot be achieved through other types of variables.
API request variables do not have a variable value input box; instead, the specific properties of the required API are set in the editing panel.
HTML Variable
HTML variables are used to add custom styled content to the quiz page. They can also be used with HTML techniques to adjust how content is displayed on the quiz page, typically within problem text and option text.
The variable value input box for HTML variables is an HTML code editor where you can enter any valid HTML code and CSS style code embedded within style tags. There are two buttons in the upper right corner of the input box, one for formatting the code and the other for entering fullscreen mode.
HTML Placeholder
Entering code in the format "{{XXX}}" within HTML code creates a placeholder. The half-width curly braces mark the beginning and end of the placeholder declaration. After a variable containing a placeholder is used, clicking on the inserted variable tag will bring up the Variable Filter panel, where you can set the specific value of the placeholder. During the quiz, the placeholder will be replaced with the actual content.
Global Mode
If an HTML variable's name contains the "TO_GLOBAL" characters, that HTML variable will be injected into the head of the quiz page. This mode allows for custom styling code and changes to the overall appearance of the quiz page. Global mode is only effective for styling code.
Categorize Variables by Characteristics
Based on their behavioral characteristics, variables can be classified into:
Explicit Variable
Variables manually created by users in the variable panel are called explicit variables.
Implicit Variable
Implicit variables are those that appear automatically when certain conditions are met, without the need for manual creation. These variables emerge based on predefined conditions. Common implicit variables are generated from nodes, and by selecting any node in the node list within the Variable Selector, you can view the implicit variables contained within it. Typically, a questionnaire node can reference variables extracted from previous questionnaire nodes. Additionally, Loop Variables are also a type of implicit variable that cannot be manually added but will automatically appear after adding a loop node.
Commonly Extracted Implicit Variables from Nodes
- Question Name: The name of the target Question.
- Question Runtime ID: The dynamic number of the target question during runtime;
- Question Text: The question text of the target Question.
- Question Description: The Question description of the target Question.
- Time Spent: The time taken by the respondent to answer the target question, measured in milliseconds.
- Result: The response content provided by the respondent for the target question.
- Time taken is too long: A boolean variable indicating whether the respondent took longer to answer the target question than the time specified in the Response Time Validation Settings.
- Time taken is insufficient: A boolean variable indicating whether the respondent took less time to answer the target question than the time specified in the Response Time Validation Settings.
- Question Image: The image associated with the target Question.
- Custom Validation Failed: A boolean variable indicating whether the respondent's answer to the target question failed the custom validation.
- Custom Validation Failure Count: The number of times the respondent's answer to the target question failed the custom validation.
- Question Label: The label of the target Question.
- Phone Number: The phone number entered by the respondent in the target validation node, available only for validation nodes.
- Password/Verification Code: The password or verification code entered by the respondent in the target validation node, available only for validation nodes.
- Phone Number Already Used: A boolean variable indicating whether the phone number entered by the respondent in the target validation node has been used before in a previous response to the questionnaire, available only for validation nodes.
In addition to extracting variables directly from nodes, variables can also be extracted from certain options within nodes. To extract variables from options, you first need to determine the variable group extracted from the node and then extract the variables from it.
Common Variable Groups Extracted from Nodes
- All Options: Extract subsequent variables based on all options of the target question.
- Specified Option: Extract subsequent variables based on a specified option. You can specify other options here.
Variables unique to Choice question
- Selected Options: Extract subsequent variables based on the selected options of the target question.
- Unselected Options: Extract subsequent variables based on the unselected options of the target question.
Variables unique to Rating Scale question
- Rated Options: Extract subsequent variables based on the rated options of the target question.
- Unrated Options: Extract subsequent variables based on the unrated options of the target question.
Variables unique to Input Text question
- Entered Options: Extract subsequent variables based on the entered options of the target question.
- Unentered Options: Extract subsequent variables based on the unentered options of the target question.
Variables unique to Ranking question
- Sorted Options: Extract subsequent variables based on the sorted options of the target question.
- Unsorted Options: Extract subsequent variables based on the unsorted options of the target question.
Variables unique to Location Detection question
- Matched Options: Extract subsequent variables based on the matched (or selected) options of the target question. This applies only to location-based questions, where matching essentially means selection.
- Unmatched Options: Extract subsequent variables based on the unmatched options of the target question. This applies only to location-based questions.
- Location: Applies only to questions that contain location information. The coordinates, country, province, city, and district/county within it have the same meaning as in the system variables;
- Positioning Failed: A boolean variable indicating that the target node location failed.
- Positioning Successful: A boolean variable indicating that the target node location succeeded.
- Positioning failed and skipping is Allowed: A boolean variable indicating that the referenced location node did not obtain valid location information (True).
Once the variable group is determined, variables can be extracted from the options.
Common Variables Extractable After Selecting a Question
- Option Text: The text of the target option.
- Option Number: The number assigned to the target option.
- Option Score: The score value of the target option.
- Input Value: The content entered for the target option.
For text input, rating scale, and other input-type questions, the option score and input content are essentially the same.
- Option Group Name: The name of the group to which the target option belongs;
- Number of Options: The number of options that meet the conditions specified by the previous variable group.
- Option Image: The image associated with the target option.
Media variables inserted into option text may be displayed as images, but they are not option images. Instead, they are part of the option text. Option images specifically refer to image objects selected through an image selector or obtained through option references.
- Option Label: The label associated with the target option.
- Option Selected: Returns True if any option is selected in the target question, apart from other options;
- Addtional input content for options: Respondents input additional content in the options;
Variables unique to Rating Scale, Slider Scale, Continuous Scale and Point Allocation
- Same Score: Returns True if the scores of the target options are the same;
- Different Score: Returns True if the scores of the target options are different;
Variables unique to Text Input
- Same Input Value: Returns True if the input values of the target options are the same;
- Different Input Value: Returns True if the input values of the target options are different;
Variables unique to Ranking
- Option Sort Order:The sorted index number of the option after sorting.
Implicit Reference Data Transfer
When referencing an option, an implicit reference data transfer is generated by default. For grading, multiple-choice, and other types of questions, there are no option images by default. Therefore, if an image from their options is referenced, the desired content cannot be retrieved. However, if valid implicit reference data has been previously generated, the image may still be referenced.
For example, if an image question references the option image of a preceding multiple-choice question, the reference will fail because multiple-choice options do not have image resources. Subsequently, if a new image question is added before the multiple-choice question, and the multiple-choice options are set to reference the selected option of the preceding image question, the subsequent image question will obtain non-existent image resources from the multiple-choice question through implicit referencing.
This occurs because the system intelligently searches for matching resources during referencing. If an option already has a certain attribute data, this data is used preferentially when referenced. In this case, even if the implicit reference data also contains this data, it will not be used, as it is overridden by the option's own data. The updated data will also be stored in the implicit reference data for subsequent nodes.
Not only images but also other data such as option scores and option input content can be implicitly referenced.
Loop Variables
Loop variables are also a type of implicit variable.
- They can be referenced within the loop process to access the running status of previous iterations of the loop up to the current one.
- They can be referenced after the loop process to access the running status of all iterations of the loop.
System Variables
System variables are predefined by the system and located within the system variable group in the variable selector. They include the following categories:
Date
Commonly used date-related variables.
Basic
- Questionnaire ID: The unique identifier of the current questionnaire.
- Respondent ID: The WeChat ID of the respondent, which requires WeChat authorization to be set up in the questionnaire. It cannot be resolved in preview mode.
- Respondent Union ID: The union ID of the respondent's WeChat account, which also requires WeChat authorization. It cannot be resolved in preview mode.
- Respondent Nickname: The nickname of the respondent's WeChat account, which requires WeChat authorization. It cannot be resolved in preview mode.
- Respondent Source: Get the application information used by the respondent to open the questionnaire. If the respondent opens the questionnaire in WeChat, it will return "WeChat"; if the respondent opens it in a browser, it will return "Web".
- Response ID: A unique ID generated when the respondent downloads the questionnaire. It cannot be resolved in preview mode.
- Collector Code: The code of the collector used to publish the questionnaire. It cannot be resolved in preview mode.
- Collector Name: The name of the collector used to publish the questionnaire. It cannot be resolved in preview mode.
- Start Time: The time when the respondent began answering the questionnaire.
- Time Spent: The time taken by the respondent to complete the questionnaire.
- Result: All answers provided by the respondent up to the current progress.
- Current Language: The current language of the questionnaire.
- Link Type: Return the type of link for the current questionnaire, either a formal or a preview link.
Location
- Coordinates: The latitude and longitude code of the location point.
- Country: The country where the location point is situated.
- Province: The province where the location point is situated.
- City: The city where the location point is situated.
- District/County: The district or county where the location point is situated.
Context
It provides state variables that capture the instantaneous status at a specific point in time during the process of answering questions.
-
Option Text: The text of the current option.
-
Option Number: The number assigned to the current option.
-
Option Score: The score or input value of the current option.
-
Option Label: The label associated with the current option.
-
Outer Loop Text: The text of the current outer loop variable.
-
Outer Loop Index: The index of the current outer loop variable.
-
Outer Loop Number: The number assigned to the current outer loop variable.
-
Outer Loop Value: The value of the current outer loop variable.
-
Outer Loop Label: The label associated with the current outer loop variable.
-
Inner Loop Text: The text of the current inner loop variable.
-
Inner Loop Index: The index of the current inner loop variable.
-
Inner Loop Number: The number assigned to the current inner loop variable.
-
Inner Loop Value: The value of the current inner loop variable.
-
Inner Loop Label: The label associated with the current inner loop variable.
Context variables are primarily used for those that cannot be determined at creation time but only during runtime. They are most frequently used in interface request variables and advanced settings for options.
For example, consider a question with 100 options where the display of these options needs to be controlled based on the response to a previous question and the text of the current option, followed by some calculations to determine whether the option should be displayed. In this case, we need to create an interface request variable with parameters that include the response to the previous question and the text of the current option.
When setting parameters for this interface request variable, it can be cumbersome to set the text for the current option because there are so many options, and it is unclear which value to set.
If we set the text for each option to be the text of that option itself, we would need to create 100 such interface request variables and then set logical conditions for each option in the logic editor, referencing the corresponding interface request variable for each. While this approach can achieve the desired effect, it is very inefficient.
At this point, using the context option text variable directly in the setting for the option text parameter, along with a single interface request variable, can easily solve the problem. All options use the context option text variable as the logical condition. During runtime, when performing a logical judgment on a particular option, the context option text can be correctly resolved to the text of the desired option.
Another scenario is that, in the example above, the question involves a loop where the parameters of the interface request variable need to include the loop variable from the current iteration. In this case, it's not possible to directly access the target loop variable because its value can only be accessed within the loop's node. This is where the use of a contextual outer loop literal variable comes into play to overcome this limitation. When the loop reaches its Nth iteration, the contextual outer loop literal variable will capture the literal value of the loop variable at that runtime moment.
The above two cases also explain why the concept of context variables exists. Although variables are used to solve the problem of dynamic values, there are some situations where conventional variables cannot meet the needs. When creating the interface request variable in the above examples, it is not certain where it will be used or which nodes it may be used in, so it is not possible to obtain a clear setting at that time. Therefore, the concept of context variables is introduced.
With the use of context variables, regardless of which node the interface request variable is used in, as long as the target option attribute exists at the moment of execution, the text of that option can be obtained. For example, if it is used for the first option in node A, the text of the first option in node A can be obtained; if it is used for the third option in node B, the text of the third option in node B can be obtained.
When designing a questionnaire, context variables can be accessed anywhere, meaning they can be used anywhere. However, if used improperly, the variables may not always resolve to the corresponding values. For example, if the above interface request variable is referenced in the question text, the parameter for the option text will be empty because there are no runtime options at the moment the question text is generated, leading to incorrect execution of the interface code and failure to resolve the result.
Device
Information about the current respondent's terminal device.
- OS Name
- OS Version
- Browser Name
- Browser Version
- Device Vendor
- Device Model
- Device Type
Language
Information about the language of the current respondent's terminal.
URL Parameters
The URL of the answer page can carry up to 20 parsable parameters, with any additional parameters being ignored. The names of these parameters must be key1, key2, key3, ..., up to key20.
After the parameters are parsed, they can be referenced by corresponding key-named variables under the URL parameter group. If a URL parameter variable is referenced but the corresponding parameter is not present in the URL, no content can be referenced.
Suppose we design an employee survey with an original published address of DemoSurveyLink. The answer address distributed to each employee is the original address with the corresponding employee ID appended: DemoSurveyLink&key1=ID.
By referencing the key1 variable for URL parameters in the survey, we can obtain the employee ID.