Start a conversation with your customers by adding a Business Chat button to your website.
Overview
To use the Business Chat button on your website, add the JavaScript library in your site's HTML. The library links to a file that contains business logic and assets for the button. You can customize layout, colors, sizes and fonts. For more information on design guidelines, see Business Chat Entry Points Guide.
Add the JavaScript Library to the Page Headers
Wherever you intend to use a Business Chat button, you'll need to add the JavaScript
library to a script
tag in the page
header.
You can place the script
tag in one of two
places:
-
Within the
<head>...</head>
element of the page. -
Following the
</body>
element at the end of the page.
Use the following script tag for calling the JavaScript library:
<script src="https://static.cdn-apple.com/businesschat/start-chat-button/2/index.js"></script>
Add a Container for the Business Chat Button
With the JavaScript library in place, the next step is to include a <div>
tag where you want the Business Chat button to appear on your web page.
The <div>
tag must include the
following:
-
A
class
attribute with the value "apple-business-chat-banner-container
", "apple-business-chat-phone-container
", or "apple-business-chat-message-container
". (See below for details of each class.) -
A
data-apple-business-id
attribute with the business ID you received when you registered your company with Business Chat.
Banner mode
In addition to the above-mentioned attribute and class, Banner mode button layout also
requires that a data-apple-banner-cta
attribute with a
Call-to-Action (CTA) or a data-apple-banner-context
attribute
message to engage customers, or both be present on the container div
.
For example, here is the base structure of what your <div>
tag for the Business Chat
button should look like for the message and phone icons:
Icons mode
In this mode, the button can appear as a Phone or a Message icon depending on which
class name value we add. To display a Phone icon, class
"apple-business-chat-phone-container
"
should be added and data-apple-business-phone
attribute should be set:
In this case, data-apple-business-id
is not required since the icon's sole
function is to start a call.
To display a Message icon, class "apple-business-chat-message-container
"
should be added, as well as
the data-apple-icon-title
attribute:
Handling unsupported devices
Business Chat is supported on macOS (from version 10.13.4) and iOS (from version 11.3) devices, which means that the Message icon (in either Banner or Icon modes) will be shown only on supported devices.
In Banner mode, if the data-apple-business-phone
attribute is not populated, the entire banner will be hidden on unsupported devices.
isSupported
function
To allow for further customization, Business Chat JS library exports a function that can be used to check if Business Chat is supported.
window.appleBusinessChat.isSupported()
Fallback child element
Another way to handle unsupported devices is to add a child
div
with a class name
"apple-business-chat-fallback-container
" inside the
"apple-business-chat-banner-container
" element.
Custom content inside the fallback container will be shown if Business Chat is not supported.
Single Page Application (SPA) support
The script that creates BC Banners/Icons runs only once, on page load. This means that if you dynamically generate content which should be transformed into BC Banners/Icons, the transformation would not happen automatically.
For cases like the one mentioned (usually the case in SPAs), Business Chat JS library exports a function that can be used to initialize BC components manually:
window.appleBusinessChat.refresh()
Data attributes
Configuration for the button passes through as data-*
attributes for the
<div>
tag.
The following data attributes are supported:
-
data-apple-banner-background-color
-
The banner’s background color. You can use red, green, blue (RGB) or RGB-alpha (RGBA) parameters, or a hexadecimal color code to set the color. The default value in RGB is
rgb(255,255,255)
, and the hex color code is#FFFFFF
. (Optional) -
data-apple-banner-cta
-
Call-to-Action (CTA) text for the icons. This is required if you don’t provide context.
-
data-apple-banner-context
-
Lets customers know what they can expect when tapping the icon. This is required if you don’t provide a CTA.
-
data-apple-banner-rounded-corners
-
A boolean value that allows you to have rounded or square corners (value:
false
). If not set then the banner defaults totrue
, or rounded corners. (Optional) -
data-apple-banner-font-family
-
A string value allowing you to choose the font of the context and CTA text. All standard OS fonts are supported. (Optional)
-
data-apple-banner-icon-background-color
-
Color of the phone and message icon's circular background. You can use RGB or RGBA parameters, or a hex color code to set the color. The default value in RGB is
rgb(239,239,244)
, and the hex color code value is#EFEFF4
. (Optional) -
data-apple-banner-icon-color
-
Color of the phone and message icons. You can use RGB or RGBA parameters, or a hex color code to set the color. The default value in RGB is
rgb(0,122,255)
, and the hex color code value is#007AFF
. (Optional) -
data-apple-banner-orientation
-
Identifies the orientation of the container. You can choose either horizontal or vertical. The default is horizontal. (Optional)
-
data-apple-banner-scale
-
A string value that allows you to scale the contents of the banner. The values are between 1 through 2 for scaling, the icons are between 45-90px, and the font is 10 through 20pt. (Optional)
-
data-apple-banner-text-color
-
Color of the context and CTA text on the banner. You can use RGB or RGBA parameters, or a hex color code to set the color. If no color is specified, then the color defaults to
rgb(0, 0, 0)
. (Optional) -
data-apple-business-id
-
Identifies and routes messages to the owner of the business chat ID. Insert your Business Chat ID between the quotes. For example, "
insert your business id here
". (Required) -
data-apple-business-phone
-
The phone number you want customers to call if they cannot use the chat button. If not included, then the phone icon does not display. (Optional)
-
data-apple-business-intent-id
-
The intent for initiating the chat conversation. This can be anything that you specify; for example, "
account statement
" or "track order
". (Optional) -
data-apple-business-group-id
-
The group to receive chat messages based on the message's intent. For example, "
billing department
" or "shipping
". (Optional) -
data-apple-business-body
-
A parameter that prepopulates a message for your customers so all they need to do is tap Send in Messages. For example, "
Order an additional credit card.
". (Optional) -
data-apple-icon-color
-
[Icons mode only] Color of the phone or message icons. You can use RGB or RGBA parameters, or a hex color code to set the color. The default value in RGB is
rgb(0,122,255)
, and the hex color code value is#007AFF
. (Optional) -
data-apple-icon-background-color
-
[Icons mode only] Color of the phone and message icon's circular background. You can use RGB or RGBA parameters, or a hex color code to set the color. The default value in RGB is
rgb(239,239,244)
, and the hex color code value is#EFEFF4
. (Optional) -
data-apple-icon-scale
-
[Icons mode only] Decimal value, 1 through 2, in the range that determines the scale of the icons. The default scale value is 1. (Optional)
-
data-apple-icon-title
-
[Icons mode only] Text displayed as a tooltip on the icon. (Optional)