Start survey programmatically
Manually trigger a survey by its ID.
import { useScreeb } from "@screeb/sdk-react";
const MyComponent = () => {
const { surveyStart } = useScreeb();
const handleShowSurvey = async () => {
await surveyStart(
"<survey-id>",
"<distribution-id>",
false,
{ // optional hidden fields
color: "green",
article_id: 42
},
{ // optional hooks
version: "1.0.0",
onSurveyShowed: (payload) => console.log("Survey showed", payload),
},
"en", // optional language
"#screeb-survey-container" // optional CSS selector for the container
);
};
return <button onClick={handleShowSurvey}>Show survey</button>;
};
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
surveyId | string | Yes | The survey UUID from your Screeb workspace |
distributionId | string | No | Distribution channel ID |
allowMultipleResponses | boolean | No | Allow the survey to be shown multiple times (default: false) |
hiddenFields | PropertyRecord | No | Hidden fields to pass to the survey |
hooks | HooksSurveyStart | No | Callback hooks for survey events |
language | string | No | Force a specific language (e.g., "en", "fr") |
selectors | string | string[] | No | CSS selector(s) for custom container |
Close survey
Close the currently running survey:
import { useScreeb } from "@screeb/sdk-react";
const MyComponent = () => {
const { surveyClose } = useScreeb();
const handleCloseSurvey = async () => {
await surveyClose();
};
return <button onClick={handleCloseSurvey}>Close survey</button>;
};