Embedding ResponseDock
ResponseDock can run as an embedded admin workspace or as a respondent dashboard inside a host platform. The host backend keeps the secret API key, requests a short-lived embed URL, and places that URL in an iframe.
For a step-by-step walkthrough of giving each of your customers their own survey builder, see Embedding a survey builder for your customers.
Recommended Architecture
- Create a secret API key in ResponseDock and store it only on your backend.
- Add your host application origin in Workspace Settings under Allowed embed origins.
- Use an admin embed when staff need to create, edit, publish, or review surveys.
- Listen for
responsedock.questionnaire.createdand store the returned questionnaire ID in your system. - For end users, request a respondent embed with that stored survey ID list and your user ID.
Admin Embed
Admin embeds are for trusted operators in your platform. They open an embedded questionnaire workspace where, depending on the capabilities you sign into the token, they can create questionnaires, edit drafts, publish, and review results.
POST https://api.responsedock.com/api/v1/auth/embed-token
Authorization: Bearer sk_live_your_secret_key
Content-Type: application/json
{
"workspaceId": "ws_xxxx",
"role": "admin",
"mode": "workspace",
"allowedOrigin": "https://app.yourplatform.com",
"tenant": { "id": "tenant_42", "name": "Acme Clubs" },
"user": { "id": "manager_7", "name": "Jordan Manager" },
"capabilities": [
"questionnaire:view",
"questionnaire:create",
"questionnaire:edit",
"questionnaire:publish",
"results:view"
],
"subject": { "type": "club", "id": "club_18", "label": "Falcon Club" },
"theme": {
"logoUrl": "https://app.yourplatform.com/logo.svg",
"primaryColor": "#1D4ED8",
"primaryTextColor": "#FFFFFF",
"secondaryColor": "#14B8A6",
"backgroundColor": "#F8FAFC",
"surfaceColor": "#FFFFFF",
"textColor": "#111827",
"mutedColor": "#64748B",
"borderColor": "#CBD5E1",
"errorColor": "#DC2626",
"fontFamily": "Host Sans",
"fontUrl": "https://app.yourplatform.com/fonts/host.woff2",
"borderRadius": "12px",
"buttonStyle": "rounded",
"optionStyle": "bordered",
"cardShadow": "elevated",
"questionSize": "large",
"surveyWidth": "wide",
"hidePlatformBranding": true
}
}Grant the least privilege each user needs. If you omit capabilities, an admin session gets all five; create, edit and publish always include view. The iframe hides actions a session lacks, and the API refuses them.
| Capability | Allows |
|---|---|
questionnaire:view | Open the workspace and list or read questionnaires in scope |
questionnaire:create | Create a questionnaire in the signed scope |
questionnaire:edit | Open the builder and save drafts |
questionnaire:publish | Publish, pause, close or archive a questionnaire |
results:view | Open analytics and responses, and export results |
tenant, user and subject are optional and signed into the token. A subject (for example a club or a customer account) partitions the workspace: the session only sees questionnaires with the same subject type and id, and questionnaires it creates are filed under that subject, with the signed user recorded as their creator. The tenant and subject are also included in the messages the iframe posts to your page.
Sessions with questionnaire:create can also start from a template: the embedded workspace offers Start from a template next to the blank option, listing the built-in sample templates and the templates saved in your workspace. A questionnaire created from a template is filed under the session’s signed subject like any other new questionnaire, and it takes your workspace brand rather than colours stored in the template. Embedded sessions can use templates but cannot create, edit or delete them.
The response is { token, expiresIn, embedUrl }. Place the embedUrl in your iframe:
<iframe src="EMBED_URL_FROM_YOUR_BACKEND" width="100%" height="760" frameborder="0" allow="clipboard-write" ></iframe>
The exchanged bearer session and effective theme are retained in frame-scoped session storage, so a browser reload does not expose or reuse the short-lived URL token.
Integration Wizard
Workspace administrators can open Embed setup in the dashboard to approve a host origin, create a server credential, copy backend and iframe snippets, and run a real cross-origin protocol diagnostic. The diagnostic verifies ready, resize, ping/pong, and runtime theme messages against the public renderer.
Iframe Lifecycle Protocol
New integrations should accept only messages from the exact ResponseDock origin and iframe window, then require protocol responsedock.embed version 1.
window.addEventListener('message', (event) => {
if (event.origin !== 'https://app.responsedock.com') return;
if (event.source !== iframe.contentWindow) return;
const message = event.data;
if (message?.protocol !== 'responsedock.embed' || message.version !== 1) return;
switch (message.type) {
case 'responsedock.lifecycle.ready':
console.log(message.payload.capabilities);
break;
case 'responsedock.lifecycle.resize':
iframe.style.height = `${message.payload.height}px`;
break;
case 'responsedock.lifecycle.session_expired':
// Request a fresh embed URL from your backend.
break;
case 'responsedock.lifecycle.error':
console.error(message.payload.code, message.payload.message);
break;
}
});Other lifecycle events cover navigation, completion, close requests, locale updates, theme acknowledgements, and ping/pong health checks. Every event includes a message ID, timestamp, frame context, and protocol version.
Runtime Theme Updates
After receiving responsedock.lifecycle.ready, the host may update individual tokens. Messages are accepted only from the exact allowedOrigin bound into the token.
iframe.contentWindow.postMessage({
protocol: 'responsedock.embed',
version: 1,
type: 'responsedock.command.theme.update',
theme: { primaryColor: '#7C3AED', backgroundColor: '#0F172A' }
}, 'https://app.responsedock.com');Hosted fonts must be HTTPS WOFF2 assets with cross-origin access enabled. Without a fontUrl, fontFamily must name a system font.
Store Created Questionnaire IDs
When an embedded admin creates, saves or publishes a questionnaire, ResponseDock posts a message to the parent window, only to the signed allowedOrigin. Each message carries the signed workspaceId, tenant and subject. Store the created questionnaire ID against your object, course, account, or project.
window.addEventListener('message', (event) => {
if (event.origin !== 'https://app.responsedock.com') return;
if (event.source !== iframe.contentWindow) return;
if (event.data?.type === 'responsedock.questionnaire.created') {
const { id, slug, title, status } = event.data.questionnaire;
// Store id in your database, e.g. against event.data.subject.
}
if (event.data?.type === 'responsedock.questionnaire.published') {
// event.data.surveyId is now available to respondents.
}
});| Event | Data |
|---|---|
responsedock.questionnaire.created | questionnaire: id, slug, title, status |
responsedock.questionnaire.saved | surveyId |
responsedock.questionnaire.published | surveyId |
responsedock.questionnaire.selected | surveyId, slug |
Older integrations can keep listening for the legacy events, which are still sent alongside: responsedock.survey.created (with the same summary in survey), responsedock.survey.published and responsedock.survey.opened.
Respondent Embed
Respondent embeds are scoped to one external user and a survey allowlist. ResponseDock only returns the surveys you pass in allowedSurveyIds, plus completion state for externalUserId.
POST https://api.responsedock.com/api/v1/auth/embed-token
Authorization: Bearer sk_live_your_secret_key
Content-Type: application/json
{
"workspaceId": "ws_xxxx",
"role": "respondent",
"allowedSurveyIds": ["survey_id_stored_in_your_system"],
"externalUserId": "user_12345",
"allowedOrigin": "https://app.yourplatform.com"
}The returned iframe opens the respondent dashboard at /embedded/surveys. Users can see assigned flows, completed history, and start unfinished surveys without leaving your platform.
For a single-survey embed, you may pass surveyId instead of allowedSurveyIds. During local development, allowedOrigin may be an exact http://localhost:PORT or http://127.0.0.1:PORT origin, provided that same origin is configured in the workspace allowlist.
Duplicate Protection
For user-specific embeds, set each published survey duplicate rule to ONE_PER_EXTERNAL_USER. The respondent dashboard passes your externalUserId into the survey renderer, and the API blocks a second completed response for that user and survey.
Backend Example
async function createResponseDockEmbed({
role,
workspaceId,
allowedSurveyIds,
externalUserId
}) {
const response = await fetch('https://api.responsedock.com/api/v1/auth/embed-token', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RESPONSEDOCK_SECRET_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
workspaceId,
role,
allowedSurveyIds,
externalUserId,
allowedOrigin: 'https://app.yourplatform.com'
})
});
if (!response.ok) throw new Error('Unable to create embed token');
return response.json(); // { token, expiresIn, embedUrl }
}Security Checklist
- Never expose a secret API key in browser code.
- Generate embed URLs on demand; the initial embed token expires after 5 minutes.
- Set
allowedOriginand configure workspace allowed origins. - Pass only survey IDs the current user should see.
- Use stable, non-sensitive IDs for
externalUserId.
Standalone Survey Embeds
You can still embed a single published survey directly:
<iframe src="https://survey.responsedock.com/s/your-survey-slug?source=in-app&utm_campaign=onboarding" width="100%" height="640" frameborder="0" allow="clipboard-write" ></iframe>
The survey page reads these optional query parameters. Source fields are stored with the response unless the survey is anonymous or its source tracking is turned off:
| Parameter | Stored as |
|---|---|
rid (or respondentToken) | Signed respondent token that ties the response to one of your users. Create it server-side with POST /surveys/:id/respondent-tokens and { "externalUserId": "user_12345" }; the reply includes a ready-made surveyUrl. Never put a raw user ID in the URL. |
source (or channel) | Source channel, e.g. email or in-app. Falls back to utm_source. |
utm_source, utm_medium, utm_campaign | UTM attribution. |
campaignId (or campaign_id) | Your campaign identifier. |
eventContextId (or context_id) | An ID for the event or context that prompted the survey. |
pageUrl, referrer | The host page and referrer, saved without their query string and fragment. Default to the survey page URL and the browser referrer. |