Skip to main content
This guide covers how to install Userplane in a SvelteKit application.

Adding the script

The fastest way to add Userplane is the CDN embed. Add these two tags to the <head> in src/app.html:
You can copy the snippet with your workspace ID pre-filled from Workspace Settings > Domains in the Userplane dashboard.

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 in src/routes/+layout.svelte using onMount. onMount only runs in the browser, so it is safe to import and call the SDK there.
Set the variable in your .env file:
SvelteKit’s $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 appends userplane-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:
See Installation for the full list of parameters.

Sensitive data

Add data-userplane-blur to any element you want blurred in recordings. See Sensitive Data Redaction for the full reference.

Metadata

Call set() inside onMount after initialize():
See Metadata SDK for the full API.

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.

Example app

A complete SvelteKit example is available at github.com/userplanehq/userplane-sdk-examples/tree/main/examples/sveltekit.

Example app