For DevelopersJavaScript & TypeScript
Submit Feedback Programmatically
Use submitFeedback to send a survey response without opening the tinyDialog widget.
Submit a response
Pass the survey ID and the response to submitFeedback:
import {submitFeedback} from '@tinydialog/sdk-js';
await submitFeedback(
'01959b56-1bce-7d41-a68c-f19aeffc62cc',
'The new search is easy to use.',
);The response must be a string, number, or boolean. Use a value that is valid for the survey type.
The SDK sends the current page URL and the browser viewport size with the response.
Add response data
Use the optional third argument to send a user identifier, extra data, or a different page URL:
await submitFeedback(
'01959b56-1bce-7d41-a68c-f19aeffc62cc',
9,
{
user: '[email protected]',
extraData: {
userTier: 'PAID',
},
currentUrl: 'https://example.com/account',
},
);useris the contact or user identifier.extraDatacontains additional metadata values for the response.currentUrloverwrites the page URL that the SDK auto-detects.
The sent extra data is displayed in the tinyDialog dashboard.
Handle errors
submitFeedback returns a Promise<void>. It throws an error when the server rejects the response.
try {
await submitFeedback(surveyId, response);
} catch (error) {
console.error('Could not submit feedback.', error);
}Limitations
- Captcha-protected surveys do currently not support programmatic submission. The server rejects these requests.
Last updated on
