A Turnkey Solution for Graphing Qualtrics Data for Participants

As I’ve mentioned previously, Qualtrics is a web-based, point-and-click survey platform that is excellent for gathering data. Qualtrics allows quick development of surveys, the data for which are stored on the contracting institution’s own servers, making it strong in both functionality and data security. The University of Oregon

I’m currently a graduate student at the U. of Oregon, and thus have access to the site license.
maintains a site license for Qualtrics; thus, it’s a product that I have been getting to know better.

While Qualtrics offers many features for survey creation, it offers almost none for data analysis or visualization. Thus, I’ve written a ready-to-go script for showing survey participants customized feedback based on their responses. Once participants click “Submit” on a Qualtrics survey, they can be redirected to a page running the script below, which will score their responses for any subscales in the survey, graph those subscale scores (in any form — bar chart, pie chart, etc.), and, optionally, also graph the average or summed scores of everyone else who has taken the survey:


A working example can be found here . Feel free to enter answers without reading the items — the survey is just for demo. purposes, and is not actually intended to collect usable data.

Should you be interested, the items are from from the SDI-46, available from Prof. Gerard Saucier here.

I’ve written the script in PHP because the language is ubiquitous and thus typically does not require setup by the user. Given that providing customized feedback seems to be a common request among the researchers with whom I’ve interacted, this script is designed to be easy to use, requiring as little programming experience as possible. For graphing, it uses HighCharts, an excellent javascript library for data visualization. HighCharts is free to use for personal and non-profit projects.

What you will need

  • A Qualtrics license (as many institutions, such as the University of Oregon, maintain).
  • A web server running PHP. There is no requirement for the most up-to-date version; any reasonably-current version should work. The code has been tested with PHP v.5.4 and 5.5, but will likely work with older versions, as well.
    Many institutions also provide free web hosting to their members. The University of Oregon, e.g., provides free hosting through its pages.uoregon.edu service.
  • For most web hosts, an FTP client, such as FileZilla.
  • Two script files, “qualtrics_graph_helper.php” and “example_qualtrics_page.php”.

For those of you who would like to add to and contribute to the development of this tool, the most up-to-date versions of the files can be found in a Git repository on GitHub. I am releasing these scripts under the MIT License, and welcome feedback and contributions.

Setting up the survey in Qualtrics

Once you have created a survey in Qualtrics, you will need to follow several steps to set up the scripts:

Collect initial information from Qualtrics

For the scripts to work, you’ll need to enter some information from Qualtrics. To gather this initial information,

  1. Log into Qualtrics.
  2. Click on your name in the top right corner of the window, and click “Account Settings…”

Finding your Qualtrics username

  1. Within the “Account Settings” page, you will see a box titled “Recent Logins.” Look in the “user” column for your Qualtrics login name (e.g., “jleverni#oregon”). Note the username for later.
  2. From the “Account Settings” page, click “Qualtrics IDs”.

Finding your survey’s ID

Within the “Qualtrics IDs” page, you will see a box titled “Surveys.” Find your survey in the list, and note the ID number that appears beside it (it may start with “SV_“).

Generating an API Token

Within the “Qualtrics IDs” page, you will also see a box titled “API.” An API (Application Programming Interface) is a portal for scripts to gain access to a system such as Qualtrics’. The API checks that a script has been set up by an authorized user by using a “Token.” Tokens are like passwords, except that they are designed to be embedded in scripts, and thus are easy to change. Further, if others see your token, they won’t be able to log into your account, as they would with your actual password.

Tokens should be kept private, because having one and your survey ID will allow access to the raw survey data. However, if your script is seen by someone unauthorized, you can just come back to this Qualtrics screen and generate a new token, thereby automatically making the leaked one invalid.

Click “Generate Token”. Note the Token that is automatically generated.

Edit the file “example_qualtrics_page.php”

Note well: The .php files included here can be opened and edited in any text editor (e.g., TextEdit for Mac OSX, NotePad++ for Windows, etc.). They will not run, however, until loaded onto a web server (a process that we will discuss below).

This tutorial comes with two files: “qualtrics_graph_helper.php”, and “example_qualtrics_page.php”. Both need to live in the same directory

To be clear, “directory” = “folder.”
on your web host, but only the latter needs to be edited. “qualtrics_graph_helper.php” contains the code that makes everything work, but doesn’t need to be edited directly. Instead, we will use “example_qualtrics_page.php” to reference the code from “qualtrics_graph_helper.php” while making edits specific to your survey and user account, starting by entering the information that you gathered above. “example_qualtrics_page.php” is also where you will program how you want your survey to be scored, and what you want to be shown to the user upon survey completion.

Enter your Qualtrics information from above

“example_qualtrics_page.php” is designed to be as easy-to-understand and to require as little programming knowledge as possible. Almost every line is annotated, with the intention being that you be able to go line-by-line through this file and make edits for your own survey. Note that there is a primer on the scripting language we’re using, PHP, on approximately line 17 of the file:

// A few notes, before we get started:
    // The language we're using here is called PHP.
    // Variables in PHP have a dollar sign in front of them. For example, $example is a variable.
    // Every line of code has to have a semicolon (;) at the end of it, to show that that's the end of the line.
    // We're going to use the code that we loaded above and use it to create a variable. We can set the data within that variable with an arrow. For example, $variable_name->option_name = "whatever"


// Ok, we're ready to start!

Just below the primer, you will see a section to enter your information from above:

// You should now edit a few Qualtrics-related options from our new holder variable:

$example->qualtrics_options["User"] = 'jleverni#oregon';

$example->qualtrics_options["Token"] = "4Wf0nfJ1ivsxuctN8ZUHmK";

$example->qualtrics_options["SurveyID"] = "SV_eaK7DqH8d7DvDYV";

Scoring subscales

Further down in the file, you have the option to score any subscales of your survey (e.g., in a Big 6 personality test, “Agreeableness,” “Extraversion,” etc.):

$example->subscale_equations["Alpha"] = "{SDI_46_9} + {SDI_46_16} + {SDI_46_22} + {SDI_46_32} - {SDI_46_3} - {SDI_46_18} - {SDI_46_25} - {SDI_46_37}";

$example->subscale_equations["Beta"] = "{SDI_46_6} + {SDI_46_10} + {SDI_46_23} + {SDI_46_41} + {SDI_46_43} + {SDI_46_45} - {SDI_46_14} - {SDI_46_31} - {SDI_46_33} - {SDI_46_39}";

You can score as many subscales as you want, using the format $example->subscale_equations[subscale_name_goes_here] = {Qualtrics_QuestionID_1} + {Qualtrics_QuestionID_2} / {Qualtrics_QuestionID_3} etc. — all normal arithmetic operators (+,-,*,/, etc.) are available. See here for a full list of arithmetic operators allowed by PHP.

In the format above, Qualtrics_QuestionID_1 is the ID of a specific question in your Qualtrics survey. Some question IDs can be seen and edited from within Qualtrics, by clicking in the top left corner of the question. In the picture below, “Q3”, “Q5”, and “Q6” are question IDs for the three example questions shown. Thus, in the script above, “Q3” would be referenced with {Q3}.


For other types of questions (e.g., Matrix questions), it may be harder to set IDs for specific Questions. In the image below, e.g., the item “Enlightenment can be gained…” would be referenced by {SDI_46_2}. If you have doubt about variable names within Qualtrics, I recommend downloading the data file from the survey (“Download Data” in the “View Results” tab) and checking the data file’s column names.


The script also allows getting averages and sums of dataset columns, enabling users to see their scores graphed against others’:

$average_Alpha_subscale = $example->get_average_of_column($scored_subscales, "Alpha");
$summed_Beta_subscale = $example->get_sum_of_column($scored_subscales, "Beta");

Displaying a graph

Finally, the script includes directions for generating valid syntax for use with HighCharts. The easiest way to do this is to go to the HighCharts Demo page, select the type of chart that you would like to make, and then edit the example code (click “View Options”), pasting it within the double-quotes at approximately line 95:

$code_for_our_graph = "
    HighCharts code goes here. You can reference any of the variables above (e.g., $average_Alpha_subscale).

The code that produces the bar chart in the example survey above is included in “example_qualtrics_page.php”.

The final note in the script is simply that you should insert the following code wherever you want the graph placed on your webpage:

<div id="graph_from_qualtrics_data" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>

Upload the script files to your web host

Once your scripts have been edited, you will need to upload them to a web host.

Note: “Web host” here does NOT mean a WordPress or similar site. It means a server provider that allows you to upload files that can be run as scripts.

Most web hosting providers will allow you to upload files to your hosting space using FTP (“File Transfer Protocol”). Assuming that you have FTP access to the server (as do, e.g., all faculty, researchers, and students at the University of Oregon for the pages.uoregon.edu server), I recommend installing FileZilla, a free, cross-platform FTP client, to do this. Instructions for using FileZilla can be found here.

The files can be uploaded anywhere on the server that is accessible to the web (if you have a “public_html” directory within your hosting space, the files should go anywhere within that), as long as they are in the same directory. Also, you can rename example_qualtrics_page.php to whatever you want (as long as it retains the “.php” file extension).

If your web hosts uses CGI to run PHP files (this does not apply to most web hosts, but does apply to pages.uoregon.edu)

Some web hosts (including the University of Oregon) run PHP files through a “CGI” interpreter, meaning that two changes need to be made:

  1. The following line needs to be added to the very top of “example_qualtrics_page.php”: #!/usr/local/bin/php
  2. “example_qualtrics_page.php” needs to be given the ability to be run as a script. To do this, in FileZilla, right click on the copy of “example_qualtrics_page.php” that you uploaded to the server, click “File permissions…”, and enter the number 755 under “Numeric Value”:
    To confirm, if you are familiar with the *nix command line, this is a cross-platform graphical method for running chmod 755 example_qualtrics_page.php.


You should now be able to visit example_qualtrics_page.php in your web browser at the address of the web host (e.g., http://pages.uoregon.edu/jleverni/example_qualtrics_page.php).

Edit the Qualtrics survey to redirect users to the script page

Now that the scripts are ready, the Qualtrics survey itself needs to be set up to redirect users upon completing the survey. This is a short process:

  1. In Qualtrics, enter the Edit screen for your survey.""
  2. Click “Survey Flow.” Add an “End of Survey” element as the final element in your survey.""
  3. Click “Customize” on the Survey Flow element. Select “Redirect to a URL…” and enter the URL to “example_qualtrics_page.php” on your web server, followed by ?id=${e://Field/ResponseID (e.g., http://pages.uoregon.edu/jleverni/example_qualtrics_page.php?id=${e://Field/ResponseID}). This tells Qualtrics to redirect the user to your page upon survey completion, and also to forward the user’s Qualtrics Response ID to your page.""


After completing the above steps (and possibly going back to make sure that your edits were correct), you should have a working mechanism for providing participants with customized follow-up to their responses. I’m happy for constructive feedback, either through the GitHub repository above or by other means of contact.