1

I am looking for a solution using javascript to record whether a user clicked on a link in qualtrics

I have followed these instructions - Javascript code to record click on link to PDF - Qualtrics but they no longer work

Another person had asked the same question but then went to adopt a different method (Tracking when an external link is clicked in Qualtrics?)

Any thoughts on how to get it working?

Community
  • 1
  • 1
John
  • 13
  • 1
  • 3

1 Answers1

4

Excuse my bluntness, but the problem with the previous questions on this subject were the OPs inability to follow directions rather than the answers given. Here it is one more time:

1) Add the embedded variable to your survey flow before the question block:

clicked = 0

2) Add the link to your question text (in HTML mode):

This is a link: <a href="http://www.google.com" target="_blank" id="extLink">Click here</a>

3) Add the following JavaScript to your question where "extLink" matches the id of your link in (2) and "clicked" matches the embedded variable in (1).

Qualtrics.SurveyEngine.addOnload(function() {
    $('extLink').on('click', function(name, event) {
        Qualtrics.SurveyEngine.setEmbeddedData('clicked', '1');
    });
});

If it doesn't work, you are doing something wrong. Here is a survey that shows it works: https://marketinview.qualtrics.com/jfe5/preview/SV_02JbXhz8qyHgv2d

Click on the next button (>>) on the first page to see the value of 'clicked' on the next page.

T. Gibbons
  • 4,919
  • 2
  • 15
  • 32
  • Thanks for the quick response. Apologies I have never used javascript before. Users are sent to one of four "blocks" but this one link appears in every block - will each block need a unique embedded variable? – John Jul 06 '16 at 14:30
  • No, but each question that includes the link will need to include the code provided, and in addition the embedded data needs to exist before the blocks in question in survey flow. – Anthony Rivas Jul 06 '16 at 17:41
  • An additional thing to add to this would be that it does not register if someone right clicks/macbook two-finger clicks and opens the link purposely as a new tab. You can also set an observer for this by replacing 'click' with 'contextmenu' – Jamie Jul 29 '22 at 08:20