AI Tab Widget

The AI Tab widget adds a small tab with a sparkle icon to the right-hand edge of your pages. When a customer clicks it, the Genius Chat Widget opens with a message, such as I'd like to talk about Trail Runner 2, so your flow can pick up the conversation.

It's a quieter alternative to the Help Me Choose widget: a white tab with no text that slides out a little when a customer hovers over it.

Prerequisites

  • Your DigitalGenius widget ID.
  • Your region: eu or us.
  • The Genius Chat Widget on the same page. The widget opens the chat to send its message. See Integrating Genius Chat Widget.
  • A flow that responds to conversations started from the widget. See Conversation starter.
  • Access to edit the HTML of the page the widget is displayed on.

Installation

Add the following code to your page, after the Genius Chat Widget. Replace your-widget-id with your widget ID, and update env to match your region if required.

<script>
  window.DG_SDK_CONFIG = {
    components: [
      {
        widgetId: 'your-widget-id',
        env: 'eu',
        type: 'aiTab',
      },
    ],
  };
</script>
<script src="https://chat.digitalgenius.com/init-sdk.js"></script>

The tab is docked to the right-hand edge of the page, so it doesn't need a container. targetDOMNode isn't used.

Configuration

The following properties are set on each entry in components.

PropertyTypeRequiredDescription
widgetIdstringYesYour DigitalGenius widget ID.
envstringYesYour region: 'eu', 'us', or 'dev.us'.
typestringYesMust be 'aiTab'.
config.productNamestringNoThe product name, or a CSS selector for the element containing it when retrievalMethod is 'selector'. Added to the end of lang.message. If it isn't set, the tab sends lang.message on its own.
config.retrievalMethod'config' | 'selector'NoHow the product name is provided. Defaults to 'config'. See Providing the product name.
config.productNameExcludestringNoOnly when retrievalMethod is 'selector'. A CSS selector for elements inside the productName element whose text is left out, such as screen reader only text.
config.langobjectNoOverrides the widget's text. See Customising text.
config.style.backgroundColorstringNoThe tab background colour. Defaults to white.
config.style.textColorstringNoThe icon colour. Defaults to #222222.
config.style.topstringNoThe vertical position of the centre of the tab, as any CSS length, for example '40%' or '320px'. Defaults to '50%', the middle of the screen.
config.style.radiusstringNoThe corner radius of the tab, as any CSS length, for example '0' or '12px'. Defaults to 32px.

Providing the product name

On product pages, set productName so the conversation opens about the product the customer is viewing. retrievalMethod controls where it comes from.

With retrievalMethod set to 'config' (the default), productName is the product name itself. Use this when your page template can output the product name into the script:

config: {
  // replace with the product name output by your page template
  productName: 'Trail Runner 2',
},

With retrievalMethod set to 'selector', productName is a CSS selector for an element already on the page, and the widget reads the product name from it:

config: {
  retrievalMethod: 'selector',
  productName: 'h1.product-name',
  // optional, leaves out screen reader only text inside the element
  productNameExclude: '.accessibility-hidden',
},

The product name is read when the customer clicks the tab, so elements rendered after the widget loads, or changed when a customer picks a different variant, are supported. For form fields (input, select and textarea) the field's value is used; for other elements, their text content is used, with line breaks and repeated spaces collapsed into single spaces.

Localisation

The widget is displayed in British English by default. To change the language, set locale in your configuration:

window.DG_SDK_CONFIG = {
  locale: 'fr-FR',
  components: [
    {
      widgetId: 'your-widget-id',
      env: 'eu',
      type: 'aiTab',
    },
  ],
};

The following locales are supported: cs-CZ, da-DK, de-DE, en-GB, en-LU, en-US, es-ES, et-EE, fi-FI, fr-FR, it-IT, ja-JP, ko-KR, lt-LT, lv-LV, nl-NL, no-NO, pl-PL, pt-PT, ro-RO, sk-SK, sv-SE, zh-CN and zh-TW. Unsupported locales fall back to British English.

Customising text

The text listed below can be customised using a lang object in the app's config. Only the properties you specify are overridden; all other text uses the default wording for the selected locale.

config: {
  productName: 'Trail Runner 2',
  lang: {
    buttonLabel: 'Chat with our assistant',
    message: 'Can you tell me more about the',
  },
},
PropertyDefault (en-GB)Location
buttonLabelAsk AIThe tab's tooltip, and the label read out by screen readers.
messageI'd like to talk aboutThe message sent to the chat. When a product name is set, it's added after it, separated by a space.

With the configuration above, the customer's first message is Can you tell me more about the Trail Runner 2. Your flow doesn't need to recognise this wording. The conversation opens with a conversation_starter chat event with source set to ai_tab and action set to product_enquiry, and the product name in data.productName when one is set, so branch on those instead:

{
  "from": "customer",
  "type": "chat_event",
  "payload": {
    "name": "conversation_starter",
    "source": "ai_tab",
    "action": "product_enquiry",
    "text": "Can you tell me more about the Trail Runner 2",
    "data": { "productName": "Trail Runner 2" }
  }
}

Behaviour

  • Loading: the tab slides in from the right-hand edge of the page as soon as the widget loads. If it's clicked before the Genius Chat Widget has loaded, nothing happens and a warning is logged to the browser console.
  • Hovering: the tab slides out a little further and the sparkle tilts. The same happens when the tab has keyboard focus.
  • Clicking the tab: opens the chat widget and sends the message as the customer's first message. While the bot is replying, the tab is disabled.
  • Position: the tab stays in place as the customer scrolls, and appears behind the chat widget when it's open.
  • Reduced motion: if a customer's device is set to reduce motion, the tab doesn't slide in or animate on hover.

Styling

The widget renders inside a shadow DOM, so the styles on your page don't affect it. To change the colours, position or corner radius, use config.style:

config: {
  style: {
    backgroundColor: '#1f3d2b',
    textColor: '#ffffff',
    top: '40%',
    radius: '12px',
  },
},

Troubleshooting

If the tab does not appear, check that type is set to 'aiTab', widgetId is correct and env matches your region.

If clicking the tab does nothing, check that the Genius Chat Widget is on the page and loads without errors. A warning is logged to the browser console when it isn't available.

If the message doesn't include the product name, check the browser console. When retrievalMethod is 'selector', an error is logged if the selector doesn't match an element on the page.


Did this page help you?