Skip to content

Chat widget

The chat widget is a chat bubble in the corner of your website. A visitor opens it and talks to your tkana assistant, with the same knowledge and skills it uses on WhatsApp.

In the tkana portal, open Channels, then Install on your website on the Website widget card. The Install tab shows your code with a Copy code button. It looks like this, with your own widget id in place of <your-widget-id>:

<script>
(function() {
const script = document.createElement('script');
script.src = 'https://dev-my.tkana.sa/js/widget.js?id=<your-widget-id>';
script.onload = function() {
tkanaChatWidget.init();
};
document.body.appendChild(script);
})();
</script>

If the Install tab says the widget is not set up yet, your business has no widget id. Contact tkana support to set it up.

  1. Copy the code from the Install tab.

  2. Paste it just before the closing </body> tag, on every page where the chat should appear. A site builder has a custom code section for this.

  3. Publish your site. The chat bubble appears on each page that has the code.

Platform Where
Salla Open your store’s design settings and paste it in the custom code box that adds code to every page.
WordPress Install a header and footer code plugin, such as WPCode, and paste it in the footer box.
Shopify Go to Online Store, Themes, Edit code. Open theme.liquid and paste it just before </body>.
Wix Go to Settings, Custom code, Add custom code. Choose All pages and place it at Body - end. Wix allows custom code only on a site with a connected domain.
Plain HTML Paste it just before </body> on every page, or once in the layout file your pages share.

The widget reads its options from window.tkanaChatWidget.config. Set them in a script above your widget code. An option you set there wins over your business’s settings in tkana, so you can change the widget on your site without changing anything in tkana.

<script>
window.tkanaChatWidget = {
config: {
openOnLoad: true,
greetingMessage: {
en: "Hi! How can we help?",
ar: "أهلاً! كيف نقدر نساعدك؟",
},
},
};
</script>
<!-- your widget code goes here -->

Put every option in this one config object. A second window.tkanaChatWidget = ... line replaces the first, and its options are lost.

Option Type Default What it does
greetingMessage string, or { en, ar } your business’s greeting The first message a visitor sees in an empty chat. With { en, ar }, the widget follows your page’s lang, and uses Arabic when it cannot tell.
openOnLoad boolean false Opens the chat when the page loads.
closeOnOutsideClick boolean true Closes the chat when the visitor clicks outside it.
widgetTitle string your assistant’s name The name in the bubble’s label for screen readers, and in the header when your business has no name set.
agentName string your assistant’s name The name shown beside each reply.
branding { primaryColor, secondaryColor } your business’s colors The widget’s colors, as hex values such as "#7d0fc4". Set one or both.
disableErrorAlert boolean false Stops the browser alert the widget shows when a message cannot be sent.
user { firstName, lastName, email } none Details about a visitor who is signed in to your site. They are sent with the chat, so your team sees who wrote.

url, id and threadId are set by tkana. Do not change them: the widget then talks to the wrong place, or loses the visitor’s conversation.

The bubble always shows. To open the chat from a button of your own as well, add the data-tkana-chat-widget-button attribute to it:

<button data-tkana-chat-widget-button>Chat with us</button>

The widget connects the first button on the page with this attribute when it starts. For a button added to the page later, call tkanaChatWidget.init() after adding it, or call open() from the button yourself.

Once the widget has loaded, window.tkanaChatWidget has two functions:

tkanaChatWidget.open();
tkanaChatWidget.close();

Use them from a link, after a form is sent, or from any code of your own.

The widget starts once, when the page loads. If your app clears the page on a route change and the bubble disappears with it, start the widget again after the change:

tkanaChatWidget.init();

A call while the bubble is still on the page starts nothing new. It only connects your own button, which helps when the route change drew a new one.