Integrate your AI chatbot with Next.js applications using our optimized Script component approach.
Add your Dot configuration to your environment variables for secure and flexible deployment.
Use Next.js Script component with proper loading strategy for optimal performance.
# .env.local
NEXT_PUBLIC_DOT_ID=your-dot-id
NEXT_PUBLIC_DOT_POSITION=bottom-center
NEXT_PUBLIC_DOT_WELCOME_MESSAGE=Hi! How can I help you today?
// app/layout.tsx
import Script from 'next/script';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
<Script
id="dot-chatbot"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
window.DOT_CHATBOT = {
dotId: process.env.NEXT_PUBLIC_DOT_ID,
position: process.env.NEXT_PUBLIC_DOT_POSITION || 'bottom-center',
welcomeMessage: process.env.NEXT_PUBLIC_DOT_WELCOME_MESSAGE || 'Hi! How can I help you today?',
hints: ['How can I help you?', 'Ask me anything!']
};
`,
}}
/>
<Script
src="https://cdn.d0t.my/dot.js"
strategy="afterInteractive"
/>
</body>
</html>
);
}
strategy="afterInteractive"
for optimal loadingFollow the steps above to add Dot to your Next.js application, or explore other integration methods.