Initialize userorbit-js in a Client Component so it runs only in the browser.

Install

npm install userorbit-jsBash

App Router

"use client";
import { useEffect } from "react";
import userorbit from "userorbit-js";

export function UserorbitInit() {
  useEffect(() => {
    void userorbit.init({ accountId: process.env.NEXT_PUBLIC_USERORBIT_ACCOUNT_ID! });
  }, []);
  return null;
}TSX

Pages Router

Render the same initializer from _app.tsx. Do not call the SDK during server rendering.

Identity and routes

Call identify() when a session becomes available and logout() on sign-out. Next.js route detection is automatic in common cases; use registerRouteChange() with usePathname() or router events as a fallback.

Verify

Use the workspace Account ID from Settings → Widget installation and confirm the test contact and network requests.

Was this helpful?