IntegrationsNextjs

Add a Custom Trigger to your Next.js app

Trigger the Inkeep modal with a custom button in your Next.js app.

What is Next.js

Next.js is a React full-stack app development framework. You can use Inkeep's React component library to Add AI Search & Chat functionality to apps or documentation and marketing sites built with Next.js.

Get an API key

  1. Go to the Inkeep Dashboard
  2. Select your project under Projects
  3. Go to the Integrations tab
  4. Click on Create integration
  5. Select Web
  6. Provide a Name and URL (optional) for the integration
  7. Click on Create
  8. Click the Example < /> button to get your API key and view suggested settings

Copy and add the apiKey, integrationId and organizationId to your environment variables:

.env
NEXT_PUBLIC_INKEEP_API_KEY="INKEEP_API_KEY"
NEXT_PUBLIC_INKEEP_INTEGRATION_ID="INKEEP_INTEGRATION_ID"
NEXT_PUBLIC_INKEEP_ORGANIZATION_ID="INKEEP_ORGANIZATION_ID"

Install the component library

npm install @inkeep/uikit
bun add @inkeep/uikit
pnpm add @inkeep/uikit
yarn add @inkeep/uikit

Customize your settings

Create a useInkeepSettings.ts file that will contain a hook that will return the configuration for Inkeep component(s).

const useInkeepSettings = () => {
  const baseSettings = {
    apiKey: process.env.NEXT_PUBLIC_INKEEP_API_KEY!,
    integrationId: process.env.NEXT_PUBLIC_INKEEP_INTEGRATION_ID!,
    organizationId: process.env.NEXT_PUBLIC_INKEEP_ORGANIZATION_ID!,
    primaryBrandColor: "#26D6FF", // your brand color, widget color scheme is derived from this
    organizationDisplayName: "Inkeep",
    // ...optional settings
  };
 
  const modalSettings = {
    // optional settings
  };
 
  const searchSettings = {
    // optional settings
  };
 
  const aiChatSettings = {
    // optional settings
    botAvatarSrcUrl: "/img/logo.svg", // use your own bot avatar
    quickQuestions: [
      "Example question 1?",
      "Example question 2?",
      "Example question 3?",
    ],
  };
 
  return { baseSettings, aiChatSettings, searchSettings, modalSettings };
};
 
export default useInkeepSettings;
import type {
  InkeepAIChatSettings,
  InkeepSearchSettings,
  InkeepBaseSettings,
  InkeepModalSettings,
} from "@inkeep/uikit";
 
type InkeepSharedSettings = {
  baseSettings: InkeepBaseSettings;
  aiChatSettings: InkeepAIChatSettings;
  searchSettings: InkeepSearchSettings;
  modalSettings: InkeepModalSettings;
};
 
const useInkeepSettings = (): InkeepSharedSettings => {
  const baseSettings: InkeepBaseSettings = {
    apiKey: process.env.NEXT_PUBLIC_INKEEP_API_KEY!,
    integrationId: process.env.NEXT_PUBLIC_INKEEP_INTEGRATION_ID!,
    organizationId: process.env.NEXT_PUBLIC_INKEEP_ORGANIZATION_ID!,
    primaryBrandColor: "#26D6FF", // your brand color, widget color scheme is derived from this
    organizationDisplayName: "Inkeep",
    // ...optional settings
  };
 
  const modalSettings: InkeepModalSettings = {
    // optional settings
  };
 
  const searchSettings: InkeepSearchSettings = {
    // optional settings
  };
 
  const aiChatSettings: InkeepAIChatSettings = {
    // optional settings
    botAvatarSrcUrl: "/img/logo.svg", // use your own bot avatar
    quickQuestions: [
      "Example question 1?",
      "Example question 2?",
      "Example question 3?",
    ],
  };
 
  return { baseSettings, aiChatSettings, searchSettings, modalSettings };
};
 
export default useInkeepSettings;

Make sure to add your Inkeep identifiers to your environment settings.

Define the component

Create an InkeepCustomTrigger.tsx file for our Custom Trigger component. <button> represents whatever UI element you'd like to use to trigger the Inkeep Modal.

Note
Note

For Next.js apps that use App Router, use the "use client" directive at the top of the file to load the widget client side.

import dynamic from 'next/dynamic';
import { useCallback, useState } from 'react';
import useInkeepSettings from '@/utils/useInkeepSettings';
 
const CustomTrigger = dynamic(
  () => import('@inkeep/uikit').then((mod) => mod.InkeepCustomTrigger),
  {
    ssr: false,
  },
);
 
function InkeepCustomTrigger() {
  const [isOpen, setIsOpen] = useState(false);
  const {
    baseSettings, aiChatSettings, searchSettings, modalSettings
  } = useInkeepSettings();
 
  const handleClose = useCallback(() => {
    console.log("Modal closed");
    setIsOpen(false);
  }, []);
 
  const customTriggerProps = {
    isOpen,
    onClose: handleClose,
    baseSettings,
    aiChatSettings,
    searchSettings,
    modalSettings,
  };
 
  return (
    <div>
      <button onClick={() => setIsOpen(!isOpen)}>Toggle Modal</button>
      <CustomTrigger {...customTriggerProps} />
    </div>
  );
}
 
export default InkeepCustomTrigger;
import dynamic from 'next/dynamic';
import { useCallback, useState } from 'react';
import { InkeepCustomTriggerProps } from '@inkeep/uikit';
import useInkeepSettings from '@/utils/useInkeepSettings';
 
const CustomTrigger = dynamic(
  () => import('@inkeep/uikit').then((mod) => mod.InkeepCustomTrigger),
  {
    ssr: false,
  },
);
 
function InkeepCustomTrigger() {
  const [isOpen, setIsOpen] = useState(false);
  const {
    baseSettings, aiChatSettings, searchSettings, modalSettings
  } = useInkeepSettings();
 
  const handleClose = useCallback(() => {
    console.log("Modal closed");
    setIsOpen(false);
  }, []);
 
  const customTriggerProps: InkeepCustomTriggerProps = {
    isOpen,
    onClose: handleClose,
    baseSettings,
    aiChatSettings,
    searchSettings,
    modalSettings,
  };
 
  return (
    <div>
      <button onClick={() => setIsOpen(!isOpen)}>Toggle Modal</button>
      <CustomTrigger {...customTriggerProps} />
    </div>
  );
}
 
export default InkeepCustomTrigger;

For a full list of customizations, check out the Custom Trigger documentation.

On this page