Advanced Configuration
Chat Configuration
interface InitConfig {
siteId: string; // Unique site ID (required)
apiEndpoint: string; // API endpoint URL (required)
chatHidden?: boolean; // Start chat hidden (default: false)
chat?: ChatConfig; // Chat configuration
}
interface ChatConfig {
enabled: boolean; // Enable/disable chat
position?: 'bottom-right' | 'bottom-left'; // Widget position
theme?: {
primaryColor?: string; // Primary color
secondaryColor?: string; // Secondary color
textColor?: string; // Text color
};
accentColor?: string; // Accent color
agentName?: string; // Agent name
agentAvatar?: string; // Agent avatar
agentId?: string; // Agent ID
welcomeMessage?: string; // Default welcome message
chatTitle?: string; // Chat title
allowAnonymousMessages?: boolean; // Allow anonymous messages
}Chat States
interface ChatState {
isOpen: boolean; // Chat open/closed
messages: ChatMessage[]; // Array of messages
unreadCount: number; // Unread count
minimized: boolean; // Chat minimized
user?: UserInfo; // Identified user info
}
interface ChatMessage {
id: string; // Unique message ID
content: string; // Message content
timestamp: number; // Message timestamp
sender: 'user' | 'agent'; // Message sender
status?: 'sent' | 'delivered' | 'read'; // Message status
}
interface UserInfo {
name?: string; // User name
email?: string; // User email
phone?: string; // User phone
userId?: string; // Unique ID in your system
[key: string]: any; // Custom fields
}Event Integration
Event Listeners
// Listen when chat is opened
window.addEventListener('marketfit:chat:opened', (event) => {
console.log('Chat opened', event.detail);
});
// Listen when a message is sent
window.addEventListener('marketfit:chat:message:sent', (event) => {
console.log('Message sent', event.detail);
});
// Listen when a new message is received
window.addEventListener('marketfit:chat:message:received', (event) => {
console.log('New message received', event.detail);
});Configuration Callbacks
window.MarketFit.init({
// ... other configurations
chat: {
enabled: true,
onLeadInfoSubmit: (leadInfo) => {
// Handle captured lead info
console.log('Lead captured:', leadInfo);
// Integrate with your CRM
sendToCRM(leadInfo);
}
}
});Best Practices
-
Contextual Use
- Use
openChatWithTask()to create targeted experiences. - Pre-fill specific tasks based on page context.
- Use
newConversation: trueto ensure clean context.
- Use
-
UX Optimization
- Do not abuse automatic triggers.
- Use
clearExistingMessages: truefor new contexts. - Consider using
autoSend: trueonly for very specific actions.
-
Personalization
- Adapt
welcomeMessagebased on the site section. - Use different
agentNamefor different support types. - Configure themes that match your brand.
- Adapt
-
Performance
- Initialize chat only when necessary.
- Use
chat.remove()to clean up resources when not needed. - Monitor chat state to avoid unnecessary operations.
Last updated on