SDK: Initialization
ftools('init', options)
Initializes a survey. Asynchronous — returns a Promise, but the call itself can be made before the SDK script loads (it will be queued and replayed once ready).
ftools('init', { surveyId: '__SURVEY_ID__', publishableKey: '__PUBLISHABLE_KEY__' });
ftools('init', { surveyId: '__SURVEY_ID__', publishableKey: '__PUBLISHABLE_KEY__', root: '#container' });Parameters
| Parameter | Type | Description |
|---|---|---|
options.surveyId | string | Survey ID from the dashboard. |
options.publishableKey | string | Publishable API key (pk_...) from the dashboard. |
options.root | string | HTMLElement | Container for embed mode — a CSS selector or an element reference. Omit for popup mode. |
options.metadata | object | Custom data attached to the survey response. See Custom variables. |
options.channel | string | Override the channel (web-popup, web-inline, ...). Defaults to web-popup, or web-inline when root is set. |
options.userId | string | Optional identifier for the current user, attached to the session. |
options.userEmail | string | Optional email for the current user, attached to the session. |
userId/userEmail identify the respondent on the session — separate from metadata, which is attached to the response instead:
ftools('init', {
surveyId: '__SURVEY_ID__',
publishableKey: '__PUBLISHABLE_KEY__',
userId: 'user_123',
userEmail: 'jane@example.com'
});- A known
userEmailskips the survey's contact-collection screen, if enabled. A knownuserIdalone does not. - If the survey doesn't allow multiple responses, a known
userIdis used to recognize a returning respondent across sessions (a fresh page load gets a new session, but the sameuserIdis still recognized); without it, the check is limited to the current session. - Both are read once, at
init()time — there's no separate command to attach them to a session afterward.
Popup mode
ftools('init', {
surveyId: '__SURVEY_ID__',
publishableKey: '__PUBLISHABLE_KEY__'
});The survey shows automatically based on the triggers configured in the dashboard, or manually via open().
Embed mode
Pass root to render the survey inline inside a container you provide:
// CSS selector
ftools('init', {
surveyId: '__SURVEY_ID__',
publishableKey: '__PUBLISHABLE_KEY__',
root: '#my-container'
});
// HTMLElement reference
ftools('init', {
surveyId: '__SURVEY_ID__',
publishableKey: '__PUBLISHABLE_KEY__',
root: document.getElementById('my-container')
});root accepts either a CSS selector string or a direct HTMLElement reference. Use an element reference if the container lives inside a Shadow DOM — document.querySelector cannot traverse into Shadow DOM from the main document.
See Survey modes for the full behavior differences between popup and embed.