On your website

Chat on a coded site

Add the website chat line to a site you build yourself, in plain HTML, a React app or Next.js, and set your content security policy.

On a site you build yourself, the line goes in the HTML every page shares.

Before you start

  • The line, with your key in it. Steps 1 to 4 of Add chat to your website cover it.
  • A key for every address the site answers on. Use a Test key that lists your staging address for a staging site. To try the chat on your own computer, list your dev server's address with http:// and its port, such as http://localhost:3000. A line typed without http:// is read as https://, which a local dev server doesn't answer on.

Plain HTML

Paste the line just before the closing </body> tag of every page:

    <script src="https://app.verticalai.com.au/embed/widget.js" data-key="pk_live_xxxxxxxx" async></script>
  </body>
</html>

If your pages share a footer template or include, put it there once.

React

In a Vite app, index.html at the project root is the page every route is served from. Paste the line just before its closing </body> tag. An older Create React App project keeps that file at public/index.html.

Put the line in that HTML file, so it loads once for the whole app.

Next.js

Add next/script to the root layout, app/layout.tsx. It passes data-key through to the script tag, and it loads the script once, however many pages a visitor opens:

import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://app.verticalai.com.au/embed/widget.js"
          data-key="pk_live_xxxxxxxx"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}

A Pages Router app does the same in pages/_app.tsx.

Content security policy

If your site sends a Content-Security-Policy header, add the app's address to three directives, beside what they already allow:

script-src https://app.verticalai.com.au;
frame-src https://app.verticalai.com.au;
connect-src https://app.verticalai.com.au;

script-src loads the line, and frame-src lets the chat panel open. Without connect-src the chat still works, but the button can't load the colours set in the app.

Check it

Open the site in a private window and follow Check it works.

On this page