Track whether a link is clicked in qualtrics even a respondent leaves for the opened new page | XM Community
Skip to main content
Dear all:



I have a question. In my survey, I have an external link inserted. I want a value of 1 is recorded if the link is clicked; otherwise a value of 0 is recorded. I followed a instruction given on a website: https://stackoverflow.com/questions/38225021/tracking-when-an-external-link-is-clicked-in-qualtrics-with-javascript. It works very well if a respondent's response is recorded as complete. But suppose a respondent clicks the link and then leaves for the new page and never comes back, then his response is recorded as response in progress. And when I check his response, a value of 0 is recorded even though he clicks the link. Is there a way to deal with this? Thanks.
@daniel_navarro Did you put the embedded data in the survey flow in the very beginning?
@daniel_navarro,



I'm the author of the Stackoverflow post you cited. Embedded variables don't get saved on the Qualtrics server until the page is submitted. So, you just need to add a line to the script to click the Next Button. I've updated it to use jQuery instead of prototypejs:

```

Qualtrics.SurveyEngine.addOnload(function() {

jQuery('#extLink').click(function(event) {

Qualtrics.SurveyEngine.setEmbeddedData("clicked", "1");

jQuery("#NextButton").click();

});

});

```
@TomG ,

Thanks a lot. Do you mean I need to put the codes above as Javascript of the descriptive text in Qualtrics? And after I attach the new code, the qualtrics page will go to next page automatically after the link is clicked?
> @daniel_navarro said:

> @TomG ,

> Thanks a lot. Do you mean I need to put the codes above as Javascript of the descriptive text in Qualtrics? And after I attach the new code, the qualtrics page will go to next page automatically after the link is clicked?

Yes and yes
@TomG

I am using the same javascript concept of id you show in that stackoverflow post, but to a different aim - I want to check how many times each answer choice in a multiple choice question is being clicked. I gave an id to the text in the following way: <p id="choice_name">choice_text</p>, and the code was:



var clicked = parseInt(Qualtrics.SurveyEngine.getEmbeddedData("clicked_choice"));



$('choice_name').on('click', function(name, event) {

clicked++

Qualtrics.SurveyEngine.setEmbeddedData('clicked_choice',clicked);

});



(There is a embedded data field called clicked_choice which is initially set to 0)



This almost works, the only problem is that if participants click on the answer choice box but not on the text itself, the code doesn't count it (so for some participants, it shows eventually that none of the choices was clicked and the participant moved forward, even though I force response on the question (and I get an answer in the data). For some of my answer choices, the choice text is very small relative to the size of the box, so there is very little chance that the participant will click on the text itself.



Thanks in advance!
How did you give an id to choice_text and what is choice_name?



MC questions work with labels where the label includes the choice text associated with a checkbox (multi-select) or radio button (single select). Clicking the label will fire the checkbox/radio input click event. So, you should attach your event listener to the checkbox/radio input element.
@TomG

Thanks for answering so quickly!



Sorry, I put in the html text so you couldn't see it. Here it is snipped (This is the text I put into the selection choice, in normal view only "choice_name" is seen):



!



(So, you can see that choice_name is the id I gave to the paragraph)



It's a single select, can you please show me how do I refer to the radio button? (I am just now learning to use html+JS through Qualtrics.
There are a number of different ways to do it. To simplify, let's say the choiceid of the choice you are interested in is 1. Then:

```

jQuery("#"+this.questionId+" input[choiceid=1]").click(function() { ... etc...

```
@TomG



Thanks a lot, works like magic! (or like coding)



You Tom, are the king of this forum, and probably of many other forums as well.

TomG
I'm very new to Qualtrics and Javascript, and have tried to implement your Javascript code, so please excuse the silly sounding question.
Where does the result of the embedded variable get stored after the respondent submits their survey responses?
I do not seem to find anywhere in their individual report that shows the "clicked" variable.
Should it be there and have I perhaps not implemented your solution correctly?


tennysonwu - Did you define "clicked" in the survey flow prior to the block that contains the link?


Hi again TomG
Thanks for getting back to me so quickly. I think I defined "clicked" prior. (I called it "clicked1" since I plan on tracking several links out of my survey).
Question 7 is where I have my link:
Qualtrics screen 1.pngI have included the "clicked" variable in question 6 just before question 7:
Qualtrics screen 2.pngand I have also included the same variable in the last question of the previous block of questions:
Qualtrics screen 3.pngWhat am I doing wrong?

Thanks again for your help
Tennyson


Your jQuery selector is wrong. It isn't the url. Give the link an id in your html:
Link text
Then your jQuery is:
jQuery("#click1").click( ...
Also, you need to define the embedded data field 'click1' in the Survey Flow, not in JS.


Hi there TomG
I'm trying to use the code to count when a respondent clicks a hyperlink within my qualtrics survey, but it doesn't seem to be working. I'm not sure what I'm doing wrong?
I've included three screen shots from the survey below. The first is the JS for the question that contains the hyperlink I want to count the clicks on, the second is the HTML for the question that contains the hyperlink, and the third is the embedded data identifying the variable clicked.
I appreciate any help you might be able to offer - I'm sure it's something super simple that I'm overlooking.

thanks in advance

Alison
pic1.pngpic2.pngpic3.png


The original code is perfect for one link, but is there a way to do this in a scenario in which I want to provide the respondent multiple link options, all of which they can click without getting bumped off the page? With the original code, as soon as a respondent clicks one of the links, the survey automatically goes to the next page, so the respondent can't explore the other link options.


https://www.qualtrics.com/community/discussion/comment/33411#Comment_33411Remove the line in the script that clicks the Next button.


That solved it! Thank you so much!



TomG
Dear Tom,
I already looked at all the comments you gave until now and really tried to solve the problem myself. Unfortunately, I always receive "clicked1=0" in the outcome of my data. I put the Embedded data on top of the survey flow.
Could you maybe tell me what is wrong? I would be super thankful!
Until now I did the following steps:
Screenshot 2021-04-03 at 12.50.23.pngScreenshot 2021-04-03 at 12.50.49.pngScreenshot 2021-04-03 at 12.51.17.pngScreenshot 2021-04-03 at 12.50.12.png


It should be:
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#clicked1").click(function(event) {
Qualtrics.SurveyEngine.setEmbeddedData("clicked1","1");
});
});


TomG
Thank you for your answer, unfortunately, it still shows me clicked1:0, even if the respondent clicks on the link. Is there anything else I can do?


Katha TomG
I am also experiencing this problem--regardless of whether I click the link or not it always shows as "0" in my SPSS data file of output--and was wondering whether either of you had figured out how to fix it. Screenshots of what I have done are shown below. Thanks in advance!
image.pngimage.pngimage.png


https://www.qualtrics.com/community/discussion/comment/37011#Comment_37011You have your addOnload function inside your addOnload function. Remove one of them.


TomG
Thanks so much for the quick reply! I fixed that issue (I think--see below), but still am getting all 0s in my output regardless of whether I clicked the link.
image.png


Is it possible to track if people click an URL link even when this link is inserted at the End of the Survey page and not in an actual Block of the Qualitrics survey?


Hi TomG

Just been reading this thread with interest as I wanted to replicate this but for the end of survey message. Do you think this is feasible?

Thanks

Rod Pestell


Leave a Reply