Integrate Ragged into Your Website
Add an AI-powered chatbot to your React or Next.js application in minutes. Our SDK provides a fully customizable chat widget that works seamlessly with modern frameworks.
1Using the Platform in Your React Website
Integrate Ragged's AI chatbot into your React application in minutes. Our SDK provides a fully customizable chat widget that works seamlessly with React, Next.js, and other frameworks.
Installation
Basic Usage
Import the SDK and initialize it with your chatbot's subdomain. The widget will automatically appear on your page.
import { useEffect } from 'react';
Option 1: Using Environment Variables (Recommended)
Create a .env.local file in your project root and add your subdomain. The SDK will automatically detect it.
Then, simply initialize the SDK without passing a subdomain in your code.
init();
}, []);
Option 2: Explicit Initialization
You can also pass the subdomain explicitly in your code block.
init({
subdomain: 'your-chatbot-subdomain'
});
}, []);
<div>Your App Content</div>
);
Next.js Integration
For Next.js applications, add the SDK to your root layout or a client component.
import { useEffect } from 'react';
init(); // Auto-detects NEXT_PUBLIC_RAGGED_SUBDOMAIN from .env
}, []);
Next.js Test SDK Example
Explore our reference implementation for Next.js applications
Vanilla HTML/CSS/JavaScript
For projects not using a framework, you can use the SDK with a simple script tag.
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
</head>
<body>
<!-- Your content here -->
<script>
window.RAGGED_CONFIG = {
subdomain: "your-chatbot-subdomain",
apiUrl: "/api"
};
</script>
<!-- Load the SDK -->
<script src="/sdk/ragged-sdk.js"></script>
</html>