Before you start
Check four things first:- Your video is ready (
vid_...). See Manage videos. - The host that serves your React app is a verified domain of the project.
localhostcannot be verified. Use a staging host you control, such asstaging.example.com, while you develop. See Integration guide, section 3. - Your backend has a route that returns a playback token for a video. See Create playback tokens on your server.
- The API key stays on your server. Never put it in React code, a bundle or an environment variable that reaches the browser. The React app asks your backend for a token; it never talks to the segmnt API itself.
token, expiresAt, embedUrl and playlistUrl.
The embed paths below use token; the white-label direct-mount path uses
playlistUrl.
Path 1: iframe in JSX
Your backend mints a fresh token per page load. Your component fetches it and renders the iframe:- Fetch a token per page load. Do not store the token in
localStorage, a context or a global store across sessions: it expires (4 hours by default), and a stored token stops working. - A long-lived single-page app can outlive a token. If the player shows “expired”, ask your backend for a new token and re-render. The error codes tell you which case you are in.
- Keep the wrapper
divand theaspect-ratiostyle, so the player resizes with its container.
Path 2: the player script
With many videos on one page, load the player script once and let a component mount the embed. The script goes in your page<head> — in Create React App
or Vite, add it to the index.html:
useEffect, and remove it on cleanup:
SegmntPlayer.embed(target, options) builds the same responsive iframe as
Path 1 inside target. It returns the <iframe> element, so the cleanup can
remove it. The script defines window.SegmntPlayer after it loads; because the
token arrives from your backend after render, the effect runs after the script
is ready in practice. If your app renders before the script loads, gate the
effect on the script (for example, set state in the script’s load event).
Options for embed(): videoId, token, baseUrl, locale, title and
aspectRatio. The locale is "ar" (default, RTL) or "en".
Next.js and other server-rendered setups
The embed is browser-only, so:- Put the component in a client component (
"use client"in the App Router) or render it only after mount. The iframe andSegmntPlayerexist only in the browser. - Put the
<script src=...>tag for Path 2 in your layout’s<head>(App Router: thehead/metadata of the root layout; Pages Router:next/head). Keepdefer. - Fetch the token from a route handler or API route on your server, which
holds the API key in a server-side environment variable. Never put the key
in
NEXT_PUBLIC_*or any other variable that reaches the browser.
Common problems
Where to go next
- Embed a video on any website: the plain-HTML version of both embeds.
- Create playback tokens on your server
- How playback protection works
Tested against the current release
Checked on 24 Oct 2026:- The JSX iframe path renders the same markup as the dashboard’s iframe embed:
same
/e/{videoId}URL shape,allowlist,referrerpolicyand responsive wrapper. - Both components from this page were run in a DOM test harness (React 18,
StrictMode on) against the real player bundle:
SegmntPlayer.embed(target, { videoId, token, locale })puts one iframe in the target, the cleanup removes it on unmount, and a StrictMode double-mount still leaves one player. GET https://cdn.segmnt.cloud/segmnt-player.js→200.GET /e/{videoId}with no token →403token_missing(checked on the TEST deploy), so an app with a broken token fetch shows the player’s error message, not a blank box.- The token response fields (
token,expiresAt,embedUrl,playlistUrl) match Playback tokens and the OpenAPI spec.