SDK: Users and metadata
Two kinds of data can go with a response:
userId, userEmail | metadata | |
|---|---|---|
| Describes | The respondent | This response |
| Stored on | The session | The response |
| Set in | init() | init() or open() |
| Example | user_123, jane@example.com | { plan: 'pro', orderId: 'A-42' } |
ftools('init', {
surveyId: '__SURVEY_ID__',
publishableKey: '__PUBLISHABLE_KEY__',
userId: 'user_123',
userEmail: 'jane@example.com',
metadata: { plan: 'pro' }
});userId and userEmail
- A known
userEmailskips the survey's contact screen, if the survey has one. A knownuserIdalone does not. - If the survey doesn't allow repeat responses,
userIdrecognizes a returning respondent across sessions. Without it, the check works only within one session. - Both are read once, at
init().
metadata
- A flat object: string keys, values are strings, numbers or booleans. No nested objects, arrays or
null. metadatafrominit()goes with every response of that survey on the page.metadatapassed toopen()replaces it for that opening; the two are not merged.page_urlis reserved: the SDK always sets it to the current page URL.
With Manual event tracking on, pass metadata to open() at the moment you know the most, for example right after a checkout:
ftools('open', '__SURVEY_ID__', {
metadata: { orderId: 'A-42' }
});