React SDK (preview)
@responsedock/sdk-react provides React components and hooks for embedding surveys in React applications. It wraps the browser SDK, so inline embeds, modals, event triggers, theming and identity verification behave exactly the same.
The React SDK is MIT-licensed, like the browser SDK. It ships as an ES module with TypeScript declarations and a "use client" directive for the Next.js App Router. The React SDK is a preview: its npm package is coming soon. Once it is published to npm, install it with npm install @responsedock/sdk-react; until then, load the hosted browser SDK directly or build the package from packages/sdk-react.
Installation
npm package coming soon.
React and React DOM 18 or later are peer dependencies; @responsedock/sdk-browser is installed with the package.
Provider Setup
Wrap your app (or the relevant subtree) with SurveyProvider. It configures the SDK with your public project key before any child survey loads, and accepts the browser SDK's init() options:
import { SurveyProvider } from '@responsedock/sdk-react';
export default function App() {
return (
<SurveyProvider
projectKey="pk_live_xxxx"
theme={{ primaryColor: '#0f766e', fontFamily: 'Inter, sans-serif' }}
identity={user ? { externalUserId: user.id, userHash: user.responseDockHash } : null}
autoTrack={{ pageViews: true, scrollDepth: [50, 90] }}
callbacks={{ onComplete: ({ surveyId }) => console.log('Completed', surveyId) }}
>
<YourApp />
</SurveyProvider>
);
}identity is applied before any child survey loads; set it back to null on sign-out. When the workspace uses identity verification, compute userHash on your server as hex(HMAC-SHA256(identitySecret, externalUserId)). Theme changes are applied live, and changing callbacks never re-initialises the SDK.
autoTrack is forwarded to the browser SDK, which then emits $pageview, $scroll_depth, $time_on_page and $exit_intent for your trigger rules (see Automatic Events). Page views follow client-side navigation, including the Next.js router. The provider compares autoTrack by value, so an inline object doesn't restart tracking on every render; changing its contents re-initialises the SDK.
Anonymous visitors get a persisted anonymousId from the browser SDK, so trigger caps and sampling work before sign-in. Setting identity back to null calls ResponseDock.reset(), which also clears that id, so the next person on the device starts fresh.
SurveyEmbed Component
Embed a survey inline anywhere in your component tree. The iframe sizes itself to the survey:
import { SurveyEmbed } from '@responsedock/sdk-react';
function FeedbackPage() {
return (
<div>
<h1>How did we do?</h1>
<SurveyEmbed
surveyId="your-workspace/post-purchase"
minHeight={480}
onComplete={({ responseId }) => console.log('Response', responseId)}
/>
</div>
);
}SurveyModal Component
A controlled modal that is open while open is true:
import { SurveyModal } from '@responsedock/sdk-react';
function HomePage() {
const [open, setOpen] = React.useState(false);
return (
<>
<button onClick={() => setOpen(true)}>Give feedback</button>
<SurveyModal
open={open}
surveyId="your-workspace/nps"
autoCloseAfterMs={3000}
onClose={() => setOpen(false)}
/>
</>
);
}onClose fires when the respondent or the survey closes the modal, not when you set open to false yourself.
useSurvey Hook
Inside a SurveyProvider, useSurvey() returns the imperative SDK API:
import { useSurvey } from '@responsedock/sdk-react';
function MatchPage({ matchId, result }) {
const { track, show } = useSurvey();
// Fire an event when the match result arrives; matching trigger rules open a survey.
React.useEffect(() => {
if (result) {
void track('match_completed', { matchId, result });
}
}, [result]);
return <button onClick={() => show('your-workspace/match-feedback')}>Rate this match</button>;
}| Member | Description |
|---|---|
track(event, properties?) | Sends a product event for trigger rules |
show(surveyIdOrSlug, options?) | Opens a modal and returns a { iframe, close(), destroy() } controller |
identify(payload) | Sets the respondent; prefer the provider's identity prop for the signed-in user |
Floating Launcher
The package re-exports the browser SDK's ResponseDock object, so you can add a floating feedback button with ResponseDock.launcher() inside a provider. Destroy it on unmount:
import { ResponseDock } from '@responsedock/sdk-react';
function FeedbackLauncher() {
React.useEffect(() => {
const launcher = ResponseDock.launcher({ surveyId: 'your-workspace/feedback', label: 'Feedback' });
return () => launcher.destroy();
}, []);
return null;
}Server-Side Rendering (Next.js)
The package is SSR-safe and every entry point carries the "use client" directive, so you can render SurveyProvider, SurveyEmbed and SurveyModal directly from App Router server components. Embeds load in the browser after hydration. Call useSurvey() from your own client components.
// app/feedback/page.tsx (Next.js App Router, a server component)
import { SurveyEmbed } from '@responsedock/sdk-react';
export default function FeedbackPage() {
return <SurveyEmbed surveyId="your-workspace/feedback" />;
}Props Reference
| Prop | Component | Description |
|---|---|---|
surveyId | Embed, Modal | Required. Survey ID, or workspaceSlug/surveySlug |
title | Embed, Modal | Accessible iframe title. Default "Survey" |
loadTimeoutMs | Embed, Modal | Raise onError({ code: 'LOAD_TIMEOUT' }) when the survey is not ready in time. Default 15000; 0 disables |
minHeight | Embed | Placeholder height until the survey reports its size. Default 400 |
loading | Embed | 'eager' or 'lazy' |
scrollOffset | Embed | Space kept above a question the survey scrolls to, e.g. a sticky header |
style, className | Embed | Applied to the container element |
open | Modal | Required. Whether the modal is open |
autoCloseAfterMs | Modal | Close this many ms after completion. By default the thank-you screen stays until dismissed |
onClose | Modal | Called when the respondent or the survey closes the modal |
onReady, onComplete, onDismiss, onError, onResize, onStepChange, onRedirect | Embed, Modal | Callbacks for this survey, in addition to the provider's |