Widget Integration

Add the Dochat widget to your website with a single script tag. We provide integration code for HTML, React, Next.js, and vanilla JavaScript.

Getting Your Code

  1. Select your agent from the workspace
  2. Go to Setup & Integrations
  3. Choose your platform
  4. Copy the code snippet

HTML

Add this script before the closing </body> tag:

index.html
<script
  src="https://widget.dochat.site/widget.js"
  data-organization-id="YOUR_ORG_ID"
  data-agent-id="YOUR_AGENT_ID"
  async
></script>

React

Load the widget in your root component:

App.tsx
import { useEffect } from "react";

function App() {
  useEffect(() => {
    const script = document.createElement("script");
    script.src = "https://widget.dochat.site/widget.js";
    script.setAttribute("data-organization-id", "YOUR_ORG_ID");
    script.setAttribute("data-agent-id", "YOUR_AGENT_ID");
    script.async = true;
    document.body.appendChild(script);

    return () => { script.remove(); };
  }, []);

  return <div>{/* Your app */}</div>;
}

Next.js (App Router)

app/layout.tsx
import Script from "next/script";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://widget.dochat.site/widget.js"
          data-organization-id="YOUR_ORG_ID"
          data-agent-id="YOUR_AGENT_ID"
          strategy="lazyOnload"
        />
      </body>
    </html>
  );
}

Next.js (Pages Router)

pages/_app.tsx
import Script from "next/script";

function MyApp({ Component, pageProps }) {
  return (
    <>
      <Component {...pageProps} />
      <Script
        src="https://widget.dochat.site/widget.js"
        data-organization-id="YOUR_ORG_ID"
        data-agent-id="YOUR_AGENT_ID"
        strategy="lazyOnload"
      />
    </>
  );
}

Vanilla JavaScript

const script = document.createElement("script");
script.src = "https://widget.dochat.site/widget.js";
script.setAttribute("data-organization-id", "YOUR_ORG_ID");
script.setAttribute("data-agent-id", "YOUR_AGENT_ID");
script.async = true;
document.body.appendChild(script);

Configuration Attributes

Required

AttributeDescription
data-organization-idYour organization ID
data-agent-idYour agent ID

Optional

AttributeDescriptionDefault
data-positionWidget button positionbottom-right

Verification

  1. Refresh your website after adding the code
  2. Look for the chat button in the bottom corner
  3. Click to open and send a test message
  4. Check that the conversation appears in your dashboard

Troubleshooting

Widget not appearing

  • Verify the script is inside <body>, not <head>
  • Check that organization ID and agent ID are correct
  • Look for errors in the browser console
  • Ensure ad blockers aren't interfering

Widget not responding

  • Confirm your agent status is "Active" (not "Provisioning")
  • Ensure the agent has an indexed knowledge base attached
  • Check network requests in browser DevTools

Performance

The widget is optimized for minimal impact on your site:

  • Lazy loaded — doesn't block initial page render
  • Loads in an isolated iframe — no CSS conflicts
  • Cached for fast subsequent page loads