Skip to main content
Version: React SDK

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:

ParameterTypeRequiredDescription
surveyIdstringYesThe survey UUID from your Screeb workspace
distributionIdstringNoDistribution channel ID
allowMultipleResponsesbooleanNoAllow the survey to be shown multiple times (default: false)
hiddenFieldsPropertyRecordNoHidden fields to pass to the survey
hooksHooksSurveyStartNoCallback hooks for survey events
languagestringNoForce a specific language (e.g., "en", "fr")
selectorsstring | string[]NoCSS 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>;
};