INTRO
Case 1 Language Switch
First, we need to create a question for them to choose the language they want to answer the survey:
After this question, we need to add another page for the language switch. On this new page, we will add the following code:
/* STARTS EDITING PART */
let surveyCode = "814631"; //put the link for the question following the redirect
let langList = ['en', 'es', 'fr']; //add the lang codes in the same order first should be the same language as the link above, in this example both are en
let qCode = "LANG";
let nextQuestionCode = "66404" /*Enter the 5-digit code of the next question,
for example, the last 5 numbers from the survey link:
https://survey.synoint.com/en/p/891909/66357 <--- These last 5 numbers
You can get them by testing the survey and reaching the next question that
the user should see after choosing the language*/
/* ENDS EDITING PART */
document.querySelector("body").style.display = "none";
let linkPart1 = `https://survey.synoint.com/`;
let currentLang = Number(response.answers.find(elem => elem.questionCode === qCode).code) - 1;
let finalLink = linkPart1 + langList[currentLang] + "/p/" + surveyCode + "/" + nextQuestionCode;
window.location.replace(
finalLink
);
The code above is divided into 2 sections, we will focus on the first part, the editable one. We need to replace the contents of the variables following what they need:
surveyCode | This is the Survey ID |
langList | Enter the language codes, in the same order as the answers in the language question |
qCode | This is the question code for the language question. If you make the language code have this question, you don’t have to change it |
nextQuestionCode | This code is shown when testing the survey. It is the part of the link referring to the question after the redirect, in this case DEM1, as shown below: https://survey.synoint.com/en/p/814631/66404 We will use the number "66404" for this. |
If you follow the steps, you will get results similar to this:
Case 2: Select the country given the survey’s language
Let’s say you have one survey that will be for the Nordic countries:
- Finland
- Sweden
- Norway
Obviously, to ensure the quality of the data, you will have the CONTROL2 question. But in order to validate this, we need a question before that to match the country.
- Add a question with all the countries that the survey will be in
- Add the following code:
// Hide page content
const lang = document.querySelector('html').getAttribute('lang').substring(0, 2);
const buttons = document.querySelectorAll(".form-check > input");
// Click buttons depending on language
switch(lang){
case "sv":
buttons[0].click();
break;
case "fi":
buttons[1].click();
break;
case "nb":
buttons[2].click();
break;
}
document.querySelector("body").style.display = "none";
// Go next page
document.querySelector("#p_next").click();
- In case you need to add more languages/countries, add more cases, as such, adding the language code as it appears in the survey link between quotes, and add the corresponding button[position] after it.
case "nb":
buttons[2].click();
break;
Remember that this counts with logic 0, so in the example, Sweden has the answer code of 1, but in the JS it must be set as 0.