Centre d'assistance

Survey CSL snippets

Pas de commentaire

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

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.

{{#if (eq respondent.questions.questiongender.orderNumber 1)}}He{{else}}She{{/if}}

“His” or “Her” depending on the selection in a question with label “questiongender”.

{{#if (eq respondent.questions.questiongender.orderNumber 1)}}his{{else}}her{{/if}}

When based on the contact gender, this is the code to use:

He/She

{{#if contact.gender.isMale}}He{{else}}She{{/if}}

His/her

{{#if contact.gender.isMale}}his{{else}}her{{/if}}

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

  1. First create the questions, and assign labels to each question.
    In the Live example we added 3 quiz questions:
    1. How often do you eat fruit? (label: “fruitconsumption”)
    2. How often do you exercise? (label:”exercise”)
    3. Do you smoke? (label: “smoking”)
  2. Decide which answers yield which score.
  3. Create outcome questions to register that score. Hide these questions for the respondents.
    In our example the outcome questions are set up as follows:
    1. 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.
    2. 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.
    3. 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

{{#if (eq respondent.questions.fruitconsumption.orderNumber 1)}}1

{{! if the respondent selects the first answer option then we tick the first answer option in this result question, which stands for "green"}}

{{else if (or (eq respondent.questions.fruitconsumption.orderNumber 2)(eq respondent.questions.fruitconsumption.orderNumber 3))}}2

{{! if the respondent selects the 2nd or 3rd answer option then we tick the second answer option in this result question, which is the "orange" result}}

{{else}}3

{{! all other cases get "red" as result}}

{{/if}}

Excercise

{{#if 


{{! if the respondents selects the first or second answer option then he gets "green" as a result}}

(or (eq respondent.questions.exercise.orderNumber 1)(eq respondent.questions.exercise.orderNumber 2))}}1

{{!if he selects the 3rd option he gets "orange" as a result}}

{{else if (eq respondent.questions.exercise.orderNumber 3)}}2

{{! all other cases are "red"}}

{{else}}3{{/if}}

Smoking

{{#if (eq respondent.questions.smoking.orderNumber 1)}}1{{else}}2{{/if}}

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

{{#if (eq respondent.questions.fruitconsumption.orderNumber 1)}}
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.

{{else if (or (eq respondent.questions.fruitconsumption.orderNumber 2)(eq respondent.questions.fruitconsumption.orderNumber 3))}}
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? 

{{else}}
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.{{/if}}

Excercise

{{#if (or (eq respondent.questions.exercise.orderNumber 1)(eq respondent.questions.exercise.orderNumber 2))}}

You exercise (almost) daily, which is great!

Keep up the good work.

{{else if (eq respondent.questions.exercise.orderNumber 3)}}

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.

{{else}}
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.{{/if}}

Smoking

{{#if (eq respondent.questions.smoking.orderNumber 1)}}
You smoke.

Quit! It's a nasty habit, and no good ever came from it.

{{else}}

You don't smoke

Best decision of your life! It's a nasty habit, and no good ever came from it.{{/if}}

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.

{{#if 
{{! this bit says if the age is the first, second or third option, then show image 1}}
(or (eq respondent.questions.agequestion.orderNumber 1)(eq respondent.questions.agequestion.orderNumber 2)(eq respondent.questions.agequestion.orderNumber 3))}}[html code of image 1]

{{! if not, show image 2}}

{{else}}[html code of image 2]{{/if}}

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:

{{#if

{{! we check 2 things: 1: is the gender the first answer option AND is the age one of the first 3 answer options}}

(and (eq respondent.questions.genderquestion.orderNumber 1)(le respondent.questions.agequestion.orderNumber 3))}}[html code of image 1]

{{else if 

{{! again check if the age is one of the first 3 answer options, but now we need the 2nd answer option for gender, i.e. the women}}

(and (eq respondent.questions.genderquestion.orderNumber 1)(gt respondent.questions.agequestion.orderNumber 3))}}[html code of image 2]


{{else if

{{! now we look for the older respondents so the age must be the 4th answer option or higher. Gender is back to "men"}}

(and (eq respondent.questions.genderquestion.orderNumber 2)(le respondent.questions.agequestion.orderNumber 3))}}[html code of image 3]

{{else}}

{{! all other cases, meaning the women of 45 and older}}

[html code of image 4]{{/if}}

It also works with regular text of course:

{{#if (and (eq respondent.questions.genderquestion.orderNumber 1)(le respondent.questions.agequestion.orderNumber 3))}}young man{{else if (and (eq respondent.questions.genderquestion.orderNumber 2)(le respondent.questions.agequestion.orderNumber 3))}} young woman{{else if (and (eq respondent.questions.genderquestion.orderNumber 1)(gt respondent.questions.agequestion.orderNumber 3))}}slightly less young man{{else}}slightly less young woman{{/if}}

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.

  1. First create the province question. Assign a label to it. In this particular case the label “provinceQuestion” was used.
  2. Assign a score “1”, “2” or “3” to each province. Each score represents a region, e.g. 1 = Vlaanderen, 2 = Brussel and 3 = Wallonië.
  3. Create the region question.
  4. 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.
  5. Go to the Prefill tab and select Fixed text.
  6. Add the score variable:
    {{respondent.questions.provinceQuestion.score}}

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.

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.

  1. First create the province question. Assign a label to it. For this example, the label “provinceNielsen” was used.
  2. Assign a score between 1 and 5 to each province. Each score represents a Nielsen region.
  3. Create the Nielsen region question.
  4. Make sure that the order of the regions is consistent with the allotted score.
  5. Go to the Prefill tab and select Fixed text.
  6. Add the score variable:
    {{respondent.questions.provinceNielsen.score}}

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.

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.

  1. First create the state question. Assign a label to it. In this example the label usstate was used.
  2. Assign a score between 1 and 4 to each state. Each score represents a region.
Tip! To quickly add scores to long lists of answer options, click on add in bulk and then use the format [answer option]~[score].

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

Copy the below list to register all US states (including the District of Columbia) along with the scores assuming that the regions are in the following order:

  1. Northeast
  2. Midwest
  3. South
  4. West

Alabama~3
Alaska~4
Arizona~4
Arkansas~3
California~4
Colorado~4
Connecticut~1
Delaware~3
District of Columbia~3
Florida~3
Georgia~3
Hawaii~4
Idaho~4
Illinois~2
Indiana~2
Iowa~2
Kansas~2
Kentucky~3
Louisiana~3
Maine~1
Maryland~3
Massachusetts~1
Michigan~2
Minnesota~2
Mississippi~3
Missouri~2
Montana~4
Nebraska~2
Nevada~4
New Hampshire~1
New Jersey~1
New Mexico~4
New York~1
North Carolina~3
North Dakota~2
Ohio~2
Oklahoma~3
Oregon~4
Pennsylvania~1
Rhode Island~1
South Carolina~3
South Dakota~2
Tennessee~3
Texas~3
Utah~4
Vermont~1
Virginia~3
Washington~4
West Virginia~3
Wisconsin~2
Wyoming~4

  1. 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
  1. 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”.
  2. Go to the Prefill tab and select Fixed text.
  3. Add the score variable:
    {{respondent.questions.usstate.score}}

This way the correct region will be selected based on the score of each answer option in the state question.

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.

{{set "questionCount" 0}}
{{set "ratingSum" 0}}

{{#each respondent.questions}}
  {{#if (eq question.pageNumber 1)}}
    {{set "questionCount" (add (get "questionCount") 1)}}
    {{set "ratingSum" (add (get "ratingSum") scaleValue)}}
  {{/if}}
{{/each}}

{{divide (get "ratingSum") (get "questionCount")}}

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.

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.

{{#each respondent.questions}}
{{questionNumber}} {{question.text}}: {{value}}
{{/each}}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.