Skip to content

Install the chat on your website

You add the chat to your site by pasting code snippets. The look of the chat is set in the admin, so you paste the snippets once.

You need a chat bot with an Amio Chat channel. See Webchat.

  1. Open Bots and select your bot, then the Amio Chat channel.
  2. Check the theme and texts, then select Deploy chat.
  3. The Install the chat on your site dialog opens. Use the JavaScript or Google Tag Manager tab and select Copy.

The snippets already contain your channel ID. The same dialog appears at the end of the onboarding flow.

The Install the chat on your site dialog with the JavaScript tab

Add the chat on every page where it should appear. Put the first snippet before the closing </head> tag and the second before the closing </body> tag.

Head:

<script src="https://chat-widget.static-amio.com/static/amio-webchat-loader.min.js" type="text/javascript"></script>

Body:

<script type="text/javascript">
window.amioWebchat.init({
channelId: 'YOUR_CHANNEL_ID'
})
</script>

Use one tag instead of two snippets. In Google Tag Manager create a Custom HTML tag, paste the code below and trigger it on the pages where the chat should appear.

<script>
(function(d, s, id) {
if (d.getElementById(id)) return;
var js = d.createElement(s);
js.async = true;
js.src = "https://chat-widget.static-amio.com/static/amio-webchat-loader.min.js";
js.id = id;
js.onload = function () {
window.amioWebchat.init({
channelId: 'YOUR_CHANNEL_ID'
});
};
d.head.appendChild(js);
}) (document, 'script', 'amio-webchat');
</script>

If your website uses a Content Security Policy (CSP), allow https://chat-widget.static-amio.com in script-src for the loader. Allow https://chat.amio.io and https://chat-widget.static-amio.com in frame-src for the chat iframe; chat.amio.io is the iframe origin used by production chat and the static host is used by the current loader deployment. Older policies may use child-src instead of frame-src. The JavaScript snippet also contains an inline init call; authorize that snippet with your site’s nonce or hash policy.

The loader adds a <style> element and inline styles to your page when it mounts the chat. A policy that blocks inline styles can prevent the chat from displaying correctly. Test your style-src, style-src-elem, and style-src-attr rules with the chat open before enforcing them. The chat iframe has its own origin, so its connection to https://chat.amio.io and its font and image requests normally do not need to be added to your page’s connect-src, font-src, or img-src. A custom theme can load fonts or images from additional hosts inside the iframe.

If you enable showVoice and restrict microphone access with Permissions-Policy, allow microphone access for the chat iframe’s origin. Test the browser permission prompt after changing the policy.

Your chat theme and text settings are applied from the admin. When you save and deploy a change, it reaches your site automatically. You do not need to update the snippet when you edit a theme.

You can pass more options to init next to channelId. These are read by the loader script.

Option What it does
startOpened Opens the chat when the page loads (true).
lang Language code of the chat window, for example 'cs' or 'de'. Without it, the language set for the channel is used, and 'en' if none is set.
hideLauncher 'never' (default) always shows the launcher. 'chatOpen' hides it while the chat is open. 'always' never shows it.
hideCloseButton, hideHeader Hide the close button or the header.
forceFullScreen Shows the chat in full screen.
chatWindowPosition Set to 'left' to open the wide chat window on the left.
wideButton Uses a wide launcher button.
container Mounts the chat inside a page element instead of floating. Give the element an explicit height.
externalContactId Your own ID for the visitor.
storageType 'local' (default) keeps the session in the browser’s localStorage, 'session' in sessionStorage.
theme Name of a built-in colour theme: 'red', 'green' or 'blue' (default). The theme you deploy from the admin is applied on top.
logoUrl, launcherImageUrl URL of the logo in the header and of the image on the launcher.
themeOverride, langOverride Objects that change theme colours or chat texts for this page only. See below.
zIndex, iframeOffsetX, iframeOffsetY Position and stacking of the floating chat.
showVoice, disablePopUpMessages, disableAmioLink Turn voice, pop-up messages or the Amio link on or off.

themeOverride is merged over the theme from the admin, so you only pass the values you want to change. langOverride does the same for the chat texts of the selected lang.

Use text values in langOverride. The header’s welcome text also supports <strong>, <b>, <em>, <i>, <span> and <br> for simple formatting. Other HTML, attributes, images and SVG are removed from that value.

window.amioWebchat.init({
channelId: 'YOUR_CHANNEL_ID',
themeOverride: { header: { bg: '#222222', text: '#ffffff' } },
langOverride: { welcome: 'Hi, how can we help?', buttonTitle: 'Ask us' }
})

Theme sections are header, launcher, messageBubble, messageList, sentMessage, receivedMessage, userInput, statusInfo and font. Colours are CSS colour values and sizes are CSS lengths. Set fontStylesheetUrl alongside font to load a custom web font stylesheet; use an absolute HTTPS URL to a CSS stylesheet that declares the font with @font-face.

window.amioWebchat.init({
channelId: 'YOUR_CHANNEL_ID',
themeOverride: {
font: 'Brand Sans, Arial, sans-serif',
fontStylesheetUrl: 'https://cdn.example.com/brand-fonts.css'
}
})

The stylesheet must include the font weights and styles you use, and its host must allow the chat iframe to load the stylesheet and font files. Fonts loaded only by your website are not available inside the chat iframe. For details, see Install the chat on your website.

Set themeOverride.header.showRestartConversationButton to true to show a refresh button in the chat header. A visitor can click it to start a new conversation. Set it to false to hide the button for that page.

Text keys are interface.* (for example writeMessage, send, attachFile, chatOffline), error.* (for example messageSend), welcome and buttonTitle. English defaults are 'Write a message...', 'Send' and 'Need help?'.

After init, your page can open the chat, send messages for the visitor and listen to chat events for your analytics: see Control the chat from your page. To build your own chat window instead, see the Chat SDK reference.

  1. Open a page where you added the snippets, in a new private window.
  2. Look for the chat launcher button in the bottom corner.
  3. Open the chat and send a message. The bot should answer.
  4. If you changed the theme, deploy again and reload the page to see the change.