Script tag
Add Docs Embed to any website with a simple script tag
Steps
2
Add the script tag to your HTML
<script src="https://docs.company.com/~gitbook/embed/script.js"></script>
<script>
// Initialize with Authenticated Access (optional)
window.GitBook('init',
{ siteURL: 'https://docs.company.com' },
{ visitor: { token: 'your-jwt-token' } }
);
window.GitBook('show');
</script>5
Optionally configure the embed
<script src="https://docs.company.com/~gitbook/embed/script.js"></script>
<script>
window.GitBook('init', { siteURL: 'https://docs.company.com' });
window.GitBook('configure', {
button: {
label: 'Ask',
icon: 'assistant' // 'assistant' | 'sparkle' | 'help' | 'book'
},
tabs: ['assistant', 'docs'],
actions: [
{
icon: 'circle-question',
label: 'Contact Support',
onClick: () => window.open('https://support.example.com', '_blank')
}
],
greeting: { title: 'Welcome!', subtitle: 'How can I help?' },
suggestions: ['What is GitBook?', 'How do I get started?']
});
window.GitBook('show');
</script>6
7
Navigate and interact programmatically
<script>
// Navigate to a specific page in the docs tab
window.GitBook('navigateToPage', '/getting-started');
// Switch to the assistant tab
window.GitBook('navigateToAssistant');
// Post a message to the chat
window.GitBook('postUserMessage', 'How do I get started?');
// Clear chat history
window.GitBook('clearChat');
</script>8
Load dynamically (optional)
<script>
function loadGitBookEmbed() {
var script = document.createElement("script");
script.src = "https://docs.company.com/~gitbook/embed/script.js";
script.async = true;
script.onload = function () {
window.GitBook('init', { siteURL: 'https://docs.company.com' });
window.GitBook("show");
};
document.head.appendChild(script);
}
// Load when ready
loadGitBookEmbed();
</script>API Reference
Initialization
Widget Control
Navigation
Chat
Configuration
Configuration Options
tabs
tabsactions
actionsgreeting
greetingsuggestions
suggestionstools
toolsbutton
buttonvisitor (Authenticated Access)
visitor (Authenticated Access)Common pitfalls
Last updated
Was this helpful?