Javascript for creating embedded data for hotspot | XM Community

Javascript for creating embedded data for hotspot

  • 31 August 2022
  • 1 reply
  • 27 views

Userlevel 2
Badge +1

I am using a hotspot question which has a lot of regions about 30. I would like to group these regions and create embedded data to report them. I was wondering if anyone can help me with the javascript.
I want something in lines of
Group1: region1-5
Group2: region 6-10
...
Many thanks in advance


1 reply

Userlevel 5
Badge +25

Hi Simin,
Are you just wanting to report the on/off state of each?
If you don't mind doing things (fairly) manually, you could do soemthing like the following:
var group1 = [
"${q://QID1/ChoiceGroup/SelectedAnswers/1}",
"${q://QID1/ChoiceGroup/SelectedAnswers/2}",
"${q://QID1/ChoiceGroup/SelectedAnswers/3}",
"${q://QID1/ChoiceGroup/SelectedAnswers/4}",
"${q://QID1/ChoiceGroup/SelectedAnswers/5}"
];

var group2 = [
"${q://QID1/ChoiceGroup/SelectedAnswers/6}",
"${q://QID1/ChoiceGroup/SelectedAnswers/7}",
//etc, continue until you have all of your groups completed
];

//if you want to store each group as embedded data
Qualtrics.SurveyEngine.setEmbeddedData('Group1', group1);
Qualtrics.SurveyEngine.setEmbeddedData('Group2', group2);
//etc
Note: QID1 probably won't be the correct ID to use and that your SelectedAnswers might not start at 1 either. Qualtrics assigns these IDs automatically. An easy way to check is to just pipe in the first value in your survey somewhere and note down what it spits out.
image.pngimage.png
If you also want to store the description of each region, you'll need to play around with the code a bit more and probably tweak it for your specific use-case.
Good luck!

Leave a Reply