Did respondents click on the embedded link or not? | XM Community
Skip to main content

Hello
In my survey I have embedded two links. On the same page there are two questions, each with a link. I am asking participants to click on any one of the two. I want Qualtrics to tell me which of the two links they clicked on. I have a Javacript code for showing "1" if the participant clicks on the link, but Qualtrics isn't recording if the link was clicked. Irrespective of whether people clicked or not, I get a value of "0" when I export the data (my embedded variable t2.shared has set value to 0).
It might be because the "click.NextButton" command is interfering with it. I need that command in too because I want the survey to automatically be taken to the next if the page if they have clicked on any one of the links.
Please help!
Here is what I have so far in the code:

  • Screen Shot 2021-06-23 at 15.30.37.png

Screen Shot 2021-06-23 at 15.30.47.png

Use the following code in the click function of the link;
if(jQuery('#extLink1').data('clicked', true))
{

//Code to check console if inside and then click next button

}



https://community.qualtrics.com/XMcommunity/discussion/comment/38577#Comment_38577Do I replace any part of the original code with this or add this to the original code?


https://community.qualtrics.com/XMcommunity/discussion/comment/38577#Comment_38577
Hello. I tried it and unfortunately it did not work. This is what my code looks like:
Where am I going wrong? It still shows "0" for both links even though one of them was surely clicked.

Qualtrics.SurveyEngine.addOnload(function()
{
jQuery("#extLink").click(function(event) {
Qualtrics.SurveyEngine.setEmbeddedData("t2.sharedvaccine", "1");
 });
});
Qualtrics.SurveyEngine.addOnReady(function()
{
  var qobj2 = this;
  qobj2.hideNextButton();
  jQuery("#extLink").click(function(event) {
qobj2.clickNextButton(); 
if(jQuery('#extLink').data('clicked', true))
{//Code to check console if inside and then click next button
}
  });
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});


Use this code for "on Next button" click and call in "onReady" .

jQuery("#NextButton").click(function(event) {
if(jQuery('#extLink').data('clicked', true))
{
Qualtrics.SurveyEngine.setEmbeddedData("t2.sharedvaccine", "1");
}

 });


https://community.qualtrics.com/XMcommunity/discussion/comment/38598#Comment_38598
Thanks for the quick reply! Is it possible for you to copy my full code and edit it and post it here for me to better understand where to fit it? I think I might be getting confused about it's placement.


It should look like below; Hope this helps though not sure about hidenextbutton and clicknextbutton :')

Qualtrics.SurveyEngine.addOnload(function()
{
jQuery("#extLink").click(function(event) {
if(jQuery('#extLink').data('clicked', true))
{
Qualtrics.SurveyEngine.setEmbeddedData("t2.sharedvaccine", "1");
}
 });
});
Qualtrics.SurveyEngine.addOnReady(function()
{
 var qobj2 = this;
 qobj2.hideNextButton();
 jQuery("#extLink").click(function(event) {
qobj2.clickNextButton(); 
if(jQuery('#extLink').data('clicked', true))
{//Code to check console if inside and then click next button
console.log('Yes Clicked')
jQuery("#NextButton").click();
}
 });
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});


https://community.qualtrics.com/XMcommunity/discussion/comment/38615#Comment_38615
Thank you Rahul. But it still doesn't work. Qualtrics is showing "0" even when people click on the link. :(


Try console log and see whether the if logic is getting executed or not. That should let you know if the error is with the logic or setting the embedded data.


Leave a Reply