SDK reference
Web SDK
Every method of @axceera/playstep and the script-tag build, with examples.
The same API is available as window.playstep (script tag) and as the playstep export of @axceera/playstep. Every method is safe to call before the SDK has loaded, and none of them ever throws into your app.
init
Starts PlayStep. Call it once; later calls are ignored.
import { playstep } from '@axceera/playstep'
playstep.init({
appKey: 'ps_pub_prod_your_key',
locale: 'pt-BR',
autoPageViews: true,
onEvent: (event) => analytics.capture(`playstep_${event.type}`, event),
})
| Option | Default | What it does |
|---|---|---|
appKey | required | Your publishable key, ps_pub_…. |
apiBase | https://cdn.playstep.app | Where configs and events live (self-hosting and tests). |
locale | The browser language | The language guides show in, when a guide has it (else its default). See setLocale. |
autoPageViews | true | Report a page view on client-side navigation. |
onEvent | none | Called for every guide event, to pipe them into your own analytics. |
colorMode | 'auto' | 'light' or 'dark' guides. 'auto' follows your page (see below), then the device. |
navigate | none | Your router, so a replay begins where the guide starts. See Take users to where a guide starts. SDK 0.8+. |
startPage | none | Fills in a guide's start page yourself, for pages whose URL lacks a * part. See below. SDK 0.9+. |
config | none | Use this config instead of fetching one. Nothing is sent (preview mode). |
preview | false | Preview mode: nothing is sent. Set automatically by ?playstep_preview= links. |
With the script tag, init runs for you from data-app-key; data-api and data-locale set apiBase and locale.
Light and dark mode
Guides wear your app's appearance and, by default, follow your page into dark mode and back, even while one is showing: a dark or light class on <html> or <body>, dark or light in a data-* attribute there (data-theme="dark", data-bs-theme, data-mantine-color-scheme…), or a color-scheme of dark or light. Most apps already do one of these. If yours keeps its mode somewhere else, set the class or attribute when it changes, or pass colorMode to init. A guide or appearance set to always light or always dark wins over both.
<script async src="https://cdn.playstep.app/sdk/v1/loader.js" data-app-key="ps_pub_prod_your_key" data-locale="en"></script>
Pin a version
/sdk/v1/ always serves the latest release, so fixes reach you without a deploy. To control upgrades yourself, load a version's immutable path with its Subresource Integrity hash. Each release lists its files, their hashes and the exact snippet at https://cdn.playstep.app/sdk/<version>/manifest.json:
<script async src="https://cdn.playstep.app/sdk/0.3.0/loader.js" integrity="sha384-…" crossorigin="anonymous"
data-app-key="ps_pub_prod_your_key"></script>
The loader carries the hashes of the chunks it loads (the guide UI and the launcher button) and adds them with integrity too; the launcher chunk carries the hash of the capture chunk. A changed file never runs: the browser refuses it and your app carries on without guides.
Take users to where a guide starts
A guide can name the page it begins on (Starts on page in its settings, like /app/*/projects). Pass your router as navigate, and when someone starts that guide from another page, PlayStep takes them there first and shows step 1 once the page view arrives. That happens when they pick it in the guide list (Start or Replay), press Replay or Next guide on the finish screen, or your code calls start. A * in the start page is filled in from the same part of the current path, so /app/*/projects from /app/acme/settings goes to /app/acme/projects.
// Vue Router
playstep.init({ appKey: 'ps_pub_prod_your_key', navigate: (path) => router.push(path) })
// Nuxt (in a client plugin)
playstep.init({ appKey: 'ps_pub_prod_your_key', navigate: (path) => navigateTo(path) })
// React Router (inside the router, with const navigate = useNavigate())
playstep.init({ appKey: 'ps_pub_prod_your_key', navigate: (path) => navigate(path) })
// Next.js App Router (with const router = useRouter() from next/navigation)
playstep.init({ appKey: 'ps_pub_prod_your_key', navigate: (path) => router.push(path) })
- The guide begins on step 1 on the page your router lands on, so a page step that the page they came from happens to satisfy is not skipped.
- Triggers (first visit, a page, an event) never navigate: a guide they start shows where the user is.
- The page view comes from your router's navigation as usual (or your own
page()call withautoPageViews: false). - Without
navigate, a guide without a start page, or when a*cannot be filled in (the current path is shorter), the guide starts where the user is, as before. Ifnavigatethrows, the guide starts where the user is and ansdk_erroris sent.
If some of your pages lack the part a * stands for (a workspace app's /app/home or /app/notifications next to /app/acme/…), filling it in from the URL would build a page that does not exist (/app/home/projects). Pass startPage and fill it in from your app's own state instead. It gets the start page as set in the dashboard and the guide's id; return the page to go to, or nothing to start the guide where the user is. If it throws, the guide starts where the user is and an sdk_error is sent.
playstep.init({
appKey: 'ps_pub_prod_your_key',
navigate: (path) => router.push(path),
startPage: (startPath) => (workspace.slug ? startPath.replace('*', workspace.slug) : undefined),
})
Preview and capture links
?playstep_preview=… on any page loads a draft from the dashboard's Open in my app, with its own trigger and targeting, or, for a Generate with AI capture link, shows the capture panel instead of guides. Either lasts for the tab's session across page loads, until it expires or you press Finish. Nothing in a preview is counted, and a preview keeps guide progress in memory: it never reads or changes the progress stored in this browser, so testing a draft does not change what you see once it is live. During a preview the draft is always in the launcher, which shows even if your app turned the floating button off, so you can start it by hand. Mark elements whose labels must never leave the page with data-private; capture skips them and everything inside.
identify
Tells PlayStep who the user is. The id is hashed with SHA-256, together with your publishable key, in the browser before it is sent. Traits are used by segments and stay on the device.
playstep.identify(user.id, { plan: 'pro', role: 'admin', guides: 0 })
Traits merge with the ones you passed before. To remove one, pass it as null; a null trait matches no eq, in or exists rule. reset clears them all.
playstep.identify(user.id, { role: null }) // no longer an admin; plan stays
A signed-in user's guide progress follows them across devices (SDK 0.10+; see triggers). It comes with the config when the page loads, so call identify before PlayStep loads to have it on the first page. It needs a secure page (https or localhost); elsewhere progress stays per device.
track
Reports one of your events. It can start a guide with an event trigger and complete an event step.
playstep.track('invoice_page_opened')
playstep.track('invoice_sent', { amount: 49 }) // properties (SDK 0.10+) go to add-ons; guides use the name
start
Starts a guide now, by id, even if the user has finished it before. With navigate, a guide with a start page begins there.
helpButton.addEventListener('click', () => playstep.start('create-first-invoice'))
complete
Completes the current step if its id matches. Use it for manual steps.
await saveClient()
playstep.complete('fill-client')
page
Reports a page or screen view. Only needed with autoPageViews: false, or for screens that do not change the URL. Page triggers and page steps use these paths.
playstep.page('/invoices/new')
openLauncher
Opens the launcher: the list of guides people can replay. It works whether or not the floating "?" button is on, so you can open it from your own help menu. It does nothing when there are no guides to list, and a call made before the SDK has loaded opens the list once it has. A guide that is showing waits while the list is open and carries on when it closes.
menu.on('help', () => playstep.openLauncher())
// Open the list next to the button that opened it:
helpButton.addEventListener('click', () => playstep.openLauncher({ anchor: helpButton }))
Bring your own button
The floating button sits in a corner where many apps already have a chat or help button. To use your own menu item instead, turn off Show the floating button in the dashboard's Guides › Launcher for that environment, then open the list from your item:
<button type="button" onclick="playstep.openLauncher({ anchor: this })">Replay product tours</button>
The list opens next to the anchor you pass, or next to the element that has focus (usually the button that was pressed). Without either, it sits in the launcher's corner. It takes focus when it opens and gives it back to your button when it closes, with its close button or Esc. Each guide the user has started shows Replay, which plays it again from the first step, and Start over lets every guide start again (see resetProgress).
resetProgress
Clears guide progress on this device so guides can start again: every guide, or only the one you name. The user's identity, traits and device id stay, so there is no need to identify again or reload.
// A "Replay product tours" setting: every guide can start again.
playstep.resetProgress()
// One guide, played now.
playstep.resetProgress('create-first-invoice')
playstep.start('create-first-invoice')
- A guide it clears closes if it is showing.
- First-visit and page triggers are checked again straight away for the current page, so this page's guide starts again without a reload. Other guides start the next time their trigger fires.
- An id that is not one of your guides does nothing. Anything that is not a string, such as a click event, means every guide.
- It reports a
progress_resetevent, withguide_idwhen you named a guide. - It is safe to call before the SDK has loaded.
A reset applies to the browser it runs in. Other devices of a signed-in user keep their own copy; to let a guide start again on all of them, use the server API. To forget the user as well, on sign-out, use reset.
reset
Forgets the user, their traits and their guide progress on this device. Call it on sign-out. A signed-in user's progress kept on the server stays, for when they sign in again. To let a signed-in user replay guides, use resetProgress.
async function signOut() {
await api.signOut()
playstep.reset()
}
It does not end a pause.
pause and resume
Stops guides for now, for a user who should not see them at the moment: a guest in this workspace, say, who was a member in the last one, all in the same page load.
function onWorkspaceChange(workspace) {
if (workspace.role === 'guest') playstep.pause()
else playstep.resume()
}
if (playstep.isPaused()) helpMenu.hideTours()
While paused:
- Nothing starts: no events, page views or first-visit triggers start a guide, and
start()does nothing. - A guide that is showing leaves the screen. Nothing is stored and no event is sent: it is not a dismissal.
- The guide list closes, the launcher button goes, and
openLauncher()does nothing. - Stored progress is untouched, and
identify,resetProgressandresetstill work.
resume() brings the guide that was showing back on the same step. With none showing, it checks first-visit and page triggers for the current page again, against the user's traits as they are now. isPaused() tells you whether guides are paused.
A pause lasts for the page load: after a reload guides run again until you call pause(). Call it before init (or before the SDK has loaded) and nothing starts at all.
Which to use: reset on sign-out, to forget the user and their progress; pause when the signed-in user should not see guides right now, keeping their progress for later; resetProgress to let guides play again.
setLocale
Shows guides in another language from now on, for an app that switches language without a reload. The SDK fetches that language's guides from PlayStep (one small request), and a guide that is showing switches to it at the same step. SDK 0.7+.
playstep.setLocale('fr')
Each guide shows in the user's language when it has it (fr-CA uses fr), else in its default language; text not translated yet falls back too. The card's own words (Next, Back, the step counter, the guide list) follow the same language, from your app's languages. Arabic, Hebrew, Persian and Urdu read right to left. Without setLocale, the language is init's locale, then the browser's.
version
The SDK version, for support requests.
console.log(playstep.version)
use
Attaches an add-on (SDK 0.10+). An add-on is one function that hears the config once it has loaded, then each
identify (with every trait so far), track (with its properties), page and reset. When the app's config turns
analytics on, the first add-on also hears up to 50 calls made before the config loaded; otherwise those are dropped.
An add-on that throws is reported as an sdk_error event and never breaks your app, and an app turned off with the
kill switch tells add-ons nothing. Attach each add-on once.
playstep.use((call, ...args) => {
if (call === 'track') console.debug('PlayStep event', args[0], args[1])
})
Keyboard
Esc belongs to your app unless it is pressed in PlayStep's own UI: a step card, the completion card, the launcher or the guide list. PlayStep also leaves it alone when your app has already handled it (event.preventDefault()).
An Esc pressed in PlayStep's UI is PlayStep's even while your app has a dialog open, so keyboard users can always put a guide card away. PlayStep then stops it (preventDefault() and stopPropagation()), so your dialog does not close on it too and what was typed in it is kept. PlayStep listens on window in the capture phase, ahead of Radix, reka-ui, Headless UI and other libraries that listen on document or window. An Esc anywhere else, such as in your dialog's fields, reaches your app untouched.
- On a step card, Esc hides the guide for now. It is not a dismissal: no
guide_dismissedis sent, nothing starts the guide again on its own until the page is loaded again (or resetProgress runs), and the next load picks it up at the same step. The launcher can still start it. Focus goes back to the step's element. - On the completion card or the guide list, Esc closes it, as its close button does.
Events
onEvent receives the same events the dashboard counts: guide_shown, step_shown, step_completed, clip_loaded, clip_played, clip_unmuted, guide_completed, guide_dismissed, anchor_missing and sdk_error, plus progress_reset after resetProgress (with guide_id when one guide was reset). guide_shown says what started the guide in source (SDK 0.8+): trigger (a trigger), launcher (the guide list or the finish screen) or api (your start() call), so you can react to a replay yourself. A guide that comes back part-way on the same visit sends no second guide_shown; one resumed on a later visit sends one with the source of the start it continues (SDK 0.9+; before that, trigger). Events are sent in batches, and only after a guide has been shown: a visitor who never sees a guide costs one config request and nothing else. Each event carries an id. A batch that cannot be sent (offline, a server error, a rate limit) is retried with backoff and kept in local storage until it goes, on a later page if need be; when the page closes, what is left goes with sendBeacon. A retried event still counts once. If onEvent throws, the event is sent anyway. The delivery code is its own small chunk (events.js, beside ui.js), loaded with the guide UI.