

# Embed a workspace

You can embed a workspace that contains a step-by-step guide on your website. Your customers can complete the same guided workflows that your agents and business users complete in their workspaces, such as filing a claim or requesting a refund. Customers complete the guide on your website without signing in to Connect Customer.

To embed a workspace, you create a workspace for customers, add a step-by-step guide to it, and then generate a script that you add to your website.

## Prerequisites
<a name="embed-workspaces-customer-website-prerequisites"></a>
+ An account assigned to a security profile that has the **Users and permissions** - **Workspaces - Create**, **Workspaces - Edit**, and **Workspaces - Edit visibility** permissions. For more information, see [List of security profile permissions in Connect Customer](security-profile-list.md).
+ Customer Profiles enabled for your instance. For more information, see [Enable Customer Profiles for your Connect Customer instance](enable-customer-profiles.md).
+ An instance that uses the `https://{{your-instance-alias}}.my.connect.aws/` domain. You can't embed a workspace from an instance that uses the legacy `awsapps.com` domain. For more information, see [Update your Connect Customer domain](update-your-connect-domain.md).
+ A step-by-step guide. For more information, see [Set up step-by-step guides in Connect Customer](step-by-step-guided-experiences.md).

## Step 1: Add your website domain to approved origins
<a name="embed-workspaces-customer-website-approved-origins"></a>

The domain of the website where you embed the workspace must be an approved origin for your instance. Otherwise, the browser doesn't display the embedded workspace.

**To add your website domain to approved origins**

1. Open the Connect Customer console at [https://console.aws.amazon.com/connect/](https://console.aws.amazon.com/connect/).

1. Choose the instance alias.

1. In the navigation pane, choose **Approved origins**.

1. Choose **Add origin**, enter the URL of the website where you embed the workspace, and then choose **Add**.

For more information, see [Use an allowlist for integrated applications in Connect Customer](app-integration.md).

## Step 2: Create a workspace for customers
<a name="embed-workspaces-customer-website-create"></a>

**To create a workspace for customers**

1. Log in to the Connect Customer admin website at https://{{instance name}}.my.connect.aws/.

1. On the navigation menu, choose **UI Management**, **Workspaces**.

1. Choose **Create workspace**.

1. For **Who is this workspace for?**, choose **Customers**. You can't change this setting after you create the workspace.

1. Enter a name for the workspace.

1. (Optional) Enter a description and a title.

1. Choose **Save**. The workspace details page opens, and the workspace visibility is **Visible to public**.

A workspace for customers is always visible to the public. Anyone who loads the script on a website that's an approved origin for your instance can open the guide.

For general information about workspaces, see [Set up workspaces](amazon-connect-workspaces.md).

## Step 3: Add a step-by-step guide
<a name="embed-workspaces-customer-website-add-guide"></a>

**To add a step-by-step guide**

1. On the workspace details page, in the **Guide** section, choose **Add guide**.

1. For **Contact flow**, choose the flow for your guide. If you don't have permission to browse flows, enter the flow ID.

1. (Optional) For **Container height**, enter the height of the guide on your website, in pixels. The default is 480 pixels.

1. (Optional) For **Completion message**, enter the text that appears when a customer completes the guide. The default is "You're all set."

1. (Optional) For **Error message**, enter the text that appears when the guide encounters an error. The default is "We encountered an error. Reload the page and try again."

1. Choose **Save**.

The **Guide** section shows the flow, container height, completion message, and error message. To change these values, choose **Edit**. To remove the guide from the workspace, choose **Remove**.

To enter the guide settings as JSON instead, turn off **Use form mode**. Use JSON mode to set a container height in a unit other than pixels, such as `vh`, `rem`, `em`, or `%`.

To fill in the default values, choose **Generate**. The input data must match the schema that appears next to the editor. The following example shows input data for a guide.

```json
{
  "ContactFlowId": "{{contact-flow-id}}",
  "EndScreenMessage": "You're all set.",
  "ErrorScreenMessage": "We encountered an error. Reload the page and try again.",
  "Style": {
    "--connect-application-height": "480px"
  }
}
```

## Step 4: Generate the embed script
<a name="embed-workspaces-customer-website-generate-script"></a>

**To generate the script**

1. On the workspace details page, in the **Guide** section, choose **Generate embeddable script**.

1. On the webpage where you want the workspace to appear, add an empty HTML element with an `id` attribute. If the page already has an element for the workspace, skip this step.

   ```html
   <div id="{{my-workspace-container}}"></div>
   ```

   In the next step, for **Container ID**, enter this value, `{{my-workspace-container}}`. The element must already exist on the page before the generated script runs, and its `id` must be unique on the page.

1. On the **Generate embeddable script** page, enter the following information:
   + **Container ID**: Enter the ID of the HTML element on your webpage where the workspace appears. For more information, see the previous step.
   + **Language**: Choose the language of the embedded workspace. The default is English.
   + **Theme mode**: Choose **Automatic**, **Light**, or **Dark**. The default is **Automatic**.
   + (Optional) **Start view**: Enter the HTML for a view that appears when the workspace loads. The guide loads only after a customer chooses a start button. A start view improves your website's performance and avoids unnecessary costs. We recommend that you use a start view. You can edit the HTML to customize the start view, but it must include a button. To discard your changes to the HTML, choose **Reset script**.

1. Choose **Update script**.

1. Choose **Copy script**.

The generated script looks similar to the following example.

```html
<script type="text/javascript">
  (function(w, d, x, id){
    s=d.createElement('script');
    s.src='https://{{instance-name}}.my.connect.aws/connectwidget/static/amazon-connect-end-customer-workspace-client.js';
    s.async=1;
    s.id=id;
    d.getElementsByTagName('head')[0].appendChild(s);
    w[x] = w[x] || function() { (w[x].ac = w[x].ac || []).push(arguments) };
  })(window, document, 'amazon_connect_workspace', 'amazon-connect-workspace-widget');
  amazon_connect_workspace('instanceUrl', 'https://{{instance-name}}.my.connect.aws');
  amazon_connect_workspace('workspaceId', '{{workspace-id}}');
  amazon_connect_workspace('styles', {
    openWorkspace: { color: '#fff', backgroundColor: '#003A70' },
    closeWorkspace: { color: '#fff', backgroundColor: '#003A70' }
  });
  amazon_connect_workspace('pageSlug', '{{page-slug}}');
  amazon_connect_workspace('getOtc', {{get-one-time-code-function}});
  amazon_connect_workspace('containerId', '{{container-id}}');
  amazon_connect_workspace('locale', '{{locale}}');
  amazon_connect_workspace('theme', '{{theme-mode}}');
  amazon_connect_workspace('startScreen', `
    {{start-view-html}}
  `);
</script>
```

The value of `getOtc` is a function that you write. For more information, see [Step 6: Authenticate customers in production](#embed-workspaces-customer-website-production-auth).

## Step 5: Test the embedded workspace
<a name="embed-workspaces-customer-website-test"></a>

Test an embedded workspace before you make it available to customers. To test as a customer, your security profile needs the **Workspaces - Test** permission. For more information, see [List of security profile permissions in Connect Customer](security-profile-list.md).

**To test the embedded workspace**

1. On the **Generate embeddable script** page, choose **Test as a customer**.

1. For **Security profiles**, choose the security profiles for the test session. You can choose up to 10.

1. For **Customer profile**, choose the customer profile to test as.

1. Choose **Generate code and update script**. The script now includes a one-time code.

1. Choose **Copy script**, and then add the script to a webpage on an approved origin.

The one-time code works for a single session and expires 5 minutes after it's generated. To test again, generate a new code.

## Step 6: Authenticate customers in production
<a name="embed-workspaces-customer-website-production-auth"></a>

In production, your website gets a one-time code from your backend for each customer session. Your backend calls the [CreateAuthCode](https://docs.aws.amazon.com/connect/latest/APIReference/API_CreateAuthCode.html) API with the customer's profile ID, your Customer Profiles domain name, and the security profiles for the session. A one-time code can include up to 10 security profiles. At least one of these security profiles must have the **Workspaces - Embed** permission. For more information, see [List of security profile permissions in Connect Customer](security-profile-list.md).

Each embedded session is authenticated as the customer profile that you specify, not as a Connect Customer user. To authenticate these sessions, Customer Profiles must be enabled for your instance.

## Service quotas for embedded workspaces
<a name="embed-workspaces-customer-website-quotas"></a>

An embedded workspace uses the default service quotas of the apps that it runs. For example, step-by-step guides run as chat contacts, so they use the chat quotas. For more information, see [Enable step-by-step guides in Connect Customer](enable-guided-experiences-sg.md) and [Connect Customer service quotas](amazon-connect-service-limits.md).

## Troubleshoot an embedded workspace
<a name="embed-workspaces-customer-website-troubleshoot"></a>


| Issue | Likely cause | Fix | 
| --- | --- | --- | 
| The embedded workspace is blank. | The domain of your website isn't an approved origin for your instance. The browser blocks the embedded workspace even though the request succeeds. | Add the domain to **Approved origins**. For more information, see [Step 1: Add your website domain to approved origins](#embed-workspaces-customer-website-approved-origins). | 
| The embedded workspace shows an error. | The guide was removed from the workspace. | Add the guide again, and then generate a new script. | 
| The workspace loads, but the language or theme is wrong. | The `locale` or `theme` value in the script isn't supported. The script sets these values when the workspace loads. | On the **Generate embeddable script** page, choose a **Language** and **Theme mode**, and then choose **Update script**. Copy the updated script to your website. | 