Install the live chat widget on Next.js
XACUBE puts a live chat widget on your Next.js site, so your live agents can answer visitors the moment they ask, from one shared inbox. The free plan covers one agent.
Why XACUBE live chat on Next.js
- Add the
Scriptto your root layout,app/layout.tsx. - Publish your site. The chat appears on every page.
import Script from 'next/script'
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<Script src="https://chat.xacube.chat/w.js" data-key="YOUR_PUBLIC_KEY" strategy="afterInteractive" />
</body>
</html>
)
}Replace YOUR_PUBLIC_KEY with your own key. In your panel, open your website and this code is shown with your key already in it.
Recognise signed-in customers
import { createHmac } from 'node:crypto'
import Script from 'next/script'
// In a Server Component, so the secret never reaches the browser.
const hash = createHmac('sha256', process.env.XACUBE_SECRET_KEY!).update(String(user.id)).digest('hex')
<Script src="https://chat.xacube.chat/w.js" data-key="YOUR_PUBLIC_KEY"
data-user-id={String(user.id)} data-user-hash={hash}
data-user-name={user.name} data-user-email={user.email} strategy="afterInteractive" />