Detecting the count of values in a JavaScript variable | XM Community
Skip to main content

Hello!
I am currently running an intercept survey on our website using Website / App Feedback. The intercept is embedding a Javascript variable that can have 1 or more values and is passing that variable to the survey.
I'd like to create a new variable/field in the survey that counts the number of values in the embedded field for each respondent.
For example: Perhaps the questionnaire is surveying fast food customers after placing an online order. The intercept embeds a JavaScript variable called

condiment
which can have the values
ketchup
mustard
and/or
mayo
. In this case, I would like to create a new variable that counts the number of condiments for each respondent. So, if someone had ordered ketchup, mustard, and mayo, the new variable would return
3
, if just ketchup, it would return
1
and so on.
Is this possible?
Thanks so much for your help and generosity!

Once the value of condiment ED is capatured, using JS split function you can calculate the number of elements in it and store it in new ED.


Leave a Reply