Adding the script
The fastest way to add Userplane is the CDN embed. Add these two tags to the<head> in src/app.html:
npm SDK
Use the npm SDK when you need programmatic control — triggering recordings from a button, attaching user metadata, or reading recording state.Installation
Initialization
Initialize the SDK insrc/routes/+layout.svelte using onMount. onMount only runs in the browser, so it is safe to import and call the SDK there.
.env file:
$env/static/public module only exposes variables prefixed with PUBLIC_, and the module is inlined at build time.
URL parameters
When a customer opens a recording link, Userplane appendsuserplane-token and userplane-action to the URL. If your app uses a SvelteKit server hook or layout load function that redirects unauthenticated users, preserve the userplane- prefixed parameters through the redirect:
Sensitive data
Adddata-userplane-blur to any element you want blurred in recordings. See Sensitive Data Redaction for the full reference.
Metadata
Callset() inside onMount after initialize():
SSR
@userplane/sdk is SSR-safe to import — it does not reference window or document at module evaluation time. The initialize() call must run client-side, which onMount guarantees. You do not need export const ssr = false in your layout.
| Concern | Safe? | Notes |
|---|---|---|
Static import at top of <script> | Yes | Module is SSR-safe |
Calling initialize() inside onMount | Yes | Runs browser-only |
Dynamic import('@userplane/sdk') in onMount | Yes | Bundle-size optimization only |
Calling initialize() in a load function | No | load runs on the server |
export const ssr = false | Not needed | onMount is sufficient |
Example app
A complete SvelteKit example is available at github.com/wizenheimer/userplane-sdk-examples/tree/main/examples/sveltekit.| Variable | Description |
|---|---|
PUBLIC_USERPLANE_WORKSPACE_ID | Your Userplane workspace ID |
Related articles
- Installation — CDN script placement, CSP, and redirect handling.
- Web SDK — full SDK API reference.
- Metadata SDK — attach user context to recordings.
- Sensitive Data Redaction — blur sensitive content in recordings.