1

Based on these instructions- Javascript code to record click on link to PDF - Qualtrics

I set up the link (with unique ID of human) in the question, I added the javascript to the javascript panel in the question but I am not sure what to add into the survey flow section.

This is what I have now and it doesn't seem to be working:

1=human

Thanks

Here is my link I need to track-

<a href="http://vpf2.cise.ufl.edu/Classic/Interaction/Prototype/23341" id="human" target="_blank">Test Link</a>

and here is the javascript I put with the question.

Qualtrics.SurveyEngine.addOnload(function()
{
    var a = $("human"); //adjust ID here

      a.onclick = function() {
          Qualtrics.SurveyEngine.setEmbeddedData("clicked", 1); //adjust embedded data variable here
      }

});
Community
  • 1
  • 1

2 Answers2

0

The variable a is getting undefined, since the selector is searching for the tag <human>.

Try this: $('#human') to select the element by it's ID.

[EDIT]

And use to bind the click event:

    a.on('click',function() {
        Qualtrics.SurveyEngine.setEmbeddedData("clicked", 1); //adjust embedded data variable here
    });
Filipe
  • 1,788
  • 2
  • 13
  • 18
  • That didn't work. When I go to check the results it says " 1. $('#human') . here is a link to the survey in case that helps. The link is on the second page- https://ufl.qualtrics.com/SE/?SID=SV_892LRskwk3jgNX7 –  Apr 02 '16 at 22:33
  • Hmm, my bad. You're using jQuery, didn't notice the `onclick`. – Filipe Apr 02 '16 at 22:42
  • Still nothing, sorry. I'm looking at the help section of their site and it says something about inside or outside the function? Do I have that correctly in my code? https://www.qualtrics.com/university/researchsuite/developer-tools/custom-programming/javascript-in-qualtrics/ –  Apr 02 '16 at 23:16
  • Well, the code is fine. But it seems Qualtrics has some conflicts with jQuery. So they suggest to use `var $j = jQuery.noConflict();` to select the elements. So you add that and then use `$j('#human')` instead `$('#human')` – Filipe Apr 02 '16 at 23:25
  • Add the no conflict line right above the other var line? –  Apr 02 '16 at 23:31
  • Before `Qualtrics.SurveyEngine`. – Filipe Apr 03 '16 at 00:03
  • It still displays $j('#human'), not "Clicked", in the results section and displays that regardless of whether the link was clicked or not. Sorry, I hope I'm not miscommunicating something. –  Apr 03 '16 at 15:05
  • Hi Filipe, I wanted to thank you for your help and advice! We ended up doing a different method to create a unique URL with a username attached using embedded data and the website they're clicking to can extract that username, allowing us to track. Just wanted to thank you and let you know so you didn't spend any more time on this! –  Apr 03 '16 at 22:17
  • Ohn, no problem. Glad to help a bit. :) – Filipe Apr 04 '16 at 17:22
0

Try this:

In survey flow:

human = 0

Question html:

<a href="http://vpf2.cise.ufl.edu/Classic/Interaction/Prototype/22318?username=" id="human" target="_blank">Click here</a>

JavaScript:

Qualtrics.SurveyEngine.addOnload(function()
{
       $('human').observe('click',function(event) {
            Qualtrics.SurveyEngine.setEmbeddedData("human", "1"); 
       });
});

Note: In Qualtrics $ refers to prototypejs, not jquery.

T. Gibbons
  • 4,919
  • 2
  • 15
  • 32
  • That didn't work, but thank you for your response and time! We found a workaround that does almost what we want and we are going with that. Thanks again –  Apr 04 '16 at 00:02