How to log Google searches? | XM Community
Skip to main content

In my survey I am trying to find out how people search to verify information. I want to have a search bar in my question which records the searches and saves them to a data field I can access when I do my data analysis. Ideally, I would also be able to log the links they click through on for each search, but I have no idea how to approach this. I have managed to code a search bar that opens a new tab of the google search onclick, and I have a JS function which appends each search in a local JS array, but I can't access those variables in the analysis. Does anyone know if this is possible/how I could do this?
This is the code I already have:
Search bar:




JS:
arr = =];

function userInput()
{
    var input = document.getElementById("userInput").value;
    arr.push(input);
    Qualtrics.SurveyEngine.QuestionData.addEmbeddedData(url_list, arr); //tried to save as embedded data
    Qualtrics.SurveyEngine.QuestionData.setEmbeddedData(url_list, arr); //but doesn't work
    return arr;
}
Thanks

Remove the onclick event from HTML and make the following changes to the question JS:
document.getElementById("submit").onclick = function() {userInput()};
arr = ];
function userInput()
{
    var input = document.getElementById("userInput").value;
    arr.push(input);
    //seEmbeddedData doesn't need QuestionData
    //The name of the Embedded Data variable needs to be passed as a string
    //In you case, it was trying to parse the value of url_list, which was undefined
    Qualtrics.SurveyEngine.setEmbeddedData("url_list", arr);
}


Leave a Reply