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

I wanted to record data from my custom Javascript code

  • Mar 26, 2018 3:44 PM UTC
  • 16 replies
  • 2437 views

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 ●●●●●●●●
  • Mar 26, 2018 4:29 PM UTC
Just a note on this, you need to "declare" your embedded data in the survey flow somewhere before your JavaScript executes.

  • Author
  • Mar 26, 2018 4:33 PM UTC
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 ●●●●●●●●
  • Mar 26, 2018 4:37 PM UTC
Just add your variable to an embedded data block in the survey flow: !

  • Author
  • Mar 26, 2018 4:38 PM UTC
> @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
  • Mar 26, 2018 4:45 PM UTC
> @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
  • Mar 26, 2018 10:42 PM UTC
Qualtrics.SurveyEngine.setEmbeddedData('FIELD', value); what is the field over here?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Mar 26, 2018 11:01 PM UTC
FIELD is the name of the Qualtrics embedded variable.

  • Author
  • Mar 26, 2018 11:09 PM UTC
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 ●●●●●●●●
  • Mar 26, 2018 11:16 PM UTC
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
  • Jul 16, 2019 3:46 PM UTC
> @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: !

  • Dec 8, 2019 4:03 PM UTC
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 ●●●●●●●●
  • Dec 8, 2019 6:06 PM UTC
You have to add the embedded data variables to your survey flow prior to the question where JS sets them.

Forum|alt.badge.img
  • Aug 23, 2022 7:43 AM UTC

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 ●
  • Aug 21, 2023 9:44 PM UTC

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