Create a new component file (e.g., components/ChatWidget.tsx) with the following code:
'use client';
import { useEffect } from 'react';
import Script from 'next/script';
export default function ChatWidget() {
useEffect(() => {
window.chatim = window.chatim || {};
window.chatim.cmd = window.chatim.cmd || [];
window.chatim.settings = { projectId: 'YOUR_PROJECT_ID' };
}, []);
return (
<Script
src="https://widget.chatim.app/widget.js"
strategy="lazyOnload"
/>
);
}Replace YOUR_PROJECT_ID with your actual project ID from the Chatim dashboard.
Import and add <ChatWidget /> to your root layout file (e.g., app/layout.tsx):
import ChatWidget from '../components/ChatWidget';
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<ChatWidget />
</body>
</html>
);
}If you're using plain React (not Next.js), you can add the widget like this:
import { useEffect } from 'react';
function App() {
useEffect(() => {
window.chatim = window.chatim || {};
window.chatim.cmd = window.chatim.cmd || [];
window.chatim.settings = { projectId: 'YOUR_PROJECT_ID' };
const script = document.createElement('script');
script.src = 'https://widget.chatim.app/widget.js';
script.async = true;
document.body.appendChild(script);
return () => document.body.removeChild(script);
}, []);
return <div>{/* Your app */}</div>;
}For Vue.js projects:
<script>
export default {
mounted() {
window.chatim = window.chatim || {};
window.chatim.cmd = window.chatim.cmd || [];
window.chatim.settings = { projectId: 'YOUR_PROJECT_ID' };
const script = document.createElement('script');
script.src = 'https://widget.chatim.app/widget.js';
script.async = true;
document.body.appendChild(script);
}
}
</script>Return to your Chatim dashboard to monitor customer interactions, view analytics, and make any necessary adjustments to the widget's behavior, appearance, or responses based on user feedback and engagement.
If you encounter any issues during the installation process, contact us.
Get started