SDK reference

The survey npm package. React-first with a framework-agnostic core. The same component tree powers the customer runtime and the dashboard preview, so what you see in preview is what your respondents see.

Install

npm install survey
# or
pnpm add survey

<Survey>

The default export. Fetches a published survey by id, renders it, posts responses.

import { Survey } from "survey";

<Survey
  projectId="proj_..."
  surveyId="srv_..."
  publishableKey="pk_..."
  metadata={{ planId: "pro" }}
  respondentId="user_42"
  onAnswer={(answer) => track("answer", answer)}
  onSubmitted={(responseId) => console.log("submitted", responseId)}
/>

Props: projectId, surveyId, publishableKey (required); baseUrl, metadata, respondentId, onAnswer, onSubmitted (optional).

<SurveyView>

Lower-level component that renders a fully-loaded Survey object. Useful for previews and custom data sources.

import { SurveyView, type SurveyDefinition } from "survey";

const survey: SurveyDefinition = { /* ... */ };

<SurveyView
  survey={survey}
  isPreview
  onSubmit={async (answers) => { /* post yourself */ }}
/>

SurveyClient

Headless, framework-agnostic. Use it from Node services, mobile shells, CLIs.

import { SurveyClient, buildSubmission } from "survey";

const client = new SurveyClient({
  publishableKey: "pk_...",
  baseUrl: "https://getsurvey.dev",
});

const survey = await client.fetchSurvey("proj_...", "srv_...");
const submission = buildSubmission(survey, [/* answers */]);
const { id } = await client.submitResponse(submission);

Bundle size

The SDK targets <30 kB gzipped. Styles inject once per page; no CSS file to import.