How to integrate this Javascript? | XM Community
Skip to main content

Hello,
i want to integrate the following javascript:

grafik.png













Embedding the script like this leads to the error message: "unexpected token: <".
If I remove the "<" logically the error message: "unexpected identifier" comes up.
Does anyone have an idea how to solve this? Thanks in advance for any helpful hint.

You should move your script to the header.
image.png


https://www.qualtrics.com/community/discussion/comment/33079#Comment_33079Hi,
this does not work. The Javascript-widget should pop up only on one specific question, not on every site. I have integrated the script via the html option for the question. I do not get any error message for the script itself, but the widget i want to add does not show up and i dont know whats the problem.


Qualtrics removes all scripts from the question HTML. You can try pasting your script as an answer choice, but its not something that I would bank upon.
Your best option seems to be header, import the script files over there. And do the execution in the question JS.


https://www.qualtrics.com/community/discussion/comment/33117#Comment_33117
I think I know what you mean, but regrettably i have no experience in coding.
I just have this snippet above. Which part of this should I import into the header and how does the execution look like in my case?

I really appreciate your help! Thanks for your time.


Have you tried putting it as an answer choice? Remove all line breaks from the code, then just paste it as an answer choice. When you paste it, if it spills into another answer choice, then you haven't removed all line breaks. Since, this is only the script, you'll not see anything as the answer choice, so that's fine.
Also, this needs to be on the same page, but is not required to be in the same questions, so if you want, you can also hide this question by using FALSE in display logic.


https://www.qualtrics.com/community/discussion/comment/33123#Comment_33123I added the script into the answer like the following:
grafik.pngso that the code is in one line. unfortunetly this does not work at all.
What did you mean with "this needs to be on the same page, but is not required to be in the same questions"?


It needs to be on the same page, on which you want the widget. But you it doesn't need to be in the same question. Suppose in your survey, you want it to appear on page 2 for question number of 4. So, this script needs to be on a question in page 2, but it is not necessary for it to be a part of question 4. You can create another question on page 2 with just one answer choice and add the script there.


Thanks for the explanation. Then I have understood you correctly.
Theoretically, there has to be no other question on the page where the widget should show up, just the question for the widget.
Unfortunately, the solution does not work to paste the script into an answer choice as shown in the screenshot above.



I keep getting an alert "No Bot ID found", please check your snippet. That means the script is working.


Yes, when I paste the script via the HTML option of a question, I also get this error message.
It seems that the script only in Qualtrics does not work as it should and this error message pops up. If you test the script via https://codepen.io/ for example, the widget opens (with the same bot ID).
So I suspect the problem is how Qualtrics opens or handles the srcipt, but unfortunately I don't know what I need to change about the script. Or rather which part of this script I should put in the header and which in the question on the page where the widget should show up.


Leave a Reply