I have added a button in my survey, which respondents can click on to read more information. I want to track whether a respondent has clicked on this button and read the additional information. While the button works well, I am not able to track if a respondent has clicked on the button and read the additional information.
Below you can find the Javascript that I included to track if a respondent clicks on the button. I also include the HTML code which creates the button. Finally, I have also set embedded data to track the button: I called it “clicked1” and set it as empty.
I have tried multiple times, with various Javascript options, and I have not been able to track it in any of the attempts. Would any of you know how to fix this??? I’d immensely appreciate it! :)
JAVASCRIPT TO TRACK CLICKS:
Qualtrics.SurveyEngine.addOnload(function() {
var questionContainer = this.getQuestionContainer();
var infobutton1 = questionContainer.querySelector('#infobutton1');
var infotext1 = questionContainer.querySelector('#infotext1');
if (infobutton1 && infotext1) {
infobutton1.onclick = function() {
infotext1.style.display = 'block';
Qualtrics.SurveyEngine.setEmbeddedData('clicked1', '1');
};
} else {
console.error('Elements not found');
}
});
HTML TO DISPLAY THE BUTTON:
<button id="infobutton1" style="background-color: #6C757D; color: white; padding: 10px 20px; font-size: 14px; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 10px;">
Click here for more information
</button>
<div id="infotext1" style="display: none; font-size: 12px;">
<p>Here goes the text with the information.</p>