Skip to content
Longplay
Docs
Browse docs / IAM build integration

IAM build integration

Generate an App page map with Next.js, Vite or React Native builds, upload it and bind browser visual experiments.

Markdown
API v1Updated

1. Install the build tooling#

IAM (Longplay App Manifest) generates an App page map from application source during builds, for Console previews and visual experiment authoring. The independent build package is 0.7.10 and requires Node.js 22+. Its version is separate from the business SDK and CLI. Generating an IAM does not start experiments or publish visual changes.

terminalShell
npm install --save-dev --save-exact @tinkerlandai/longplay-iam@0.7.10
  • Select the existing App and Sandbox/Live environment. An Owner or Admin enables the App page map in Console.
  • Generate locally and review preview content before authorizing an upload. Preserve the application's authentication, routing and build process.

2. Next.js#

For Next.js 15.4.1+, wrap the existing config to generate an IAM during normal production builds. This example disables uploads; strict mode fails the build if generation fails.

next.config.mjsJavaScript
import { withLongplayIam } from "@tinkerlandai/longplay-iam/next"; export default withLongplayIam(  { /* your existing Next.js configuration */ },  { strict: true, upload: false },);

Run the project's existing next build. The plugin injects process.env.INDIANA_IAM_RELEASE_URL into browser code and writes this build's descriptor to public/.well-known/indiana/releases/<id>.json after compilation; with basePath, the URL includes that prefix. Add public/.well-known/indiana/ to .gitignore. next dev does not generate an IAM. The .well-known/indiana/ path and the indiana-app-manifest.json file name written by standalone generation are fixed protocol names in the IAM build package, not renamed with the Longplay brand, so use them exactly as shown.

3. Vite / React Router / TanStack Router#

Add IAM to the existing plugin list and retain the framework's plugins. Use an ESM config; do not require this entry from CommonJS.

vite.config.mjsJavaScript
import { defineConfig } from "vite";import react from "@vitejs/plugin-react";import { longplayIam } from "@tinkerlandai/longplay-iam/vite"; export default defineConfig({  plugins: [react(), longplayIam({ strict: true, upload: false })],});

Run the normal vite build. Client code reads import.meta.env.INDIANA_IAM_RELEASE_URL; descriptors are written under .well-known/indiana/releases/ in the build output, and an absolute base such as /shop/ prefixes the URL. SSR builds skip IAM. For multiple entries, set entry: "src/main.tsx" to the browser entry inside the project root.

4. Bind the browser runtime#

The build plugin only generates the map; the application explicitly starts visual experiments. Choose npm or script loading and use the descriptor from that same build. These examples use the production API's Sandbox. environmentId is the App environment UUID, not the App UUID or the sandbox string.

terminalShell
npm install --save-exact @tinkerlandai/longplay-sdk@latest
visual.tsTypeScript
import {  createVisualExperiments,  loadAppManifestRelease,} from "@tinkerlandai/longplay-sdk/visual"; // Call from the browser after the page has mounted.export async function startVisualChanges(releaseUrl: string, environmentId: string) {  const appManifestRelease = await loadAppManifestRelease(    releaseUrl, document, new AbortController().signal,  );  const visual = createVisualExperiments({    baseUrl: "https://api.longplayai.com",    environmentId,    appManifestRelease,  });  try {    await visual.start();    return () => visual.destroy();  } catch (error) {    visual.destroy();    throw error;  }}

Call startVisualChanges after mounting: pass the injected process.env.INDIANA_IAM_RELEASE_URL in Next.js, or import.meta.env.INDIANA_IAM_RELEASE_URL in Vite. Call the returned cleanup function on unmount, logout or identity change.

index.htmlHTML
<script src="https://cdn.longplayai.com/sdk.js"></script><script type="module">  const { createVisualExperiments, loadAppManifestRelease } = await Longplay.ready;  // Use the descriptor written by this exact deployed build, after any base path such as /shop.  const releaseUrl = "/.well-known/indiana/releases/<BUILD_RELEASE_ID>.json";  const appManifestRelease = await loadAppManifestRelease(    releaseUrl, document, new AbortController().signal,  );  const visual = createVisualExperiments({    baseUrl: "https://api.longplayai.com",    environmentId: "<ENVIRONMENT_UUID>",    appManifestRelease,  });  addEventListener("pagehide", () => visual.destroy(), { once: true });  try {    await visual.start();  } catch (error) {    visual.destroy();    throw error;  }</script>

The script example needs no business SDK npm dependency. Replace BUILD_RELEASE_ID with this build's actual ID and preserve that binding in the application's template or build step; do not use a mutable latest descriptor. Load the loader as a classic script; with async/defer, wait for its load event before accessing Longplay.

Related: Web SDK script installation

Funnel + IAM: entries and page assignments#

For the first layer, choose a uniquely identifiable Web page or button in the App page map, open Funnel entries, save to the existing Funnel draft and publish it. Install the latest stable business SDK (0.10.20 or later) and start the entry host below. The independent createVisualExperiments consumer does not start Funnels.

funnel-entries.tsTypeScript
import { createIamFunnelEntries } from "@tinkerlandai/longplay-sdk";import { loadAppManifestRelease } from "@tinkerlandai/longplay-sdk/visual"; export async function startFunnelEntries(  releaseUrl: string,  options: Omit<Parameters<typeof createIamFunnelEntries>[0], "appManifestRelease">,) {  const appManifestRelease = await loadAppManifestRelease(    releaseUrl, document, new AbortController().signal,  );  const entries = createIamFunnelEntries({ ...options, appManifestRelease });  try {    await entries.start();    return entries; // .retry() reconciles an uncertain start; .destroy() releases the host.  } catch (error) {    entries.destroy();    throw error;  }}
  • After mounting, pass this build's releaseUrl and options containing the App scope, environmentId, API baseUrl, shared Customer session and presentation container. The existing identity flow supplies the Customer session; IAM does not create an identity.
  • Use onStatus for identity_required, configuration_unavailable, incompatible and start_failed. A paused Funnel or a Run waiting on a timer/event step reports run_background and hides its UI. Configuration reads default to a five-second deadline and recover on later polls. Call the returned handle's retry() after an uncertain start, and destroy() on unmount.
  • From SDK 0.10.8, a full Customer Session retains the original entry request and target in this tab's sessionStorage, without Customer or Run credentials. The merchant must first restore the same logical Customer Session and renew it with its Refresh Token. SDK credentials are memory-only by default; the merchant isolates storage of the latest pair by native account and App/environment and clears it on sign-out or account changes. Reloading during a background Wait or after a lost start response then recovers the same Run in the original build and scene, without another allocation. Records are isolated by API, App, environment, Customer and IAM release; bare-token sessions remain memory-only. Set recoveryStorage: false to disable persistence; unavailable storage reports recovery_unavailable.
  • Screen entry matches the route template and render: dynamic routes cover all matching instances, and query/hash changes are not new visits. Entries are tried in stable order; a cooldown or existing-Run refusal allows the next entry. Each visit presents at most one automatic entry: others matched during or after that presentation wait for the next visit, while button clicks still start.
  • Button clicks preserve merchant handlers and navigation; a full-page departure may happen before the Funnel appears. Hidden retained pages do not count as active targets; multiple active targets still refuse entry.

For the second layer, select an experiment with IAM changes on a Funnel Split and enable its page experiment. A Local Funnel requires Local experiment rules. The entry host already passes the build binding; manual Run hosts use the binding below. Custom headless hosts can use createFunnelPageExperiments and own its start()/destroy() lifecycle.

funnel-page.tsTypeScript
import { showFunnelRun } from "@tinkerlandai/longplay-sdk";import { loadAppManifestRelease } from "@tinkerlandai/longplay-sdk/visual"; export async function showFunnelWithPageChanges(  container: HTMLElement,  options: Omit<Parameters<typeof showFunnelRun>[1], "appManifestRelease">,  releaseUrl: string,) {  const appManifestRelease = await loadAppManifestRelease(    releaseUrl, document, new AbortController().signal,  );  return showFunnelRun(container, { ...options, appManifestRelease });}

The page uses the Run's accepted variation without rebucketing. Split-owned experiments leave standalone visitor delivery. Stop, completion or host destruction restores the page. Every eligible page changeset is returned with one assignment per accepted Split, within the visual payload's existing 100-item and 2 MiB budgets.

After a build upgrade, open Version applicability to check experiments and published Funnel entries. Invalid entries list the Funnel, entry and route with a link to the Funnel editor; reselect the page or button and publish. Missing current versions, failed reads and incomplete scans remain explicit. Applicability describes the current IAM, not proof that the merchant deployed that build.

5. Configure build uploads#

Create a separate Key with only app-manifests:write in the selected App environment and store it as the build secret INDIANA_IAM_KEY. The IAM build package reads only INDIANA_IAM_-prefixed variables, unlike the LONGPLAY_ names in other guides, so set them exactly as shown. Do not combine it with other permissions or expose it in browsers, descriptors, source or logs. Review generated content before making it available to the App's members.

Upload and runtime origins
DeploymentINDIANA_IAM_BASE_URLBrowser API baseUrl
Productionhttps://console.longplayai.comhttps://api.longplayai.com

Upload and runtime origins

  • Production

    INDIANA_IAM_BASE_URL
    https://console.longplayai.com
    Browser API baseUrl
    https://api.longplayai.com
build environmentShell
INDIANA_IAM_BASE_URL=https://console.longplayai.comINDIANA_IAM_CLIENT=web
  • Change upload: false in the Next.js/Vite example to upload: "production". This skips Vercel Preview by default; other build environments upload when a Key is present. Use upload: "always" only for builds explicitly intended to upload.
  • Uploads go to Longplay Console (console.longplayai.com), not the api subdomain. BASE_URL, Key and App environment must belong to the same deployment.
  • client defaults to web; other builds can use names such as web-dashboard. Each client has its own current version and its first upload fixes its platform. Successful validation makes the version current but does not publish an experiment.
  • Keep strict: true so an upload failure fails the build. Rerun the same build or command after interruption to resume. CI can retain recovery state in a private INDIANA_IAM_CACHE_DIR; never include this cache in public artifacts.

Related: Keys and permissions

6. React Native / Expo#

The IAM /react-native entry is build tooling that generates separate iOS and Android source previews. It installs no native runtime, scans no Swift/Kotlin source, and does not let the Web visual script control native views.

build-iam.mjsJavaScript
import {  prepareReactNativeIam,  finishReactNativeIam,} from "@tinkerlandai/longplay-iam/react-native"; const options = {  root: process.cwd(), platform: "ios", routerRoot: "app", strict: true,  bundleDirectory: "dist/ios", // asset staging inside root, never scanned as source};const prepared = await prepareReactNativeIam(options);if (!prepared) throw new Error("IAM preparation failed");// Run your existing Expo / Metro bundle step using the same unchanged source.const result = await finishReactNativeIam({  ...options, releaseId: prepared.releaseId,  upload: { upload: false },});// Package dist/ios and result.descriptorPath with this native release.

Prepare first, run the application's existing Metro/Expo bundle step, then finish against the unchanged source. For Android, use platform: "android" and its bundleDirectory. Without Expo Router, use entry: "App.tsx". Uploads default to disabled; explicitly enable them in finish's upload options with the matching client.

Related: React Native business SDK

7. Verify results and troubleshoot#

terminalShell
npx --no-install longplay-iam generate --root . --out ../my-app-iamnpx --no-install longplay-iam validate --file ../my-app-iam/indiana-app-manifest.json
  • Standalone generation uses a new output directory outside the project and executes no application code or server. Inspect coverage.gaps; missing runtime data is not fabricated.
  • Generation and completed upload are separate results. Confirm uploaded/already uploaded in the build log and inspect the client's current version in Console. Console has no manual upload button.
  • Serve the descriptor as public same-origin JSON without authentication or redirects for GET/HEAD. Only the release ID and digest are public; never place the complete IAM or upload credentials in public.
  • Allow the SDK script origin and API connections in CSP. The page and IAM must come from the same build. If changes do not apply, check the descriptor, environment UUID, website Origin, published experiment and coverage.gaps.