I wanted to record data from my custom Javascript code | XM Community
Skip to main content
Solved

I wanted to record data from my custom Javascript code


Hello everyone, I'm new to Qualtrics, I wanted to save the data in qualtrics from custom javascript code. can anyone tell me how to do that ? Thanks, Abhi

Best answer by Michael_Campbell_RedPepper

Yeah! Save it as an Embedded Data Field! It will show up in reporting and exports. Here is some API code to get you started! `Qualtrics.SurveyEngine.setEmbeddedData('FIELD', value);` `Qualtrics.SurveyEngine.getEmbeddedData('FIELD');`
View original

16 replies

Michael_Campbell_RedPepper
QPN Level 3 ●●●
Forum|alt.badge.img+3
Yeah! Save it as an Embedded Data Field! It will show up in reporting and exports. Here is some API code to get you started! `Qualtrics.SurveyEngine.setEmbeddedData('FIELD', value);` `Qualtrics.SurveyEngine.getEmbeddedData('FIELD');`

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5932 replies
  • March 26, 2018
Just a note on this, you need to "declare" your embedded data in the survey flow somewhere before your JavaScript executes.

  • Author
  • 11 replies
  • March 26, 2018
As a beginner it is little tough to understand can you tell me how to do that if you guys have any documentation can you share that with me? Thanks Abhi

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5932 replies
  • March 26, 2018
Just add your variable to an embedded data block in the survey flow: !

  • Author
  • 11 replies
  • March 26, 2018
> @TomG said: > Just add your variable to an embedded data block in the survey flow: > ! > Thank you

Michael_Campbell_RedPepper
QPN Level 3 ●●●
Forum|alt.badge.img+3
For sure!

  • Author
  • 11 replies
  • March 26, 2018
> @Michael_Campbell_RedPepper said: > Yeah! Save it as an Embedded Data Field! It will show up in reporting and exports. > > Here is some API code to get you started! > > `Qualtrics.SurveyEngine.setEmbeddedData('FIELD', value);` > `Qualtrics.SurveyEngine.getEmbeddedData('FIELD');` thank you

  • Author
  • 11 replies
  • March 26, 2018
Qualtrics.SurveyEngine.setEmbeddedData('FIELD', value); what is the field over here?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5932 replies
  • March 26, 2018
FIELD is the name of the Qualtrics embedded variable.

  • Author
  • 11 replies
  • March 26, 2018
where i need to put Qualtrics.SurveyEngine.setEmbeddedData('FIELD', value); Qualtrics.SurveyEngine.getEmbeddedData('FIELD'); in my custom javascript code?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5932 replies
  • March 26, 2018
Since we haven't seen your JavaScript code, it is impossible for use to tell you where to put that line of code. If you post your code, we may be able to help.

mallove
  • 1 reply
  • July 16, 2019
> @TomG said: > Just add your variable to an embedded data block in the survey flow: > ! > Just adding a screen grab of what the "Survey Flow" tab looks like: !

  • 2 replies
  • December 8, 2019
I had found the setEmbeddedData API call, but none of the values pass to it appear in the exported csv file. What might account for this?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5932 replies
  • December 8, 2019
You have to add the embedded data variables to your survey flow prior to the question where JS sets them.

Forum|alt.badge.img
  • 5 replies
  • August 23, 2022

Hi everyone! I'm also in a similar position. I'm using Qualtrics to record feedback data. However, I also want to record some metadata (

groupId
) around this. I'm passing the metadata through JavaScript according to the documentations mentioned. Below is my HTML code snippet:




I have included this in the base HTML file. Most of the script was mentioned in the documentation. I've only added the
addOnload
method. However, on my server, it says
Uncaught ReferenceError: Qualtrics is not defined
. Isn't the script supposed to define Qualtrics on its own? Could anyone point out what I'm missing here? Thanks!


Forum|alt.badge.img+1
  • Level 1 ●
  • 3 replies
  • August 21, 2023

So if I am following this thread correctly, The Set embed data block should appear before the script executes like this assuming the script executes in Block 8:

I am unclear where to put the script to record the data. This is where I put it:

Qualtrics.SurveyEngine.addOnload(function()
{
    var qid = this.questionId;

    document.onkeydown = function(event) {
        console.log('keydown',event);
        if (event.which == 37) {
            event.preventDefault();
            Qualtrics.SurveyEngine.registry[qid].setChoiceValue(1, true);
            jQuery('#NextButton').click();
        } else if (event.which == 39) {
            event.preventDefault();
            Qualtrics.SurveyEngine.registry[qid].setChoiceValue(2, true);
            jQuery('#NextButton').click();
        }
    }


});

Qualtrics.SurveyEngine.addOnReady(function()
{
    var qobj = this;
    setTimeout(function() { jQuery("#"+qobj.questionId+" .hideAfter45").hide(); },5000);


});

Qualtrics.SurveyEngine.addOnUnload(function()
{
    `Qualtrics.SurveyEngine.setEmbeddedData('FIELD', value);`
`Qualtrics.SurveyEngine.getEmbeddedData('FIELD');`

});

 

Is this correct?

I have a series of questions that I want to capture the embedded data. Do I need a embed data block before each question or just one embed data block at the start of the series