Basic Usage
Display a chatbot with default settings using a minimal script tag.
<script src="https://sokuto.ai/script.js" data-id="YOUR_API_KEY" defer></script>Full Example
Example using all data attributes.
<script
src="https://sokuto.ai/script.js"
data-id="YOUR_API_KEY"
data-theme-color="#FF5733"
data-welcome-message="Hello! How can I help you?"
data-context="This is the pricing page"
data-user-context='{"is_logged_in":true,"plan":"pro"}'
data-lang="en"
defer
></script>Data Attributes
List of data attributes you can set on the script tag. Attributes that support dynamic updates will reflect changes immediately when modified via JavaScript.
data-idRequiredChatbot API key (required)
data-id="YOUR_API_KEY"data-theme-colorDynamicTheme color for chat button and header (HEX code)
data-theme-color="#FF5733"data-welcome-messageDynamicWelcome message displayed when chat opens
data-welcome-message="Hello! How can I help you?"data-contextPass additional context to AI (e.g., page-specific information)
data-context="This is the pricing page"data-user-contextPass user information in JSON format (login status, plan info, etc.)
data-user-context='{"is_logged_in":true,"plan":"pro"}'data-langLanguage setting (ja or en)
data-lang="en"Custom Events
Listen to custom events fired by the chatbot to integrate with analytics tools.
sokutoai:chat_openFired when the chat widget is opened
Detail: timestamp: Time opened (milliseconds)
sokutoai:message_sentFired when user sends a message
Detail: message: Sent message, timestamp: Send time
Google Analytics Integration
// Track chat open
window.addEventListener('sokutoai:chat_open', function(event) {
gtag('event', 'chat_open', {
'event_category': 'engagement',
'event_label': 'sokuto_chatbot'
});
});
// Track message sent
window.addEventListener('sokutoai:message_sent', function(event) {
gtag('event', 'chat_message', {
'event_category': 'engagement',
'event_label': event.detail.message
});
});Dynamic Updates
Modifying script tag data attributes via JavaScript will instantly update chatbot settings. Theme color and welcome message support dynamic updates.
// Dynamically change theme color
var script = document.querySelector('script[data-id]');
script.setAttribute('data-theme-color', '#00FF00');
// Dynamically change welcome message
script.setAttribute('data-welcome-message', 'New message!');WordPress Plugin Comparison
Achieve the same functionality as WordPress plugin hooks and filters using data attributes.
| WordPress Hook | Data Attribute / Event |
|---|---|
sokutoai_widget_enabled | Control by adding/removing script tag |
sokutoai_welcome_message | data-welcome-message |
sokutoai_user_context | data-user-context |
sokutoai_script_attributes | Set each data attribute directly |
sokutoai_on_chat_open | sokutoai:chat_open |
sokutoai_on_message_sent | sokutoai:message_sent |