Copy-paste recipes for common patterns. Every snippet expects to run on the respondent page (live or preview) after the page has finished rendering — open the browser console while a question is on screen and try them out.
Inspect the current page#
const api = window.Intuify.survey;
console.log({
screen: api.getScreenType(),
progress: api.getProgress(),
questions: api.getCurrentQuestions().map((q) => q.id),
});
Read a question's choices#
const api = window.Intuify.survey;
api.getChoices("q_color").forEach((c) => console.log(c.id, c.text));
For matrix questions, use getRows / getColumns instead.
Pre-fill an answer from a URL parameter#
const api = window.Intuify.survey;
const { urlParams } = api.getEmbeddedData();
if (urlParams.color) {
api.setResponse("q_color", urlParams.color);
}
Set a survey variable#
window.Intuify.survey.setVariable("source", "tag_manager");
// or, equivalently:
window.Intuify.setVariable("source", "tag_manager");
Variables persist across pages for the active session and feed back
into piping (${e://Field/source}) and conditional logic.
Resolve piped text in JS#
const api = window.Intuify.survey;
const greeting = api.resolveText("Hello ${e://Field/name}, welcome back!");
document.title = greeting;
Read the loop iteration#
When the current section is inside a loop-and-merge block,
getMetadata() shows the active navPosition and getResponseKey
returns the loop-scoped key:
const api = window.Intuify.survey;
console.log("key", api.getResponseKey("q_satisfaction"));
// → "item_pasta::q_satisfaction" inside the Pasta iteration
Inspect a plugin question payload#
Useful when porting Qualtrics widgets:
const api = window.Intuify.survey;
const payload = api.getQuestionPayload("q_grid_choice");
console.log(payload.pluginConfig, payload.answers, payload.columns);
payload is the exact same object the standalone widget iframe
receives via postMessage (initQuestion).
Listen for the next page#
The runtime API recomputes per page, so the simplest way to react to
the respondent advancing is to compare the previous and current
session metadata in a small polling loop or via a MutationObserver
on the survey container. The dedicated onLoad / onSubmit hooks
will remove this boilerplate — track it via the
Custom JS overview.
Common pitfalls#
- Question id vs. qid. The runtime API uses the engine question id
(the value stored in the survey JSON's
idfield, e.g.q_color). The shorterqidyou see in the response export (Q1,Q2, …) is not accepted. - Calling getters too early. If you run a script before the page
hydrates,
window.Intuifymay beundefined. Wait for the first render (or rely ononLoadonce it ships). - Mutating returned arrays.
getChoices,getRows, etc. return fresh arrays. Mutating them does not change the survey — callsetResponseor update the survey definition instead. setResponsedoes not navigate. Use it to seed answers; Next still has to be clicked (or trigger an auto-advance rule).
Related guides#
Was this page helpful?