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!



  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.

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

  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.

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

  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?

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

  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! :)

  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?