Engaging Visitors: Deploying Your AI Agent on Your Website

Deploy your AI agent directly on your website to provide instant support, answer questions, and engage visitors—all with a customizable, always-available chat experience.

Connect your Agent to your Website’s Chat Widget

Quick Start (2 Minutes)

Add these two elements to your website, just before the closing </body> tag:

1<!-- Step 1: Configure your widget -->
2<script>
3 window.__CHAT_WIDGET_CONFIG = {
4 agentId: "YOUR_AGENT_ID_HERE",
5 widgetButtonImageUrl: "https://your-site.com/path/to/avatar.jpg",
6 };
7</script>
8
9<!-- Step 2: Load the widget -->
10<script src="https://widget-cdn.flockx.io/flockx-chat.min.js" async></script>

That’s it! A chat bubble will appear in the bottom-right corner of your website.

Configuration Options

PropertyTypeRequiredDescription
agentIdstring (UUID)✅ YesYour Flockx agent’s unique identifier
widgetButtonImageUrlstring (URL)❌ NoCustom avatar image for the chat button

Step 1: Access Your Agent Settings

  1. Log in to your Flockx dashboard at flockx.io.
  2. Select the specific agent you want to integrate with your website.
  3. Click on the Settings tab in the agent management panel.

Step 2: Locate the Chat Widget Section

  1. Scroll down to find the Chat Widget section.
  2. This section handles all website-based deployment options.

Step 3: Upgrade to Enterprise (If Needed)

If you haven’t yet subscribed to the Enterprise plan:

  1. Click Upgrade to Enterprise within the Chat Widget section.
  2. You’ll be taken to the package selection screen.
  3. Select a plan and proceed to the Stripe payment page.
  4. Complete your billing information and submit.
  5. You’ll be automatically redirected to your settings dashboard upon completion.

Step 4: Configure Your Widget

Once upgraded:

  1. Enable the Chat Widget via toggle.
  2. Click Configure to:
    • Customize widget appearance (color, size, placement)
    • Set behavior rules (when to open, how it greets)
    • Craft a custom welcome message
  3. A Flockx representative will assist you with setup and design preferences.

Step 5: Add the Widget to Your Website

Finding Your Agent ID

  1. In your Flockx dashboard, navigate to Agents
  2. Click on your agent
  3. Copy the Agent ID from the agent settings or URL (UUID format like f4393fac-1e23-4549-85fe-cd5b6cafff39)

Framework-Specific Examples

In your root layout (src/app/layout.tsx):

1import Script from 'next/script';
2
3export default function RootLayout({ children }) {
4 return (
5 <html lang="en">
6 <body>
7 {children}
8
9 {/* Flockx Chat Widget Configuration */}
10 <Script id="flockx-chat-config" strategy="beforeInteractive">
11 {`
12 window.__CHAT_WIDGET_CONFIG = {
13 agentId: "YOUR_AGENT_ID_HERE",
14 widgetButtonImageUrl: "/images/your-avatar.jpg",
15 };
16 `}
17 </Script>
18
19 {/* Flockx Chat Widget Script */}
20 <Script
21 src="https://widget-cdn.flockx.io/flockx-chat.min.js"
22 strategy="lazyOnload"
23 />
24 </body>
25 </html>
26 );
27}

Best Practices

Avatar Image Recommendations

  • Format: Use .webp for best performance, or .jpg/.png
  • Size: Recommended 80x80px to 200x200px
  • Shape: The widget displays it as a circle, so center your subject
  • Hosting: Use your own domain or a CDN for reliability

Performance Optimization

The widget script loads asynchronously and won’t block your page rendering. For additional optimization, you can delay loading until user interaction:

1// Load only after user interaction (click, scroll, etc.)
2document.addEventListener('scroll', function loadWidget() {
3 window.__CHAT_WIDGET_CONFIG = {
4 agentId: "YOUR_AGENT_ID_HERE",
5 };
6
7 const script = document.createElement('script');
8 script.src = 'https://widget-cdn.flockx.io/flockx-chat.min.js';
9 document.body.appendChild(script);
10
11 // Remove listener after first trigger
12 document.removeEventListener('scroll', loadWidget);
13}, { once: true });

Agent Preparation

Before embedding, ensure your agent is configured with:

  • ✅ Clear personality and response style
  • ✅ Relevant knowledge base documents
  • ✅ Welcome message for first-time visitors
  • ✅ Appropriate response length settings

Troubleshooting Tips

  • Widget not appearing? Check browser console for JavaScript errors. Verify your agent ID is correct (UUID format).
  • Enterprise not activated? Ensure payment completed successfully and refresh your settings page.
  • Widget appears but no responses? Test your agent in the Flockx dashboard first. Ensure it’s active and not paused.
  • Customization changes not visible? Clear your browser cache or test in incognito mode.
  • Need hands-on help? Reach out to your assigned rep or contact contact@flockx.io

Security Considerations

  • The widget uses secure WebSocket connections (wss://)
  • Agent ID is public (visible in page source)—this is expected and safe
  • API authentication happens server-side via Flockx infrastructure
  • No sensitive credentials should be placed in client-side code

Benefits of Website Integration

  • Provide real-time AI-powered support to your website visitors
  • Answer frequently asked questions instantly
  • Guide users through your products or services
  • Collect initial information before human handoff (if needed)
  • Operate 24/7 without staffing concerns

JavaScript API

The Flockx widget exposes a global FlockxWidget object for programmatic control. This is useful for:

  • Opening the widget when users click a custom button
  • Sending messages based on page context
  • Tracking conversations in your analytics
  • Personalizing responses with user data

Methods

MethodDescription
FlockxWidget.open()Open the chat widget
FlockxWidget.close()Close the chat widget
FlockxWidget.toggle()Toggle the widget open/closed
FlockxWidget.sendMessage(text)Send a message programmatically
FlockxWidget.setUser(userData)Set user context for personalization
FlockxWidget.destroy()Remove the widget from the page

Events

Listen for widget events to integrate with your application:

EventPayloadDescription
flockx:ready{}Widget loaded and ready
flockx:open{}Widget opened
flockx:close{}Widget closed
flockx:message:sent{ text, timestamp }User sent a message
flockx:message:received{ text, agent, timestamp }Agent responded

Example: Advanced Integration

1// Wait for widget to be ready
2window.addEventListener('flockx:ready', () => {
3 console.log('Flockx widget is ready!');
4
5 // Set user context for personalized responses
6 FlockxWidget.setUser({
7 name: 'Alex Creator',
8 email: 'alex@example.com',
9 plan: 'pro',
10 interests: ['podcasting', 'content creation']
11 });
12});
13
14// Track messages in your analytics
15window.addEventListener('flockx:message:sent', (event) => {
16 analytics.track('chat_message_sent', {
17 text: event.detail.text,
18 page: window.location.pathname
19 });
20});
21
22window.addEventListener('flockx:message:received', (event) => {
23 analytics.track('chat_message_received', {
24 agent: event.detail.agent,
25 responseTime: event.detail.responseTime
26 });
27});
28
29// Open widget when clicking a custom button
30document.getElementById('help-button').addEventListener('click', () => {
31 FlockxWidget.open();
32});
33
34// Send contextual message based on page
35if (window.location.pathname.includes('/pricing')) {
36 window.addEventListener('flockx:open', () => {
37 FlockxWidget.sendMessage('I have a question about pricing');
38 }, { once: true });
39}

Example: Custom Trigger Button

Replace the default floating button with your own:

1<!-- Hide the default widget button -->
2<script>
3 window.__CHAT_WIDGET_CONFIG = {
4 agentId: "YOUR_AGENT_ID",
5 hideButton: true // Hide default floating button
6 };
7</script>
8<script src="https://widget-cdn.flockx.io/flockx-chat.min.js" async></script>
9
10<!-- Your custom button -->
11<button id="chat-with-ai" class="my-custom-button">
12 Chat with our AI Team
13</button>
14
15<script>
16 document.getElementById('chat-with-ai').addEventListener('click', () => {
17 FlockxWidget.open();
18 });
19</script>

Full Configuration Options

Here’s a complete list of configuration options:

1window.__CHAT_WIDGET_CONFIG = {
2 // Required
3 agentId: "YOUR_AGENT_ID", // UUID of your Flockx agent
4
5 // Appearance
6 widgetButtonImageUrl: "/avatar.jpg", // Custom avatar image
7 widgetButtonSize: 60, // Button size in pixels (default: 60)
8 position: "bottom-right", // "bottom-right" | "bottom-left"
9 theme: "auto", // "light" | "dark" | "auto"
10 primaryColor: "#6A67FF", // Accent color (hex)
11
12 // Branding
13 headerTitle: "Chat with us", // Header text when open
14 inputPlaceholder: "Type a message...", // Input placeholder text
15 welcomeMessage: "Hi! How can I help?", // First message from agent
16
17 // Behavior
18 hideButton: false, // Hide default floating button
19 autoOpen: false, // Auto-open on page load
20 autoOpenDelay: 5000, // Delay before auto-open (ms)
21
22 // Advanced
23 persistSession: true, // Remember conversation across pages
24 enableSounds: true, // Play notification sounds
25 enableNotifications: false, // Browser notifications (requires permission)
26
27 // Analytics
28 onReady: function() {}, // Callback when widget is ready
29 onOpen: function() {}, // Callback when widget opens
30 onClose: function() {}, // Callback when widget closes
31 onMessageSent: function(message) {}, // Callback when user sends message
32 onMessageReceived: function(message) {} // Callback when agent responds
33};

Use Cases for Creative Professionals

Podcasters

1window.__CHAT_WIDGET_CONFIG = {
2 agentId: "YOUR_AGENT_ID",
3 welcomeMessage: "Hey! I can help you find episodes, get show notes, or answer questions about our podcast. What are you looking for?",
4 headerTitle: "Podcast Assistant"
5};

Artists & Designers

1window.__CHAT_WIDGET_CONFIG = {
2 agentId: "YOUR_AGENT_ID",
3 welcomeMessage: "Welcome to my studio! I can help with commission inquiries, portfolio questions, or booking information.",
4 headerTitle: "Studio Assistant"
5};

Writers & Bloggers

1window.__CHAT_WIDGET_CONFIG = {
2 agentId: "YOUR_AGENT_ID",
3 welcomeMessage: "Thanks for visiting! I can help you find articles, answer questions about my work, or discuss collaboration opportunities.",
4 headerTitle: "Content Assistant"
5};

Musicians

1window.__CHAT_WIDGET_CONFIG = {
2 agentId: "YOUR_AGENT_ID",
3 welcomeMessage: "Hey there! I can help with booking inquiries, merchandise, or finding information about upcoming shows.",
4 headerTitle: "Music Assistant"
5};

Embedding Multiple Agents (AI Team)

For advanced use cases, you can embed multiple specialized agents:

1// Example: Different agents for different pages
2const agentConfig = {
3 '/support': 'support-agent-uuid',
4 '/sales': 'sales-agent-uuid',
5 '/booking': 'booking-agent-uuid',
6 default: 'general-agent-uuid'
7};
8
9const currentPath = window.location.pathname;
10const agentId = Object.keys(agentConfig).find(path =>
11 currentPath.includes(path)
12) ? agentConfig[Object.keys(agentConfig).find(path =>
13 currentPath.includes(path))] : agentConfig.default;
14
15window.__CHAT_WIDGET_CONFIG = {
16 agentId: agentId,
17 // ... other config
18};

Analytics Integration

Google Analytics 4

1window.addEventListener('flockx:message:sent', (e) => {
2 gtag('event', 'chat_message', {
3 event_category: 'engagement',
4 event_label: 'user_message',
5 value: 1
6 });
7});
8
9window.addEventListener('flockx:message:received', (e) => {
10 gtag('event', 'chat_response', {
11 event_category: 'engagement',
12 event_label: 'ai_response',
13 value: 1
14 });
15});

Segment

1window.addEventListener('flockx:message:sent', (e) => {
2 analytics.track('Chat Message Sent', {
3 text: e.detail.text,
4 page: window.location.pathname
5 });
6});

Mobile Considerations

The widget is fully responsive. On mobile devices:

  • The widget opens as a full-screen overlay
  • Touch interactions are optimized
  • Keyboard handling is automatic

For mobile-specific configuration:

1const isMobile = window.innerWidth < 768;
2
3window.__CHAT_WIDGET_CONFIG = {
4 agentId: "YOUR_AGENT_ID",
5 widgetButtonSize: isMobile ? 50 : 60,
6 position: isMobile ? "bottom-right" : "bottom-right"
7};

Accessibility

The widget follows WCAG 2.1 guidelines:

  • Full keyboard navigation support
  • Screen reader compatible
  • Focus management
  • High contrast support

To enable additional accessibility features:

1window.__CHAT_WIDGET_CONFIG = {
2 agentId: "YOUR_AGENT_ID",
3 a11y: {
4 announceMessages: true, // Announce new messages to screen readers
5 highContrast: false // Force high contrast mode
6 }
7};