passing info to scriptingrt

when embedding a scriptingrt swf in a web page, it is possible to pass information from the html page to the flash swf in the form of flashvars (see Flashvars on the examples page).

however, we noticed some problems when embedding a swf in a qualtrics page – the swf seemed to loose focus, or at least it was sometimes hard to give the focus back to it after clicking somewhere else. As an alternative, we decided to test opening the swf in a separate window directly, without embedding it in a html wrapper. Question is, can you then still transfer info to it?

Turns out you can. This swf displays 4 trials. Two of them are taken from flashvars, and we pass them here appended after the file name in the link, with “…flashvars.swf?myFirstName=thomas&myLastName=schubert” target=”_blank” (opening in a new window). If you change those values, you get different trials.

using videos on qualtrics

how to use a video in a qualtrics survey (easy & lazy version)

– upload your video to youtube. adjust the privacy and other settings (e.g., unlisted, don’t allow comments)

– change the name to something appropriate, it will be displayed when the video starts

– click on Embed, adjust the settings (size, turn off video suggestions at the end), and then copy the code, something like

iframe width="640" height="480" src="" frameborder="0" allowfullscreen  /iframe

(but with brackets before and after, which I took out here, otherwise you would see the video and not the link)

– in your qualtrics survey, create a text/graphic item, edit it, click on html view, and paste the iframe line above.

– done, it will look something like this:


to specify a beginning and an end, add start:xx&end=yy after the ? in the link, like in the example, with xx and yy being seconds of the video.

The rel=0 gets rid of video suggestions at the end.



Update 18.06.14:

some people commented recently that there are problems with embedding video this way.

We are currently using a different method, and it works flawlessly. Perhaps that works for others as well. We use the youtube API, which embeds videos via javascript. In your item, switch to HTML view, and paste this code:

<div id="ytplayer">&nbsp;</div>
 // Load the IFrame Player API code asynchronously.
 var tag = document.createElement('script');
 tag.src = "";
 var firstScriptTag = document.getElementsByTagName('script')[0];
 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

 // Replace the 'ytplayer' element with an <iframe> and
 // YouTube player after the API code downloads.
 var player;
 function onYouTubePlayerAPIReady() {
 player = new YT.Player('ytplayer', {
 playerVars: {'disablekb': 1,'modestbranding': 1,'autoplay': 1,'autohide': 1,'fs': 0,'iv_load_policy': 3,'showinfo': 0,'rel': 0}, 
 height: '390',
 width: '640',
 videoId: 'y6Sxv-sUYtM' 

to put in your own video, replace the videoid with the one of your video; you’ll get see it at the end of the URL when you watch a video on youtube.

You will not see anything on this when you switch from HTML view back to normal view, but the video should be there if you preview the question.

The youtube player API used here is well documented.


setting an embedded data with javascript instead of a web service in qualtrics

qualtrics’ web service was a bit unreliable during the last days. It’s a problem because we use it to connect qualtrics and mturk. qualtrics support suggested to use javascript instead, in particular the Qualtrics.SurveyEngine.setEmbeddedData() function. It works nice, and I set up an example how it works.

so, if you have trouble with the random number generator, just stick this javascript in the first question (but AFTER the embedded data field has been created). Note that it takes one page break to actually update the value (see the example).

embedding scriptingRT SWFs in HTML

in recent weeks, we switched to embedding SWFs using the swf object, and it works well. here is how to do it:

the page describing swfobject, and providing all downloads:

We put a copy of swfobject.js on our server

and also a copy of the handy generator html page

in Qualtrics, we paste this code, which also transmits two flashvars (You can delete these two lines if you don’t need them)

<script type="text/javascript" src=""></script>
  <script type="text/javascript">
   var flashvars = {};
   flashvars.mtwid = "${e://Field/mtwid}";
   flashvars.mturkcode = "${e://Field/mturkcode}";
   var params = {}; = "true";
   params.loop = "false"; = "true";
   params.allowfullscreen = "true";
   params.allowscriptaccess = "always";
   var attributes = {};
   swfobject.embedSWF("", "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes);
  <div id="myAlternativeContent">
   <a href="">
    <img src="" alt="Get Adobe Flash player">
<p>Click on the START button above to begin the task.</p>
<p>Only proceed to the next page after you are told that the data are saved.</p>


connecting mturk to qualtrics to scriptingrt

After describing how to get the mturk worder ID into qualtrics, how to get qualtrics data into scriptingRT, and how to use a code number to give mturk workers something to submit, I now put it all together in one template.

This qualtrics survey

– takes the mturk worker id as a value in the url (here 888888) and puts it in an embedded data field called mtwid; the full link is

– generates a code number mturkcode

– embeds the flash file using swfobject, and transmits mtwid and mturkcode as flashvars

The scriptingRT file imports mtwid and mturkcode, displays it, and appends it to the data it saves.

I exported the qualtrics survey, maybe that’s useful. See also the examples page for for the mturk.swf and mturk.html files.

Survey Flow should look like this. Note that all of these variable names are case sensitive, if you put mturkcode here, it cannot be MTurkCode later.

HTML to put into a text field in HTML View:

<script type="text/javascript" src=""></script>
  <script type="text/javascript">
   var flashvars = {};
   flashvars.mtwid = "${e://Field/mtwid}";
   flashvars.mturkcode = "${e://Field/mturkcode}";
   var params = {}; = "true";
   params.loop = "false"; = "true";
   params.allowfullscreen = "true";
   params.allowscriptaccess = "always";
   var attributes = {};
   swfobject.embedSWF("", "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes);
  <div id="myAlternativeContent">
   <a href="">
    <img src="" alt="Get Adobe Flash player" />
<p>Only proceed to the next page after you are told that the data are saved.</p>

How to connect Qualtrics and mturk, Part II

(Updated 15.02., with a description on how to add the confirmation number as a safety net.)

Some time ago, I posted our simple method on how to connect mturk and Qualtrics data. The idea was then to generate a random number in Qualtrics, save that in the dataset as an embedded data field, tell it to the participants at the every end of the study, after which they copy it into a text field in mturk and hit submit.

This method worked reasonably well in many studies, but it has its weaknesses, most importantly that wrong codes end up in the mturk database for probably many reasons. Sometimes, people forget to copy, or don’t see the code, or loose connection to Qualtrics, etc. In short, it would be nice to have a more automated backup connection.

Here I describe how this can be achieved with the workerId. This ID is unique for every MTurk worker, and Amazon makes it available as soon as a worker accepts a HIT (thanks to Winter Mason for suggesting this).

First the technical background:

The workerId is accessible in the source of the frame that presents the HIT. You can try this by accepting a HIT, then (using Firefox) right-click on the frame with the HIT, choose This Frame –> Frame Info, and then look at the location.

Here is an example:******&

You see the workerId (which is mine, and I masked the end with asterisks) in the middle of the path.

To extract this workerId and submit it to Qualtrics, I wrote a little javascript that has to go into the mturk task.

The html and script:

<p>Go to <a href=""
 target="_blank" onClick="addId()">this website and work on the task there</a>
 (link opens new page).

<p>At the end, you will get a confirmation number. Copy that number and
paste it into the field below, and then submit the HIT.</p>

<script type="text/javascript">
//from here on leave everything as it is
function addId(){
    //setting default values. If the parsing of the workerId fails,
    //99999 will be transmitted.
    var workerId="99999";
    var iFrameURL=document.location.toString();
    var temp="";
    //parsing and extracting the workerId
    if (iFrameURL.indexOf("workerId") > 0){
        if (iFrameURL.indexOf("?") > 0){
            if (temp.indexOf("&") > 0){
                if (temp.indexOf("=") > 0){
    //appending the workerId to the link
    document.links[0].href+="&mtwid=" + workerId;
<p>confirmation number:</p>
<p><textarea rows="3" cols="80" name="answer"></textarea></p>

The first two paragraphs are HTML and simply add the link. The link contains an onClick event handler that executes the javascript function in the script before the link is followed. If the browser has no javascript activated, the link is followed without the workerId being added.

The javascript function takes the location of the frame, and tries to extract the workerId. If the extraction fails, the workerId keeps the default value of 99999. The workerId is appended to the link, using the syntax that Qualtrics expects.

If it works, the link will call:, with the correct workerId instead of 99999.

How to actually do it:

1. Create your HIT in mturk. Make sure you do that via creating a HIT template, not by “create HIT manually” – in the latter case, the workerID does not seem to be available. When designing the layout, switch to “Edit HTML Source” and enter the code above. Obviously, you want to change the link to the actual link to your Qualtrics survey, but be careful to leave all quotes etc. as they are.

When you preview the HIT, it will look like this:

This is also what workers will see.

In Qualtrics, add an embedded data field and call it mtwid – this is what is appended to the link in the form of … .html?mtwid=999999. It will look like this:

That’s already it. The embedded data field is saved in your data file.

For testing purposes, you can ask Qualtrics to display the content of the embedded data field, like this:

When the link is followed, this will produce this qualtrics page:


Adding a safety net: Giving a confirmation number.

I still recommend that in the end, Qualtrics should give a confirmation number that has to be pasted back into qualtrics. It directs participants back to mturk and make sure they actually submit and don’t loose their HIT because of going over the time limit. Also, if a worker has javascript turned of, the transmission will fail, and the confirmation number is then a backup to match datasets.

In a nutshell, here is how to do this:

In the survey flow, add a web service element that gets a random number from a qualtrics web service, and stores it in an embedded data field that we call mturkcode

It’s important to place this at the beginning of your survey, before the actual question blocks.

The web service URL is You can choose any name for the embedded data field you like (instead of mturkcode), but the “random” has to be exactly that. min and max will be the limits of the returned random number.

Then, at the end of the survey, you tell the generated number to your participants. This is done by using the piped text function, which you can easier click on while editing a text field, or directly entering the text as shown below:

or, in plain text: “Thank you for taking part in this study. Your validation code for mTurk is ${e://Field/mturkcode}. Please press on the continue button >>> one more time.”

In MTurk, you then ask for this confirmation number before people submit the HIT.

For more info, see the earlier post on this.

Some additional notes:

  • I hope this is not violating any mTurk policies. I read them carefully and don’t think it does. If you think otherwise, please let me know.
  • Testing this in the mturk Sandbox does not work, as no workerId is assigned there for a task.
  • While creating this, I learned something that might be useful in the future: To store a value in an embedded data field in Qualtrics from Javascript, it’s possible to use a hidden input field: <input type=hidden id=’myField’ name=’ED~myED’ value=’remember_this’> will save “remember_this” in the embedded data field myED, which has to be created in the survey flow.