Banner Widget
The Banner widget adds a rounded banner to your page that shows short messages, such as Do you offer free returns?, with an optional button on the right. With more than one message, it rotates through them: the current message slides up and out of view as the next one slides in from below. When a customer clicks the banner, the Genius Chat Widget opens with the message that's showing as the customer's first message, so your flow can pick up the conversation.
By default the banner matches your page: it uses your page's font and text colour, with a light tint of the text colour as its background.
Prerequisites
- Your DigitalGenius widget ID.
- Your region:
euorus. - The Genius Chat Widget on the same page. The banner opens the chat to send its message. See Integrating Genius Chat Widget.
- A flow that responds to conversations started from the banner. See Conversation starter.
- Access to edit the HTML of the page the banner is displayed on.
Installation
Add an empty element where the banner should appear:
<div id="dg-banner"></div>Then 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: 'banner',
targetDOMNode: '#dg-banner',
config: {
lang: {
texts: [
'**Carbon plate on trails?** Is it stable on rocky descents?',
'**Between sizes?** Does it run true to size?',
'**Muddy routes?** How does it grip on wet rock?',
],
},
},
},
],
};
</script>
<script src="https://chat.digitalgenius.com/init-sdk.js"></script>The banner fills the width of its container.
Configuration
The following properties are set on each entry in components.
| Property | Type | Required | Description |
|---|---|---|---|
widgetId | string | Yes | Your DigitalGenius widget ID. |
env | string | Yes | Your region: 'eu', 'us', or 'dev.us'. |
type | string | Yes | Must be 'banner'. |
targetDOMNode | string | Yes | A CSS selector for the element the banner is shown in. |
config.lang.texts | string[] | Yes | The messages shown in the banner. With more than one, the banner rotates through them. Wrap words in double asterisks to make them bold, for example '**Between sizes?** Does it run true to size?'. If it's empty, the banner isn't shown and a warning is logged to the browser console. |
config.textInterval | number | No | How long each message is shown for, in milliseconds. Defaults to 7000. |
config.showButton | boolean | No | Whether to show the button on the right. Defaults to true. |
config.lang | object | No | Overrides the widget's text. See Customising text. |
config.style | object | No | Overrides the banner's colours and shape. See Styling. |
Localisation
The button is labelled in British English by default. To change the language, set locale in your configuration:
window.DG_SDK_CONFIG = {
locale: 'fr-FR',
components: [
// ...
],
};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.
lang.texts isn't translated: write your messages in the language of the page.
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: {
lang: {
texts: ['Do you offer free returns?', 'How long does delivery take?'],
buttonLabel: 'Chat now',
},
},| Property | Default (en-GB) | Location |
|---|---|---|
texts | None | The messages shown in the banner, and sent as the customer's first message. |
Bold text
Wrap any part of a message in double asterisks to show it in bold. The rest of the message keeps the normal weight:
texts: [
'**Between sizes?** Does it run true to size?',
],The asterisks are removed from the message sent to the chat, so the customer's first message is Between sizes? Does it run true to size?. An asterisk without a matching pair is shown as it is.
| buttonLabel | Ask AI | The button on the right of the banner. |
When the customer clicks the banner, the message that's showing is sent as their first message. Your flow doesn't need to recognise this wording. The conversation opens with a conversation_starter chat event with source set to banner and action set to question, so branch on those instead:
{
"from": "customer",
"type": "chat_event",
"payload": {
"name": "conversation_starter",
"source": "banner",
"action": "question",
"text": "Between sizes? Does it run true to size?",
"data": { "url": "https://www.example.com/products/trail-runner-2" }
}
}Behaviour
- Clicking: the whole banner, including the button, opens the chat widget and sends the message that's showing as the customer's first message. While the bot is replying, the banner is disabled. If it's clicked before the Genius Chat Widget has loaded, nothing happens and a warning is logged to the browser console.
- Rotating messages: each message is shown for
textIntervalmilliseconds. Rotation pauses while the customer hovers over the banner or it has keyboard focus, so the message doesn't change just before they click. - Height: the banner is as tall as its longest message, so it doesn't change height as the messages rotate.
- Reduced motion: if a customer's device is set to reduce motion, the messages switch over without sliding.
Styling
The banner renders inside a shadow DOM. It takes its font and text colour from the element it's shown in, but other styles on your page don't affect it. Without any style config:
- the background is a light tint of the text colour.
- the button swaps your page's colours: its background is the text colour and its text is the page's background colour.
- the corners are rounded.
To change these, use config.style:
| Property | Type | Description |
|---|---|---|
backgroundColor | string | The banner's background colour. |
gradientColors | string[] | Two or three colours for a gradient background, spread evenly across the banner. Takes priority over backgroundColor. With fewer than two or more than three colours, the gradient isn't shown and a warning is logged to the browser console. |
gradientAngle | string | The direction of the gradient, as a CSS angle. Defaults to '90deg', left to right. |
textColor | string | The colour of the messages. |
buttonBackgroundColor | string | The button's background colour. Defaults to textColor, or the page's text colour. |
buttonTextColor | string | The button's text colour. Defaults to the first gradient colour, backgroundColor, or the page's background colour. |
radius | string | The corner radius of the banner, as any CSS length. Defaults to 12px. Use '0' for square corners or '999px' for a pill. |
buttonRadius | string | The corner radius of the button. Defaults to 8px. |
border | string | A CSS border for the banner, for example '1px solid #e5e5e5'. None by default. |
maxWidth | string | The maximum width of the banner. Defaults to the full width of its container. |
For example, a pill shaped banner with a three colour gradient:
config: {
lang: {
texts: ['Do you offer free returns?', 'How long does delivery take?'],
},
style: {
gradientColors: ['#4f2bd8', '#9b5cf6', '#f472b6'],
gradientAngle: '90deg',
textColor: '#ffffff',
buttonBackgroundColor: '#ffffff',
radius: '999px',
buttonRadius: '999px',
},
},Troubleshooting
If the banner does not appear, check that type is set to 'banner', targetDOMNode matches an element on the page, lang.texts has at least one message, widgetId is correct and env matches your region. The browser console shows a warning or error for each of these.
If clicking the banner 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.
Updated about 2 hours ago
