Embedding Public AI Chat
Add Public AI Chat to your website using a simple CDN integration. No build step or complex setup required—just include the CSS and JavaScript files, and the public chat is ready to use.
Purpose
This document provides technical instructions for embedding Public AI Chat on your website. It covers CDN integration, configuration options, and troubleshooting common issues.
Scope
Covered
- CDN-based integration method
- Configuration options and initialization
- HTML data attributes for automatic setup
- JavaScript initialization method
- Troubleshooting common errors
Not Covered
- Public AI Chat configuration (see Public AI Chat)
- Access key creation and management (see Public AI Chat and Access Keys)
- API-level implementation details
Prerequisites
- Public AI Chat configured and enabled for your Site
- Access key created for Public AI Chat with the correct scopes:
public_chat:send(required for text chat)public_chat:voice(required if voice chat is enabled)
- Website domain added to allowed origins in Public AI Chat settings
- Access to modify your website's HTML
Important: If you plan to use voice chat, ensure your access key includes the public_chat:voice scope in addition to public_chat:send. Voice chat requires both the scope in the access key and voice chat enabled in Public AI Chat settings.
CDN Integration
The simplest way to add Public AI Chat is using the CDN method. All dependencies including Vue are bundled, so no build step is required.
Step 1: Load CSS and JavaScript
Add the following to your HTML page's <head> section:
<!-- Load Public AI Chat CSS -->
<link rel="stylesheet" href="https://cdn.clearideas.com/clearideas-chat/clearideas-chat.css">
<!-- Load Public AI Chat JavaScript (includes Vue and all dependencies) -->
<script src="https://cdn.clearideas.com/clearideas-chat/clearideas-chat.iife.js"></script>
Step 2: Initialize the Public Chat
Choose one of two initialization methods:
Method 1: HTML Data Attributes (Automatic)
Add a <div> element with data attributes. The public chat initializes automatically:
<div
data-clearideas-chat
data-access-key="your-access-key-here"
data-api-base-url="https://api.clearideas.com"
data-position="bottom-right"
data-width="380"
data-height="540"
></div>
Method 2: JavaScript Initialization
Use JavaScript to initialize the public chat programmatically:
<script>
const chat = window.ClearIdeasChat.init({
accessKey: 'your-access-key-here',
apiBaseUrl: 'https://api.clearideas.com',
position: 'bottom-right',
width: 380,
height: 540
})
</script>
Configuration Options
Required Options
accessKey: Your Public AI Chat access key. Get this from Site Settings > Public AI Chat Settings > Public AI Chat Access Keys.
apiBaseUrl: The Clear Ideas API base URL. Use https://api.clearideas.com for production.
Optional Options
position: Where to position the public chat on the page. Options:
bottom-right(default)bottom-lefttop-righttop-left
width: Width of the public chat window in pixels. Default: 380
height: Height of the public chat window in pixels. Default: 540
openOnLoad: Whether to open the public chat automatically when the page loads. Default: false
placeholder: Placeholder text for the message input field
userName: Optional user name to associate with chat sessions
userEmail: Optional user email to associate with chat sessions
userId: Optional user ID to associate with chat sessions
voiceEnabled: Enable voice chat functionality. Default: false (uses Site configuration)
darkMode: Override dark mode detection. Set to true or false to force a specific theme
Complete Example
Here's a complete HTML example using data attributes:
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<!-- Load Public AI Chat CSS -->
<link rel="stylesheet" href="https://cdn.clearideas.com/clearideas-chat/clearideas-chat.css">
<!-- Load Public AI Chat JavaScript -->
<script src="https://cdn.clearideas.com/clearideas-chat/clearideas-chat.iife.js"></script>
</head>
<body>
<!-- Your website content -->
<!-- Public AI Chat - Auto-initializes from data attributes -->
<div
data-clearideas-chat
data-access-key="your-access-key-here"
data-api-base-url="https://api.clearideas.com"
data-position="bottom-right"
data-width="380"
data-height="540"
></div>
</body>
</html>
JavaScript API
When using JavaScript initialization, the init() function returns a chat instance with methods to control the public chat:
open(): Opens the public chat window
close(): Closes the public chat window
toggle(): Toggles the public chat open/closed state
sendMessage(content): Sends a message programmatically
destroy(): Removes the public chat from the page
Example:
const chat = window.ClearIdeasChat.init({
accessKey: 'your-access-key-here',
apiBaseUrl: 'https://api.clearideas.com'
})
// Open the chat when a button is clicked
document.getElementById('open-chat-button').addEventListener('click', () => {
chat.open()
})
Security Considerations
CORS Configuration
Public AI Chat uses CORS (Cross-Origin Resource Sharing) to ensure only authorized websites can embed the chat. Your website's domain must be added to the allowed origins list in Public AI Chat settings.
Important: After adding a new origin, CORS changes can take up to 60 seconds to propagate. If you encounter CORS errors immediately after adding an origin, wait up to 60 seconds and try again.
Access Key Security
- Store access keys securely
- Never commit access keys to version control
- Rotate access keys regularly
- Revoke unused or compromised keys immediately
- Use different access keys for different environments (development, staging, production)
Best Practices
- Use HTTPS for your website to ensure secure communication
- Validate that your domain is in the allowed origins list before embedding
- Monitor access key usage for suspicious activity
- Keep the Public AI Chat JavaScript and CSS files up to date
Troubleshooting
CORS Errors
Error: "Access to fetch at 'https://api.clearideas.com' from origin 'https://yourdomain.com' has been blocked by CORS policy"
Solutions:
- Verify your domain is added to the allowed origins list in Public AI Chat settings
- Ensure the domain matches exactly (including
https://andwww.if applicable) - Wait up to 60 seconds after adding a new origin—CORS changes can take time to propagate
- Check browser console for the exact origin being blocked
- Verify you're using the correct access key for the Site
Invalid Access Key
Error: "401 Unauthorized" or "Invalid access key"
Solutions:
- Verify the access key is correct and copied completely
- Check that the access key is active (not revoked or expired)
- Ensure the access key is for the correct Site
- Verify the access key has the required scopes:
public_chat:send(required for text chat)public_chat:voice(required if voice chat is enabled)
- If voice chat isn't working, ensure the access key includes the
public_chat:voicescope
Public Chat Not Appearing
Error: Public chat doesn't appear on the page
Solutions:
- Check browser console for JavaScript errors
- Verify CSS and JavaScript files are loading correctly
- Ensure the initialization code is executed after the page loads
- Check that
data-clearideas-chatattribute is present (for data attribute method) - Verify the access key is valid and the Site has Public AI Chat enabled
Voice Chat Not Working
Error: Voice chat button doesn't work or microphone access is denied
Solutions:
- Verify voice chat is enabled in Public AI Chat settings
- Check access key scopes: Ensure your access key includes the
public_chat:voicescope. This is required in addition to enabling voice chat in settings - Check that the user has granted microphone permission in their browser
- Ensure the website is served over HTTPS (required for microphone access)
- Test in different browsers—some browsers have stricter permission requirements
- Check browser console for permission-related errors
Important: Voice chat requires two things:
- Voice chat enabled in Public AI Chat settings
- An access key with the
public_chat:voicescope
Both conditions must be met for voice chat to work.
Note: Voice chat requires explicit user consent for microphone access. Users must click "Allow" when prompted by their browser. This is a browser security requirement and cannot be bypassed.
Network Errors
Error: "Network error" or "Failed to fetch"
Solutions:
- Check internet connection
- Verify the API base URL is correct (
https://api.clearideas.com) - Check for firewall or network restrictions blocking API requests
- Verify the Site has Public AI Chat enabled
- Check browser console for detailed error messages
Styling Issues
Error: Public chat styling doesn't match your website
Solutions:
- Verify CSS file is loading correctly
- Check for CSS conflicts with your website's styles
- Use custom accent color in Public AI Chat settings to match your brand
- Test theme mode settings (system, light, dark)
- Check browser developer tools for CSS conflicts
Related Documentation
- Public AI Chat - Configure Public AI Chat settings
- Access Keys - General access key management
- Web Import - Import content to power Public AI Chat