logo image
  • Build progress docs

    • Start NextJs project
    • Install linting and formatting (optional)

    • Setup Mongo DB
    • Setup authentication

    • Setup dark mode
    • Multiple languages
    • Setup online payment

    • Setup live chat
    • Setup Top Progress Loader
  • Other tech docs

    • Useful commands in Yarn
    • Basic Git tutorial
    • Basic Gitlab
    • Install WSL in Window
    • Testing - Jest testing library
    • Tools

    • Using icons in NextJs
    • Setup environment variables
    • Basic of Moongoose, MongDB
    • Unitest in Next.js
    • NVM - Node version management
    • Write CI/CD Gitlab for Next.js
    • Setup Messenger live chat for Next.js/React.js
  1. Home
  2. Build Progress Docs
  3. Live Chat

Setup Hubspot live chat for Next.js app

Learn how to set up HubSpot Live Chat in your Next.js app to improve customer engagement and support. This step-by-step guide covers integration, customization, and best practices for seamless live chat functionality.


Signin Hubspot

Please signin the Hubspot, if you do not have the account, please sign up or you can sign in by Google, Gitbhub, or Mirosoft.

After signin you ger into the dashboard like that:

Hubspot dashboard

Integrate Hubspot live chat into the Next.js App

Add this script bellow into the root layout.tsx file (Script is a build in component from Next.js):

jsx
<Script id="hs-script-loader" type="text/javascript" src={`https://js.hs-scripts.com/${config.HUBSPOT.ID}.js`} strategy="lazyOnload" defer />

Notes: Make sure it is at the end of body tag, you can refer my code below:

jsx
... import Script from "next/script"; ... export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en" className={clsx("h-full scroll-smooth bg-white antialiased", inter.variable, lexend.variable)} > <body className="flex h-full flex-col"> ... <Script id="hs-script-loader" type="text/javascript" src={`https://js.hs-scripts.com/${config.HUBSPOT.ID}.js`} strategy="lazyOnload" defer /> </body> </html> ); }

As you can see the variable ${config.HUBSPOT.ID} in the script, this value is got from the .env file. You can handle environment variables by yourself, or you can refer on my docs.

If you handle env variables like me, please add the HUBSPOT_ID value on the .env file:

json
... HUBSPOT_ID="xxxxxxxxxxx" ...

The HUBSPOT_ID value you can get on the Hubspot profile:

Hubspot user profile

After update the .evn file, you need to update config.ts file at the root of source code folder:

js
/* eslint-disable import/no-anonymous-default-export */ export default { ... // Hubspot HUBSPOT: { ID: process.env.HUBSPOT_ID, }, ... };

Create a new chat flow

In the left navigation, go Automations -> Chatflows:

Hubspot chat flows

In the Chatflows page we click "Create chatflow" button:

Hubspot chat flows

Choose "Website" option.

Hubspot chat flows

Choose "Live agent" option.

setup Hubspot chat flows settings

In this settings, we can setup the "welcome messages", setup the page URL which you want to show the live chat, setup the avatar which shown on the live chat, ... After settings, you can get back to the chatflows.

Hubspot chatflow list page

Custom look and fell of live chat

In this chatflows page, click on the More -> Go to inbox settings:

Hubspot inbox settings

Custom the live chat color

You can choose the color for your live chat base on your brand color:

custom Hubspot live chat color

Custom available time

You can choose the live chat can be shown on the bottom left or bottom right of page:

custom Hubspot live chat available time

Custom position of live chat:

You can choose the live chat can be shown on the bottom left or bottom right of page:

custom Hubspot live chat position

Custom the avatar:

If you want to add avatar of supporter on the live chat like this:

custom Hubspot live chat avatar

You need get back to setup the chat flow on previous step:

Hubspot chatflow settings

In display tab setting, you need choose the user who can reply the customer, if user have the avatar, the avatar image will be shown on the live chat.

Hubspot avatar setting

See the result

After integrate with Next.js and custom the look and feel of live chat, so you will see the result like that on your website:

Hubspot live chat

After customer send the message, the message will be show on the Inbox section on the Hubspot:

Hubspot inbox section

Cool! Now you can see any messages from your customers, you can chat with them and get the feedbacks.

Previous
Setup online payment
Next
Setup Top Progress Loader

On this page

  1. Signin Hubspot

  2. Integrate Hubspot live chat into the Next.js App

  3. Create a new chat flow

  4. Custom look and fell of live chat

    1. Custom the live chat color
    2. Custom available time
    3. Custom position of live chat:
    4. Custom the avatar:
  5. See the result