AI Support Widget Documentation

Complete integration guide for all platforms and frameworks

Generate Widget Key

Quick Start Guide

Get your AI support widget running in under 5 minutes

1

Generate Widget Key

Create your unique widget identifier in the dashboard

2

Choose Platform

Select your website platform from the dropdown

3

Add Code

Copy and paste the integration code to your site

Basic HTML Integration

HTML/JavaScript

<!-- Add before closing </body> tag -->
<script>
  window.aiSupportConfig = {
    widgetKey: 'YOUR_WIDGET_KEY',
    theme: 'light',
    position: 'bottom-right'
  };
  
  // Optional: Set customer data for personalized support
  window.customerData = {
    customerId: 'unique-customer-id',
    name: 'John Doe',
    email: 'john@example.com',
    phone: '+1234567890',
    metadata: {
      plan: 'premium',
      company: 'Acme Corp',
      role: 'admin'
    }
  };
</script>
<script src="${process.env.NEXT_PUBLIC_APP_URL}/api/widget/js?key=YOUR_WIDGET_KEY"></script>
<div id="ai-support-chat"></div>

Dynamic Customer Data

You can also set customer data dynamically after widget initialization:

Dynamic Customer Setup

// Set customer data after user login
function setCustomerData(user) {
  if (window.setAIChatCustomer) {
    window.setAIChatCustomer(user.id, {
      name: user.name,
      email: user.email,
      phone: user.phone,
      metadata: {
        plan: user.subscriptionPlan,
        company: user.company,
        lastLogin: user.lastLogin
      }
    });
  }
}

// Clear customer data on logout
function clearCustomerData() {
  if (window.setAIChatCustomer) {
    window.setAIChatCustomer(null);
  }
}

Platform Integrations

Detailed integration guides for popular platforms and frameworks

React Component

Create a reusable React component for your AI support widget.

TypeScript Ready
Hooks Compatible

AISupportWidget.tsx

import { useEffect } from 'react';

interface CustomerData {
  customerId: string;
  name?: string;
  email?: string;
  phone?: string;
  metadata?: Record<string, any>;
}

interface AISupportWidgetProps {
  widgetKey: string;
  theme?: 'light' | 'dark';
  position?: 'bottom-right' | 'bottom-left';
  customerData?: CustomerData;
}

const AISupportWidget: React.FC<AISupportWidgetProps> = ({
  widgetKey,
  theme = 'light',
  position = 'bottom-right',
  customerData
}) => {
  useEffect(() => {
    // Configuration
    window.aiSupportConfig = {
      widgetKey,
      theme,
      position
    };

    // Set customer data if provided
    if (customerData) {
      window.customerData = customerData;
    }

    // Load widget script
    const script = document.createElement('script');
    script.src = `${baseUrl}/api/widget/js?key=${widgetKey}`;
    script.async = true;
    document.body.appendChild(script);

    return () => {
      // Cleanup
      if (document.body.contains(script)) {
        document.body.removeChild(script);
      }
    };
  }, [widgetKey, theme, position, customerData]);

  return <div id="ai-support-chat" />;
};

export default AISupportWidget;

Usage in App.tsx

import AISupportWidget from './components/AISupportWidget';
import { useAuth } from './hooks/useAuth'; // Your auth hook

function App() {
  const { user, isAuthenticated } = useAuth();

  return (
    <div className="App">
      {/* Your app content */}
      <AISupportWidget 
        widgetKey="your-widget-key"
        theme="light"
        position="bottom-right"
        customerData={isAuthenticated ? {
          customerId: user.id,
          name: user.name,
          email: user.email,
          phone: user.phone,
          metadata: {
            plan: user.subscriptionPlan,
            company: user.company,
            registeredAt: user.createdAt
          }
        } : undefined}
      />
    </div>
  );
}

useAISupport Hook

import { useEffect, useCallback } from 'react';

export const useAISupport = () => {
  const setCustomer = useCallback((customerData: CustomerData) => {
    if (window.setAIChatCustomer) {
      const { customerId, ...data } = customerData;
      window.setAIChatCustomer(customerId, data);
    }
  }, []);

  const clearCustomer = useCallback(() => {
    if (window.setAIChatCustomer) {
      window.setAIChatCustomer(null);
    }
  }, []);

  return { setCustomer, clearCustomer };
};

Customization Options

Customize the appearance and behavior of your AI support widget

Theme & Styling

theme: 'light' | 'dark' | 'auto'

Set widget color scheme

primaryColor: '#your-color'

Custom brand color

borderRadius: '8px'

Widget border radius

Position & Layout

position: 'bottom-right' | 'bottom-left'

Widget position on screen

zIndex: 9999

Widget stack order

minimized: true

Start in minimized state

Behavior Settings

autoOpen: false

Auto-open widget on page load

showBranding: true

Display "Powered by" text

soundEnabled: true

Enable notification sounds

Mobile Options

mobileFullscreen: true

Fullscreen on mobile devices

hideOnMobile: false

Hide widget on mobile

mobileBreakpoint: 768

Mobile breakpoint in pixels

Complete Configuration Example

window.aiSupportConfig = {
  // Required
  widgetKey: 'your-widget-key',
  
  // Appearance
  theme: 'auto', // 'light' | 'dark' | 'auto'
  primaryColor: '#3b82f6',
  borderRadius: '12px',
  
  // Position & Layout
  position: 'bottom-right', // 'bottom-right' | 'bottom-left'
  zIndex: 9999,
  minimized: false,
  
  // Behavior
  autoOpen: false,
  showBranding: true,
  soundEnabled: true,
  
  // Mobile
  mobileFullscreen: true,
  hideOnMobile: false,
  mobileBreakpoint: 768,
  
  // Custom Messages
  welcomeMessage: 'Hello! How can I help you today?',
  placeholderText: 'Type your message...',
  
  // User Info (optional)
  user: {
    id: 'user-123',
    name: 'John Doe',
    email: 'john@example.com'
  },
  
  // Custom CSS (optional)
  customCSS: `
    .ai-widget-bubble {
      box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    }
  `
};

API Reference

JavaScript API methods and events for advanced integration

Widget Methods

window.AiSupport.open()

Open the chat widget

window.AiSupport.close()

Close the chat widget

window.AiSupport.toggle()

Toggle widget open/close

window.AiSupport.sendMessage(text)

Send a message programmatically

Events

ai-widget-ready

Widget loaded and ready

ai-widget-opened

Widget was opened

ai-widget-closed

Widget was closed

ai-message-sent

User sent a message

API Usage Examples

// Listen for widget events
document.addEventListener('ai-widget-ready', function() {
  console.log('AI Support widget is ready!');
});

document.addEventListener('ai-widget-opened', function() {
  // Track widget opens in analytics
  gtag('event', 'widget_opened', {
    event_category: 'ai_support'
  });
});

document.addEventListener('ai-message-sent', function(event) {
  console.log('Message sent:', event.detail.message);
});

// Programmatically control the widget
function openSupportChat() {
  window.AiSupport.open();
}

function sendWelcomeMessage() {
  window.AiSupport.sendMessage('Hello, I need help with my order');
}

// Open widget when user clicks a custom button
document.getElementById('help-button').addEventListener('click', function() {
  window.AiSupport.open();
});

// Update customer data dynamically
function updateCustomerData(customerData) {
  window.AiSupport.setCustomer(customerData);
}

// Example: Update customer after login
function onUserLogin(user) {
  updateCustomerData({
    customerId: user.id,
    name: user.name,
    email: user.email,
    metadata: {
      accountType: user.subscription,
      loginTime: new Date().toISOString()
    }
  });
}

Customer Data API

Customer Data Schema

Customer Data Interface

interface CustomerData {
  customerId: string;          // Required: Unique customer identifier
  name?: string;               // Optional: Customer's full name
  email?: string;              // Optional: Customer's email address
  phone?: string;              // Optional: Customer's phone number
  metadata?: {                 // Optional: Additional customer information
    [key: string]: any;        // Any custom data relevant to your business
    
    // Common examples:
    accountType?: string;      // e.g., 'premium', 'basic', 'enterprise'
    registeredAt?: string;     // ISO date string
    lastLoginAt?: string;      // ISO date string
    totalOrders?: number;      // Total number of orders
    totalSpent?: number;       // Total amount spent
    preferences?: object;      // User preferences
    tags?: string[];           // Customer tags/categories
    location?: {               // Customer location data
      city?: string;
      country?: string;
      timezone?: string;
    };
  };
}

// Example customer data objects:
const basicCustomer = {
  customerId: 'user-123',
  name: 'John Doe',
  email: 'john@example.com'
};

const detailedCustomer = {
  customerId: 'premium-user-456',
  name: 'Jane Smith',
  email: 'jane@company.com',
  phone: '+1-555-0123',
  metadata: {
    accountType: 'premium',
    registeredAt: '2023-01-15T10:30:00Z',
    totalOrders: 12,
    totalSpent: 2449.99,
    preferences: {
      newsletter: true,
      smsNotifications: false
    },
    tags: ['vip', 'enterprise'],
    location: {
      city: 'San Francisco',
      country: 'USA',
      timezone: 'America/Los_Angeles'
    }
  }
};

Dynamic Customer Updates

Updating Customer Data

// Method 1: Update via window.customerData
function updateCustomerData(newData) {
  window.customerData = {
    ...window.customerData,
    ...newData
  };
  
  // Notify widget of the update
  if (window.AiSupport) {
    window.AiSupport.updateCustomer(window.customerData);
  }
}

// Method 2: Direct API call
function setCustomerData(customerData) {
  if (window.AiSupport) {
    window.AiSupport.setCustomer(customerData);
  }
}

// Example: Update after user action
function onPurchaseComplete(orderData) {
  updateCustomerData({
    metadata: {
      ...window.customerData?.metadata,
      lastPurchase: new Date().toISOString(),
      totalOrders: (window.customerData?.metadata?.totalOrders || 0) + 1,
      recentOrder: {
        id: orderData.id,
        total: orderData.total,
        items: orderData.items.length
      }
    }
  });
}

// Example: Clear customer data on logout
function onUserLogout() {
  window.customerData = null;
  if (window.AiSupport) {
    window.AiSupport.clearCustomer();
  }
}

Troubleshooting

Common issues and solutions for widget integration

Widget Not Loading

Symptoms: Widget doesn't appear on the page

  • • Check if widget key is correct and valid
  • • Verify script URL is accessible
  • • Check browser console for JavaScript errors
  • • Ensure div with id="ai-support-chat" exists

Styling Issues

Symptoms: Widget appears but styling is broken

  • • Check for CSS conflicts with your site styles
  • • Verify z-index is high enough (default: 9999)
  • • Check if Content Security Policy allows widget resources
  • • Try setting a custom container position

Mobile Issues

Symptoms: Widget doesn't work properly on mobile devices

  • • Enable mobileFullscreen for better mobile experience
  • • Check viewport meta tag is properly set
  • • Verify touch events are not being blocked
  • • Test on actual devices, not just browser dev tools

Debug Script

// Add this to your page to debug widget issues
window.aiSupportDebug = true;

// Check if widget is loaded
setTimeout(function() {
  if (typeof window.AiSupport !== 'undefined') {
    console.log('✅ AI Support widget loaded successfully');
    console.log('Widget version:', window.AiSupport.version);
    console.log('Configuration:', window.aiSupportConfig);
  } else {
    console.error('❌ AI Support widget failed to load');
    console.log('Check script URL and widget key');
  }
}, 3000);

// Monitor for common issues
if (!document.getElementById('ai-support-chat')) {
  console.warn('⚠️ Widget container div not found');
}

if (!window.aiSupportConfig || !window.aiSupportConfig.widgetKey) {
  console.error('❌ Widget configuration missing or invalid');
}

Support & FAQ

Get help and find answers to frequently asked questions

Frequently Asked Questions

Can I customize the widget appearance?

Yes! You can customize colors, position, theme, and much more through the configuration options.

Does the widget work on mobile devices?

Absolutely! The widget is fully responsive and includes special mobile optimizations.

How do I track widget usage?

Use the JavaScript events (ai-widget-opened, ai-message-sent) to integrate with your analytics platform.

Can I use multiple widgets on one site?

Each widget key is unique to one instance. Contact support for multi-widget scenarios.

Need More Help?

Email Support

support@yourcompany.com

Live Chat

Available 24/7

Knowledge Base

Self-service articles