Skip to content

Embeddable Session Replay for partners

Embeddable Session Replay puts a Cognitive3D Session Replay viewer on your own website. Your users watch participant sessions on your page without a Cognitive3D account or login. You add one script, one HTML element, and one call to EmbeddableSessionReplay.initializeApp().

For every method, event, and config field, see the Embeddable Session Replay API reference.

This is an early release. For support and feedback, contact us with the Intercom button (purple circle) below.

Sample implementation

The screenshot below shows Embeddable Session Replay running inside a partner's own analytics dashboard.

Embeddable Session Replay running in a partner dashboard, showing a warehouse training scene with a participant avatar, gaze cone, and controller overlay

The viewer sits alongside the partner's own navigation and participant list. The controller overlay, play space boundary, and gaze cone come from the session data recorded on Cognitive3D, not from the partner's dashboard.

Prerequisites

  • A Cognitive3D Organization with at least one Project that has recorded sessions.
  • An organization API key with Read-Write permissions. See Create an organization API key.
  • A web server you control. The browser never receives your organization API key, so your server issues the credential the viewer uses.

How it works

The embed is a small SDK served from the Cognitive3D dashboard:

  • One script, session-replay-<version>.min.js (about 8 kB gzipped). It defines window.EmbeddableSessionReplay.
  • One HTML element, <c3d-session-replay>. It hosts the viewer inside its shadow DOM, so your page's CSS can't affect it.
  • One object, EmbeddableSessionReplay, with methods to load sessions, change the display, drive the camera and playback, and listen for events.

Your page asks your own server for a credential. The SDK hands that credential to the viewer by postMessage, never in the iframe URL. No SDK method, event, or error ever returns the credential.

sequenceDiagram participant Page as Your page participant Server as Your server participant C3D as Cognitive3D API participant Viewer as Session Replay viewer Page->>Server: GET /api/session-replay-token?sessionIds=[...] Server->>C3D: POST /projects/{id}/srEmbedTokens (organization API key) C3D-->>Server: user-level JWT Server-->>Page: { "token": "..." } Page->>Viewer: initializeApp({ key, ids }) Viewer->>C3D: Load session (JWT)

Create an organization API key

Your server uses an organization API key to mint the credential the viewer uses.

  1. Open the account menu in the top right of the Dashboard and select Organization Settings.

    The Cognitive3D Dashboard account menu with Organization Settings highlighted

  2. Select Manage API Keys in the left sidebar. Press Create API Key.

    The Manage API Keys page with the Manage API Keys sidebar entry and the Create API Key button highlighted

  3. Enter a description. Set Permissions to Read-Write. Press Generate API Key.

    The Create API Key dialog with the Permissions dropdown set to Read-Write and the Generate API Key button highlighted

    A read-only key cannot mint user-level JWTs.

  4. Copy the key and store it somewhere safe.

    The Create API Key dialog showing the generated orgkey value and the copy button highlighted

Cognitive3D shows the key once and cannot retrieve it after you close the dialog. If you lose it, generate a new key.

Generate the embed code with the Embed Configurator

The Embed Configurator builds the embed code and the backend example for you, with a live preview.

  1. Open a session in Session Replay.
  2. Open Advanced > Developer and select Open in Embed. This opens the Embed Configurator at https://replay.cognitive3d.com/embed with the project, scene, version, and session filled in.

    The Session Replay Advanced menu expanded, showing the Open in Embed button under the Developer section

  3. Enter your organization API key under Authentication. The key stays in your browser and is used only to browse your projects and mint preview credentials.

    The Authentication panel of the Embed Configurator with the Organization Key field filled in and a Verify Write Permission button below it

  4. Adjust Rendering and Camera until the preview looks the way you want.

    The Rendering and Camera panels of the Embed Configurator, with Camera Controls set to Top Down and an Elevation Clip slider at 66 percent

  5. Select Example Code: Embed iframe to copy the front-end code.

    The example code buttons in the Embed Configurator below a Reload Preview button

  6. Select Example Code: Generate JWT (backend) or Example Code: Generate Project Key (backend) to copy the server route. Each example has tabs for Express, Next.js App Router, Fastify, standalone Node.js, and curl.

The rest of this page explains what that code does, so you can adapt it.

Step 1: Add a credential route to your server

Your server exposes a route that returns { "token": "..." } with the header Cache-Control: no-store. The examples use GET /api/session-replay-token. Choose one of two credentials:

Credential How your server gets it What it can read Expiry
User-level JWT (recommended) POST /projects/{projectId}/srEmbedTokens with your organization API key, on every request Only the sessions, participant, or device it was minted for Up to 12 hours (the examples use 60 minutes)
Project API key Minted once with POST /projects/{projectId}/apiKeys and role: projectObserver, then stored as a server secret Every session in the project Never

Warning

Before you return a credential, check that the signed-in user may watch what they asked for. The backend examples leave this check (userMayViewSessions / userMayViewProject) unimplemented on purpose, so a route you haven't finished fails instead of handing out a credential.

Mint a user-level JWT

curl -X POST 'https://api.cognitive3d.com/v0/projects/{projectId}/srEmbedTokens' \
  -H "Authorization: $C3D_ORG_KEY" \
  -H 'Content-Type: application/json' \
  -d '{ "sessionIds": ["1794565147_5b5bf7747b54905cdfc70b71a65b8114"], "expireInMinutes": 60 }'
# 200 { "token": "<jwt>", "expiresAt": <Unix ms> }

C3D_ORG_KEY holds your organization API key on the server.

The request takes exactly one subject. Pick the one that fits your page:

Send Token reads Use it when
sessionIds (1 to 20 ids, each up to 128 characters) Exactly the listed sessions Your page shows specific sessions, such as a review page for one recording or a multiplayer lobby.
participantId Every session of that participant, including sessions recorded after the token was minted A user watches their own sessions, such as a learner reviewing their training history.
deviceId Every session of that device Sessions have no participant, such as a robot or a shared kiosk headset.

Sending no subject, or more than one, returns 400. A session ID that isn't in the project is not rejected; it never loads.

To switch from sessionIds to participantId or deviceId, change the body in the example's mintSessionReplayToken() and change the route's permission check to match. The front-end code keeps sending sessionIds, because the viewer still needs to know which session to open; the route ignores them.

Step 2: Load the script

Add the script once per page:

<script src="https://app.cognitive3d.com/scripts/session-replay-1.0.0.min.js"></script>

The version is part of the file name. Only the current version is served, so an embed pinned to an older version stops loading after an upgrade. Check the Embed Configurator for the current version.

To host the file yourself, use the Download link in the Embed Configurator and pass viewerOrigin: "https://replay.cognitive3d.com" to initializeApp().

Step 3: Add the element

Place the element where the viewer belongs, and size it like any block element. The default size is 100% wide and 600 px tall.

<c3d-session-replay style="width: 100%; height: 600px"></c3d-session-replay>

Step 4: Initialize the viewer

Call initializeApp() with a function that fetches the credential from your route, plus the IDs of what to show:

<script>
  const SESSION_IDS = ["1794565147_5b5bf7747b54905cdfc70b71a65b8114"];

  async function getKey() {
    const url = new URL("/api/session-replay-token", location.href);
    url.searchParams.set("sessionIds", JSON.stringify(SESSION_IDS));
    const res = await fetch(url, { credentials: "same-origin" });
    if (!res.ok) throw new Error("token route answered " + res.status);
    return (await res.json()).token;
  }

  EmbeddableSessionReplay.initializeApp({
    key: getKey,
    projectId: 431,
    sceneId: "e28e5aa7-74f3-45ae-8453-3d485f6ff319",
    sceneVersion: 18,
    sessionId: SESSION_IDS,
    config: { controlType: "followCamera", renderConfig: { autoplay: true } },
  });
</script>

When key is a function, the SDK calls it whenever the viewer needs a credential, including when a JWT expires. You can also pass the credential as a string.

The IDs you pass decide what loads:

You pass The viewer loads
sceneId + sceneVersion + sessionId A scene session. sceneVersion is the version number, not its ID.
sessionId without both scene fields A project session.
lobbyId The whole multiplayer lobby.
lobbyId + sessionId The listed sessions of that lobby.

You can find each ID in the Embed Configurator, or in Session Replay under Advanced > Developer.

Step 5: Change the display

Use updateConfig to change the viewer after it loads. Pass an object, or chain methods:

// Object
EmbeddableSessionReplay.updateConfig({ verticalSliceAmount: 0.5, renderConfig: { ui: false } });

// Chain
EmbeddableSessionReplay.updateConfig.hideUI().updateElevationClip(0.5).pausePlayback();

A chain is sent as one message, and later calls override earlier ones. Changes made before the viewer is ready are queued.

To try a change before you write it into your page, paste it into Preview Config Code in the Embed Configurator and select Submit Config.

Step 6: Switch sessions, refresh the key, and clean up

  • Switch session: call initializeApp() again with the new IDs. You can leave out key; the same element reloads.
  • Refresh the key: call EmbeddableSessionReplay.updateKey(newKey). A key function is called again automatically when the viewer asks; a string key that is refused emits the keyExpired event.
  • Clean up: in a single-page app, call EmbeddableSessionReplay.destroy() on route change. It removes the viewer and every listener.

Handle errors

The SDK never throws. It logs every problem to the console with the prefix [Cognitive3D Session Replay] and emits an error event. The valid part of a change still applies.

EmbeddableSessionReplay.on("error", ({ message, detail }) => {
  console.warn("Session Replay:", message, detail);
});
EmbeddableSessionReplay.on("ready", ({ kind, sessionIds }) => {
  console.log("Loaded", kind, sessionIds);
});

Common causes are a missing or invalid ID, an unknown config key, a refused credential, and a viewer that doesn't start within 60 seconds.

Credential types

The SDK detects the credential type from its shape:

Credential Recognized by
User-level JWT Three base64url segments.
Project API key projectkey- prefix.
Organization API key orgkey- prefix.

Warning

Never put an organization API key in a public web page. Anyone who opens the page can read it and use it against your whole organization. Use a user-level JWT or a project API key from your server instead.

See also

intercom If you have a question or any feedback about our documentation please use the Intercom button (purple circle) in the lower right corner of any web page or join our Discord.