Qualtrics Integration ===================== Overview -------- Use ChatbotLab to embed conversational tasks into your Qualtrics survey pages. .. important:: Note that your Qualtrics account must be able to edit JavaScript. Some institutions disable this for security reasons. Contact your Qualtrics administrator if iframes are not permitted. Data Needed to Embed Bot ------------------------ ChatbotLab Domain ^^^^^^^^^^^^^^^^^ Deploy ChatbotLab first, following the :doc:`/deployment/index` guide. You will then have a domain name for your chatbot. Use it in place of ```` below. Survey ID ^^^^^^^^^ 1. Navigate to your survey. 2. Click on Distributions. 3. Click on **Anonymous link**. If needed you can generate one. 4. Copy the survey ID from the link. It typically starts with ``SV_`` (for example, ``SV_cBaJiOettfQqZRY``). 5. Replace ```` with your survey ID in the code below. Bot Name ^^^^^^^^ 1. Navigate to the ChatbotLab admin panel and login. 2. On the left, under CHATBOT, click on `Bots`. 3. You can use the search bar to find your bot. 4. Copy the name under the NAME column. 5. Replace ```` with your bot name in the code below. Alternatively, this could be created in your survey flow and saved to an Embedded Data field. For example, if your embedded data field was called ``model`` then you would replace ```` with ``${e://Field/model}`` in the code below. This allows you to build sophisticated survey flows and serve different bots depending on how your participants answer survey questions. .. important:: This **must** exactly match the bot name in ChatbotLab's database. Study Name ^^^^^^^^^^ This is a descriptive name for your study, which will be saved in ChatbotLab's. For example, if you study was related to a therapy bot, you could call the study ``therapy_bot``. We recommend keeping the name simple, yet descriptive, so that you can distinguish between multiple studies. Replace ```` with your name in the code below. Participant ID (Optional) ^^^^^^^^^^^^^^^^^^^^^^^^^ You may also have an ID for your participant saved in an Embedded Data field. This could be a Prolific or Mturk Worker ID. If so, you can replace ```` with your embedded data, for example ``${e://Field/pid}`` if your embedded data field is ``pid``. If you do not have this then you can set this value as the Response ID ``${e://Field/ResponseID}``, i.e., a unique identifier for each row in your survey data. Embedding ChatbotLab --------------------- 1. Deploy ChatbotLab on AWS following the :doc:`/deployment/index` guide. 2. In Qualtrics, add a **Text / Graphic** question. 3. Open the JavaScript editor. This is typically on the left under Edit Question -> Question Behavior 4. Add the following code in the editor under Edit Question JavaScript: .. code-block:: javascript Qualtrics.SurveyEngine.addOnload(function() { var studyName = ""; var botName = ""; // Match expected value var surveyID = ""; //unique survey ID var participantID = ""; // Unique prolific participant ID var conversationID = "${e://Field/ResponseID}"; // qualtrics session Id window.totalTimeOnPage = 0; window.totalTimeAwayFromPage = 0; window.pageStartTime = new Date(); window.awayStartTime = null; // Construct chatbot URL with encoded parameters var botURL = "https:///conversation"; botURL += "?bot_name=" + encodeURIComponent(botName); botURL += "&conversation_id=" + encodeURIComponent(conversationID); botURL += "&participant_id=" + encodeURIComponent(participantID); botURL += "&study_name=" + encodeURIComponent(studyName); botURL += "&user_group=" + encodeURIComponent(userGroup); botURL += "&survey_id=" + encodeURIComponent(surveyID); console.log("Generated botURL:", botURL); // Debugging var container = this.getQuestionTextContainer(); // Ensure valid container if (container) { var iframe = jQuery("