Start survey programmatically
Manually trigger a survey by its ID.
<script setup lang="ts">
import { useScreeb } from "@screeb/sdk-vue";
const { surveyStart } = useScreeb();
async function showSurvey() {
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
);
}
</script>
<template>
<button @click="showSurvey">Show survey</button>
</template>
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:
<script setup lang="ts">
import { useScreeb } from "@screeb/sdk-vue";
const { surveyClose } = useScreeb();
</script>
<template>
<button @click="surveyClose">Close survey</button>
</template>