Teaflask Docs

Steep

Install

By the end of this page, Steep will capture journeys from your app and you'll see the first one in the dashboard. There are six steps. Do them in order, because each step builds on the one before.

Each step follows from how Steep works. If you haven't read that page, read it first. It's short.

Before you start

Steep can't capture anything until two things are true, and neither is in your code:

  1. You have a Steep key. An owner creates one under Steep, in the Keys section, with New key.
  2. The key allows the origin you're testing on. An origin is a scheme and a host, with a port if there is one, so http://localhost:5173 and http://localhost:3000 are different origins. You can change a key's origins at any time. See Steep keys.

If you're an AI coding agent and you don't have a Steep key yet, stop and ask your user for one; see Install with an AI coding agent.

1. Choose npm or the script tag

If your app… Use
has a bundler, whatever its framework: React, Vue, Svelte, Angular and others the npm package
has no bundler, or is server-rendered: Rails, Django, Laravel, WordPress, plain HTML the script tag

Both are the same Steep. The npm package has no dependencies and no framework of its own, so it suits any app with a bundler, and it stays on the version you installed. The script tag isn't pinned: /v1/ always serves the current release.

Use one or the other on a page, never both. Only one Steep runs per page, so a second start is refused with a console warning.

2. Start it where you choose

Steep starts when your page calls startSteep, or when the <teaflask-steep> element is on the page. Start it only for the users you choose to capture.

Importing the package does nothing by itself. Start Steep once per page load, in the code that runs when your app starts, not in a page component: Steep follows a single-page app's route changes by itself. If you capture only some users, start Steep once you know, and not before. Steep shows your users nothing, so any notice or consent is yours to give. See Privacy controls.

3. Add it

npm package

npm install @teaflask/steep
import { startSteep, optOut, optIn, isOptedOut } from "@teaflask/steep";

const steep = startSteep({ steepKey: "stp_live_…" });

startSteep returns a handle:

Member What it does
steep.stop() Stops capture for the rest of the page, after sending what was already captured
steep.identify({ userId, getEndUserToken }) Signs the user in, or switches to another user. identify(null) signs them out
steep.emit(name, details) Adds an app event to the journey
steep.state Where Steep is, such as starting, capturing or stopped

optOut, optIn and isOptedOut work whether or not Steep is running. See Privacy controls.

The key is meant to sit in your page's code. Teaflask accepts it only from the origins you allow on it.

Script tag

Add both lines to every page you capture:

<script async src="https://app.teaflask.com/steep/v1/steep.js"></script>
<teaflask-steep steep-key="stp_live_…"></teaflask-steep>

Steep starts once the element is on the page with a steep-key, so you can set the attribute later. Changing steep-key or base-url restarts it once, and removing steep-key or the element stops it.

Setting npm option Element attribute Element property Default
Steep key steepKey steep-key required
API address baseUrl base-url https://api.teaflask.com
Signed-in user userId, getEndUserToken userId, getEndUserToken anonymous
Errors onError onError none

The element also has the methods stop, optOut, optIn, emit and identify, which do what their npm counterparts do.

4. Identify signed-in users

Steep identifies users the same way the assistant does: your server signs a short-lived token, and your page passes the user's id and a function that fetches the token. One end-user token works for both the assistant and Steep when the Steep key and the publishable key belong to the same Teaflask organization. Identity shows how to sign the token on your server.

Pass userId and getEndUserToken together, when Steep starts or later with identify:

async function getEndUserToken(): Promise<string> {
  const response = await fetch("/api/teaflask-token", { cache: "no-store" });
  return response.text();
}

const steep = startSteep({
  steepKey: "stp_live_…",
  userId: user.id,
  getEndUserToken,
});

// On sign-in, or when another user signs in
steep.identify({ userId: user.id, getEndUserToken });

// On sign-out
steep.identify(null);

With the script tag, set the userId and getEndUserToken properties on the element, and set both to null on sign-out.

If a user signs in during a journey, the earlier part of that journey becomes theirs. Signing out, or another user signing in, ends the journey and starts a new one. userId must equal the token's user_id. If it doesn't, the journey stays anonymous and onError hears identity_mismatch. If Teaflask can't verify the token, for example because it has expired or was signed with a JWT secret you've since rotated, the journey stays anonymous too, and onError hears END_USER_TOKEN_INVALID.

If the key is set to Only capture signed-in users, Steep captures nothing until your page identifies the user and Teaflask verifies the token.

5. Content Security Policy

Skip this step if your site doesn't send a Content-Security-Policy header. If it does, add these sources to your existing policy:

Directive Add Why
script-src https://app.teaflask.com Script tag only: the Steep script
connect-src https://api.teaflask.com, or your baseUrl origin The key's settings, the user's sign-in and the events

6. Check that it works

Open a page on one of the key's allowed origins, and click around for a moment.

Under Steep, in the Keys section, the key's row stops reading Waiting for the first events… and shows the key's origins, and the key's own page reads Events received …. The journey then appears under Steep → All journeys.

If the row doesn't change, steep.state (or the element's state) and the browser's Network panel say why:

What you see Meaning
403 ORIGIN_NOT_ALLOWED This page's origin isn't on the key's list
401 STEEP_KEY_INVALID The key is wrong, or it was rotated or revoked
A CSP violation in the console The script or its requests were blocked; revisit step 5
state reads privacy-signal Your browser sends Global Privacy Control, and the key respects it
state reads awaiting-sign-in The key captures only signed-in users, and none is identified yet
state reads opted-out This browser opted out with optOut(). optIn() clears it

Requirements

The npm package is an ES module with no dependencies, and ships its own types.

Steep needs a current browser. The script tag also needs custom elements. Page outlines are taken only on secure pages, served over https or from localhost. If the browser blocks sessionStorage, a reload starts a new journey instead of continuing the current one.

More resources

  • Overview – what Steep captures, and how it works
  • Steep keys – allowed origins, and the settings that decide whom and what a key captures
  • Privacy controls – stopping, opting out, and keeping parts of a page out
  • Identity – signing the end-user token on your server
  • View journeys – finding the journeys your app sends