16 Advanced Survey Building
16.1 Piped Text
Piped text lets you use text from one part of your survey elsewhere. It functions kind of like an instruction to Qualtrics to copy and paste the text (or, for those with some programming experience, it’s a way of storing and printing text variables.)
This section will mainly discuss using piped text inside a survey question, but the same procedure applies if you use piped text in the survey flow (Chapter 3), embedded data (Section 16.3), display logic (Section 2.5.1), or elsewhere. For more details, see the Qualtrics documentation on piped text.
In this example, let’s use a set of two questions. The first asks, “Which video game is your favorite?” and the second asks why they prefer that game.
We can use piped text to personalize the follow-up question, so that it says (for example) “Why do you prefer Mario Kart?” rather than a generic “Please explain why that game is your favorite.”
To add piped text to the question, click the text of the question and then select the **Piped Text” button that appears.
In the piped text menu, select the source where the text comes from. In this case, we want to pipe in their response to the previous survey question, so select Survey Question > GameChoice (the name of the question) > Selected Choices.
When you add piped text, it will appear as a line of code, prefaced by a dollar sign ($
) and enclosed in curly brackets { }
. You can edit the text before or after the code, such as by adding a question mark at the end, just be sure not to change the code itself if you want it to work properly.
Finally, while it’s not part of piped text itself, you may want to add display logic or skip logic (Section 2.5) to the question so that it’s not displayed to people who answered “None of the above” in the previous question.
When someone takes the survey, the piped text code is replaced with the correct text. You can double-check this behavior by previewing the survey.
Note that piped text doesn’t work correctly with display logic if the display logic is set up “in page.”
16.2 Carry Forward Choices
Carry Forward Choices allows you to pipe specific answer choices into future questions so that respondents only see options that apply to them. Depending on the type of question, values can be carried forward as choices, statements, or scale points. Additional answer choices can also be provided in questions that feature carried forward choices.
To implement Carry Forward Choices, select the question into which the choices should be carried and choose Carry forward choices from the “Question behavior” section of the “Edit Question” menu.
For matrix questions, the text may say “Carry forward statements” (instead of “choices”).
Then select the question the choices should be carried forward from and the choices that should be carried forward. Usually, you will want Selected Choices, but you can select other options depending on your needs.
If implemented correctly, a flag will then appear on the target question indicating that carry forward choices is in use, which question the choices are being carried forward from, and which choices are being carried forward. When taking the survey, respondents should now only see the relevant options based on their responses to the trigger question.
If desired, you can also add additional non-carried-forward response options to the target question in addition to the carried-forward options by increasing the number of choices in the Choices menu from 0 and then manually adding the additional options.
The carried forward choices will be marked with a green arrow, while the manual additions will be marked with a black circle with line across it.
Respondents will now see both the selected response from the previous question (“No” in the example below) and the manually added option.
For additional details, see the Qualtrics documentation on Carry Forward Choices.
16.3 Embedded Data
Embedding data allows you to record information about your survey respondents, which you can then use inside the survey and/or when you analyze the results. For example, if you upload a contact list that contains students’ names and majors, you can embed their major into the survey, which would let you personalize questions (i.e, “How well do you like [your major]?” and auto-fill their major), ask specific questions to certain groups (i.e., “Which instrument do you play” is only shown to music majors), as well as have their majors listed in the survey results.
To add embedded data to a survey, go to the survey flow (see Chapter 3), add a new element, and choose Embedded data.
In the embedded data element, name the embedded data on the left, then determine what data should be included (the “value”) on the right.
- For query strings (see below), leave the “value” to the default that says “Value will be set from panel or URL.”
- For most other uses, click Set a value now.
- Most often, you’ll use the dropdown menu and insert piped text (see Section 16.1 above). In this context, piped text can insert random numbers, today’s date, etc. as well as the normal options to insert responses to survey questions.
- If you’re working with a more involved survey flow, you might branch participants who meet certain criteria and set a value manually for their embedded data.
Once you’ve set embedded data, it can be used in branch logic, piped text, display logic, and other places throughout your survey.
When you look at the survey responses (in the Data & Analysis tab, by downloading the file, etc.), the embedded data will show up next to the respondents’ answers.
To use embedded data in visualizations in Qualtrics Reports, they must be set as “Text Set” in the options.
16.3.1 Query Strings
Query strings are a way of embedding data based on the URL that somebody used to take the survey. For example, you could generate an anonymous link to take your survey, and use a query string to record whether participants found it through Facebook, Instagram, or TikTok.
There are two steps to set up a query string.
First, add an embedded data element using the instructions above. Leave the value blank so it will be set “by panel or URL.” Move the embedded data to the top of the survey flow so it will be recorded before respondents start the survey.
The embedded data field will be visible in the URL bar when respondents take the survey, and savvy respondents are able to delete it. So, consider short and innocuous names and values for your query string, such as “s” for “source” or “o” for “organization.”
Second, you’ll need to create the URLs that contain the embedded data.
Start by generating an anonymous URL.
(It will look something like: https://illinois.qualtrics.com/jfe/form/SV_something-or-other/
)
In a text editor, make a list of the different values you’d like your query string to take. For example, if you want to track social media platforms, list out Facebook
, Instagram
, and TikTok
(as well as any others you may need). Consider using Notepad, TextEdit, or Excel – Word works but isn’t ideal because of how it tries to format the links for you.
Copy and paste the anonymous link into the text editor.
At the end of each URL, add the following pieces in order:
- a question mark (
?
) - the name of your query string (
s
in this example) - an equals sign (
=
) - the value you would like to be stored in the data set.
- In this example, I’m using
f
for Facebook,i
for Instagram, andt
for TikTok. - You can use numbers, letters, or entire words, but avoid spaces and punctuation.
- In this example, I’m using
Altogether, it should look something like this: ?s=f
When it’s appended to the end of the URL, it should look approximately like this: https://illinois.qualtrics.com/jfe/form/SV_something-or-other/?s=f
Remember to SAVE this file so that (a) you can distribute the URLs to people and (b) you can make sense of the query strings when they appear alongside the responses.
To add multiple query strings to a URL, separate them with an ampersand (&
).
For example, I could embed year, semester, and course using the following: ?y=2024&sem=FA&crs=LAS100
which would set year (y
) to 2024
, semester (sem
) to Fall (FA
), and course (crs
) to LAS100
.
16.4 Dates
By default, survey responses record a Start date, End date, and Recorded date that are properly formatted, so it is easy to see when people started and finished taking the survey. However, it’s also possible to include date entry questions in a survey.
Below, we describe two relatively easy ways to add date questions. However, other methods exist, and are described in detail in Chapter 18.
If you download survey responses and re-upload them into Qualtrics, the Recorded date will be set to the day you re-uploaded them. (This also applies if a survey was migrated from another Qualtrics account.)
16.4.1 Text Entry Question with Validation (Easiest)
The simplest way to obtain a date is for respondents to type it in.
As outlined in the image below, you can create a text entry question, then add validation by content type, then select the appropriate “Date format” option (e.g., mm/dd/yyyy, dd/mm/yyyy, or yyyy/mm/dd).
This method requires respondents to enter leading zeroes (e.g., 01/01/2020 instead of 1/1/2020) and prevents invalid dates (e.g., February 30th).
16.4.2 Text Entry Question with JavaScript
After creating a text entry question, instead of adding validation, you can choose to add a JavaScript element that will provide the “mm/dd/yyyy” template as well as a clickable date picker.
When clicked, the date picker displays a small popup calendar.
To add the JavaScript, select the question, and in the “Edit Question” pane, scroll all the way down to the “Question Behavior” section and click “JavaScript.”
The pop-up window will contain 3 small chunks of code. Replace the first chunk of code with the following:
Qualtrics.SurveyEngine.addOnload(function() {
var textInputs = this.questionContainer.querySelectorAll('input[type="text"]');
if (typeof textInputs[0] !== 'undefined') {
textInputs[0].type = 'date';
}
});
Then click “Save.”
JavaScript code comes from Curt Grimes on StackOverflow
Adding the JavaScript does not in itself validate dates, and it also complicates the formatting used by the date validator. So, we recommend picking validation or JavaScript. If you need both, see Chapter 18.
16.5 Custom JavaScript
It’s possible to add JavaScript into Qualtrics questions to add functionality that isn’t originally present. While some CITL consultants may have JavaScript experience, it’s not one of our core consulting services, so some requests may fall outside our ability to help.
In Qualtrics, Javascript functions fall into three main categories: those that run when the page loads (addOnload
), those that run when the page is fully displayed (addOnReady
), and those that run when the page is unloaded (addOnUnload
). When you edit a question’s Javascript, you’ll generally write (or copy-paste) the code into the appropriate section of the editor, leaving the other two sections untouched.
Though it’s not practical to keep a record of everything that JavaScript can do in Qualtrics surveys, this section contains some short code snippets to do common tasks. Those with coding experience can check out the Qualtrics JavaScript API details for further implementation details.
For custom dates, see Section 16.4.
16.5.1 Language selection question
To make it easy for people to change the survey language, it’s possible to add Javascript to the language selection question to automatically update the survey language based on their response.
To do so, first create a question that asks them to choose a language.
Use the following, changing ES-ES
to the correct abbreviation for the language you’re using (as specified in the Translations tab; see Section 14.3).
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
this.questionclick = function(event,element){
if (element.type == 'radio')
{
var choiceNum = element.id.split('~')[2];
if(choiceNum==1)
{
jQuery("select[id='Q_lang']").val('EN');
}
if(choiceNum==2)
{
jQuery("select[id='Q_lang']").val('ES-ES');
}
jQuery("select[id='Q_lang']").trigger( "change" );
}
}
});
If you have more than two language choices, edit the code accordingly (possibly with the help of ChatGPT or a programmer friend).
You can also optionally hide the drop-down menu that lets survey respondents choose their language using the following code:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
jQuery(".LanguageSelectorContainer").hide();
});
As always, remember to test your changes before publishing the survey.
16.5.2 Click up/down
If you have a number entry question and want respondents to be able to click to increment the number, you can add buttons to the right of the entry field.
For a Text Entry question, use this:
Qualtrics.SurveyEngine.addOnload(function()
{
var q = document.getElementById("QR~"+this.questionId);
q.type = 'number';
q.min = 0;
q.max = 100;
});
(You can adjust min and max as desired.)
Source: Qualtrics Community post by ElieD
For a Constant Sum or Form Field question, use this:
Qualtrics.SurveyEngine.addOnReady(function()
{
var that = this.questionId;
jQuery("#"+this.questionId+" .InputText").attr({"type":"number","min":"0"});
});
Source: Adapted from a Qualtrics Community post by Shashi/Anonymous
16.5.3 Conditional looping
It’s possible to set up a block to loop a variable number of times, for example, if you ask respondents to report on incidents where a power line failed or happy memories of childhood, and you anticipate that partway through one iteration of the loop they may think of another incident.
- Set up Loop & Merge for the appropriate block. In the ‘field’ column, insert any text you would like to pipe into the questions (i.e., “first”, “second” etc. for “describe the n-th incident”), making sure to include as many iterations as you think want to permit. (i.e., if you want to allow up to 5 incidents, make sure the ‘field’ column has 5 rows.)
- In the Survey Flow, above the block that will be looped, set Embedded Data. Call the field
EndLoop
and set it equal to 1.
- For all questions in the block, add display logic (see Section 2.5.1) so that the question only displays if EndLoop is equal to 1.
- The final question in the block should be something like, “Do you want to report another incident?”
- Add the following JavaScript to that question. (Note that if you named your variable something other than
EndLoop
in step 2, you should replace it below with the appropriate variable name.)
Qualtrics.SurveyEngine.addOnload(function ()
{
this.questionclick = function(event,element)
{
console.log(event,element);
if (element.type == 'radio')
{
var choiceNum = element.id.split('~')[2];
if (choiceNum == 2)
{
Qualtrics.SurveyEngine.setEmbeddedData("EndLoop", choiceNum);
}
}
}
});