PAI Chat Widget
The PAI Chat widget embeds a Purchase AI conversation within your product pages. Shoppers can ask a question or select a suggested prompt, and receive tailored guidance and product recommendations in the same panel, without opening a chat window.
To start the conversation in the Genius Chat Widget instead, use the PAI Prompts widget.
Prerequisites
- Your DigitalGenius widget ID.
- Your region:
euorus. - Access to edit the HTML of your product pages.
Installation
Add the following code to your product page, at the position where the widget should appear. Replace your-widget-id with your widget ID, and update env to match your region if required.
<div id="pai-chat"></div>
<script>
window.DG_SDK_CONFIG = {
components: [
{
widgetId: 'your-widget-id',
env: 'eu',
targetDOMNode: '#pai-chat',
type: 'paiChat',
config: {
productName: 'Trail Runner 2',
buttonLabels: [
'What would you recommend?',
'Something for a gift',
'Show me similar products',
],
},
},
],
};
</script>
<script src="https://chat.digitalgenius.com/init-sdk.js"></script>The widget is rendered inside the <div id="pai-chat"></div> container.
Configuration
The following properties are set on each entry in components.
| Property | Type | Required | Description |
|---|---|---|---|
targetDOMNode | string | Yes | A CSS selector for the container the widget is rendered in, for example #pai-chat. |
widgetId | string | Yes | Your DigitalGenius widget ID. |
env | string | Yes | Your region: 'eu', 'us', or 'dev.us'. |
type | string | Yes | Must be 'paiChat'. |
config.productName | string | No | The product the shopper is viewing, or a CSS selector for the element containing its name when retrievalMethod is 'selector'. |
config.retrievalMethod | 'config' | 'selector' | No | How the product name is provided. Defaults to 'config'. See Providing the product. |
config.productNameExclude | string | No | Only 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.buttonLabels | string[] | No | A list of suggested prompts, displayed as buttons. Selecting a prompt submits it as the shopper's question. If omitted, only the text input is displayed. |
config.showChatInput | boolean | No | Controls whether the text input is displayed. Defaults to true. Set to false to limit shoppers to the suggested prompts. |
config.lang | object | No | Overrides the widget's text. See Customising text. |
config.style.maxWidth | string | No | The maximum width of the widget, as any CSS length, for example '28rem'. Defaults to the full width of the container. |
config.style.maxHeight | string | No | The maximum height of the conversation before it scrolls, as any CSS length. Defaults to 20em. |
config.style.radius | string | No | The corner radius of the widget, as any CSS length. Defaults to 12px. |
config.style.panelBackground | string | No | The widget's background colour. Defaults to transparent. |
config.style.userBackground | string | No | The background colour of shopper messages and the send button. Defaults to the inherited text colour. |
config.style.userColor | string | No | The text colour of shopper messages. Defaults to the browser's default background colour (white in light mode). |
config.style.assistantBackground | string | No | The background colour of responses. Defaults to a light tint of the inherited text colour. |
config.style.assistantColor | string | No | The text colour of responses. Defaults to the inherited text colour. |
Providing the product
retrievalMethod controls where the product name comes from.
Example: value in the configuration
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:
<div id="pai-chat"></div>
<script>
window.DG_SDK_CONFIG = {
components: [
{
widgetId: 'your-widget-id',
env: 'eu',
targetDOMNode: '#pai-chat',
type: 'paiChat',
config: {
retrievalMethod: 'config',
// replace with the product name output by your page template
productName: 'Trail Runner 2',
},
},
],
};
</script>
<script src="https://chat.digitalgenius.com/init-sdk.js"></script>Example: value read from the page
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. Use this when the product name is displayed on the page but can't easily be added to the script:
<h1 class="product-title">Trail Runner 2</h1>
<div id="pai-chat"></div>
<script>
window.DG_SDK_CONFIG = {
components: [
{
widgetId: 'your-widget-id',
env: 'eu',
targetDOMNode: '#pai-chat',
type: 'paiChat',
config: {
retrievalMethod: 'selector',
productName: '.product-title',
},
},
],
};
</script>
<script src="https://chat.digitalgenius.com/init-sdk.js"></script>For form fields (input, select and textarea) the field's value is used; for other elements, their text content is used, with surrounding spaces removed.
Leaving out hidden text
Some product name elements contain extra text for screen readers that isn't shown on screen, for example:
<h1 class="product-name">
<span class="accessibility-hidden">details about product:</span>
Pure Linen Polo - Olive
</h1>The widget reads all the text in the element, so set productNameExclude to a CSS selector for the elements inside it to leave out:
config: {
retrievalMethod: 'selector',
productName: 'h1.product-name',
productNameExclude: '.accessibility-hidden',
},The product name read is then Pure Linen Polo - Olive. Line breaks and repeated spaces in the element's text are always collapsed into single spaces.
Shopper experience
On load, the widget displays:
- The heading "Ask about this product".
- A text input for free-form questions.
- Any suggested prompts you have configured.
Once a shopper submits a question, the widget displays the conversation. Responses may include a product carousel, from which shoppers can browse and select one or more products.
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',
targetDOMNode: '#pai-chat',
type: 'paiChat',
},
],
};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.
window.DG_SDK_CONFIG = {
components: [
{
widgetId: 'your-widget-id',
env: 'eu',
targetDOMNode: '#pai-chat',
type: 'paiChat',
config: {
lang: {
title: 'Find the right product',
askAQuestionPlaceholder: 'Tell us what you need',
},
},
},
],
};Visible text
| Property | Default (en-GB) | Location |
|---|---|---|
title | Ask about this product | The widget heading. |
askAQuestionPlaceholder | Ask a question... | The placeholder text in the text input. |
carouselSelectionButtonText | Select | The button on each product card, where the flow does not define its own label. |
carouselMultiSelectButtonText | Confirm your selection | The button used to confirm a multi-product selection. |
For example, to adjust the product carousel buttons to suit your brand's tone of voice:
config: {
lang: {
carouselSelectionButtonText: 'Choose this',
carouselMultiSelectButtonText: 'Show my picks',
},
},Accessibility text
The following text is not displayed visually but is announced by screen readers. If you provide your own translations, we recommend including these properties to ensure an accessible experience.
| Property | Default (en-GB) | Announced |
|---|---|---|
askAQuestion | Ask a question | On the text input. |
send | Send | On the send button. |
promptButtonsLabel | Prompt buttons | On the group of suggested prompts. |
quickRepliesLabel | Suggested replies | On the group of quick reply buttons. |
conversationLabel | Conversation | On the conversation area. |
you | You | Before each shopper message. |
assistant | Assistant | Before each response. |
assistantTyping | Assistant is typing | While a response is being generated. |
carouselPrevious | Go to previous item | On the carousel's previous button. |
carouselNext | Go to next item | On the carousel's next button. |
Styling
By default, the widget inherits your page's font and text colour, and uses a transparent background, so it integrates with your existing design. Sizes are set in em, so the widget scales with your font size.
To change its appearance, use config.style. Only the properties you specify are overridden.
config: {
style: {
accentColor: '#4a3428',
maxWidth: '28rem',
maxHeight: '24em',
radius: '16px',
panelBackground: '#ffffff',
userBackground: '#4a3428',
userColor: '#f4efe6',
assistantBackground: '#f4efe6',
assistantColor: '#4a3428',
},
},Troubleshooting
If the widget does not appear, check that:
- The
<div id="pai-chat"></div>container is on the page and placed before the scripts. targetDOMNodematches the container's id, including the#prefix.typeis set to'paiChat'.widgetIdis correct andenvmatches your region.
When retrievalMethod is 'selector', an error is logged if the selector doesn't match an element on the page.
Updated about 6 hours ago
