Add an AI support agent to your Next.js site.

A chat on every page of your Next.js site that answers from your docs, shows the passage it used, and hands what it can’t answer to you.

Add to your code · 8 steps

Before you start.

  • On Next.js

    None.

  • On hiy

    A Support Agent. Making your first one starts a 14-day free trial, no card needed, one per account.

    Make one from your site
  • Who can ask it

    Anyone, even a script, can ask an open agent, so treat what it knows as public.

    Open on your site
  • Visitors who sign in

    Leave it closed and have your own server sign each visitor a token instead.

    The Next.js recipe

Step by step.

Three steps in hiy, 4 on Next.js, then a test.

In hiy

  1. Add your site in hiy

    In your Support Agent, on the Install card, type your site’s address and press Save.

  2. Switch on Open on your site

    It asks you once before it opens. Anyone on your sites, even a script, can then ask it, so treat what it knows as public.

  3. Copy the line

    Copy the one line it shows. data-agent names your agent.

    <script src="https://hiy.ai/embed.js" data-agent="your-agent" data-mode="bubble" async></script>

On Next.js

  1. Copy your snippet

    In hiy, open Channels, then Install, and copy your snippet. It carries your door, so the site follows the agent if you move it.

  2. Open a public layout

    Open a layout that wraps your public pages and stays mounted, such as app/(site)/layout.tsx. Keep the embed off sign-in and app pages.

  3. Add the Script

    Import Script from next/script and render it after {children}, with every attribute from your snippet. Next.js passes the data attributes through to the script tag.

    app/(site)/layout.tsx

    import Script from 'next/script'
    
    export default function SiteLayout({ children }: { children: React.ReactNode }) {
      return (
        <>
          {children}
          <Script
            src="https://hiy.ai/embed.js"
            data-agent="your-agent"
            data-mode="bubble"
            strategy="lazyOnload"
          />
        </>
      )
    }
  4. Deploy

    Deploy your site.

Then

  1. Test it on your live site

    Open a page of your published site and ask something your docs answer, then something they don’t. hiy opens only on https pages of the sites on your list.

Worth watching for.

  • lazyOnload, which Next.js suggests for chat plugins, loads the embed once the page is idle.
  • Next.js loads one script per src. If a page also carries the chat bar, add the second snippet from an effect.
  • If your site sets a nonce for scripts, pass nonce={nonce} to Script. Under 'strict-dynamic' the script-src host is ignored.
  • If your site sends a Content-Security-Policy, add script-src https://hiy.ai and frame-src https://hiy.ai and connect-src https://hiy.ai.
  • On an address like yours.vercel.app, list that exact host in hiy. hiy refuses vercel.app on its own, because many sites share it.

Train it on your Next.js site.

In hiy, go to Agents, press New Support Agent, paste your site’s address and press Find its pages. It lists the pages and reads none of them until you create the agent, and a pop-up lets you untick pages or add more.

When the site changes, open it in Knowledge and press Re-sync now, or have it re-read weekly or monthly. New pages are offered, never added.

How setup worksSyncing a website

Questions people ask first.

Do I need a developer to add hiy to Next.js?

Whoever edits a layout your public pages share and deploys the site can do it. hiy needs no server of yours.

Is my agent’s knowledge public on my Next.js site?

With Open on your site switched on, yes. Anyone on the sites you list can ask it, and so can a script, so treat what it knows and its instructions as public.

What if my visitors sign in?

Leave Open on your site off and have your own server sign each visitor a short-lived token instead. The chat API guide shows how.

Put it on your own site. Start free; the paid plan is free for 14 days.

Start free
  • 14-day free trial
  • No card needed
  • Paste a URL to start