For the complete documentation index, see llms.txt. This page is also available as Markdown.

Embed an experience with a script tag

Load the Pixel Streaming Embed package from a CDN with a script tag and render a published experience in a plain HTML page, with no build step.

Render a published Convai Pixel Streaming experience in a plain HTML page by loading the package's UMD build from a CDN. Use this page when the site has no bundler. At the end, the page shows the experience's start screen.

Prerequisites

  • The experience ID of a published experience, and a way to authorize it: a server route that returns a Convai auth token, or a domain that Convai has allowlisted. See Publish and authorize an experience.

  • A web server for the page, since the example fetches the token from a route on the same server.

Add the script and the container

The UMD build is dist/core/convai-embed.umd.js. It is self-contained, and it defines one global, PixelStreamCore, whose PixelStreamClient property is the class that renders the experience. The client fills its container, so give the container a size:

index.html
<!doctype html>
<html>
  <body>
    <div id="experience" style="width: 100%; height: 600px"></div>

    <script src="https://unpkg.com/@convai/experience-embed/dist/core/convai-embed.umd.js"></script>
    <script>
      fetch('/api/convai-token')
        .then((response) => response.json())
        .then((body) => {
          window.experience = new PixelStreamCore.PixelStreamClient({
            container: document.getElementById('experience'),
            expId: 'YOUR_EXPERIENCE_ID',
            authToken: body.token,
          });
        });
    </script>
  </body>
</html>

The example fetches an auth token from a route on your server, /api/convai-token. If Convai has allowlisted your domain instead, leave out authToken and create the client without fetching anything.

Control the experience

The client shows a Click to start your experience screen and starts the experience when the user clicks it. Once the experience has loaded, call its methods from your own controls:

The Pixel Streaming Embed API reference lists every method, option, and callback.

Verify the embed

Open the page through your web server.

If the container shows Please contact convai to get <origin> whitelisted! or a message about the auth token, see Troubleshooting; the causes are the same.

Next steps

Embed an experience with JavaScript modulesPixel Streaming Embed API reference

Last updated

Was this helpful?