You can make your chatbot’s answers more relevant by passing custom data attributes with your embed code. These attributes are automatically included in the chatbot’s search for related articles.
Context attributes are extra details about where or how the chatbot is being used. You can pass any attributes you want — product, page name, user type, or plan level — to help the chatbot better understand the reader’s situation.
To use context attributes:
- Go to KB settings > AI chatbot. The AI chatbot settings page opens.
- In the Embed code section, copy the sample code provided under Context attributes (optional).
- Use the sample code to pass any context attributes you’d like.
Sample context attributes:
<!-- Option 1: Set context via data attributes -->
<script
src="https://dyzz9obi78pm5.cloudfront.net/min/js/ko-ai-chatbot.js"
data-host="YOUR.WEBSITE-DOMAIN.COM"
data-domain="support.knowledgeowl.com"
data-context-page="checkout"
data-context-project="store"
data-context-section="payment"
data-context-user-type="premium">
</script>
<!-- Option 2: Set context dynamically with JavaScript -->
<script
src="https://dyzz9obi78pm5.cloudfront.net/min/js/ko-ai-chatbot.js"
data-host="YOUR.WEBSITE-DOMAIN.COM"
data-domain="support.knowledgeowl.com">
</script>
<script>
// Set full context (replaces existing)
window.KnowledgeOwlChatbot.setContext({
page: 'checkout',
project: 'store',
section: 'payment',
userType: 'premium'
});
// Update specific fields (merges with existing)
window.KnowledgeOwlChatbot.updateContext({
page: 'confirmation',
section: 'order-summary'
});
// For single-page apps, update on route changes
window.addEventListener('routechange', (event) => {
window.KnowledgeOwlChatbot.updateContext({
page: event.detail.newRoute
});
});
</script>