next/script in a layout, calling identify() from a small client component, and calling reset() in the browser when the user signs out. This page covers both the App Router and the Pages Router.
Next.js install at a glance
- Load the script with the
Scriptcomponent fromnext/scriptin a layout, withstrategy="afterInteractive". - Put the layout’s
Scriptin the root layout for every page, or in your signed-in area’s layout to load it only after login. - Call
identify()from a client component ("use client"), because it runs in the browser. - Pass that component only the user fields HelpAlive needs, never your whole session object.
- Call
reset()in the browser at sign-out, even when the sign-out itself runs on the server.
Before you start
- Your project key, from Settings → Setup & API Key. It is public, which means that it is safe in client code. If you keep it in an environment variable, the variable’s name must start with
NEXT_PUBLIC_to reach the browser. - A way to read the signed-in user in a server component or layout, which most auth setups give you.
- About 10 minutes.
How to install HelpAlive in the App Router
1
Load the script in your layout
Add To load HelpAlive only once someone has signed in, put the same
Script to app/layout.tsx, so it loads on every page:app/layout.tsx
Script in the layout of your signed-in area instead, for example app/(app)/layout.tsx. The agent only appears for signed-in users either way.2
Add the helper module
Create
lib/helpalive.ts. It queues calls made before the script has loaded, and the script replays them in order when it arrives. It touches window only inside its functions, so importing it during server rendering is safe:lib/helpalive.ts
3
Call identify() from a client component
Create a client component that receives the user and calls Render it in your signed-in layout, and build its Everything you pass to a client component is sent to the browser, so pass these fields only, never the session object with its tokens. Identify users describes each field.
identify() in an effect:components/helpalive-identify.tsx
user prop on the server from your own session:app/(app)/layout.tsx
4
Call reset() in the browser at sign-out
reset() runs in the browser. Call resetUser() in the click or submit handler of your sign-out control, before your sign-out call:components/sign-out-button.tsx
resetUser() in the browser first. Also call it wherever the browser learns that a session has ended, for example when a fetch comes back 401.How to install HelpAlive in the Pages Router
Load the script and identify the user inpages/_app.tsx, using the same lib/helpalive.ts module:
pages/_app.tsx
resetUser() in your sign-out handler, exactly as in the App Router.
Why use next/script instead of a plain script tag?
next/script loads the tag once and keeps it across client-side navigations, and afterInteractive loads it once the page has started hydrating, so it doesn’t hold up your first render. A plain <script> added from a client component is not guaranteed to run. Keep Script in a layout or in _app, not in a single page, or HelpAlive loads only on that page.
How do I add the nonce for a Content Security Policy?
Pass your nonce toScript with the nonce prop, the same way your other scripts get it, and add HelpAlive’s sources to your policy. Content Security Policy lists the sources and explains each one.
Do I need to tell HelpAlive about route changes?
No. HelpAlive records a page view whenever the Next.js router changes the address, including client-side navigations withLink and router.push(). There is nothing to call on navigation.
Check that it works
Sign in to your app with a test account, then open Settings → Setup & API Key on the dashboard. The first step, Add HelpAlive to your app, gets a check once HelpAlive has seen your page and a signed-in user. Check it works explains each step. To see what HelpAlive does on a page, adddata-debug to Script while you test, and remove it before you ship.
Related pages
Identify users
Every identify() field, switching company, and logout.
Verify users
Sign each user id on your server, with a Node.js example.
Install in React
The same steps for React apps built with Vite.

