Centralizing dynamically survey language change | XM Community
Skip to main content

Hi all,

Would greatly appreciate some tips on how to go about the following.

Situation
We need to personalize message tone of voice (formal or informal) based on some parameters of our website’s data layer. Therefore, I need to dynamically change the Q_Language value. I can do this in the Embedded Data section of the action set in my intercept by selecting Value: Value from JavaScript and inserting the expression: (datalayer.tone_of_voice === "informal") ? "nl-in" : "nl";
This works ok, but since we have multiple intercepts containing multiple action sets, it would be easier for me to centralize this logic somewhere.

Question
Is it possible to centralized this logic somewhere so that it is valid for all intercepts inside a web projects?
I was thinking of putting it on the theme level, inside the header. But I fail to understand how you can change the language with JavaScript from there. I know of setJSEmbeddedData function, but that is for the SurveyEngine, so question level JS, which does not seem to help me in my scenario.


Thank you!

You can run JS in the header by putting your JS inside a <script> tag:

<script>
Qualtrics.SurveyEngine.addOnload(function() {
//js goes here
});
</script>

You can’t change the language using setJSEmbeddedData.  Instead, have the JS select the language from the language selector drop-down then trigger a change event.


Hi ​@TomG ,

Thank you for your reply. We already have that solution working for our surveys where we do have the language dropdown. I thought that for web surveys, because we hide it we will not be able to change it through a click event. Now that I wanted to give this proof to you, I made a closer investigation after and I realize we can.
Therefore, thank you for the boost. Have a great day😊