I have a survey in which there are 3 URLs (see HTML below) within the question. We want to track which specific URLs are clicked rather than just a URL was clicked. I have this code for that with the embedded data of clicked=0
Qualtrics.SurveyEngine.addOnload(function() {
jQuery('#extLink').click(function(event) {
Qualtrics.SurveyEngine.setEmbeddedData("clicked", "1");
jQuery("#NextButton").click();
});
});
But I can’t figure out a good way to modify this to be able to know the specific URL clicked, since the jQuery is #extLink and really this code is only counting if something is clicked but not specifically what.
Any advice?
The HTML code is for each option in the survey question.
<div><a href="https://www.directrelief.org/" id="extLink" rel="noopener" target="_blank">Direct Relief</a> - Support for people affected by emergencies</div>
<div><a href="https://water.org/" id="extLink" rel="noopener" target="_blank">Water.org</a> - Provision of safe and accesible water</div>
<div><a href="https://www.feedingamerica.org/" id="extLink" rel="noopener" target="_blank">Feeding America</a> - Works on hunger relief</div>
2
Answers
The id of each link should be unique (e.g., extLink1, extLink2, extLink3). id should always be unique on an html page.
Then instead of having to do a separate event handler for each, you can add class=’extLink’ to all the links. Then:
id needs to be unique for each element on page, to style elements together or fetch a group of them with javascript please use classes.
any way this code may solve your problem: