Tuesday, August 26, 2014

How to transfer MTurk workers' IDs to your survey on Qualtrics

The following steps will enable you to transfer a MTurk worker's ID from MTurk to your Qualtrics survey:
  1. Create a new HIT on MTurk and, in the Design Layout section, switch to source code mode. 
  2. In the place where you want your survey link to appear, enter the following script:
    <div id="myelementLink" style="display: inline; font-family: Verdana;"><tt>URL not shown because there is an error with Javascript on your computer. To perform this HIT, you must have Javascript and cookies enabled on your browser.</tt></div>
    <script type="text/javascript" language="JavaScript"><!--
    var assignment_id_field = document.getElementById('myelementLink');
    var paramstr = window.location.search.substring(1);
    var parampairs = paramstr.split("&");
    var mturkworkerID = "";
    for (i in parampairs) {
      var pair = parampairs[i].split("=");
      if (pair[0] == "workerId")
        mturkworkerID = pair[1];
    }
    if (mturkworkerID == "" ) {
      assignment_id_field.innerHTML = '<tt>The link will appear here only if you accept this HIT.</tt>';
    } else {
      assignment_id_field.innerHTML = '<a target="_blank" href="https://YOUR_QUALTRICS_SURVEY_URL_GOES_HERE&MID=' + mturkworkerID + '"><h1><span style="color: rgb(255, 0, 0);"><span style="font-family: Courier New;"><b>CLICK HERE TO TAKE THE SURVEY!</b></span></span></h1></a>';
    }

    // --></script>

    <div class="link" id="linkDiv">&nbsp;</div>


  3.  Replace the survey url in the code (where it says "YOUR_QUALTRICS_SURVEY_URL_GOES_HERE") with your survey url. (make sure there is no space between the survey url and the code that follows it).
  4. Switch back to regular edit mode. You will see, where the survey link should be displayed, a message that says "URL not shown because there is an error with JavaScript on your computer...". This is normal. Don't worry. 
  5. Move to the Preview and Finish mode. Now the error message should be replaced by "The link will appear here only if you accept this HIT.". This is how your workers will view the HIT (if the error message still appears, you did something wrong and it won't work). 
  6. In your Qualtrics survey, add an embedded data element in your survey called MID, and set it to be populated from the survey url. This will store each worker's ID in your survey data. 
  7. Publish your survey through your HIT and collect your data! 

Note on asking workers to accept your HIT beforehand: Some workers object to accepting a HIT beforehand. The method above requires it. What I do to appease workers is add some text that says "We have to ask you to accept this HIT because we need to verify that you have not completed this survey before. According to MTurk support, accepting and then returning HITs does not affect your account or your eligibility to complete other HITs." 

In some case, I also add the full survey url (without the script) so workers who really object to accepting HITs beforehand can use it. This, of course, will defeat your original goal so it's up to you whether you want to do it or not. From my experience (and also some data I collected), HITs that use the above method show similar response rates to those that do not. In the past, I used to get some complaints from workers, but these died out in the recent months so maybe workers are getting used to this type of request. 

Best of luck in your research!




 
 

33 comments:

  1. Hi Eyal,

    Thank you for sharing this information. Can you type the code out without the box? The formatting comes out differently when I copy and paste it to MTurk, which may be why I'm getting an error.

    ReplyDelete
  2. see here - https://dl.dropboxusercontent.com/u/3863544/files%20to%20keep/appending%20ID%20script.txt

    ReplyDelete
  3. Hey Eyal - I I recently joined Qualtrics from Amazon and built a wizard that automates some of the steps required to tie a Qualtrics survey to MTurk.
    Check it out, let me know what you think, interested in your feedback.
    http://www.qualtrics.com/innovation-exchange/mturk/
    jhyde@qualtrics.com

    ReplyDelete
    Replies
    1. TurkPrime.com has this and more features to exclude specific workers, create qualifications and just launched Qualtrics integration.
      See here

      Delete
  4. Hi, can you disqualify a worker based on a screening question at the very beginning of the survey and thus not pay them? For example, if you are interested in a population of women only, can you askin about the gender as the first question of the survey and terminate the survey if the respondent is a man and thus only pay women who can complete the survry?

    ReplyDelete
    Replies
    1. You can do that using qualifications on mturk - http://docs.aws.amazon.com/AWSMechTurk/latest/AWSMechanicalTurkRequester/Concepts_QualificationsArticle.html

      Delete
  5. Hi Eyal, thank you so much for such a useful post! I have pasted your code to the MTurk design layout source section, however, although I get the "URL not shown because there is an error with Javascript on your computer. To perform this HIT, you must have Javascript and cookies enabled on your browser." message, I cannot finish editing the project. The MTurk keeps saying "Unable to update your project" and "HTML question (Layout) must contain a question". I would really appreciate it if you could teach me where I went wrong! :)

    ReplyDelete
  6. Hi, This code seems to not work anymore. I used to use it all the time, but now I can't seem to get #5 to work properly. I keep getting the same "URL not shown because there is an error with JavaScript on your computer..."

    Is there an updated code?

    ReplyDelete
    Replies
    1. I am also having the same problem. =(

      Delete
    2. Indeed there is. Here is the js snippet of how I got the workerID:

      var current_url = new URL(window.location.href);
      var workerID = current_url.searchParams.get("workerId");
      console.log("The worker ID is: " + workerID);


      Once you have it as a variable the rest should fall in place. (Note that you won't be given a workerId in the preview window, but you can use the sandbox to play around with it.)

      This might not help you specifically, but perhaps others that see this =)

      Delete
    3. Has anyone gotten this to work? I don't know where in the code to put the snippet that Unknown gave us above.

      Delete
  7. How can I embed the hitid into the survey code too?

    ReplyDelete
  8. There's a potential TYPO in the script. https://YOUR_QUALTRICS_SURVEY_URL_GOES_HERE&MID= may need to be https://YOUR_QUALTRICS_SURVEY_URL_GOES_HERE?MID=

    The "?" attaches embedded data variables, which MID will be. "&" attaches more than one embedded variable (say you had url.com?MID=2&Mood=Happy). So, if you already have embedded variables in your URL, then use the "&" to also attach MID, otherwise, use "?"

    ReplyDelete
  9. Thank you for sharing this it's very useful! However I couldn't found this as a solution in the discussion form for requesters in amazon mTurk. There are other proposed solution in the forum, but I found this much easier :)

    ReplyDelete
  10. I have noticed that only MID works for me in this example. The random code that should appear to workers it doesn't. For the code I refer to this example here that was inspired by your work (https://research-it.wharton.upenn.edu/news/capture-mturk-workers-ids-qualtrics-survey/)
    I don't know what is the problem but after submitting the study to workers, a lot of them were complaining that they didn't get any code..

    ReplyDelete