Embed API Reference
Updated: March 30, 2026
The Perspective Embed SDK lets you drop interviews into any web page with a script tag and a data attribute. For more control, use the JavaScript API to create and manage embed instances programmatically.
For the user-facing setup guide (choosing embed types, previewing, copying snippets from the dashboard), see Embed Interviews on Your Website or App.
Quick Start
Add the SDK script and a trigger element to your page:
Replace RESEARCH_ID with the ID of your perspective (visible in the dashboard URL or returned by the Create Perspective API).
The script loads asynchronously and initializes all trigger elements on the page automatically.
Embed Types
Each embed type uses a different data attribute on the trigger element:
Button-based types (Popup, Slider) require a <button> element. The user clicks it to open the interview.
Examples
Inline widget:
Popup triggered by a button:
Floating chat bubble:
URL Parameters
Pass parameters via the data-perspective-params attribute as comma-separated key=value pairs:
Built-In Parameters
Any unrecognized parameters are treated as custom key-value pairs. They are passed through to webhooks and data exports, making them useful for attribution and tracking (e.g., campaign=summer2024).
Theming
Color Mode
Force a color mode with data-perspective-theme:
Accepted values: dark, light, system (default, follows OS preference).
Brand Colors
Override brand colors with data-perspective-brand (light mode) and data-perspective-brand-dark (dark mode):
Available color tokens:
Auto-Open (Popup Only)
Trigger a popup automatically without a user click:
Auto-open triggers:
timeout:N-- Opens the popup afterNmilliseconds.exit-intent-- Opens when the user moves their cursor toward the browser chrome (desktop only).
Show-once options:
session-- Show once per browser session.visitor-- Show once per visitor (persisted in localStorage).false-- Show every time.
JavaScript API
For programmatic control, use the global Perspective object:
Callbacks
React SDK
For React and Next.js apps, use @perspective-ai/sdk-react instead of the script tag. It provides typed components and hooks with full lifecycle control.
Installation
Widget (Inline Embed)
Renders the interview directly inside a container element:
The Widget component accepts all standard div props (className, style, etc.) for sizing and layout.
Popup
Use the usePopup hook for modal overlays:
Slider
Use the useSlider hook for a side panel that slides in from the edge:
Float Bubble
A floating chat bubble anchored to the corner of the page:
Fullpage
Takes over the entire viewport:
Auto-Open
Trigger a popup automatically after a delay or on exit intent:
React Callbacks
All components and hooks accept the same callback props as the JavaScript API: onReady, onSubmit, onNavigate, onClose, and onError. See the Callbacks table above for details.
Direct Iframe Embed
If you cannot use the SDK (e.g., in environments that restrict third-party scripts), embed the interview directly in an iframe:
When using a direct iframe, you must add a postMessage listener to handle navigation and lifecycle events:
PostMessage Events
Add allow="microphone" to the iframe if the interview uses voice mode.
Best Practices
- Load the script once: If you have multiple embeds on the same page, include the SDK script tag only once. It discovers all trigger elements automatically.
- Use the SDK over iframes: The SDK handles responsive sizing, navigation, theming, and lifecycle events. Direct iframes require you to manage all of this yourself.
- Pass user identity via params: If your users are already authenticated, pass
emailandnameso participants skip the identification step. - Prefer
onNavigateover default behavior: In single-page apps, handleonNavigateto use your router instead of a full page reload.