How to random texts' links from a database on Qualtrics ?

Lafo_RLafo_R Community Member Qubie ✭

How to random texts' links from a database on Qualtrics ?

I created a survey on Qualtrics a few weeks ago. In this survey, I put a link to download a text that the respondent must read and answer questions about it.
But for the second step of this survey, I would like to generate a link to a text (preferably from a database, but if this is not possible, I can still manually add each text on qualtrics) that is randomly chosen. In addition, I would like there to be a good split between the random link so that the responses are well proportioned.
In summary, if someone connects to my survey, he or she would receive a random text's link (from a database) but I need to know what text he or she received in order to conduct my analysis.
In addition, I would like to have more or less the same number of responses for each text.

Thank you for your help!

PS : I hope to receive an answer for my first question on the Qualtricscommunity :-)

Best Answer

  • flebfleb Czech Republic Sage ✭✭✭
    edited January 24 Accepted Answer

    Hi @Lafo_R ,
    I have two solutions for you.

    The first way:
    1) put an HTML element with a given ID (in this example "div.txt"; you can see the element in the file attached I wasn't able to put it inside the answer).
    2) And put following JavaScript into this question.

    Qualtrics.SurveyEngine.addOnload(function()
        {
    
        function getRandomInt(min, max) {
        min = Math.ceil(min);
        max = Math.floor(max);
        return Math.floor(Math.random() * (max - min + 1)) + min;}
        //Define function which gives you a random integer in a given range
        //https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range
    
        var links = ["https://www.w3schools.com/html/", "https://www.qualtrics.com/", "https://www.google.com/"]; 
    //Create an array with your links
    
        var i = getRandomInt(0, links.length -1);
         //Generate a random index of your array  
        document.getElementById("my_link").innerHTML =  '<a href="'+ links[i] + '" target="_blank">Download this file</a> '; 
       //Replace your HTML element with a HTML element containing your links
    
     Qualtrics.SurveyEngine.setEmbeddedData("my_file", i);
     //Put index into the Qualtrics output. Beware it must be already defined in the survey flow
    });
    

    The second way:
    Another way will be better if you have a lot of files, but if you are starting with Qualtrics it might be a little bit more complicated to implement it.
    1) Create a separate block with Loop & Merge for the question with the link.
    2) Put some IDs or names of your files into the first field and your links onto the second field. (The first field will be used in the Qualtris output so it is not a good idea to put there links). Check that you want to randomize loop order and present only 1 loop.
    It should look somehow like this.

    This will select a random file for each respondent.

    3) Create a link to your files in the body of your question in HTML. Just put piped text referring to the Field2 there, where you usually put the URL (see file "link.txt" for an example; you have to use the "HTML View" to do this).

    4) Create a new embedded data filed in the survey flow (called for example "my_file") and place following JavaScript to the question.

    Qualtrics.SurveyEngine.setEmbeddedData("my_file", "${lm://Field/1}");

    This will create a new column in your data. This column will store the name/ID of the file a respondent was working with.

    I think you can use your own links in both cases (and don't need to put all your files into the Qualtrics) if your database is public.

Answers

  • [Deleted User][Deleted User] Qubie ✭
    edited January 23

    Hello @Lafo_R ,

    Assuming you have n number of text links and you want to show one link randomly to the respondent.

    Use Randomizer in the survey flow to randomly choose one link and assign to a embedded data. Pipe this embedded data in the question, so that the user can download. Also check "Evenly present" option in the Randomizer so the respondent are well proportioned.

  • flebfleb Czech RepublicCommunity Member Sage ✭✭✭

    Hi @Shashi ,
    I started writing before you send the answer, so I haven't seen it. Your solution is definitely more elegant than mine. I'll leave my answer here for the case someone would have many links in a table and wanted just copy and paste them.

  • Lafo_RLafo_R Community Member Qubie ✭

    Thank you to both of you for the quick answer. I decided to use the solution of @fleb as it is, I think, the best way to do what I want. As I have to add 50 texts' links (but more in a few weeks).

    I juste have the problem that the text's link doesn't appear in the survey.
    Here is where I want to add the random link

    Here is what I already did

    The fact is that I don't receive any text's link when I preview the survey ...

    I don't know if I was clear enough in the description of my question.
    But I would like that a respondant receive only one text (randomly chosen in my data base, here for example test 1 ou test2), and then he will answer the rest of the survey (questions are the same for each text) . I will, after, look at these answer and link it with the randomly chosen text.

    Thank you !

    Rémy

  • flebfleb Czech RepublicCommunity Member Sage ✭✭✭

    Hi @Lafo_R ,
    I'm glad you found my solution useful. Unfortunately, I forgot to describe you one important step. I have added it to my original answer. It is step number 3. I hope it will be OK now.

Sign In to Comment