CheckMarket offers a powerful scripting language to enhance your surveys and reports called the CheckMarket Scripting Language or CSL for short.
At its most basic level, it is easy to use. You can use it to place variables in your surveys and reports by selecting them from a drop-down.
At its most advanced, our scripting language gives you tremendous freedom to use complex logic to make calculations, show or hide certain blocks of texts or images and much more.
This article provides some ready-to-use CSL code snippets for different situations. Each snippet can be used immediately, or you can tailor it further to your own specific situation.
Survey CSL examples
- Refer to a man or woman with the correct pronoun
- Quiz
- Concept testing
- Prefill age category based on age
- Prefill region based on selected province
- Prefill Nielsen region based on selected province
- Prefill region based on selected US state
- Average of all questions on a page
- Respondent summary
- Calculate BMI
- Postfill a question to use in display logic and branching
- Write all answers given for a multi select question
Refer to a man or woman with the correct pronoun
You can use CSL to refer to a man with “he”, “him”, “his” etc. and to a woman with “she”, “her”, “hers,” etc.
This is useful, for example, for 360° surveys where employees need to review their colleagues. This way you can refer to that colleague with the correct pronoun.
In this example, the pronoun is defined by a question, but it can also be defined by the gender uploaded with the contacts. The code for that is provided as well.
You put this code directly in the question or answer option where you need the pronoun.
“He” or “She” depending on the selection in a question with label “questiongender”. The first answer option is “man” hence we use “orderNumber 1” to check this.
He She
“His” or “Her” depending on the selection in a question with label “questiongender”.
his her
When based on the contact gender, this is the code to use:
He/She
He She
His/her
his her
You can use CSL to create a quiz. Register the end score and show a different text based on that score.
You can also provide the overview of provided answers with some additional info
- First create the questions, and assign labels to each question.
In the Live example we added 3 quiz questions:- How often do you eat fruit? (label: “fruitconsumption”)
- How often do you exercise? (label:”exercise”)
- Do you smoke? (label: “smoking”)
- Decide which answers yield which score.
- Create outcome questions to register that score. Hide these questions for the respondents.
In our example the outcome questions are set up as follows:- For fruit the answer “daily” will result in a green score. Both “multiple times per week” and “once per week” result in an orange score. And “less than once per week” results in a red score.
- For exercise, both the answers “daily” and “multiple times per week” will result in a green score. “Once per week” results in an orange score. And “less than once per week” results in a red score.
- And for the smoking question: “yes” is a red score and “no” is a green score.
Now it’s time to register a score for each possible answer option.
For each score registration question, go to the Prefill tab and select Fixed Text. Then add your CSL code in that text box to register whether a respondent had a green, orange, or red score for each subject. This score can subsequently be used in the reports.
Fruit consumption
1
2
3
Excercise
(or (eq respondent.questions.exercise.orderNumber 1)(eq respondent.questions.exercise.orderNumber 2))}}1
2
3
Smoking
1 2
And then, of course, there are the different outcome texts that respondents get depending on their score.
In this case, put the code in a Text/media question.
Fruit consumption
You eat fruit every day and that's great!
Keep up the good work. Try and eat up to 3 pieces of fruit every day.
You eat fruit every week, which is already good.
Can you try to step it up a notch and see if you can incorporate fruit into your daily meals?
You do not eat enough fruit.
Try and eat at least one piece of fruit every day. Add it to a yogurt bowl or make a (green) smoothie. You'll be amazed at the results.
Exercise
You exercise (almost) daily, which is great!
Keep up the good work.
You exercise weekly, which is good.
But surely you can sneak in an extra session or 2? Even going for a walk for half an hour (or more) is better than slouching in the couch.
You don't exercise at all.
Your body (and soul) deserve better than that.
Start small: take a stroll through the neighborhood, or go cycling for half an hour. Do you like to dance? Turn your living room into a disco and dance, dance, dance! You'll be surprised at how good you feel afterwards.
Then build up gradually until you get to at least 3 exercise sessions per week.
Smoking
You smoke.
Quit! It's a nasty habit, and no good ever came from it.
You don't smoke
Best decision of your life! It's a nasty habit, and no good ever came from it.
Concept testing
Based on the answer pattern of your respondents you can show different images, text, prices, …. to them. Very useful when you want to test different concepts and these differ based on certain answers or socio-demographic criteria.
When using images, simply upload them into the media library and copy the HTML code.
In the examples below we base ourselves on 2 questions: age and gender, but you can go as broad as you like.
First a simple example, based only on the age of the respondent.
Here we are showing 2 different images: image 1 to people younger than 45 and image 2 to people of 45 and more.
(or (eq respondent.questions.agequestion.orderNumber 1)(eq respondent.questions.agequestion.orderNumber 2)(eq respondent.questions.agequestion.orderNumber 3))}}[html code of image 1]
[html code of image 2]
But you can combine age and gender.
Here we are showing 4 different images: one to women younger than 45, one to men younger than 45, another one to women of 45 and over and a fourth one to men of 45 and over:
(and (eq respondent.questions.genderquestion.orderNumber 1)(le respondent.questions.agequestion.orderNumber 3))}}[html code of image 1]
(and (eq respondent.questions.genderquestion.orderNumber 1)(gt respondent.questions.agequestion.orderNumber 3))}}[html code of image 2]
(and (eq respondent.questions.genderquestion.orderNumber 2)(le respondent.questions.agequestion.orderNumber 3))}}[html code of image 3]
[html code of image 4]
It also works with regular text of course:
young man young woman slightly less young man slightly less young woman
Prefill age category based on age
It is important to think about how you want to analyse and present your data ahead of time. A good example is ‘Age’.
Say you have birth dates or ages in a contact field. If you know that you want to present your survey results with a breakdown based on certain age categories, then it much easier to set that up ahead of time, by creating a hidden radio buttons question with the age categories you want. That way, you can easily make charts, filter and break out results based on those age categories.
A little bit of work upfront will save tons of time when it comes time to analyse your survey results.
- First add new radio buttons question.
- Enter as answer choices, the age categories you would like to have.
- Go to the Prefill tab and select Fixed text.
- Add the following CSL, adjusted to match your categories. It assumes that the source is a contact field called ‘Age’:
1 2 3 4 5 6
The numbers 1,2,3,4,5,6 stand for the answer option order number:
1 = less than 20
2 = 20 to 29
3 = 30 to 39
4 = 40 to 49
5 = 50 to 59
6 = 60 plus
The ‘lt’ stands for less than. So it basically says if the contact field ‘Age’ is less than 20 then select answer choice 1, else …
If you use other ranges, just adjust the answer choices and the code to match. The source could also be question instead of a contact field, like a slider or textbox with integer validation.
If you have a data-of-birth, then you can calculate the age and place it in a temporary variable with the following code:
{{set "age" (dateDiff respondent.questions.DOB currentDate "year")}} or {{set "age" (dateDiff contact.dateOfBirth currentDate "year")}} {{#if (lt (get "age") 20)}} 1 {{else if (lt (get "age") 30)}} 2 {{else if (lt (get "age") 40)}} 3 {{else if (lt (get "age") 50)}} 4 {{else if (lt (get "age") 60)}} 5 {{else}} 6 {{/if}}
Prefill region based on selected province
During your analysis you may sometimes wish to do an analysis based on a larger geographical region as well as based on the province or state that a respondent lives in.
Whereas this used to mean that you needed to ask both questions, or add the info manually to the raw data, using CSL you can capture the larger region in a hidden question based on the city, state or province that a respondent selected in a previous question.
More specifically, you will use the score of the base question to prefill a subsequent question. This score represents the order of the answer options in the follow-up question.
Additionally you can use this hidden question to set your quota.
- First create the province question. Assign a label to it. In this particular case the label “provinceQuestion” was used.
- Assign a score “1”, “2” or “3” to each province. Each score represents a region, e.g. 1 = Vlaanderen, 2 = Brussel and 3 = Wallonië.
- Create the region question.
- Make sure that the order of the regions is consistent with the allotted score, i.e. if the Flemish provinces received a score of 1, put Vlaanderen as the first answer option.
- Go to the Prefill tab and select Fixed text.
- Add the score variable:
This way the region question will be prefilled based on the score of each answer option in the province question.
A province with score 1 will result in the prefilling of the first answer option in the region question, a province with score 2 will prefill the 2nd answer option, etc.
Prefill Nielsen region based on selected province
Nielsen regions are also used often in market research. Respondents don’t know what Nielsen regions are, or which one they live, so asking this question would be quite useless. But you can capture this information in a hidden question based on their response to the province question.
- First create the province question. Assign a label to it. For this example, the label “provinceNielsen” was used.
- Assign a score between 1 and 5 to each province. Each score represents a Nielsen region.
- Create the Nielsen region question.
- Make sure that the order of the regions is consistent with the allotted score.
- Go to the Prefill tab and select Fixed text.
- Add the score variable:
This way the correct Nielsen region will be selected based on the score of each answer option in the province question.
A province with score 1 will result in the prefilling of the first answer option in the region question, a province with score 2 will prefill the 2nd answer option, etc.
Prefill region based on selected US state
The US Census Bureau considers there to be four regions of the US: the Northeast, the Midwest, the South, and the West. If you ask what state people live in, you can capture this region in a hidden question.
- First create the state question. Assign a label to it. In this example the label usstate was used.
- Assign a score between 1 and 4 to each state. Each score represents a region.
For example Alabama~3 registers “Alabama” as an answer option and will allot score “3” to it automatically.
Show list of US states and scores
- Create the region question. Again, if you wish to make use of the list above, put the regions in the following order:
- Northeast
- Midwest
- South
- West
- Make sure that the order of the regions is consistent with the allotted score. For example, if “Northeast” is the first answer option, then all states belonging to the Northeast region must have received score “1”.
- Go to the Prefill tab and select Fixed text.
- Add the score variable:
This way the correct region will be selected based on the score of each answer option in the state question.
Average of all questions on a page
This snippet returns the average rating for all questions on a page given by the current respondent. That means that you can add questions and sub-questions to the page without updating the CSL code.
First we create two variables: one to hold the number of questions & sub-questions found on the page and another to hold the sum of all the ratings given by the respondent to those questions. Then we loop through all the questions of the survey and if the questions are on the page we want, we add them to our variables. After the loop, we simply divide the sum of the ratings by the number of questions to get the average rating.
Tips:
- Make sure that all questions on that page have the same scale.
- Answers are only registered after a respondent clicks on the ‘Next’ button. This means that the CSL code has to be at least on the next page, otherwise CSL won’t have the answers from that page yet.
- To save and see the average later in reports, you need to prefill a hidden slider question. Set the min and max of the slider to match the min and max of the scale of the questions on the source page.
Respondent summary
This snippet returns a list of all questions in your survey along with the answers given by the current respondent.
This snippet can be used on the thank-you page, thank-you email or even in your email notifications.
:
Calculate BMI
You can use CSL to calculate various scores like BMI. Don’t forget to save the value in hidden question too or else you will not be able to see it in the reporting.
To calculate BMI, take a person’s weight in kilograms and divide it by their length in meters squared. Here is the formula:
To make things more manageable use temporary variables. Remember that temporary variables only work on the same page.
First you have page in your survey, where you ask for your respondent’s height and weight. Then on the next page, you show them their result. Thew result page would look something like this:
Weight : {{respondent.questions.weight}} kg
Height: {{respondent.questions.height}} m
{{set “BMI” (round (divide respondent.questions.weight (pow respondent.questions.height 2)) 2)}}
Your BMI is:
{{get “BMI”}}
{{#if (lt (get “BMI”) 18,5)}}
You are underweight.
{{else if (lt (get “BMI”) 25)}}
You have a healthy weight.
{{else if (lt (get “BMI”) 30)}}
You are overweight
{{else}}
You are obese.
{{/ if}}
If you want to use pounds and inches instead of the metric system use this CSL calculation:
{{set “BMI” (round multiple((divide respondent.questions.weight (pow respondent.questions.height 2)) 703) 2)}}
A couple of tips:
CSL calculations always start with the operator.
When trying to put together a calculation this one, with a lot of nestled parts, try calculating the inner parts first and then keep adding to it. So in one tab you have the question editor where you work and in another tab, you have the survey open to that page and that way, you can keep making small changes and then refreshing the survey tab to see the result. You can also work with more temporary variables to hold parts of the calculation and then use the variables in your final calculation.
Postfill a question to use in display logic and branching
Sometimes, you want to use a calculation or other CSL in page display logic or branching. Since this cannot be done directly, you can use your calculation to post-fill a question. Then you can use the question in your display logic or branching. There is an added advantage, that the question will also be available in the reporting for filters. Say you want to show a page if a respondent selected more than 1 answer in a checkboxes question, maybe to show them a rank-order question.
To get start, created a hidden radio buttons question, ‘More than 1 option chosen?’, with two answer choices, ‘yes’ and ‘no’, at the bottom of the page with the checkboxes question. Make sure your checkboxes question has a data label since you will need it to refer to the CSL. Then in the radio buttons question, go to the Prefill tab and select ‘Fixed text or CSL’ and enter the following CSL:
yes no
What this says is, if the count of answer choices selected in the question with data label ‘myLabel’, is greater than (gt) one, select ‘yes’ otherwise select ‘no’.
You can also replace the ‘yes’ and ‘no’ in the code with ‘1’ and ‘2’, which stands for the first and second answer choice. You will need to that if your survey is multilingual.
Select Yes, next to Postfill value after page is submitted?
Now you can use the radio buttons question in your display logic, branching and reporting.
Write all answers given for a multi select question
The ‘each’ takes us through each answer given by the current respondent and we add to a temporary variable. At the end, we use the ‘get’ to write out the contents of the variable.
Here is an even more complex example that only returns answer choices that the respondent answered that contain the word ‘happy’.
Comments
0 comments
Please sign in to leave a comment.